[c++ gui programming with qt4] chap8
DESCRIPTION
2D Graphics. Description of 2D graphic operations in Qt4. In this Chapter, you can learn how to handle the graphic scenes, views, and items in the Qt program.TRANSCRIPT
- 1. Ch 8 2D Graphics Author: Tony
2. QPainter
- Point
- drawPoint
3. drawPoints Line
- drawLine
4. drawLines PolyLine
- drawPolyLine
5. QPainter (cont.)
- drawPolygon
6. drawRect 7. drawRoundRect 8. drawEllipse 9. QPainter (cont.)
- drawArc
10. drawChord 11. drawPie 12. QPainter (cont.)
- DrawText
13. DrawPixmap 14. DrawPath 15. Three Main Painter Setting
- pen
- Drawing lines and shape outlines
brush
- Filling geometric shape
font
- Drawing text
16. QPainterPath
- Specify the arbitrary vector shapes
17. Workflow of Painting Path
- Create Painter object and PainterPath object
18. Set render hint 19. Set painter path 20. Set painter setting for Painter object 21. Draw the path 22. Pen Style 23. Cap Style 24. Join Style 25. Brush Style 26. Gradient Fills
- Linear
27. Radial 28. Conical 29. 30. Antialiasing 31. Antialiasing (cont.) 32. Window-Viewport Mechanism
- Make the drawing code independent of the size or resolution of the paint device
33. Convert the logical coordinates into physical coordinates
- painter.setWindow(-50, -50, 100, 100)
34. World Transformation
- Multiple transformation
- Applied in the order in which they are given
How many transformations?
- Translate
35. Scale 36. Rotate 37. Shear (ref. to Affine Transformations) 38. World Transformation (cont.) 39. Reuse the Transformation
- QTransform
40. QTimer Class
- Provide repetitive and single-shot timers
41. How to use it?
- Create
42. Connect its timeout() signal to the slots 43. Callstart() Result
- Emit thetimeout()signal at constant intervals
44. QTimer Class (cont.)
- An example,
45. QDateTime Class
- Provides date and time functions
46. For example,
- date()
47. time() 48. currentDateTime() Use of Gregorian and Julian Calendars 49. Rendering with QImage
- Rely on platform's native paint engine
50. Accuracy is more important than efficiency
- QImage
51. How to paint by Qt's platform-independent graphics engine?
- Step by step
- Create a QPainter to draw on the image
52. Perform the drawing using the QPainter 53. QPainter object (image) -> widget Exception
- Font rendering
54. How to paint by Qt's platform-independent graphics engine? (cont.) Initializes the painter's pen, background, and font 55. Composition Mode
- Default
- CompositionMode_SourceOver
56. Graphics View
- QGraphicsScene
- Provides a surface for managing a large number of 2D graphical items
QGraphicsItem
- The base class for all graphical items in a QGraphicsScene
QGraphicsView
- provides a widget for displaying the contents of a QGraphicsScene
57. Graphics View (cont.) 58.
- QGraphicsScene
- Three layers
- Background, Item, Foreground
QBrushes
- Background, Foreground
59. Grouping Items
- Two ways
- Make an item a child of another item
60. QGraphicsItemGroup 61. QGraphicsView 62. QgraphicsView's Render Engine
- Default
- Qt's build-in 2D paint engine
Optional
- setViewport (OpenGL)
63. Coordinate System
- Viewport
- Inside the QGraphicsView
Scene
- Logical coordinate (positioning top-level items on the scene)
Item
- Specific to each item
64. Coordinate System (cont.)
- In practice, we only care about the scene coordinates and item coordinates
65. QGraphicsItem
- Every item has an(x,y)position and azvalue
66. Q_DECLARE_TR_FUNCTIONS
- A class is not a QObject subclass
67. Want to use thetrfunction 68. itemChange
- ItemChange : Qvariant
- GraphicsItemChange change
69. const QVariant &value A handler for updating the item's change 70. Callupdate()to schedule a repaint 71. prepareGeometrychange()
- Call it before doing anything will affect the item's bounding rectangle
72. Ex:setText() 73. ItemChange (cont.) 74. QGraphicsItem::boundingRect()
- boundingRect () : const QrectF
- pure virtual
Called by QGraphicsView 75. whether the item needs to be re-drawn 76. QGraphicsItem::shape ()
- shape() : QPainterPath
- virtual
Called by QGraphicsView 77. Used to
- Collision detection
78. Hit test 79. Select the Multiple Items
- Use thectrl+click
80. QGraphicsView::RubberBandDrag
- Dragging a rubber band over all items you want to select
81. Z-order of Views
- sendToBack()
82. bringToFront() 83. Change the Color
- Qt's build-in dialog
- QColorDialog::getcolor()
When the link is changed, callupdate() 84. QColor::name()
- Get the color string in#RRGGBBformat
85. Zoom Factor
- QstyleOptionGraphicsItem class
- A floating-point value represents as zoom factor
86. Describe the parameters needed to draw a QGraphicsItem 87. Animation Effect
- QGraphicsItemAnimations
88. QTimeLine
- Reimplement theQObject::timeEvent()
89. Printing
- QPrinter::setPrintProgram()
90. PDF format
- setOutputFormat(QPrinter::PdfFormat)
Print the entire scene
- QGraphicsView::render()
Multiple pages printing
- Paint one page
91. callnewPage()to advance to the next page Print the range
- fromPage()-toPage()
92. Printing (cont.)