File: qcanvasitem.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (272 lines) | stat: -rw-r--r-- 18,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QCanvasItem Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>QCanvasItem Class Reference<br><small>[ <a href="canvas.html">canvas module</a> ]</small></h1><br clear="all">
<p>
The QCanvasItem is an abstract graphic object on a <a href="qcanvas.html">QCanvas</a>.
<a href="#details">More...</a>
<p>
<code>#include &lt;<a href="qcanvas-h.html">qcanvas.h</a>&gt;</code>
<p>
Inherits <a href="qt.html">Qt</a>.
<p>Inherited by <a href="qcanvaspolygonalitem.html">QCanvasPolygonalItem</a>, <a href="qcanvassprite.html">QCanvasSprite</a> and <a href="qcanvastext.html">QCanvasText</a>.
<p><a href="qcanvasitem-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#44e613"><b>QCanvasItem</b></a>(QCanvas*canvas)</div>
<li><div class="fn">virtual<a href="#92065a"><b>~QCanvasItem</b></a>()</div>
<li><div class="fn">double<a href="#e0e6af"><b>x</b></a>()const</div>
<li><div class="fn">double<a href="#2eabbd"><b>y</b></a>()const</div>
<li><div class="fn">double<a href="#929f06"><b>z</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#799882"><b>moveBy</b></a>(doubledx, doubledy)</div>
<li><div class="fn">void<a href="#1f1392"><b>move</b></a>(doublex, doubley)</div>
<li><div class="fn">void<a href="#e2d37a"><b>setX</b></a>(doublea)</div>
<li><div class="fn">void<a href="#2b7a8d"><b>setY</b></a>(doublea)</div>
<li><div class="fn">void<a href="#19641b"><b>setZ</b></a>(doublea)</div>
<li><div class="fn">bool<a href="#c79949"><b>animated</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#eeed22"><b>setAnimated</b></a>(booly)</div>
<li><div class="fn">virtualvoid<a href="#eb673b"><b>setVelocity</b></a>(doublevx, doublevy)</div>
<li><div class="fn">void<a href="#0a0d43"><b>setXVelocity</b></a>(doublevx)</div>
<li><div class="fn">void<a href="#cad33c"><b>setYVelocity</b></a>(doublevy)</div>
<li><div class="fn">double<a href="#a7ff10"><b>xVelocity</b></a>()const</div>
<li><div class="fn">double<a href="#957092"><b>yVelocity</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#3bf03d"><b>advance</b></a>(intstage)</div>
<li><div class="fn">virtualbool<a href="#1d22d3"><b>collidesWith</b></a>(constQCanvasItem*)const</div>
<li><div class="fn">QCanvasItemList<a href="#62cd80"><b>collisions</b></a>(boolexact)const</div>
<li><div class="fn">virtualvoid<a href="#52411b"><b>setCanvas</b></a>(QCanvas*)</div>
<li><div class="fn">virtualvoid<a href="#cce3d0"><b>draw</b></a>(QPainter&amp;)</div>
<li><div class="fn">void<a href="#7d6046"><b>show</b></a>()</div>
<li><div class="fn">void<a href="#a4304f"><b>hide</b></a>()</div>
<li><div class="fn">virtualvoid<a href="#fba437"><b>setVisible</b></a>(boolyes)</div>
<li><div class="fn">bool<a href="#9e40c5"><b>visible</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#d6ca3e"><b>setSelected</b></a>(boolyes)</div>
<li><div class="fn">bool<a href="#86b89e"><b>selected</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#f88ef6"><b>setEnabled</b></a>(boolyes)</div>
<li><div class="fn">bool<a href="#226783"><b>enabled</b></a>()const</div>
<li><div class="fn">virtualvoid<a href="#55dfed"><b>setActive</b></a>(boolyes)</div>
<li><div class="fn">bool<a href="#5f2b17"><b>active</b></a>()const</div>
<li><div class="fn">virtualint<a href="#f75ac7"><b>rtti</b></a>()const</div>
<li><div class="fn">virtualQRect<a href="#156958"><b>boundingRect</b></a>()const</div>
<li><div class="fn">virtualQRect<a href="#266f32"><b>boundingRectAdvanced</b></a>()const</div>
<li><div class="fn">QCanvas*<a href="#8b180c"><b>canvas</b></a>()const</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QCanvasItem is an abstract graphic object on a <a href="qcanvas.html">QCanvas</a>.
<p>
A QCanvasItem object can be moved in the <a href="#e0e6af">x</a>(), <a href="#2eabbd">y</a>() and <a href="#929f06">z</a>() dimensions
using functions such as <a href="#1f1392">move</a>(), <a href="#799882">moveBy</a>(), <a href="#2b7a8d">setY</a>() and many others. It
has a size given by <a href="#156958">boundingRect</a>().  The item can move or change
appearance automatically, using <a href="#eeed22">setAnimated</a>() and <a href="#eb673b">setVelocity</a>(), and
you can get information about whether it collides using <a href="#1d22d3">collidesWith</a>()
and <a href="#62cd80">collisions</a>().
<p>Finally, the <a href="#f75ac7">rtti</a>() function is used for identifying subclasses of
QCanvasItem, and the <a href="#8b180c">canvas</a>() returns a pointer to the canvas on which
the item lives.
<p>An item, by default, has no speed, no size, is not animated and has no
velocity.
<p>Note that you cannot easily subclass QCanvasItem yourself - the API is
too low-level.  Instead, you should subclass <a href="qcanvaspolygonalitem.html">QCanvasPolygonalItem</a>, or
perhaps <a href="qcanvasrectangle.html">QCanvasRectangle</a> or <a href="qcanvassprite.html">QCanvasSprite</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="44e613"></a>QCanvasItem::QCanvasItem(<a href="qcanvas.html">QCanvas</a>*canvas)</h3>
<p>Constructs a QCanvasItem on <em>canvas.</em>
<p>See also  <a href="#52411b">setCanvas</a>().
<h3 class="fn"><a name="92065a"></a>QCanvasItem::~QCanvasItem() <code>[virtual]</code></h3>
<p>Destructs the QCanvasItem.  It is removed from its canvas.
<h3 class="fn">bool<a name="5f2b17"></a>QCanvasItem::active()const</h3>
<p>Returns TRUE if the QCanvasItem is active.
<h3 class="fn">void<a name="3bf03d"></a>QCanvasItem::advance(intphase) <code>[virtual]</code></h3>
<p>Advances the animation of the item.  The default implementation
moves the item by the preset velocity if <em>stage</em> is 1, and does
nothing if <em>stage</em> is 0.
<p>Note that if you reimplement this funciton, you may not change the
canvas in any way, add other items, or remove items.
<p>See also  <a href="qcanvas.html#292e63">QCanvas::advance</a>().
<h3 class="fn">bool<a name="c79949"></a>QCanvasItem::animated()const</h3>
<p>Returns TRUE is the item is animated.
<p>See also  <a href="#eb673b">setVelocity</a>() and <a href="#eeed22">setAnimated</a>().
<h3 class="fn"><a href="qrect.html">QRect</a><a name="156958"></a>QCanvasItem::boundingRect()const <code>[virtual]</code></h3>
<p>Returns the bounding rectangle of pixels that the item covers.
<p>See also  <a href="#266f32">boundingRectAdvanced</a>().
<p>Reimplemented in <a href="qcanvastext.html#cd3f03">QCanvasText</a>, <a href="qcanvaspolygonalitem.html#d6f596">QCanvasPolygonalItem</a> and <a href="qcanvassprite.html#107def">QCanvasSprite</a>.
<h3 class="fn"><a href="qrect.html">QRect</a><a name="266f32"></a>QCanvasItem::boundingRectAdvanced()const <code>[virtual]</code></h3>
<p>Returns the bounding rectangle of pixels that the item <em>will</em> cover
after <a href="#3bf03d">advance</a>(1) is called.
<p>See also  <a href="#156958">boundingRect</a>().
<h3 class="fn"><a href="qcanvas.html">QCanvas</a>*<a name="8b180c"></a>QCanvasItem::canvas()const</h3>
<p>Returns the canvas containing the item.
<h3 class="fn">bool<a name="1d22d3"></a>QCanvasItem::collidesWith(constQCanvasItem*other)const <code>[virtual]</code></h3>
<p>Returns TRUE if the item will collide with the <em>other</em> item <em>after</em> they
have moved by their current velocities.
<p>See also  <a href="#62cd80">collisions</a>().
<p>Reimplemented in <a href="qcanvaspolygonalitem.html#45b639">QCanvasPolygonalItem</a>, <a href="qcanvasrectangle.html#f5573d">QCanvasRectangle</a>, <a href="qcanvassprite.html#6e05e0">QCanvasSprite</a>, <a href="qcanvasellipse.html#0e91e8">QCanvasEllipse</a> and <a href="qcanvastext.html#a637ac">QCanvasText</a>.
<h3 class="fn">QCanvasItemList<a name="62cd80"></a>QCanvasItem::collisions(boolexact)const</h3>
<p>Returns the list of items that this item collides with.
<p>A collision is generally defined as pixels of one item drawing on the
pixels of another item, but not all subclasses are so precise. Also,
since pixelwise collision detection can be slow, this function
works in either exact or inexact mode, according to the <em>exact</em>
parameter.
<p>In exact mode, items returned have been accurately tested to collide
with the item.
<p>In inexact mode, the items returned are only <em>near</em> the item and
should be tested using <a href="#1d22d3">collidesWith</a>() if they are interesting collision
candidates. By using this, you can ignore some items for which collisions
are not interesting.
<p>The returned list is just a list of QCanvasItems, but often you will need
to cast the items to more useful types. The safe way to do that is to
use <a href="#f75ac7">rtti</a>() before casting. This provides some of the functionality of
standard C++ dynamic cast operation even on compilers where that is not
available.
<p>Note that while a QCanvasItem may be `on' a <a href="qcanvas.html">QCanvas</a> even if it's
coordinates place it far off the edge of the area of the QCanvas,
collision detection only works for parts of an item
that are within the area of the canvas.
<h3 class="fn">void<a name="cce3d0"></a>QCanvasItem::draw(<a href="qpainter.html">QPainter</a>&amp;painter) <code>[virtual]</code></h3>
<p>This abstract virtual function draws the item using <em>painter.</em>
<p>Reimplemented in <a href="qcanvassprite.html#ae5194">QCanvasSprite</a> and <a href="qcanvaspolygonalitem.html#3656a8">QCanvasPolygonalItem</a>.
<h3 class="fn">bool<a name="226783"></a>QCanvasItem::enabled()const</h3>
<p>Returns TRUE if the QCanvasItem is enabled.
<h3 class="fn">void<a name="a4304f"></a>QCanvasItem::hide()</h3>
<p>Shorthand for <a href="#fba437">setVisible</a>(FALSE).
<h3 class="fn">void<a name="1f1392"></a>QCanvasItem::move(doublex, doubley)</h3>
<p>Moves the item to (<em>x, y)</em> by calling the <a href="#799882">moveBy</a>()
virtual function.
<h3 class="fn">void<a name="799882"></a>QCanvasItem::moveBy(doubledx, doubledy) <code>[virtual]</code></h3>
<p>Moves the item from its current position by the given amounts.
<p>Reimplemented in <a href="qcanvaspolygon.html#7c9c71">QCanvasPolygon</a> and <a href="qcanvastext.html#8b3b2f">QCanvasText</a>.
<h3 class="fn">int<a name="f75ac7"></a>QCanvasItem::rtti()const <code>[virtual]</code></h3>
<p>Returns 0.
<p>Although often frowned upon by purists, Run Time
Type Identification is very useful in this case, as it allows
a <a href="qcanvas.html">QCanvas</a> to be an efficient indexed storage mechanism.
<p>Make your derived classes return their own values for rtti(), and you
can distinguish between objects returned by QCanvas::at().  You should
use values greater than 1000 preferably a large random number,
to allow for extensions to this class.
<p>However, it is important not to overuse this facility, as
it damages extensibility.  For example, once you have identified
a base class of a QCanvasItem found by QCanvas::at(), cast it
to that type and call meaningful methods rather than acting
upon the object based on its rtti value.
<p>For example:
<p><pre>    <a href="qcanvasitem.html">QCanvasItem</a>* item;
    // Find an item, eg. with QCanvasItem::collisions().
    ...
    if (item-&gt;<a href="#f75ac7">rtti</a>() == MySprite::rtti()) {
        MySprite* s = (MySprite*)item;
        if (s-&gt;isDamagable()) s-&gt;loseHitPoints(1000);
        if (s-&gt;isHot()) myself-&gt;loseHitPoints(1000);
        ...
    }
</pre>
<p>Reimplemented in <a href="qcanvasrectangle.html#5353c5">QCanvasRectangle</a>, <a href="qcanvaspolygonalitem.html#e52555">QCanvasPolygonalItem</a>, <a href="qcanvasline.html#391039">QCanvasLine</a>, <a href="qcanvasellipse.html#c784c6">QCanvasEllipse</a> and <a href="qcanvaspolygon.html#03cb08">QCanvasPolygon</a>.
<h3 class="fn">bool<a name="86b89e"></a>QCanvasItem::selected()const</h3>
<p>Returns TRUE if the QCanvasItem is selected.
<h3 class="fn">void<a name="55dfed"></a>QCanvasItem::setActive(boolyes) <code>[virtual]</code></h3>
<p>Sets the active flag of the item to <em>yes</em> and causes it to be
redrawn when <a href="qcanvas.html#16e8be">QCanvas::update</a>() is next called.
<p>The behavior of <a href="qcanvas.html">QCanvas</a>, QCanvasItem or the built-in QCanvasItem
subclasses is not affected by this value.  setActive() is supplied
because many applications need it, but it is up to the application
to define its exact meaning.
<h3 class="fn">void<a name="eeed22"></a>QCanvasItem::setAnimated(booly) <code>[virtual]</code></h3>
<p>Sets the item to be animated if <em>y</em> is TRUE, or not if <em>y</em> is
FALSE.
<p>See also  <a href="#3bf03d">advance</a>() and <a href="qcanvas.html#292e63">QCanvas::advance</a>().
<h3 class="fn">void<a name="52411b"></a>QCanvasItem::setCanvas(<a href="qcanvas.html">QCanvas</a>*c) <code>[virtual]</code></h3>
<p>Sets the <a href="qcanvas.html">QCanvas</a> upon which the QCanvasItem is to be drawn to <em>c.</em>
<p>See also  <a href="#8b180c">canvas</a>().
<h3 class="fn">void<a name="f88ef6"></a>QCanvasItem::setEnabled(boolyes) <code>[virtual]</code></h3>
<p>Sets the enabled flag of the item to <em>yes</em> and causes it to be
redrawn when <a href="qcanvas.html#16e8be">QCanvas::update</a>() is next called.
<p>The behavior of <a href="qcanvas.html">QCanvas</a>, QCanvasItem or the built-in QCanvasItem
subclasses is not affected by this value.  setEnabled() is supplied
because many applications need it, but it is up to the application
to define its exact meaning.
<h3 class="fn">void<a name="d6ca3e"></a>QCanvasItem::setSelected(boolyes) <code>[virtual]</code></h3>
<p>Sets the selected flag of the item to <em>yes</em> and causes it to be
redrawn when <a href="qcanvas.html#16e8be">QCanvas::update</a>() is next called.
<p>The behavior of <a href="qcanvas.html">QCanvas</a>, QCanvasItem or the built-in QCanvasItem
subclasses is not affected by this value.  setSelected() is supplied
because many applications need it, but it is up to the application
to define its exact meaning.
<h3 class="fn">void<a name="eb673b"></a>QCanvasItem::setVelocity(doublevx, doublevy) <code>[virtual]</code></h3>
<p>Sets the item to be animated and moving by <em>dx</em> and <em>dy</em> pixels
in the horizontal and vertical directions respectively.
<p>See also  <a href="#3bf03d">advance</a>().
<h3 class="fn">void<a name="fba437"></a>QCanvasItem::setVisible(boolyes) <code>[virtual]</code></h3>
<p>Makes the items visible if <em>yes</em> is TRUE, or invisible if <em>yes</em>
is FALSE.  The change takes effect when <a href="qcanvas.html#16e8be">QCanvas::update</a>() is next
called.
<h3 class="fn">void<a name="e2d37a"></a>QCanvasItem::setX(doublex)</h3>
<p>Moves the item so that its X-position is <em>x.</em>
<p>See also  <a href="#e0e6af">x</a>() and <a href="#1f1392">move</a>().
<h3 class="fn">void<a name="0a0d43"></a>QCanvasItem::setXVelocity(doublevx)</h3>
<p>Sets the horizontal component of the item's velocity to <em>vx.</em>
<h3 class="fn">void<a name="2b7a8d"></a>QCanvasItem::setY(doubley)</h3>
<p>Moves the item so that its Y-position is <em>y.</em>
<p>See also  <a href="#2eabbd">y</a>() and <a href="#1f1392">move</a>().
<h3 class="fn">void<a name="cad33c"></a>QCanvasItem::setYVelocity(doublevy)</h3>
<p>Sets the vertical component of the item's velocity to <em>vy.</em>
<h3 class="fn">void<a name="19641b"></a>QCanvasItem::setZ(doublez)</h3>
<p>Sets the height of the item to <em>z.</em>  Higher-z items obscure lower-z
ones.
<p>See also  <a href="#929f06">z</a>() and <a href="#1f1392">move</a>().
<h3 class="fn">void<a name="7d6046"></a>QCanvasItem::show()</h3>
<p>Shorthand for <a href="#fba437">setVisible</a>(TRUE).
<h3 class="fn">bool<a name="9e40c5"></a>QCanvasItem::visible()const</h3>
<p>Returns TRUE if the QCanvasItem is visible.  This does <em>not</em> mean
the QCanvasItem is currently in a view, merely that if a view is
showing the area where the QCanvasItem is, and the item is not
obscured by items at a higher z, and the view is not obscured by
overlying windows, it would be visible.
<p>See also  <a href="#fba437">setVisible</a>() and <a href="#929f06">z</a>().
<h3 class="fn">double<a name="e0e6af"></a>QCanvasItem::x()const</h3>
<p>Returns the horizontal position of the item.  Note that subclasses
often have an origin other than the top-left corner.
<h3 class="fn">double<a name="a7ff10"></a>QCanvasItem::xVelocity()const</h3>
<p>Returns the horizontal component of the velocity of the item.
<h3 class="fn">double<a name="2eabbd"></a>QCanvasItem::y()const</h3>
<p>Returns the vertical position of the item.  Note that subclasses
often have an origin other than the top-left corner.
<h3 class="fn">double<a name="957092"></a>QCanvasItem::yVelocity()const</h3>
<p>Returns the vertical component of the velocity of the item.
<h3 class="fn">double<a name="929f06"></a>QCanvasItem::z()const</h3>
<p>Returns the z height of the item, which is used for visual order:
higher-z items obscure lower-z ones.
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright &copy; 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>