1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/canvas/qcanvas.cpp:435 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QCanvas Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QCanvas Class Reference<br><small>[<a href="canvas.html">canvas module</a>]</small></h1>
|
---|
33 |
|
---|
34 | <p>The QCanvas class provides a 2D area that can contain QCanvasItem objects.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p><tt>#include <<a href="qcanvas-h.html">qcanvas.h</a>></tt>
|
---|
37 | <p>Inherits <a href="qobject.html">QObject</a>.
|
---|
38 | <p><a href="qcanvas-members.html">List of all member functions.</a>
|
---|
39 | <h2>Public Members</h2>
|
---|
40 | <ul>
|
---|
41 | <li class=fn><a href="#QCanvas"><b>QCanvas</b></a> ( QObject * parent = 0, const char * name = 0 )</li>
|
---|
42 | <li class=fn><a href="#QCanvas-2"><b>QCanvas</b></a> ( int w, int h )</li>
|
---|
43 | <li class=fn><a href="#QCanvas-3"><b>QCanvas</b></a> ( QPixmap p, int h, int v, int tilewidth, int tileheight )</li>
|
---|
44 | <li class=fn>virtual <a href="#~QCanvas"><b>~QCanvas</b></a> ()</li>
|
---|
45 | <li class=fn>virtual void <a href="#setTiles"><b>setTiles</b></a> ( QPixmap p, int h, int v, int tilewidth, int tileheight )</li>
|
---|
46 | <li class=fn>virtual void <a href="#setBackgroundPixmap"><b>setBackgroundPixmap</b></a> ( const QPixmap & p )</li>
|
---|
47 | <li class=fn>QPixmap <a href="#backgroundPixmap"><b>backgroundPixmap</b></a> () const</li>
|
---|
48 | <li class=fn>virtual void <a href="#setBackgroundColor"><b>setBackgroundColor</b></a> ( const QColor & c )</li>
|
---|
49 | <li class=fn>QColor <a href="#backgroundColor"><b>backgroundColor</b></a> () const</li>
|
---|
50 | <li class=fn>virtual void <a href="#setTile"><b>setTile</b></a> ( int x, int y, int tilenum )</li>
|
---|
51 | <li class=fn>int <a href="#tile"><b>tile</b></a> ( int x, int y ) const</li>
|
---|
52 | <li class=fn>int <a href="#tilesHorizontally"><b>tilesHorizontally</b></a> () const</li>
|
---|
53 | <li class=fn>int <a href="#tilesVertically"><b>tilesVertically</b></a> () const</li>
|
---|
54 | <li class=fn>int <a href="#tileWidth"><b>tileWidth</b></a> () const</li>
|
---|
55 | <li class=fn>int <a href="#tileHeight"><b>tileHeight</b></a> () const</li>
|
---|
56 | <li class=fn>virtual void <a href="#resize"><b>resize</b></a> ( int w, int h )</li>
|
---|
57 | <li class=fn>int <a href="#width"><b>width</b></a> () const</li>
|
---|
58 | <li class=fn>int <a href="#height"><b>height</b></a> () const</li>
|
---|
59 | <li class=fn>QSize <a href="#size"><b>size</b></a> () const</li>
|
---|
60 | <li class=fn>QRect <a href="#rect"><b>rect</b></a> () const</li>
|
---|
61 | <li class=fn>bool <a href="#onCanvas"><b>onCanvas</b></a> ( int x, int y ) const</li>
|
---|
62 | <li class=fn>bool <a href="#onCanvas-2"><b>onCanvas</b></a> ( const QPoint & p ) const</li>
|
---|
63 | <li class=fn>bool <a href="#validChunk"><b>validChunk</b></a> ( int x, int y ) const</li>
|
---|
64 | <li class=fn>bool <a href="#validChunk-2"><b>validChunk</b></a> ( const QPoint & p ) const</li>
|
---|
65 | <li class=fn>int <a href="#chunkSize"><b>chunkSize</b></a> () const</li>
|
---|
66 | <li class=fn>virtual void <a href="#retune"><b>retune</b></a> ( int chunksze, int mxclusters = 100 )</li>
|
---|
67 | <li class=fn>virtual void <a href="#setAllChanged"><b>setAllChanged</b></a> ()</li>
|
---|
68 | <li class=fn>virtual void <a href="#setChanged"><b>setChanged</b></a> ( const QRect & area )</li>
|
---|
69 | <li class=fn>virtual void <a href="#setUnchanged"><b>setUnchanged</b></a> ( const QRect & area )</li>
|
---|
70 | <li class=fn>QCanvasItemList <a href="#allItems"><b>allItems</b></a> ()</li>
|
---|
71 | <li class=fn>QCanvasItemList <a href="#collisions"><b>collisions</b></a> ( const QPoint & p ) const</li>
|
---|
72 | <li class=fn>QCanvasItemList <a href="#collisions-2"><b>collisions</b></a> ( const QRect & r ) const</li>
|
---|
73 | <li class=fn>QCanvasItemList <a href="#collisions-3"><b>collisions</b></a> ( const QPointArray & chunklist, const QCanvasItem * item, bool exact ) const</li>
|
---|
74 | <li class=fn>void <a href="#drawArea"><b>drawArea</b></a> ( const QRect & clip, QPainter * painter, bool dbuf = FALSE )</li>
|
---|
75 | <li class=fn>virtual void <a href="#setAdvancePeriod"><b>setAdvancePeriod</b></a> ( int ms )</li>
|
---|
76 | <li class=fn>virtual void <a href="#setUpdatePeriod"><b>setUpdatePeriod</b></a> ( int ms )</li>
|
---|
77 | <li class=fn>virtual void <a href="#setDoubleBuffering"><b>setDoubleBuffering</b></a> ( bool y )</li>
|
---|
78 | </ul>
|
---|
79 | <h2>Public Slots</h2>
|
---|
80 | <ul>
|
---|
81 | <li class=fn>virtual void <a href="#advance"><b>advance</b></a> ()</li>
|
---|
82 | <li class=fn>virtual void <a href="#update"><b>update</b></a> ()</li>
|
---|
83 | </ul>
|
---|
84 | <h2>Signals</h2>
|
---|
85 | <ul>
|
---|
86 | <li class=fn>void <a href="#resized"><b>resized</b></a> ()</li>
|
---|
87 | </ul>
|
---|
88 | <h2>Protected Members</h2>
|
---|
89 | <ul>
|
---|
90 | <li class=fn>virtual void <a href="#drawBackground"><b>drawBackground</b></a> ( QPainter & painter, const QRect & clip )</li>
|
---|
91 | <li class=fn>virtual void <a href="#drawForeground"><b>drawForeground</b></a> ( QPainter & painter, const QRect & clip )</li>
|
---|
92 | </ul>
|
---|
93 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
94 |
|
---|
95 |
|
---|
96 | The QCanvas class provides a 2D area that can contain <a href="qcanvasitem.html">QCanvasItem</a> objects.
|
---|
97 |
|
---|
98 | <p>
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | <p> The QCanvas class manages its 2D graphic area and all the canvas
|
---|
104 | items the area contains. The canvas has no visual appearance of
|
---|
105 | its own. Instead, it is displayed on screen using a <a href="qcanvasview.html">QCanvasView</a>.
|
---|
106 | Multiple QCanvasView widgets may be associated with a canvas to
|
---|
107 | provide multiple views of the same canvas.
|
---|
108 | <p> The canvas is optimized for large numbers of items, particularly
|
---|
109 | where only a small percentage of the items change at any
|
---|
110 | one time. If the entire display changes very frequently, you should
|
---|
111 | consider using your own custom <a href="qscrollview.html">QScrollView</a> subclass.
|
---|
112 | <p> Qt provides a rich
|
---|
113 | set of canvas item classes, e.g. <a href="qcanvasellipse.html">QCanvasEllipse</a>, <a href="qcanvasline.html">QCanvasLine</a>,
|
---|
114 | <a href="qcanvaspolygon.html">QCanvasPolygon</a>, <a href="qcanvaspolygonalitem.html">QCanvasPolygonalItem</a>, <a href="qcanvasrectangle.html">QCanvasRectangle</a>, <a href="qcanvasspline.html">QCanvasSpline</a>,
|
---|
115 | <a href="qcanvassprite.html">QCanvasSprite</a> and <a href="qcanvastext.html">QCanvasText</a>. You can subclass to create your own
|
---|
116 | canvas items; QCanvasPolygonalItem is the most common base class used
|
---|
117 | for this purpose.
|
---|
118 | <p> Items appear on the canvas after their <a href="qcanvasitem.html#show">show()</a> function has been called (or <a href="qcanvasitem.html#setVisible">setVisible(TRUE)</a>), and <em>after</em>
|
---|
119 | <a href="#update">update</a>() has been called. The canvas only shows items that are
|
---|
120 | <a href="qcanvasitem.html#setVisible">visible</a>, and then only if
|
---|
121 | <a href="#update">update</a>() is called. (By default the canvas is white and so are
|
---|
122 | canvas items, so if nothing appears try changing colors.)
|
---|
123 | <p> If you created the canvas without passing a width and height to
|
---|
124 | the constructor you must also call <a href="#resize">resize</a>().
|
---|
125 | <p> Although a canvas may appear to be similar to a widget with child
|
---|
126 | widgets, there are several notable differences:
|
---|
127 | <p> <ul>
|
---|
128 | <li> Canvas items are usually much faster to manipulate and redraw than
|
---|
129 | child widgets, with the speed advantage becoming especially great when
|
---|
130 | there are <em>many</em> canvas items and non-rectangular items. In most
|
---|
131 | situations canvas items are also a lot more memory efficient than child
|
---|
132 | widgets.
|
---|
133 | <p> <li> It's easy to detect overlapping items (collision detection).
|
---|
134 | <p> <li> The canvas can be larger than a widget. A million-by-million canvas
|
---|
135 | is perfectly possible. At such a size a widget might be very
|
---|
136 | inefficient, and some window systems might not support it at all,
|
---|
137 | whereas QCanvas scales well. Even with a billion pixels and a million
|
---|
138 | items, finding a particular canvas item, detecting collisions, etc.,
|
---|
139 | is still fast (though the memory consumption may be prohibitive
|
---|
140 | at such extremes).
|
---|
141 | <p> <li> Two or more <a href="qcanvasview.html">QCanvasView</a> objects can view the same canvas.
|
---|
142 | <p> <li> An arbitrary <a href="qwmatrix.html#TransformationMode">transformation matrix</a> can be set on each QCanvasView
|
---|
143 | which makes it easy to zoom, rotate or shear the viewed canvas.
|
---|
144 | <p> <li> Widgets provide a lot more functionality, such as input (<a href="qkeyevent.html">QKeyEvent</a>,
|
---|
145 | <a href="qmouseevent.html">QMouseEvent</a> etc.) and layout management (<a href="qgridlayout.html">QGridLayout</a> etc.).
|
---|
146 | <p> </ul>
|
---|
147 | <p> A canvas consists of a background, a number of canvas items organized by
|
---|
148 | x, y and z coordinates, and a foreground. A canvas item's z coordinate
|
---|
149 | can be treated as a layer number -- canvas items with a higher z
|
---|
150 | coordinate appear in front of canvas items with a lower z coordinate.
|
---|
151 | <p> The background is white by default, but can be set to a different color
|
---|
152 | using <a href="#setBackgroundColor">setBackgroundColor</a>(), or to a repeated pixmap using
|
---|
153 | <a href="#setBackgroundPixmap">setBackgroundPixmap</a>() or to a mosaic of smaller pixmaps using
|
---|
154 | <a href="#setTiles">setTiles</a>(). Individual tiles can be set with <a href="#setTile">setTile</a>(). There
|
---|
155 | are corresponding get functions, e.g. <a href="#backgroundColor">backgroundColor</a>() and
|
---|
156 | <a href="#backgroundPixmap">backgroundPixmap</a>().
|
---|
157 | <p> Note that QCanvas does not inherit from <a href="qwidget.html">QWidget</a>, even though it has some
|
---|
158 | functions which provide the same functionality as those in QWidget. One
|
---|
159 | of these is setBackgroundPixmap(); some others are <a href="#resize">resize</a>(), <a href="#size">size</a>(),
|
---|
160 | <a href="#width">width</a>() and <a href="#height">height</a>(). <a href="qcanvasview.html">QCanvasView</a> is the widget used to display a
|
---|
161 | canvas on the screen.
|
---|
162 | <p> Canvas items are added to a canvas by constructing them and passing the
|
---|
163 | canvas to the canvas item's constructor. An item can be moved to a
|
---|
164 | different canvas using <a href="qcanvasitem.html#setCanvas">QCanvasItem::setCanvas</a>().
|
---|
165 | <p> Canvas items are movable (and in the case of QCanvasSprites, animated)
|
---|
166 | objects that inherit <a href="qcanvasitem.html">QCanvasItem</a>. Each canvas item has a position on the
|
---|
167 | canvas (x, y coordinates) and a height (z coordinate), all of which are
|
---|
168 | held as floating-point numbers. Moving canvas items also have x and y
|
---|
169 | velocities. It's possible for a canvas item to be outside the canvas
|
---|
170 | (for example <a href="qcanvasitem.html#x">QCanvasItem::x</a>() is greater than width()). When a canvas
|
---|
171 | item is off the canvas, <a href="#onCanvas">onCanvas</a>() returns FALSE and the canvas
|
---|
172 | disregards the item. (Canvas items off the canvas do not slow down any
|
---|
173 | of the common operations on the canvas.)
|
---|
174 | <p> Canvas items can be moved with <a href="qcanvasitem.html#move">QCanvasItem::move</a>(). The <a href="#advance">advance</a>()
|
---|
175 | function moves all <a href="qcanvasitem.html#animated">QCanvasItem::animated</a>() canvas items and
|
---|
176 | <a href="#setAdvancePeriod">setAdvancePeriod</a>() makes QCanvas move them automatically on a periodic
|
---|
177 | basis. In the context of the QCanvas classes, to `animate' a canvas item
|
---|
178 | is to set it in motion, i.e. using <a href="qcanvasitem.html#setVelocity">QCanvasItem::setVelocity</a>(). Animation
|
---|
179 | of a canvas item itself, i.e. items which change over time, is enabled
|
---|
180 | by calling <a href="qcanvassprite.html#setFrameAnimation">QCanvasSprite::setFrameAnimation</a>(), or more generally by
|
---|
181 | subclassing and reimplementing <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>(). To detect collisions
|
---|
182 | use one of the <a href="qcanvasitem.html#collisions">QCanvasItem::collisions</a>() functions.
|
---|
183 | <p> The changed parts of the canvas are redrawn (if they are visible in a
|
---|
184 | canvas view) whenever <a href="#update">update</a>() is called. You can either call update()
|
---|
185 | manually after having changed the contents of the canvas, or force
|
---|
186 | periodic updates using <a href="#setUpdatePeriod">setUpdatePeriod</a>(). If you have moving objects on
|
---|
187 | the canvas, you must call <a href="#advance">advance</a>() every time the objects should
|
---|
188 | move one step further. Periodic calls to advance() can be forced using
|
---|
189 | <a href="#setAdvancePeriod">setAdvancePeriod</a>(). The advance() function will call
|
---|
190 | QCanvasItem::advance() on every item that is <a href="qcanvasitem.html#animated">animated</a> and trigger an update of the
|
---|
191 | affected areas afterwards. (A canvas item that is `animated' is simply
|
---|
192 | a canvas item that is in motion.)
|
---|
193 | <p> QCanvas organizes its canvas items into <em>chunks</em>; these are areas on
|
---|
194 | the canvas that are used to speed up most operations. Many operations
|
---|
195 | start by eliminating most chunks (i.e. those which haven't changed)
|
---|
196 | and then process only the canvas items that are in the few interesting
|
---|
197 | (i.e. changed) chunks. A valid chunk, <a href="#validChunk">validChunk</a>(), is one which is on
|
---|
198 | the canvas.
|
---|
199 | <p> The chunk size is a key factor to QCanvas's speed: if there are too many
|
---|
200 | chunks, the speed benefit of grouping canvas items into chunks is
|
---|
201 | reduced. If the chunks are too large, it takes too long to process each
|
---|
202 | one. The QCanvas constructor tries to pick a suitable size, but you
|
---|
203 | can call <a href="#retune">retune</a>() to change it at any time. The <a href="#chunkSize">chunkSize</a>() function
|
---|
204 | returns the current chunk size. The canvas items always make sure
|
---|
205 | they're in the right chunks; all you need to make sure of is that
|
---|
206 | the canvas uses the right chunk size. A good rule of thumb is that
|
---|
207 | the size should be a bit smaller than the average canvas item
|
---|
208 | size. If you have moving objects, the chunk size should be a bit
|
---|
209 | smaller than the average size of the moving items.
|
---|
210 | <p> The foreground is normally nothing, but if you reimplement
|
---|
211 | <a href="#drawForeground">drawForeground</a>(), you can draw things in front of all the canvas
|
---|
212 | items.
|
---|
213 | <p> Areas can be set as changed with <a href="#setChanged">setChanged</a>() and set unchanged with
|
---|
214 | <a href="#setUnchanged">setUnchanged</a>(). The entire canvas can be set as changed with
|
---|
215 | <a href="#setAllChanged">setAllChanged</a>(). A list of all the items on the canvas is returned by
|
---|
216 | <a href="#allItems">allItems</a>().
|
---|
217 | <p> An area can be copied (painted) to a <a href="qpainter.html">QPainter</a> with <a href="#drawArea">drawArea</a>().
|
---|
218 | <p> If the canvas is resized it emits the <a href="#resized">resized</a>() signal.
|
---|
219 | <p> The examples/canvas application and the 2D graphics page of the
|
---|
220 | examples/demo application demonstrate many of QCanvas's facilities.
|
---|
221 | <p> <p>See also <a href="qcanvasview.html">QCanvasView</a>, <a href="qcanvasitem.html">QCanvasItem</a>, <a href="abstractwidgets.html">Abstract Widget Classes</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.
|
---|
222 |
|
---|
223 | <hr><h2>Member Function Documentation</h2>
|
---|
224 | <h3 class=fn><a name="QCanvas"></a>QCanvas::QCanvas ( <a href="qobject.html">QObject</a> * parent = 0, const char * name = 0 )
|
---|
225 | </h3>
|
---|
226 | Create a QCanvas with no size. <em>parent</em> and <em>name</em> are passed to
|
---|
227 | the <a href="qobject.html">QObject</a> superclass.
|
---|
228 | <p> <b>Warning:</b> You <em>must</em> call <a href="#resize">resize</a>() at some time after creation to
|
---|
229 | be able to use the canvas.
|
---|
230 |
|
---|
231 | <h3 class=fn><a name="QCanvas-2"></a>QCanvas::QCanvas ( int w, int h )
|
---|
232 | </h3>
|
---|
233 | Constructs a QCanvas that is <em>w</em> pixels wide and <em>h</em> pixels high.
|
---|
234 |
|
---|
235 | <h3 class=fn><a name="QCanvas-3"></a>QCanvas::QCanvas ( <a href="qpixmap.html">QPixmap</a> p, int h, int v, int tilewidth, int tileheight )
|
---|
236 | </h3>
|
---|
237 | Constructs a QCanvas which will be composed of <em>h</em> tiles
|
---|
238 | horizontally and <em>v</em> tiles vertically. Each tile will be an image
|
---|
239 | <em>tilewidth</em> by <em>tileheight</em> pixels taken from pixmap <em>p</em>.
|
---|
240 | <p> The pixmap <em>p</em> is a list of tiles, arranged left to right, (and
|
---|
241 | in the case of pixmaps that have multiple rows of tiles, top to
|
---|
242 | bottom), with tile 0 in the top-left corner, tile 1 next to the
|
---|
243 | right, and so on, e.g.
|
---|
244 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
245 | <tr bgcolor="#f0f0f0"> <td valign="top">0 <td valign="top">1 <td valign="top">2 <td valign="top">3
|
---|
246 | <tr bgcolor="#d0d0d0"> <td valign="top">4 <td valign="top">5 <td valign="top">6 <td valign="top">7
|
---|
247 | </table></center>
|
---|
248 | <p> The QCanvas is initially sized to show exactly the given number of
|
---|
249 | tiles horizontally and vertically. If it is resized to be larger,
|
---|
250 | the entire matrix of tiles will be repeated as often as necessary
|
---|
251 | to cover the area. If it is smaller, tiles to the right and bottom
|
---|
252 | will not be visible.
|
---|
253 | <p> <p>See also <a href="#setTiles">setTiles</a>().
|
---|
254 |
|
---|
255 | <h3 class=fn><a name="~QCanvas"></a>QCanvas::~QCanvas ()<tt> [virtual]</tt>
|
---|
256 | </h3>
|
---|
257 | Destroys the canvas and all the canvas's canvas items.
|
---|
258 |
|
---|
259 | <h3 class=fn>void <a name="advance"></a>QCanvas::advance ()<tt> [virtual slot]</tt>
|
---|
260 | </h3>
|
---|
261 | Moves all <a href="qcanvasitem.html#animated">QCanvasItem::animated</a>() canvas items on the canvas and
|
---|
262 | refreshes all changes to all views of the canvas. (An `animated'
|
---|
263 | item is an item that is in motion; see setVelocity().)
|
---|
264 | <p> The advance takes place in two phases. In phase 0, the
|
---|
265 | <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() function of each QCanvasItem::animated()
|
---|
266 | canvas item is called with paramater 0. Then all these canvas
|
---|
267 | items are called again, with parameter 1. In phase 0, the canvas
|
---|
268 | items should not change position, merely examine other items on
|
---|
269 | the canvas for which special processing is required, such as
|
---|
270 | collisions between items. In phase 1, all canvas items should
|
---|
271 | change positions, ignoring any other items on the canvas. This
|
---|
272 | two-phase approach allows for considerations of "fairness",
|
---|
273 | although no <a href="qcanvasitem.html">QCanvasItem</a> subclasses supplied with Qt do anything
|
---|
274 | interesting in phase 0.
|
---|
275 | <p> The canvas can be configured to call this function periodically
|
---|
276 | with <a href="#setAdvancePeriod">setAdvancePeriod</a>().
|
---|
277 | <p> <p>See also <a href="#update">update</a>().
|
---|
278 |
|
---|
279 | <h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="allItems"></a>QCanvas::allItems ()
|
---|
280 | </h3>
|
---|
281 | Returns a list of all the items in the canvas.
|
---|
282 |
|
---|
283 | <h3 class=fn><a href="qcolor.html">QColor</a> <a name="backgroundColor"></a>QCanvas::backgroundColor () const
|
---|
284 | </h3>
|
---|
285 | Returns the color set by <a href="#setBackgroundColor">setBackgroundColor</a>(). By default, this is
|
---|
286 | white.
|
---|
287 | <p> This function is not a reimplementation of
|
---|
288 | <a href="qwidget.html#backgroundColor">QWidget::backgroundColor</a>() (QCanvas is not a subclass of <a href="qwidget.html">QWidget</a>),
|
---|
289 | but all QCanvasViews that are viewing the canvas will set their
|
---|
290 | backgrounds to this color.
|
---|
291 | <p> <p>See also <a href="#setBackgroundColor">setBackgroundColor</a>() and <a href="#backgroundPixmap">backgroundPixmap</a>().
|
---|
292 |
|
---|
293 | <h3 class=fn><a href="qpixmap.html">QPixmap</a> <a name="backgroundPixmap"></a>QCanvas::backgroundPixmap () const
|
---|
294 | </h3>
|
---|
295 | Returns the pixmap set by <a href="#setBackgroundPixmap">setBackgroundPixmap</a>(). By default,
|
---|
296 | this is a null pixmap.
|
---|
297 | <p> <p>See also <a href="#setBackgroundPixmap">setBackgroundPixmap</a>() and <a href="#backgroundColor">backgroundColor</a>().
|
---|
298 |
|
---|
299 | <h3 class=fn>int <a name="chunkSize"></a>QCanvas::chunkSize () const
|
---|
300 | </h3>
|
---|
301 |
|
---|
302 | <p> Returns the chunk size of the canvas.
|
---|
303 | <p> <p>See also <a href="#retune">retune</a>().
|
---|
304 |
|
---|
305 | <h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions"></a>QCanvas::collisions ( const <a href="qpoint.html">QPoint</a> & p ) const
|
---|
306 | </h3>
|
---|
307 | Returns a list of canvas items that collide with the point <em>p</em>.
|
---|
308 | The list is ordered by z coordinates, from highest z coordinate
|
---|
309 | (front-most item) to lowest z coordinate (rear-most item).
|
---|
310 |
|
---|
311 | <h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions-2"></a>QCanvas::collisions ( const <a href="qrect.html">QRect</a> & r ) const
|
---|
312 | </h3>
|
---|
313 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
314 | <p> Returns a list of items which collide with the rectangle <em>r</em>. The
|
---|
315 | list is ordered by z coordinates, from highest z coordinate
|
---|
316 | (front-most item) to lowest z coordinate (rear-most item).
|
---|
317 |
|
---|
318 | <h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions-3"></a>QCanvas::collisions ( const <a href="qpointarray.html">QPointArray</a> & chunklist, const <a href="qcanvasitem.html">QCanvasItem</a> * item, bool exact ) const
|
---|
319 | </h3>
|
---|
320 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
321 | <p> Returns a list of canvas items which intersect with the chunks
|
---|
322 | listed in <em>chunklist</em>, excluding <em>item</em>. If <em>exact</em> is TRUE,
|
---|
323 | only those which actually <a href="qcanvasitem.html#collidesWith">collide with</a> <em>item</em> are returned; otherwise canvas items
|
---|
324 | are included just for being in the chunks.
|
---|
325 | <p> This is a utility function mainly used to implement the simpler
|
---|
326 | <a href="qcanvasitem.html#collisions">QCanvasItem::collisions</a>() function.
|
---|
327 |
|
---|
328 | <h3 class=fn>void <a name="drawArea"></a>QCanvas::drawArea ( const <a href="qrect.html">QRect</a> & clip, <a href="qpainter.html">QPainter</a> * painter, bool dbuf = FALSE )
|
---|
329 | </h3>
|
---|
330 | Paints all canvas items that are in the area <em>clip</em> to <em>painter</em>, using double-buffering if <em>dbuf</em> is TRUE.
|
---|
331 | <p> e.g. to print the canvas to a printer:
|
---|
332 | <pre>
|
---|
333 | <a href="qprinter.html">QPrinter</a> pr;
|
---|
334 | if ( pr.<a href="qprinter.html#setup">setup</a>() ) {
|
---|
335 | <a href="qpainter.html">QPainter</a> p(&pr);
|
---|
336 | canvas.drawArea( canvas.rect(), &p );
|
---|
337 | }
|
---|
338 | </pre>
|
---|
339 |
|
---|
340 |
|
---|
341 | <p>Example: <a href="canvas-example.html#x2908">canvas/canvas.cpp</a>.
|
---|
342 | <h3 class=fn>void <a name="drawBackground"></a>QCanvas::drawBackground ( <a href="qpainter.html">QPainter</a> & painter, const <a href="qrect.html">QRect</a> & clip )<tt> [virtual protected]</tt>
|
---|
343 | </h3>
|
---|
344 | This virtual function is called for all updates of the canvas. It
|
---|
345 | renders any background graphics using the painter <em>painter</em>, in
|
---|
346 | the area <em>clip</em>. If the canvas has a background pixmap or a tiled
|
---|
347 | background, that graphic is used, otherwise the canvas is cleared
|
---|
348 | using the background color.
|
---|
349 | <p> If the graphics for an area change, you must explicitly call
|
---|
350 | <a href="#setChanged">setChanged</a>(const <a href="qrect.html">QRect</a>&) for the result to be visible when
|
---|
351 | <a href="#update">update</a>() is next called.
|
---|
352 | <p> <p>See also <a href="#setBackgroundColor">setBackgroundColor</a>(), <a href="#setBackgroundPixmap">setBackgroundPixmap</a>(), and <a href="#setTiles">setTiles</a>().
|
---|
353 |
|
---|
354 | <h3 class=fn>void <a name="drawForeground"></a>QCanvas::drawForeground ( <a href="qpainter.html">QPainter</a> & painter, const <a href="qrect.html">QRect</a> & clip )<tt> [virtual protected]</tt>
|
---|
355 | </h3>
|
---|
356 | This virtual function is called for all updates of the canvas. It
|
---|
357 | renders any foreground graphics using the painter <em>painter</em>, in
|
---|
358 | the area <em>clip</em>.
|
---|
359 | <p> If the graphics for an area change, you must explicitly call
|
---|
360 | <a href="#setChanged">setChanged</a>(const <a href="qrect.html">QRect</a>&) for the result to be visible when
|
---|
361 | <a href="#update">update</a>() is next called.
|
---|
362 | <p> The default is to draw nothing.
|
---|
363 |
|
---|
364 | <h3 class=fn>int <a name="height"></a>QCanvas::height () const
|
---|
365 | </h3>
|
---|
366 |
|
---|
367 | <p> Returns the height of the canvas, in pixels.
|
---|
368 |
|
---|
369 | <p>Example: <a href="canvas-example.html#x2909">canvas/canvas.cpp</a>.
|
---|
370 | <h3 class=fn>bool <a name="onCanvas"></a>QCanvas::onCanvas ( int x, int y ) const
|
---|
371 | </h3>
|
---|
372 |
|
---|
373 | <p> Returns TRUE if the pixel position (<em>x</em>, <em>y</em>) is on the canvas;
|
---|
374 | otherwise returns FALSE.
|
---|
375 | <p> <p>See also <a href="#validChunk">validChunk</a>().
|
---|
376 |
|
---|
377 | <h3 class=fn>bool <a name="onCanvas-2"></a>QCanvas::onCanvas ( const <a href="qpoint.html">QPoint</a> & p ) const
|
---|
378 | </h3>
|
---|
379 |
|
---|
380 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
381 | <p> Returns TRUE if the pixel position <em>p</em> is on the canvas;
|
---|
382 | otherwise returns FALSE.
|
---|
383 | <p> <p>See also <a href="#validChunk">validChunk</a>().
|
---|
384 |
|
---|
385 | <h3 class=fn><a href="qrect.html">QRect</a> <a name="rect"></a>QCanvas::rect () const
|
---|
386 | </h3>
|
---|
387 |
|
---|
388 | <p> Returns a rectangle the size of the canvas.
|
---|
389 |
|
---|
390 | <h3 class=fn>void <a name="resize"></a>QCanvas::resize ( int w, int h )<tt> [virtual]</tt>
|
---|
391 | </h3>
|
---|
392 | Changes the size of the canvas to have a width of <em>w</em> and a
|
---|
393 | height of <em>h</em>. This is a slow operation.
|
---|
394 |
|
---|
395 | <p>Examples: <a href="canvas-example.html#x2910">canvas/canvas.cpp</a> and <a href="canvas-chart-example.html#x2876">chart/chartform.cpp</a>.
|
---|
396 | <h3 class=fn>void <a name="resized"></a>QCanvas::resized ()<tt> [signal]</tt>
|
---|
397 | </h3>
|
---|
398 |
|
---|
399 | <p> This signal is emitted whenever the canvas is resized. Each
|
---|
400 | <a href="qcanvasview.html">QCanvasView</a> connects to this signal to keep the scrollview's size
|
---|
401 | correct.
|
---|
402 |
|
---|
403 | <h3 class=fn>void <a name="retune"></a>QCanvas::retune ( int chunksze, int mxclusters = 100 )<tt> [virtual]</tt>
|
---|
404 | </h3>
|
---|
405 | Change the efficiency tuning parameters to <em>mxclusters</em> clusters,
|
---|
406 | each of size <em>chunksze</em>. This is a slow operation if there are
|
---|
407 | many objects on the canvas.
|
---|
408 | <p> The canvas is divided into chunks which are rectangular areas <em>chunksze</em> wide by <em>chunksze</em> high. Use a chunk size which is about
|
---|
409 | the average size of the canvas items. If you choose a chunk size
|
---|
410 | which is too small it will increase the amount of calculation
|
---|
411 | required when drawing since each change will affect many chunks.
|
---|
412 | If you choose a chunk size which is too large the amount of
|
---|
413 | drawing required will increase because for each change, a lot of
|
---|
414 | drawing will be required since there will be many (unchanged)
|
---|
415 | canvas items which are in the same chunk as the changed canvas
|
---|
416 | items.
|
---|
417 | <p> Internally, a canvas uses a low-resolution "chunk matrix" to keep
|
---|
418 | track of all the items in the canvas. A 64x64 chunk matrix is the
|
---|
419 | default for a 1024x1024 pixel canvas, where each chunk collects
|
---|
420 | canvas items in a 16x16 pixel square. This default is also
|
---|
421 | affected by <a href="#setTiles">setTiles</a>(). You can tune this default using this
|
---|
422 | function. For example if you have a very large canvas and want to
|
---|
423 | trade off speed for memory then you might set the chunk size to 32
|
---|
424 | or 64.
|
---|
425 | <p> The <em>mxclusters</em> argument is the number of rectangular groups of
|
---|
426 | chunks that will be separately drawn. If the canvas has a large
|
---|
427 | number of small, dispersed items, this should be about that
|
---|
428 | number. Our testing suggests that a large number of clusters is
|
---|
429 | almost always best.
|
---|
430 | <p>
|
---|
431 | <h3 class=fn>void <a name="setAdvancePeriod"></a>QCanvas::setAdvancePeriod ( int ms )<tt> [virtual]</tt>
|
---|
432 | </h3>
|
---|
433 | Sets the canvas to call <a href="#advance">advance</a>() every <em>ms</em> milliseconds. Any
|
---|
434 | previous setting by <a href="#setAdvancePeriod">setAdvancePeriod</a>() or <a href="#setUpdatePeriod">setUpdatePeriod</a>() is
|
---|
435 | overridden.
|
---|
436 | <p> If <em>ms</em> is less than 0 advancing will be stopped.
|
---|
437 |
|
---|
438 | <p>Example: <a href="canvas-example.html#x2962">canvas/main.cpp</a>.
|
---|
439 | <h3 class=fn>void <a name="setAllChanged"></a>QCanvas::setAllChanged ()<tt> [virtual]</tt>
|
---|
440 | </h3>
|
---|
441 | Marks the whole canvas as changed.
|
---|
442 | All views of the canvas will be entirely redrawn when
|
---|
443 | <a href="#update">update</a>() is called next.
|
---|
444 |
|
---|
445 | <h3 class=fn>void <a name="setBackgroundColor"></a>QCanvas::setBackgroundColor ( const <a href="qcolor.html">QColor</a> & c )<tt> [virtual]</tt>
|
---|
446 | </h3>
|
---|
447 | Sets the solid background to be the color <em>c</em>.
|
---|
448 | <p> <p>See also <a href="#backgroundColor">backgroundColor</a>(), <a href="#setBackgroundPixmap">setBackgroundPixmap</a>(), and <a href="#setTiles">setTiles</a>().
|
---|
449 |
|
---|
450 | <h3 class=fn>void <a name="setBackgroundPixmap"></a>QCanvas::setBackgroundPixmap ( const <a href="qpixmap.html">QPixmap</a> & p )<tt> [virtual]</tt>
|
---|
451 | </h3>
|
---|
452 | Sets the solid background to be the pixmap <em>p</em> repeated as
|
---|
453 | necessary to cover the entire canvas.
|
---|
454 | <p> <p>See also <a href="#backgroundPixmap">backgroundPixmap</a>(), <a href="#setBackgroundColor">setBackgroundColor</a>(), and <a href="#setTiles">setTiles</a>().
|
---|
455 |
|
---|
456 | <h3 class=fn>void <a name="setChanged"></a>QCanvas::setChanged ( const <a href="qrect.html">QRect</a> & area )<tt> [virtual]</tt>
|
---|
457 | </h3>
|
---|
458 | Marks <em>area</em> as changed. This <em>area</em> will be redrawn in all
|
---|
459 | views that are showing it when <a href="#update">update</a>() is called next.
|
---|
460 |
|
---|
461 | <h3 class=fn>void <a name="setDoubleBuffering"></a>QCanvas::setDoubleBuffering ( bool y )<tt> [virtual]</tt>
|
---|
462 | </h3>
|
---|
463 | If <em>y</em> is TRUE (the default) double-buffering is switched on;
|
---|
464 | otherwise double-buffering is switched off.
|
---|
465 | <p> Turning off double-buffering causes the redrawn areas to flicker a
|
---|
466 | little and also gives a (usually small) performance improvement.
|
---|
467 |
|
---|
468 | <p>Example: <a href="canvas-example.html#x2911">canvas/canvas.cpp</a>.
|
---|
469 | <h3 class=fn>void <a name="setTile"></a>QCanvas::setTile ( int x, int y, int tilenum )<tt> [virtual]</tt>
|
---|
470 | </h3>
|
---|
471 | Sets the tile at (<em>x</em>, <em>y</em>) to use tile number <em>tilenum</em>, which
|
---|
472 | is an index into the tile pixmaps. The canvas will update
|
---|
473 | appropriately when <a href="#update">update</a>() is next called.
|
---|
474 | <p> The images are taken from the pixmap set by <a href="#setTiles">setTiles</a>() and are
|
---|
475 | arranged left to right, (and in the case of pixmaps that have
|
---|
476 | multiple rows of tiles, top to bottom), with tile 0 in the
|
---|
477 | top-left corner, tile 1 next to the right, and so on, e.g.
|
---|
478 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
479 | <tr bgcolor="#f0f0f0"> <td valign="top">0 <td valign="top">1 <td valign="top">2 <td valign="top">3
|
---|
480 | <tr bgcolor="#d0d0d0"> <td valign="top">4 <td valign="top">5 <td valign="top">6 <td valign="top">7
|
---|
481 | </table></center>
|
---|
482 | <p> <p>See also <a href="#tile">tile</a>() and <a href="#setTiles">setTiles</a>().
|
---|
483 |
|
---|
484 | <h3 class=fn>void <a name="setTiles"></a>QCanvas::setTiles ( <a href="qpixmap.html">QPixmap</a> p, int h, int v, int tilewidth, int tileheight )<tt> [virtual]</tt>
|
---|
485 | </h3>
|
---|
486 | Sets the QCanvas to be composed of <em>h</em> tiles horizontally and <em>v</em> tiles vertically. Each tile will be an image <em>tilewidth</em> by <em>tileheight</em> pixels from pixmap <em>p</em>.
|
---|
487 | <p> The pixmap <em>p</em> is a list of tiles, arranged left to right, (and
|
---|
488 | in the case of pixmaps that have multiple rows of tiles, top to
|
---|
489 | bottom), with tile 0 in the top-left corner, tile 1 next to the
|
---|
490 | right, and so on, e.g.
|
---|
491 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
492 | <tr bgcolor="#f0f0f0"> <td valign="top">0 <td valign="top">1 <td valign="top">2 <td valign="top">3
|
---|
493 | <tr bgcolor="#d0d0d0"> <td valign="top">4 <td valign="top">5 <td valign="top">6 <td valign="top">7
|
---|
494 | </table></center>
|
---|
495 | <p> If the canvas is larger than the matrix of tiles, the entire
|
---|
496 | matrix is repeated as necessary to cover the whole canvas. If it
|
---|
497 | is smaller, tiles to the right and bottom are not visible.
|
---|
498 | <p> The width and height of <em>p</em> must be a multiple of <em>tilewidth</em>
|
---|
499 | and <em>tileheight</em>. If they are not the function will do nothing.
|
---|
500 | <p> If you want to unset any tiling set, then just pass in a null
|
---|
501 | pixmap and 0 for <em>h</em>, <em>v</em>, <em>tilewidth</em>, and
|
---|
502 | <em>tileheight</em>.
|
---|
503 |
|
---|
504 | <h3 class=fn>void <a name="setUnchanged"></a>QCanvas::setUnchanged ( const <a href="qrect.html">QRect</a> & area )<tt> [virtual]</tt>
|
---|
505 | </h3>
|
---|
506 | Marks <em>area</em> as <em>unchanged</em>. The area will <em>not</em> be redrawn in
|
---|
507 | the views for the next <a href="#update">update</a>(), unless it is marked or changed
|
---|
508 | again before the next call to update().
|
---|
509 |
|
---|
510 | <h3 class=fn>void <a name="setUpdatePeriod"></a>QCanvas::setUpdatePeriod ( int ms )<tt> [virtual]</tt>
|
---|
511 | </h3>
|
---|
512 | Sets the canvas to call <a href="#update">update</a>() every <em>ms</em> milliseconds. Any
|
---|
513 | previous setting by <a href="#setAdvancePeriod">setAdvancePeriod</a>() or <a href="#setUpdatePeriod">setUpdatePeriod</a>() is
|
---|
514 | overridden.
|
---|
515 | <p> If <em>ms</em> is less than 0 automatic updating will be stopped.
|
---|
516 |
|
---|
517 | <h3 class=fn><a href="qsize.html">QSize</a> <a name="size"></a>QCanvas::size () const
|
---|
518 | </h3>
|
---|
519 |
|
---|
520 | <p> Returns the size of the canvas, in pixels.
|
---|
521 |
|
---|
522 | <h3 class=fn>int <a name="tile"></a>QCanvas::tile ( int x, int y ) const
|
---|
523 | </h3>
|
---|
524 |
|
---|
525 | <p> Returns the tile at position (<em>x</em>, <em>y</em>). Initially, all tiles
|
---|
526 | are 0.
|
---|
527 | <p> The parameters must be within range, i.e.
|
---|
528 | 0 < <em>x</em> < <a href="#tilesHorizontally">tilesHorizontally</a>() and
|
---|
529 | 0 < <em>y</em> < <a href="#tilesVertically">tilesVertically</a>().
|
---|
530 | <p> <p>See also <a href="#setTile">setTile</a>().
|
---|
531 |
|
---|
532 | <h3 class=fn>int <a name="tileHeight"></a>QCanvas::tileHeight () const
|
---|
533 | </h3>
|
---|
534 |
|
---|
535 | <p> Returns the height of each tile.
|
---|
536 |
|
---|
537 | <h3 class=fn>int <a name="tileWidth"></a>QCanvas::tileWidth () const
|
---|
538 | </h3>
|
---|
539 |
|
---|
540 | <p> Returns the width of each tile.
|
---|
541 |
|
---|
542 | <h3 class=fn>int <a name="tilesHorizontally"></a>QCanvas::tilesHorizontally () const
|
---|
543 | </h3>
|
---|
544 |
|
---|
545 | <p> Returns the number of tiles horizontally.
|
---|
546 |
|
---|
547 | <h3 class=fn>int <a name="tilesVertically"></a>QCanvas::tilesVertically () const
|
---|
548 | </h3>
|
---|
549 |
|
---|
550 | <p> Returns the number of tiles vertically.
|
---|
551 |
|
---|
552 | <h3 class=fn>void <a name="update"></a>QCanvas::update ()<tt> [virtual slot]</tt>
|
---|
553 | </h3>
|
---|
554 | Repaints changed areas in all views of the canvas.
|
---|
555 | <p> <p>See also <a href="#advance">advance</a>().
|
---|
556 |
|
---|
557 | <h3 class=fn>bool <a name="validChunk"></a>QCanvas::validChunk ( int x, int y ) const
|
---|
558 | </h3>
|
---|
559 |
|
---|
560 | <p> Returns TRUE if the chunk position (<em>x</em>, <em>y</em>) is on the canvas;
|
---|
561 | otherwise returns FALSE.
|
---|
562 | <p> <p>See also <a href="#onCanvas">onCanvas</a>().
|
---|
563 |
|
---|
564 | <h3 class=fn>bool <a name="validChunk-2"></a>QCanvas::validChunk ( const <a href="qpoint.html">QPoint</a> & p ) const
|
---|
565 | </h3>
|
---|
566 |
|
---|
567 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
568 | <p> Returns TRUE if the chunk position <em>p</em> is on the canvas; otherwise
|
---|
569 | returns FALSE.
|
---|
570 | <p> <p>See also <a href="#onCanvas">onCanvas</a>().
|
---|
571 |
|
---|
572 | <h3 class=fn>int <a name="width"></a>QCanvas::width () const
|
---|
573 | </h3>
|
---|
574 |
|
---|
575 | <p> Returns the width of the canvas, in pixels.
|
---|
576 |
|
---|
577 | <p>Example: <a href="canvas-example.html#x2912">canvas/canvas.cpp</a>.
|
---|
578 | <!-- eof -->
|
---|
579 | <hr><p>
|
---|
580 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
581 | Copyright © 1995-2007
|
---|
582 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
583 | <table width=100% cellspacing=0 border=0><tr>
|
---|
584 | <td>Copyright © 2007
|
---|
585 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
586 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
587 | </table></div></address></body>
|
---|
588 | </html>
|
---|