author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
/*! |
|
43 |
\class QGraphicsItem |
|
44 |
\brief The QGraphicsItem class is the base class for all graphical |
|
45 |
items in a QGraphicsScene. |
|
46 |
\since 4.2 |
|
47 |
||
48 |
\ingroup graphicsview-api |
|
49 |
||
50 |
It provides a light-weight foundation for writing your own custom items. |
|
51 |
This includes defining the item's geometry, collision detection, its |
|
52 |
painting implementation and item interaction through its event handlers. |
|
53 |
QGraphicsItem is part of \l{The Graphics View Framework} |
|
54 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
\image graphicsview-items.png |
0 | 56 |
|
57 |
For convenience, Qt provides a set of standard graphics items for the most |
|
58 |
common shapes. These are: |
|
59 |
||
60 |
\list |
|
61 |
\o QGraphicsEllipseItem provides an ellipse item |
|
62 |
\o QGraphicsLineItem provides a line item |
|
63 |
\o QGraphicsPathItem provides an arbitrary path item |
|
64 |
\o QGraphicsPixmapItem provides a pixmap item |
|
65 |
\o QGraphicsPolygonItem provides a polygon item |
|
66 |
\o QGraphicsRectItem provides a rectangular item |
|
67 |
\o QGraphicsSimpleTextItem provides a simple text label item |
|
68 |
\o QGraphicsTextItem provides an advanced text browser item |
|
69 |
\endlist |
|
70 |
||
71 |
All of an item's geometric information is based on its local coordinate |
|
72 |
system. The item's position, pos(), is the only function that does not |
|
73 |
operate in local coordinates, as it returns a position in parent |
|
74 |
coordinates. \l {The Graphics View Coordinate System} describes the coordinate |
|
75 |
system in detail. |
|
76 |
||
77 |
You can set whether an item should be visible (i.e., drawn, and accepting |
|
78 |
events), by calling setVisible(). Hiding an item will also hide its |
|
79 |
children. Similarly, you can enable or disable an item by calling |
|
80 |
setEnabled(). If you disable an item, all its children will also be |
|
81 |
disabled. By default, items are both visible and enabled. To toggle |
|
82 |
whether an item is selected or not, first enable selection by setting |
|
83 |
the ItemIsSelectable flag, and then call setSelected(). Normally, |
|
84 |
selection is toggled by the scene, as a result of user interaction. |
|
85 |
||
86 |
To write your own graphics item, you first create a subclass of |
|
87 |
QGraphicsItem, and then start by implementing its two pure virtual public |
|
88 |
functions: boundingRect(), which returns an estimate of the area painted |
|
89 |
by the item, and paint(), which implements the actual painting. For |
|
90 |
example: |
|
91 |
||
92 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 0 |
|
93 |
||
94 |
The boundingRect() function has many different purposes. |
|
95 |
QGraphicsScene bases its item index on boundingRect(), and |
|
96 |
QGraphicsView uses it both for culling invisible items, and for |
|
97 |
determining the area that needs to be recomposed when drawing |
|
98 |
overlapping items. In addition, QGraphicsItem's collision |
|
99 |
detection mechanisms use boundingRect() to provide an efficient |
|
100 |
cut-off. The fine grained collision algorithm in |
|
101 |
collidesWithItem() is based on calling shape(), which returns an |
|
102 |
accurate outline of the item's shape as a QPainterPath. |
|
103 |
||
104 |
QGraphicsScene expects all items boundingRect() and shape() to |
|
105 |
remain unchanged unless it is notified. If you want to change an |
|
106 |
item's geometry in any way, you must first call |
|
107 |
prepareGeometryChange() to allow QGraphicsScene to update its |
|
108 |
bookkeeping. |
|
109 |
||
110 |
Collision detection can be done in two ways: |
|
111 |
||
112 |
\list 1 |
|
113 |
||
114 |
\o Reimplement shape() to return an accurate shape for your item, |
|
115 |
and rely on the default implementation of collidesWithItem() to do |
|
116 |
shape-shape intersection. This can be rather expensive if the |
|
117 |
shapes are complex. |
|
118 |
||
119 |
\o Reimplement collidesWithItem() to provide your own custom item |
|
120 |
and shape collision algorithm. |
|
121 |
||
122 |
\endlist |
|
123 |
||
124 |
The contains() function can be called to determine whether the item \e |
|
125 |
contains a point or not. This function can also be reimplemented by the |
|
126 |
item. The default behavior of contains() is based on calling shape(). |
|
127 |
||
128 |
Items can contain other items, and also be contained by other items. All |
|
129 |
items can have a parent item and a list of children. Unless the item has |
|
130 |
no parent, its position is in \e parent coordinates (i.e., the parent's |
|
131 |
local coordinates). Parent items propagate both their position and their |
|
132 |
transformation to all children. |
|
133 |
||
134 |
\img graphicsview-parentchild.png |
|
135 |
||
136 |
\section1 Transformation |
|
137 |
||
138 |
QGraphicsItem supports projective transformations in addition to its base |
|
139 |
position, pos(). There are several ways to change an item's transformation. |
|
140 |
For simple transformations, you can call either of the convenience |
|
141 |
functions setRotation() or setScale(), or you can pass any transformation |
|
142 |
matrix to setTransform(). For advanced transformation control you also have |
|
143 |
the option of setting several combined transformations by calling |
|
144 |
setTransformations(). |
|
145 |
||
146 |
Item transformations accumulate from parent to child, so if both a parent |
|
147 |
and child item are rotated 90 degrees, the child's total transformation |
|
148 |
will be 180 degrees. Similarly, if the item's parent is scaled to 2x its |
|
149 |
original size, its children will also be twice as large. An item's |
|
150 |
transformation does not affect its own local geometry; all geometry |
|
151 |
functions (e.g., contains(), update(), and all the mapping functions) still |
|
152 |
operate in local coordinates. For convenience, QGraphicsItem provides the |
|
153 |
functions sceneTransform(), which returns the item's total transformation |
|
154 |
matrix (including its position and all parents' positions and |
|
155 |
transformations), and scenePos(), which returns its position in scene |
|
156 |
coordinates. To reset an item's matrix, call resetTransform(). |
|
157 |
||
158 |
Certain transformation operations produce a different outcome depending on |
|
159 |
the order in which they are applied. For example, if you scale an |
|
160 |
transform, and then rotate it, you may get a different result than if the |
|
161 |
transform was rotated first. However, the order you set the transformation |
|
162 |
properties on QGraphicsItem does not affect the resulting transformation; |
|
163 |
QGraphicsItem always applies the properties in a fixed, defined order: |
|
164 |
||
165 |
\list |
|
166 |
\o The item's base transform is applied (transform()) |
|
167 |
\o The item's transformations list is applied in order (transformations()) |
|
168 |
\o The item is rotated relative to its transform origin point (rotation(), transformOriginPoint()) |
|
169 |
\o The item is scaled relative to its transform origin point (scale(), transformOriginPoint()) |
|
170 |
\endlist |
|
171 |
||
172 |
\section1 Painting |
|
173 |
||
174 |
The paint() function is called by QGraphicsView to paint the item's |
|
175 |
contents. The item has no background or default fill of its own; whatever |
|
176 |
is behind the item will shine through all areas that are not explicitly |
|
177 |
painted in this function. You can call update() to schedule a repaint, |
|
178 |
optionally passing the rectangle that needs a repaint. Depending on |
|
179 |
whether or not the item is visible in a view, the item may or may not be |
|
180 |
repainted; there is no equivalent to QWidget::repaint() in QGraphicsItem. |
|
181 |
||
182 |
Items are painted by the view, starting with the parent items and then |
|
183 |
drawing children, in ascending stacking order. You can set an item's |
|
184 |
stacking order by calling setZValue(), and test it by calling |
|
185 |
zValue(), where items with low z-values are painted before items with |
|
186 |
high z-values. Stacking order applies to sibling items; parents are always |
|
187 |
drawn before their children. |
|
188 |
||
189 |
\section1 Sorting |
|
190 |
||
191 |
All items are drawn in a defined, stable order, and this same order decides |
|
192 |
which items will receive mouse input first when you click on the scene. |
|
193 |
Normally you don't have to worry about sorting, as the items follow a |
|
194 |
"natural order", following the logical structure of the scene. |
|
195 |
||
196 |
An item's children are stacked on top of the parent, and sibling items are |
|
197 |
stacked by insertion order (i.e., in the same order that they were either |
|
198 |
added to the scene, or added to the same parent). If you add item A, and |
|
199 |
then B, then B will be on top of A. If you then add C, the items' stacking |
|
200 |
order will be A, then B, then C. |
|
201 |
||
202 |
\image graphicsview-zorder.png |
|
203 |
||
204 |
This example shows the stacking order of all limbs of the robot from the |
|
205 |
\l{graphicsview/dragdroprobot}{Drag and Drop Robot} example. The torso is |
|
206 |
the root item (all other items are children or descendants of the torso), |
|
207 |
so it is drawn first. Next, the head is drawn, as it is the first item in |
|
208 |
the torso's list of children. Then the upper left arm is drawn. As the |
|
209 |
lower arm is a child of the upper arm, the lower arm is then drawn, |
|
210 |
followed by the upper arm's next sibling, which is the upper right arm, and |
|
211 |
so on. |
|
212 |
||
213 |
For advanced users, there are ways to alter how your items are sorted: |
|
214 |
||
215 |
\list |
|
216 |
\o You can call setZValue() on an item to explicitly stack it on top of, or |
|
217 |
under, other sibling items. The default Z value for an item is 0. Items |
|
218 |
with the same Z value are stacked by insertion order. |
|
219 |
||
220 |
\o You can call stackBefore() to reorder the list of children. This will |
|
221 |
directly modify the insertion order. |
|
222 |
||
223 |
\o You can set the ItemStacksBehindParent flag to stack a child item behind |
|
224 |
its parent. |
|
225 |
\endlist |
|
226 |
||
227 |
The stacking order of two sibling items also counts for each item's |
|
228 |
children and descendant items. So if one item is on top of another, then |
|
229 |
all its children will also be on top of all the other item's children as |
|
230 |
well. |
|
231 |
||
232 |
\section1 Events |
|
233 |
||
234 |
QGraphicsItem receives events from QGraphicsScene through the virtual |
|
235 |
function sceneEvent(). This function distributes the most common events |
|
236 |
to a set of convenience event handlers: |
|
237 |
||
238 |
\list |
|
239 |
\o contextMenuEvent() handles context menu events |
|
240 |
\o focusInEvent() and focusOutEvent() handle focus in and out events |
|
241 |
\o hoverEnterEvent(), hoverMoveEvent(), and hoverLeaveEvent() handles |
|
242 |
hover enter, move and leave events |
|
243 |
\o inputMethodEvent() handles input events, for accessibility support |
|
244 |
\o keyPressEvent() and keyReleaseEvent() handle key press and release events |
|
245 |
\o mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), and |
|
246 |
mouseDoubleClickEvent() handles mouse press, move, release, click and |
|
247 |
doubleclick events |
|
248 |
\endlist |
|
249 |
||
250 |
You can filter events for any other item by installing event filters. This |
|
251 |
functionality is separate from Qt's regular event filters (see |
|
252 |
QObject::installEventFilter()), which only work on subclasses of QObject. After |
|
253 |
installing your item as an event filter for another item by calling |
|
254 |
installSceneEventFilter(), the filtered events will be received by the virtual |
|
255 |
function sceneEventFilter(). You can remove item event filters by calling |
|
256 |
removeSceneEventFilter(). |
|
257 |
||
258 |
\section1 Custom Data |
|
259 |
||
260 |
Sometimes it's useful to register custom data with an item, be it a custom |
|
261 |
item, or a standard item. You can call setData() on any item to store data |
|
262 |
in it using a key-value pair (the key being an integer, and the value is a |
|
263 |
QVariant). To get custom data from an item, call data(). This |
|
264 |
functionality is completely untouched by Qt itself; it is provided for the |
|
265 |
user's convenience. |
|
266 |
||
267 |
\sa QGraphicsScene, QGraphicsView, {The Graphics View Framework} |
|
268 |
*/ |
|
269 |
||
270 |
/*! |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
271 |
\variable QGraphicsItem::Type |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
272 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
273 |
The type value returned by the virtual type() function in standard |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
274 |
graphics item classes in Qt. All such standard graphics item |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
275 |
classes in Qt are associated with a unique value for Type, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
276 |
e.g. the value returned by QGraphicsPathItem::type() is 2. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
277 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
278 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 18 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
279 |
*/ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
280 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
281 |
/*! |
0 | 282 |
\variable QGraphicsItem::UserType |
283 |
||
284 |
The lowest permitted type value for custom items (subclasses |
|
285 |
of QGraphicsItem or any of the standard items). This value is |
|
286 |
used in conjunction with a reimplementation of QGraphicsItem::type() |
|
287 |
and declaring a Type enum value. Example: |
|
288 |
||
289 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 1 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
290 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
291 |
\note UserType = 65536 |
0 | 292 |
*/ |
293 |
||
294 |
/*! |
|
295 |
\enum QGraphicsItem::GraphicsItemFlag |
|
296 |
||
297 |
This enum describes different flags that you can set on an item to |
|
298 |
toggle different features in the item's behavior. |
|
299 |
||
300 |
All flags are disabled by default. |
|
301 |
||
302 |
\value ItemIsMovable The item supports interactive movement using |
|
303 |
the mouse. By clicking on the item and then dragging, the item |
|
304 |
will move together with the mouse cursor. If the item has |
|
305 |
children, all children are also moved. If the item is part of a |
|
306 |
selection, all selected items are also moved. This feature is |
|
307 |
provided as a convenience through the base implementation of |
|
308 |
QGraphicsItem's mouse event handlers. |
|
309 |
||
310 |
\value ItemIsSelectable The item supports selection. Enabling this |
|
311 |
feature will enable setSelected() to toggle selection for the |
|
312 |
item. It will also let the item be selected automatically as a |
|
313 |
result of calling QGraphicsScene::setSelectionArea(), by clicking |
|
314 |
on an item, or by using rubber band selection in QGraphicsView. |
|
315 |
||
316 |
\value ItemIsFocusable The item supports keyboard input focus (i.e., it is |
|
317 |
an input item). Enabling this flag will allow the item to accept focus, |
|
318 |
which again allows the delivery of key events to |
|
319 |
QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent(). |
|
320 |
||
321 |
\value ItemClipsToShape The item clips to its own shape. The item cannot |
|
322 |
draw or receive mouse, tablet, drag and drop or hover events outside ts |
|
323 |
shape. It is disabled by default. This behavior is enforced by |
|
324 |
QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was |
|
325 |
introduced in Qt 4.3. |
|
326 |
||
327 |
\value ItemClipsChildrenToShape The item clips the painting of all its |
|
328 |
descendants to its own shape. Items that are either direct or indirect |
|
329 |
children of this item cannot draw outside this item's shape. By default, |
|
330 |
this flag is disabled; children can draw anywhere. This behavior is |
|
331 |
enforced by QGraphicsView::drawItems() or |
|
332 |
QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3. |
|
333 |
||
334 |
\value ItemIgnoresTransformations The item ignores inherited |
|
335 |
transformations (i.e., its position is still anchored to its parent, but |
|
336 |
the parent or view rotation, zoom or shear transformations are ignored). |
|
337 |
This flag is useful for keeping text label items horizontal and unscaled, |
|
338 |
so they will still be readable if the view is transformed. When set, the |
|
339 |
item's view geometry and scene geometry will be maintained separately. You |
|
340 |
must call deviceTransform() to map coordinates and detect collisions in |
|
341 |
the view. By default, this flag is disabled. This flag was introduced in |
|
342 |
Qt 4.3. \note With this flag set you can still scale the item itself, and |
|
343 |
that scale transformation will influence the item's children. |
|
344 |
||
345 |
\value ItemIgnoresParentOpacity The item ignores its parent's opacity. The |
|
346 |
item's effective opacity is the same as its own; it does not combine with |
|
347 |
the parent's opacity. This flags allows your item to keep its absolute |
|
348 |
opacity even if the parent is semitransparent. This flag was introduced in |
|
349 |
Qt 4.5. |
|
350 |
||
351 |
\value ItemDoesntPropagateOpacityToChildren The item doesn't propagate its |
|
352 |
opacity to its children. This flag allows you to create a semitransparent |
|
353 |
item that does not affect the opacity of its children. This flag was |
|
354 |
introduced in Qt 4.5. |
|
355 |
||
356 |
\value ItemStacksBehindParent The item is stacked behind its parent. By |
|
357 |
default, child items are stacked on top of the parent item. But setting |
|
358 |
this flag, the child will be stacked behind it. This flag is useful for |
|
359 |
drop shadow effects and for decoration objects that follow the parent |
|
360 |
item's geometry without drawing on top of it. |
|
361 |
||
362 |
\value ItemUsesExtendedStyleOption The item makes use of either |
|
363 |
\l{QStyleOptionGraphicsItem::}{exposedRect} or |
|
364 |
\l{QStyleOptionGraphicsItem::}{matrix} in QStyleOptionGraphicsItem. By default, |
|
365 |
the \l{QStyleOptionGraphicsItem::}{exposedRect} is initialized to the item's |
|
366 |
boundingRect() and the \l{QStyleOptionGraphicsItem::}{matrix} is untransformed. |
|
367 |
You can enable this flag for the style options to be set up with more |
|
368 |
fine-grained values. |
|
369 |
Note that QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag |
|
370 |
and always initialized to 1. Use |
|
371 |
QStyleOptionGraphicsItem::levelOfDetailFromTransform() if you need a higher |
|
372 |
value. |
|
373 |
||
374 |
\value ItemHasNoContents The item does not paint anything (i.e., calling |
|
375 |
paint() on the item has no effect). You should set this flag on items that |
|
376 |
do not need to be painted to ensure that Graphics View avoids unnecessary |
|
377 |
painting preparations. This flag was introduced in Qt 4.6. |
|
378 |
||
379 |
\value ItemSendsGeometryChanges The item enables itemChange() |
|
380 |
notifications for ItemPositionChange, ItemPositionHasChanged, |
|
381 |
ItemMatrixChange, ItemTransformChange, and ItemTransformHasChanged. For |
|
382 |
performance reasons, these notifications are disabled by default. You must |
|
383 |
enable this flag to receive notifications for position and transform |
|
384 |
changes. This flag was introduced in Qt 4.6. |
|
385 |
||
386 |
\value ItemAcceptsInputMethod The item supports input methods typically |
|
387 |
used for Asian languages. |
|
388 |
This flag was introduced in Qt 4.6. |
|
389 |
||
390 |
\value ItemNegativeZStacksBehindParent The item automatically stacks behind |
|
391 |
it's parent if it's z-value is negative. This flag enables setZValue() to |
|
392 |
toggle ItemStacksBehindParent. |
|
393 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
\value ItemIsPanel The item is a panel. A panel provides activation and |
0 | 395 |
contained focus handling. Only one panel can be active at a time (see |
396 |
QGraphicsItem::isActive()). When no panel is active, QGraphicsScene |
|
397 |
activates all non-panel items. Window items (i.e., |
|
398 |
QGraphicsItem::isWindow() returns true) are panels. This flag was |
|
399 |
introduced in Qt 4.6. |
|
400 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
\omitvalue ItemIsFocusScope \omit Internal only (for now). \endomit |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
\value ItemSendsScenePositionChanges The item enables itemChange() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
notifications for ItemScenePositionHasChanged. For performance reasons, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
these notifications are disabled by default. You must enable this flag |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
to receive notifications for scene position changes. This flag was |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
introduced in Qt 4.6. |
0 | 408 |
*/ |
409 |
||
410 |
/*! |
|
411 |
\enum QGraphicsItem::GraphicsItemChange |
|
412 |
||
413 |
ItemVisibleHasChanged, |
|
414 |
ItemEnabledHasChanged, |
|
415 |
ItemSelectedHasChanged, |
|
416 |
ItemParentHasChanged, |
|
417 |
ItemSceneHasChanged |
|
418 |
||
419 |
This enum describes the state changes that are notified by |
|
420 |
QGraphicsItem::itemChange(). The notifications are sent as the state |
|
421 |
changes, and in some cases, adjustments can be made (see the documentation |
|
422 |
for each change for details). |
|
423 |
||
424 |
Note: Be careful with calling functions on the QGraphicsItem itself inside |
|
425 |
itemChange(), as certain function calls can lead to unwanted |
|
426 |
recursion. For example, you cannot call setPos() in itemChange() on an |
|
427 |
ItemPositionChange notification, as the setPos() function will again call |
|
428 |
itemChange(ItemPositionChange). Instead, you can return the new, adjusted |
|
429 |
position from itemChange(). |
|
430 |
||
431 |
\value ItemEnabledChange The item's enabled state changes. If the item is |
|
432 |
presently enabled, it will become disabled, and vice verca. The value |
|
433 |
argument is the new enabled state (i.e., true or false). Do not call |
|
434 |
setEnabled() in itemChange() as this notification is delivered. Instead, |
|
435 |
you can return the new state from itemChange(). |
|
436 |
||
437 |
\value ItemEnabledHasChanged The item's enabled state has changed. The |
|
438 |
value argument is the new enabled state (i.e., true or false). Do not call |
|
439 |
setEnabled() in itemChange() as this notification is delivered. The return |
|
440 |
value is ignored. |
|
441 |
||
442 |
\value ItemMatrixChange The item's affine transformation matrix is |
|
443 |
changing. This value is obsolete; you can use ItemTransformChange instead. |
|
444 |
||
445 |
\value ItemPositionChange The item's position changes. This notification |
|
446 |
is sent if the ItemSendsGeometryChanges flag is enabled, and when the |
|
447 |
item's local position changes, relative to its parent (i.e., as a result |
|
448 |
of calling setPos() or moveBy()). The value argument is the new position |
|
449 |
(i.e., a QPointF). You can call pos() to get the original position. Do |
|
450 |
not call setPos() or moveBy() in itemChange() as this notification is |
|
451 |
delivered; instead, you can return the new, adjusted position from |
|
452 |
itemChange(). After this notification, QGraphicsItem immediately sends the |
|
453 |
ItemPositionHasChanged notification if the position changed. |
|
454 |
||
455 |
\value ItemPositionHasChanged The item's position has changed. This |
|
456 |
notification is sent if the ItemSendsGeometryChanges flag is enabled, and |
|
457 |
after the item's local position, relative to its parent, has changed. The |
|
458 |
value argument is the new position (the same as pos()), and QGraphicsItem |
|
459 |
ignores the return value for this notification (i.e., a read-only |
|
460 |
notification). |
|
461 |
||
462 |
\value ItemTransformChange The item's transformation matrix changes. This |
|
463 |
notification is send if the ItemSendsGeometryChanges flag is enabled, and |
|
464 |
when the item's local transformation matrix changes (i.e., as a result of |
|
465 |
calling setTransform(). The value argument is the new matrix (i.e., a |
|
466 |
QTransform); to get the old matrix, call transform(). Do not call |
|
467 |
setTransform() or set any of the transformation properties in itemChange() |
|
468 |
as this notification is delivered; instead, you can return the new matrix |
|
469 |
from itemChange(). This notification is not sent if you change the |
|
470 |
transformation properties. |
|
471 |
||
472 |
\value ItemTransformHasChanged The item's transformation matrix has |
|
473 |
changed either because setTransform is called, or one of the |
|
474 |
transformation properties is changed. This notification is sent if the |
|
475 |
ItemSendsGeometryChanges flag is enabled, and after the item's local |
|
476 |
transformation matrix has changed. The value argument is the new matrix |
|
477 |
(same as transform()), and QGraphicsItem ignores the return value for this |
|
478 |
notification (i.e., a read-only notification). |
|
479 |
||
480 |
\value ItemSelectedChange The item's selected state changes. If the item is |
|
481 |
presently selected, it will become unselected, and vice verca. The value |
|
482 |
argument is the new selected state (i.e., true or false). Do not call |
|
483 |
setSelected() in itemChange() as this notification is delivered; instead, you |
|
484 |
can return the new selected state from itemChange(). |
|
485 |
||
486 |
\value ItemSelectedHasChanged The item's selected state has changed. The |
|
487 |
value argument is the new selected state (i.e., true or false). Do not |
|
488 |
call setSelected() in itemChange() as this notification is delivered. The |
|
489 |
return value is ignored. |
|
490 |
||
491 |
\value ItemVisibleChange The item's visible state changes. If the item is |
|
492 |
presently visible, it will become invisible, and vice verca. The value |
|
493 |
argument is the new visible state (i.e., true or false). Do not call |
|
494 |
setVisible() in itemChange() as this notification is delivered; instead, |
|
495 |
you can return the new visible state from itemChange(). |
|
496 |
||
497 |
\value ItemVisibleHasChanged The item's visible state has changed. The |
|
498 |
value argument is the new visible state (i.e., true or false). Do not call |
|
499 |
setVisible() in itemChange() as this notification is delivered. The return |
|
500 |
value is ignored. |
|
501 |
||
502 |
\value ItemParentChange The item's parent changes. The value argument is |
|
503 |
the new parent item (i.e., a QGraphicsItem pointer). Do not call |
|
504 |
setParentItem() in itemChange() as this notification is delivered; |
|
505 |
instead, you can return the new parent from itemChange(). |
|
506 |
||
507 |
\value ItemParentHasChanged The item's parent has changed. The value |
|
508 |
argument is the new parent (i.e., a pointer to a QGraphicsItem). Do not |
|
509 |
call setParentItem() in itemChange() as this notification is |
|
510 |
delivered. The return value is ignored. |
|
511 |
||
512 |
\value ItemChildAddedChange A child is added to this item. The value |
|
513 |
argument is the new child item (i.e., a QGraphicsItem pointer). Do not |
|
514 |
pass this item to any item's setParentItem() function as this notification |
|
515 |
is delivered. The return value is unused; you cannot adjust anything in |
|
516 |
this notification. Note that the new child might not be fully constructed |
|
517 |
when this notification is sent; calling pure virtual functions on |
|
518 |
the child can lead to a crash. |
|
519 |
||
520 |
\value ItemChildRemovedChange A child is removed from this item. The value |
|
521 |
argument is the child item that is about to be removed (i.e., a |
|
522 |
QGraphicsItem pointer). The return value is unused; you cannot adjust |
|
523 |
anything in this notification. |
|
524 |
||
525 |
\value ItemSceneChange The item is moved to a new scene. This notification |
|
526 |
is also sent when the item is added to its initial scene, and when it is |
|
527 |
removed. The value argument is the new scene (i.e., a QGraphicsScene |
|
528 |
pointer), or a null pointer if the item is removed from a scene. Do not |
|
529 |
override this change by passing this item to QGraphicsScene::addItem() as |
|
530 |
this notification is delivered; instead, you can return the new scene from |
|
531 |
itemChange(). Use this feature with caution; objecting to a scene change can |
|
532 |
quickly lead to unwanted recursion. |
|
533 |
||
534 |
\value ItemSceneHasChanged The item's scene has changed. The value |
|
535 |
argument is the new scene (i.e., a pointer to a QGraphicsScene). Do not |
|
536 |
call setScene() in itemChange() as this notification is delivered. The |
|
537 |
return value is ignored. |
|
538 |
||
539 |
\value ItemCursorChange The item's cursor changes. The value argument is |
|
540 |
the new cursor (i.e., a QCursor). Do not call setCursor() in itemChange() |
|
541 |
as this notification is delivered. Instead, you can return a new cursor |
|
542 |
from itemChange(). |
|
543 |
||
544 |
\value ItemCursorHasChanged The item's cursor has changed. The value |
|
545 |
argument is the new cursor (i.e., a QCursor). Do not call setCursor() as |
|
546 |
this notification is delivered. The return value is ignored. |
|
547 |
||
548 |
\value ItemToolTipChange The item's tooltip changes. The value argument is |
|
549 |
the new tooltip (i.e., a QToolTip). Do not call setToolTip() in |
|
550 |
itemChange() as this notification is delivered. Instead, you can return a |
|
551 |
new tooltip from itemChange(). |
|
552 |
||
553 |
\value ItemToolTipHasChanged The item's tooltip has changed. The value |
|
554 |
argument is the new tooltip (i.e., a QToolTip). Do not call setToolTip() |
|
555 |
as this notification is delivered. The return value is ignored. |
|
556 |
||
557 |
\value ItemFlagsChange The item's flags change. The value argument is the |
|
558 |
new flags (i.e., a quint32). Do not call setFlags() in itemChange() as |
|
559 |
this notification is delivered. Instead, you can return the new flags from |
|
560 |
itemChange(). |
|
561 |
||
562 |
\value ItemFlagsHaveChanged The item's flags have changed. The value |
|
563 |
argument is the new flags (i.e., a quint32). Do not call setFlags() in |
|
564 |
itemChange() as this notification is delivered. The return value is |
|
565 |
ignored. |
|
566 |
||
567 |
\value ItemZValueChange The item's Z-value changes. The value argument is |
|
568 |
the new Z-value (i.e., a double). Do not call setZValue() in itemChange() |
|
569 |
as this notification is delivered. Instead, you can return a new Z-value |
|
570 |
from itemChange(). |
|
571 |
||
572 |
\value ItemZValueHasChanged The item's Z-value has changed. The value |
|
573 |
argument is the new Z-value (i.e., a double). Do not call setZValue() as |
|
574 |
this notification is delivered. The return value is ignored. |
|
575 |
||
576 |
\value ItemOpacityChange The item's opacity changes. The value argument is |
|
577 |
the new opacity (i.e., a double). Do not call setOpacity() in itemChange() |
|
578 |
as this notification is delivered. Instead, you can return a new opacity |
|
579 |
from itemChange(). |
|
580 |
||
581 |
\value ItemOpacityHasChanged The item's opacity has changed. The value |
|
582 |
argument is the new opacity (i.e., a double). Do not call setOpacity() as |
|
583 |
this notification is delivered. The return value is ignored. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
\value ItemScenePositionHasChanged The item's scene position has changed. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
This notification is sent if the ItemSendsScenePositionChanges flag is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
enabled, and after the item's scene position has changed (i.e., the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
position or transformation of the item itself or the position or |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
589 |
transformation of any ancestor has changed). The value argument is the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
new scene position (the same as scenePos()), and QGraphicsItem ignores |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
591 |
the return value for this notification (i.e., a read-only notification). |
0 | 592 |
*/ |
593 |
||
594 |
/*! |
|
595 |
\enum QGraphicsItem::CacheMode |
|
596 |
\since 4.4 |
|
597 |
||
598 |
This enum describes QGraphicsItem's cache modes. Caching is used to speed |
|
599 |
up rendering by allocating and rendering to an off-screen pixel buffer, |
|
600 |
which can be reused when the item requires redrawing. For some paint |
|
601 |
devices, the cache is stored directly in graphics memory, which makes |
|
602 |
rendering very quick. |
|
603 |
||
604 |
\value NoCache The default; all item caching is |
|
605 |
disabled. QGraphicsItem::paint() is called every time the item needs |
|
606 |
redrawing. |
|
607 |
||
608 |
\value ItemCoordinateCache Caching is enabled for the item's logical |
|
609 |
(local) coordinate system. QGraphicsItem creates an off-screen pixel |
|
610 |
buffer with a configurable size / resolution that you can pass to |
|
611 |
QGraphicsItem::setCacheMode(). Rendering quality will typically degrade, |
|
612 |
depending on the resolution of the cache and the item transformation. The |
|
613 |
first time the item is redrawn, it will render itself into the cache, and |
|
614 |
the cache is then reused for every subsequent expose. The cache is also |
|
615 |
reused as the item is transformed. To adjust the resolution of the cache, |
|
616 |
you can call setCacheMode() again. |
|
617 |
||
618 |
\value DeviceCoordinateCache Caching is enabled at the paint device level, |
|
619 |
in device coordinates. This mode is for items that can move, but are not |
|
620 |
rotated, scaled or sheared. If the item is transformed directly or |
|
621 |
indirectly, the cache will be regenerated automatically. Unlike |
|
622 |
ItemCoordinateCacheMode, DeviceCoordinateCache always renders at maximum |
|
623 |
quality. |
|
624 |
||
625 |
\sa QGraphicsItem::setCacheMode() |
|
626 |
*/ |
|
627 |
||
628 |
/*! |
|
629 |
\enum QGraphicsItem::Extension |
|
630 |
\internal |
|
631 |
||
632 |
Note: This is provided as a hook to avoid future problems related |
|
633 |
to adding virtual functions. See also extension(), |
|
634 |
supportsExtension() and setExtension(). |
|
635 |
*/ |
|
636 |
||
637 |
/*! |
|
638 |
\enum QGraphicsItem::PanelModality |
|
639 |
\since 4.6 |
|
640 |
||
641 |
This enum specifies the behavior of a modal panel. A modal panel |
|
642 |
is one that blocks input to other panels. Note that items that |
|
643 |
are children of a modal panel are not blocked. |
|
644 |
||
645 |
The values are: |
|
646 |
\value NonModal The panel is not modal and does not block input to other panels. |
|
647 |
\value PanelModal The panel is modal to a single item hierarchy and blocks input to its parent pane, all grandparent panels, and all siblings of its parent and grandparent panels. |
|
648 |
\value SceneModal The window is modal to the entire scene and blocks input to all panels. |
|
649 |
||
650 |
\sa QGraphicsItem::setPanelModality(), QGraphicsItem::panelModality(), QGraphicsItem::ItemIsPanel |
|
651 |
*/ |
|
652 |
||
653 |
#include "qgraphicsitem.h" |
|
654 |
||
655 |
#ifndef QT_NO_GRAPHICSVIEW |
|
656 |
||
657 |
#include "qgraphicsscene.h" |
|
658 |
#include "qgraphicsscene_p.h" |
|
659 |
#include "qgraphicssceneevent.h" |
|
660 |
#include "qgraphicsview.h" |
|
661 |
#include "qgraphicswidget.h" |
|
662 |
#include "qgraphicsproxywidget.h" |
|
663 |
#include "qgraphicsscenebsptreeindex_p.h" |
|
664 |
#include <QtCore/qbitarray.h> |
|
665 |
#include <QtCore/qdebug.h> |
|
666 |
#include <QtCore/qpoint.h> |
|
667 |
#include <QtCore/qstack.h> |
|
668 |
#include <QtCore/qtimer.h> |
|
669 |
#include <QtCore/qvariant.h> |
|
670 |
#include <QtCore/qvarlengtharray.h> |
|
671 |
#include <QtGui/qapplication.h> |
|
672 |
#include <QtGui/qbitmap.h> |
|
673 |
#include <QtGui/qpainter.h> |
|
674 |
#include <QtGui/qpainterpath.h> |
|
675 |
#include <QtGui/qpixmapcache.h> |
|
676 |
#include <QtGui/qstyleoption.h> |
|
677 |
#include <QtGui/qevent.h> |
|
678 |
#include <QtGui/qinputcontext.h> |
|
679 |
#include <QtGui/qgraphicseffect.h> |
|
680 |
||
681 |
#include <private/qgraphicsitem_p.h> |
|
682 |
#include <private/qgraphicswidget_p.h> |
|
683 |
#include <private/qtextcontrol_p.h> |
|
684 |
#include <private/qtextdocumentlayout_p.h> |
|
685 |
#include <private/qtextengine_p.h> |
|
686 |
#include <private/qwidget_p.h> |
|
687 |
||
688 |
#ifdef Q_WS_X11 |
|
689 |
#include <private/qt_x11_p.h> |
|
690 |
#include <private/qpixmap_x11_p.h> |
|
691 |
#endif |
|
692 |
||
693 |
#include <private/qgesturemanager_p.h> |
|
694 |
||
695 |
#include <math.h> |
|
696 |
||
697 |
QT_BEGIN_NAMESPACE |
|
698 |
||
699 |
static inline void _q_adjustRect(QRect *rect) |
|
700 |
{ |
|
701 |
Q_ASSERT(rect); |
|
702 |
if (!rect->width()) |
|
703 |
rect->adjust(0, 0, 1, 0); |
|
704 |
if (!rect->height()) |
|
705 |
rect->adjust(0, 0, 0, 1); |
|
706 |
} |
|
707 |
||
708 |
/* |
|
709 |
### Move this into QGraphicsItemPrivate |
|
710 |
*/ |
|
711 |
class QGraphicsItemCustomDataStore |
|
712 |
{ |
|
713 |
public: |
|
714 |
QMap<const QGraphicsItem *, QMap<int, QVariant> > data; |
|
715 |
}; |
|
716 |
Q_GLOBAL_STATIC(QGraphicsItemCustomDataStore, qt_dataStore) |
|
717 |
||
718 |
/*! |
|
719 |
\internal |
|
720 |
||
721 |
Returns a QPainterPath of \a path when stroked with the \a pen. |
|
722 |
Ignoring dash pattern. |
|
723 |
*/ |
|
724 |
static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen) |
|
725 |
{ |
|
726 |
// We unfortunately need this hack as QPainterPathStroker will set a width of 1.0 |
|
727 |
// if we pass a value of 0.0 to QPainterPathStroker::setWidth() |
|
728 |
const qreal penWidthZero = qreal(0.00000001); |
|
729 |
||
730 |
if (path == QPainterPath()) |
|
731 |
return path; |
|
732 |
QPainterPathStroker ps; |
|
733 |
ps.setCapStyle(pen.capStyle()); |
|
734 |
if (pen.widthF() <= 0.0) |
|
735 |
ps.setWidth(penWidthZero); |
|
736 |
else |
|
737 |
ps.setWidth(pen.widthF()); |
|
738 |
ps.setJoinStyle(pen.joinStyle()); |
|
739 |
ps.setMiterLimit(pen.miterLimit()); |
|
740 |
QPainterPath p = ps.createStroke(path); |
|
741 |
p.addPath(path); |
|
742 |
return p; |
|
743 |
} |
|
744 |
||
745 |
/*! |
|
746 |
\internal |
|
747 |
||
748 |
Propagates the ancestor flag \a flag with value \a enabled to all this |
|
749 |
item's children. If \a root is false, the flag is also set on this item |
|
750 |
(default is true). |
|
751 |
*/ |
|
752 |
void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, |
|
753 |
AncestorFlag flag, bool enabled, bool root) |
|
754 |
{ |
|
755 |
Q_Q(QGraphicsItem); |
|
756 |
if (root) { |
|
757 |
// For root items only. This is the item that has either enabled or |
|
758 |
// disabled \a childFlag, or has been reparented. |
|
759 |
switch (int(childFlag)) { |
|
760 |
case -2: |
|
761 |
flag = AncestorFiltersChildEvents; |
|
762 |
enabled = q->filtersChildEvents(); |
|
763 |
break; |
|
764 |
case -1: |
|
765 |
flag = AncestorHandlesChildEvents; |
|
766 |
enabled = q->handlesChildEvents(); |
|
767 |
break; |
|
768 |
case QGraphicsItem::ItemClipsChildrenToShape: |
|
769 |
flag = AncestorClipsChildren; |
|
770 |
enabled = flags & QGraphicsItem::ItemClipsChildrenToShape; |
|
771 |
break; |
|
772 |
case QGraphicsItem::ItemIgnoresTransformations: |
|
773 |
flag = AncestorIgnoresTransformations; |
|
774 |
enabled = flags & QGraphicsItem::ItemIgnoresTransformations; |
|
775 |
break; |
|
776 |
default: |
|
777 |
return; |
|
778 |
} |
|
779 |
||
780 |
if (parent) { |
|
781 |
// Inherit the enabled-state from our parents. |
|
782 |
if ((parent->d_ptr->ancestorFlags & flag) |
|
783 |
|| (int(parent->d_ptr->flags & childFlag) == childFlag) |
|
784 |
|| (childFlag == -1 && parent->d_ptr->handlesChildEvents) |
|
785 |
|| (childFlag == -2 && parent->d_ptr->filtersDescendantEvents)) { |
|
786 |
enabled = true; |
|
787 |
ancestorFlags |= flag; |
|
788 |
} else { |
|
789 |
ancestorFlags &= ~flag; |
|
790 |
} |
|
791 |
} else { |
|
792 |
// Top-level root items don't have any ancestors, so there are no |
|
793 |
// ancestor flags either. |
|
794 |
ancestorFlags = 0; |
|
795 |
} |
|
796 |
} else { |
|
797 |
// Don't set or propagate the ancestor flag if it's already correct. |
|
798 |
if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled)) |
|
799 |
return; |
|
800 |
||
801 |
// Set the flag. |
|
802 |
if (enabled) |
|
803 |
ancestorFlags |= flag; |
|
804 |
else |
|
805 |
ancestorFlags &= ~flag; |
|
806 |
||
807 |
// Don't process children if the item has the main flag set on itself. |
|
808 |
if ((childFlag != -1 && int(flags & childFlag) == childFlag) |
|
809 |
|| (int(childFlag) == -1 && handlesChildEvents) |
|
810 |
|| (int(childFlag) == -2 && filtersDescendantEvents)) |
|
811 |
return; |
|
812 |
} |
|
813 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
814 |
for (int i = 0; i < children.size(); ++i) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
815 |
children.at(i)->d_ptr->updateAncestorFlag(childFlag, flag, enabled, false); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
816 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
817 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
818 |
void QGraphicsItemPrivate::updateAncestorFlags() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
819 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
820 |
int flags = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
821 |
if (parent) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
822 |
// Inherit the parent's ancestor flags. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
823 |
QGraphicsItemPrivate *pd = parent->d_ptr.data(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
824 |
flags = pd->ancestorFlags; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
825 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
826 |
// Add in flags from the parent. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
827 |
if (pd->filtersDescendantEvents) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
828 |
flags |= AncestorFiltersChildEvents; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
829 |
if (pd->handlesChildEvents) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
830 |
flags |= AncestorHandlesChildEvents; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
831 |
if (pd->flags & QGraphicsItem::ItemClipsChildrenToShape) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
832 |
flags |= AncestorClipsChildren; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
833 |
if (pd->flags & QGraphicsItem::ItemIgnoresTransformations) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
834 |
flags |= AncestorIgnoresTransformations; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
835 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
836 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
837 |
if (ancestorFlags == flags) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
838 |
return; // No change; stop propagation. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
839 |
ancestorFlags = flags; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
840 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
841 |
// Propagate to children recursively. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
842 |
for (int i = 0; i < children.size(); ++i) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
843 |
children.at(i)->d_ptr->updateAncestorFlags(); |
0 | 844 |
} |
845 |
||
846 |
/*! |
|
847 |
\internal |
|
848 |
||
849 |
Propagates item group membership. |
|
850 |
*/ |
|
851 |
void QGraphicsItemPrivate::setIsMemberOfGroup(bool enabled) |
|
852 |
{ |
|
853 |
Q_Q(QGraphicsItem); |
|
854 |
isMemberOfGroup = enabled; |
|
855 |
if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) { |
|
856 |
foreach (QGraphicsItem *child, children) |
|
857 |
child->d_func()->setIsMemberOfGroup(enabled); |
|
858 |
} |
|
859 |
} |
|
860 |
||
861 |
/*! |
|
862 |
\internal |
|
863 |
||
864 |
Maps any item pos properties of \a event to \a item's coordinate system. |
|
865 |
*/ |
|
866 |
void QGraphicsItemPrivate::remapItemPos(QEvent *event, QGraphicsItem *item) |
|
867 |
{ |
|
868 |
Q_Q(QGraphicsItem); |
|
869 |
switch (event->type()) { |
|
870 |
case QEvent::GraphicsSceneMouseMove: |
|
871 |
case QEvent::GraphicsSceneMousePress: |
|
872 |
case QEvent::GraphicsSceneMouseRelease: |
|
873 |
case QEvent::GraphicsSceneMouseDoubleClick: { |
|
874 |
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event); |
|
875 |
mouseEvent->setPos(item->mapFromItem(q, mouseEvent->pos())); |
|
876 |
mouseEvent->setLastPos(item->mapFromItem(q, mouseEvent->pos())); |
|
877 |
for (int i = 0x1; i <= 0x10; i <<= 1) { |
|
878 |
if (mouseEvent->buttons() & i) { |
|
879 |
Qt::MouseButton button = Qt::MouseButton(i); |
|
880 |
mouseEvent->setButtonDownPos(button, item->mapFromItem(q, mouseEvent->buttonDownPos(button))); |
|
881 |
} |
|
882 |
} |
|
883 |
break; |
|
884 |
} |
|
885 |
case QEvent::GraphicsSceneWheel: { |
|
886 |
QGraphicsSceneWheelEvent *wheelEvent = static_cast<QGraphicsSceneWheelEvent *>(event); |
|
887 |
wheelEvent->setPos(item->mapFromItem(q, wheelEvent->pos())); |
|
888 |
break; |
|
889 |
} |
|
890 |
case QEvent::GraphicsSceneContextMenu: { |
|
891 |
QGraphicsSceneContextMenuEvent *contextEvent = static_cast<QGraphicsSceneContextMenuEvent *>(event); |
|
892 |
contextEvent->setPos(item->mapFromItem(q, contextEvent->pos())); |
|
893 |
break; |
|
894 |
} |
|
895 |
case QEvent::GraphicsSceneHoverMove: { |
|
896 |
QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event); |
|
897 |
hoverEvent->setPos(item->mapFromItem(q, hoverEvent->pos())); |
|
898 |
break; |
|
899 |
} |
|
900 |
default: |
|
901 |
break; |
|
902 |
} |
|
903 |
} |
|
904 |
||
905 |
/*! |
|
906 |
\internal |
|
907 |
||
908 |
Maps the point \a pos from scene to item coordinates. If \a view is passed and the item |
|
909 |
is untransformable, this function will correctly map \a pos from the scene using the |
|
910 |
view's transformation. |
|
911 |
*/ |
|
912 |
QPointF QGraphicsItemPrivate::genericMapFromScene(const QPointF &pos, |
|
913 |
const QWidget *viewport) const |
|
914 |
{ |
|
915 |
Q_Q(const QGraphicsItem); |
|
916 |
if (!itemIsUntransformable()) |
|
917 |
return q->mapFromScene(pos); |
|
918 |
QGraphicsView *view = 0; |
|
919 |
if (viewport) |
|
920 |
view = qobject_cast<QGraphicsView *>(viewport->parentWidget()); |
|
921 |
if (!view) |
|
922 |
return q->mapFromScene(pos); |
|
923 |
// ### More ping pong than needed. |
|
924 |
return q->deviceTransform(view->viewportTransform()).inverted().map(view->mapFromScene(pos)); |
|
925 |
} |
|
926 |
||
927 |
/*! |
|
928 |
\internal |
|
929 |
||
930 |
Combines this item's position and transform onto \a transform. |
|
931 |
||
932 |
If you need to change this function (e.g., adding more transformation |
|
933 |
modes / options), make sure to change all places marked with COMBINE. |
|
934 |
*/ |
|
935 |
void QGraphicsItemPrivate::combineTransformToParent(QTransform *x, const QTransform *viewTransform) const |
|
936 |
{ |
|
937 |
// COMBINE |
|
938 |
if (viewTransform && itemIsUntransformable()) { |
|
939 |
*x = q_ptr->deviceTransform(*viewTransform); |
|
940 |
} else { |
|
941 |
if (transformData) |
|
942 |
*x *= transformData->computedFullTransform(); |
|
943 |
if (!pos.isNull()) |
|
944 |
*x *= QTransform::fromTranslate(pos.x(), pos.y()); |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
/*! |
|
949 |
\internal |
|
950 |
||
951 |
Combines this item's position and transform onto \a transform. |
|
952 |
||
953 |
If you need to change this function (e.g., adding more transformation |
|
954 |
modes / options), make sure to change QGraphicsItem::deviceTransform() as |
|
955 |
well. |
|
956 |
*/ |
|
957 |
void QGraphicsItemPrivate::combineTransformFromParent(QTransform *x, const QTransform *viewTransform) const |
|
958 |
{ |
|
959 |
// COMBINE |
|
960 |
if (viewTransform && itemIsUntransformable()) { |
|
961 |
*x = q_ptr->deviceTransform(*viewTransform); |
|
962 |
} else { |
|
963 |
x->translate(pos.x(), pos.y()); |
|
964 |
if (transformData) |
|
965 |
*x = transformData->computedFullTransform(x); |
|
966 |
} |
|
967 |
} |
|
968 |
||
969 |
void QGraphicsItemPrivate::updateSceneTransformFromParent() |
|
970 |
{ |
|
971 |
if (parent) { |
|
972 |
Q_ASSERT(!parent->d_ptr->dirtySceneTransform); |
|
973 |
if (parent->d_ptr->sceneTransformTranslateOnly) { |
|
974 |
sceneTransform = QTransform::fromTranslate(parent->d_ptr->sceneTransform.dx() + pos.x(), |
|
975 |
parent->d_ptr->sceneTransform.dy() + pos.y()); |
|
976 |
} else { |
|
977 |
sceneTransform = parent->d_ptr->sceneTransform; |
|
978 |
sceneTransform.translate(pos.x(), pos.y()); |
|
979 |
} |
|
980 |
if (transformData) { |
|
981 |
sceneTransform = transformData->computedFullTransform(&sceneTransform); |
|
982 |
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate); |
|
983 |
} else { |
|
984 |
sceneTransformTranslateOnly = parent->d_ptr->sceneTransformTranslateOnly; |
|
985 |
} |
|
986 |
} else if (!transformData) { |
|
987 |
sceneTransform = QTransform::fromTranslate(pos.x(), pos.y()); |
|
988 |
sceneTransformTranslateOnly = 1; |
|
989 |
} else if (transformData->onlyTransform) { |
|
990 |
sceneTransform = transformData->transform; |
|
991 |
if (!pos.isNull()) |
|
992 |
sceneTransform *= QTransform::fromTranslate(pos.x(), pos.y()); |
|
993 |
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate); |
|
994 |
} else if (pos.isNull()) { |
|
995 |
sceneTransform = transformData->computedFullTransform(); |
|
996 |
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate); |
|
997 |
} else { |
|
998 |
sceneTransform = QTransform::fromTranslate(pos.x(), pos.y()); |
|
999 |
sceneTransform = transformData->computedFullTransform(&sceneTransform); |
|
1000 |
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate); |
|
1001 |
} |
|
1002 |
dirtySceneTransform = 0; |
|
1003 |
} |
|
1004 |
||
1005 |
/*! |
|
1006 |
\internal |
|
1007 |
||
1008 |
This helper function helped us add input method query support in |
|
1009 |
Qt 4.4.1 without having to reimplement the inputMethodQuery() |
|
1010 |
function in QGraphicsProxyWidget. ### Qt 5: Remove. We cannot |
|
1011 |
remove it in 4.5+ even if we do reimplement the function properly, |
|
1012 |
because apps compiled with 4.4 will not be able to call the |
|
1013 |
reimplementation. |
|
1014 |
*/ |
|
1015 |
QVariant QGraphicsItemPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const |
|
1016 |
{ |
|
1017 |
Q_UNUSED(query); |
|
1018 |
return QVariant(); |
|
1019 |
} |
|
1020 |
||
1021 |
/*! |
|
1022 |
\internal |
|
1023 |
||
1024 |
Make sure not to trigger any pure virtual function calls (e.g., |
|
1025 |
prepareGeometryChange) if the item is in its destructor, i.e. |
|
1026 |
inDestructor is 1. |
|
1027 |
*/ |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1028 |
void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const QVariant *newParentVariant, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1029 |
const QVariant *thisPointerVariant) |
0 | 1030 |
{ |
1031 |
Q_Q(QGraphicsItem); |
|
1032 |
if (newParent == parent) |
|
1033 |
return; |
|
1034 |
||
1035 |
if (scene) { |
|
1036 |
// Deliver the change to the index |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1037 |
if (scene->d_func()->indexMethod != QGraphicsScene::NoIndex) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1038 |
scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParent); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1039 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1040 |
// Disable scene pos notifications for old ancestors |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1041 |
if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1042 |
scene->d_func()->setScenePosItemEnabled(q, false); |
0 | 1043 |
} |
1044 |
||
1045 |
if (subFocusItem && parent) { |
|
1046 |
// Make sure none of the old parents point to this guy. |
|
1047 |
subFocusItem->d_ptr->clearSubFocus(parent); |
|
1048 |
} |
|
1049 |
||
1050 |
// We anticipate geometry changes. If the item is deleted, it will be |
|
1051 |
// removed from the index at a later stage, and the whole scene will be |
|
1052 |
// updated. |
|
1053 |
if (!inDestructor) |
|
1054 |
q_ptr->prepareGeometryChange(); |
|
1055 |
||
1056 |
if (parent) { |
|
1057 |
// Remove from current parent |
|
1058 |
parent->d_ptr->removeChild(q); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1059 |
if (thisPointerVariant) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1060 |
parent->itemChange(QGraphicsItem::ItemChildRemovedChange, *thisPointerVariant); |
0 | 1061 |
} |
1062 |
||
1063 |
// Update toplevelitem list. If this item is being deleted, its parent |
|
1064 |
// will be 0 but we don't want to register/unregister it in the TLI list. |
|
1065 |
if (scene && !inDestructor) { |
|
1066 |
if (parent && !newParent) { |
|
1067 |
scene->d_func()->registerTopLevelItem(q); |
|
1068 |
} else if (!parent && newParent) { |
|
1069 |
scene->d_func()->unregisterTopLevelItem(q); |
|
1070 |
} |
|
1071 |
} |
|
1072 |
||
1073 |
// Ensure any last parent focus scope does not point to this item or any of |
|
1074 |
// its descendents. |
|
1075 |
QGraphicsItem *p = parent; |
|
1076 |
QGraphicsItem *parentFocusScopeItem = 0; |
|
1077 |
while (p) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1078 |
if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) { |
0 | 1079 |
// If this item's focus scope's focus scope item points |
1080 |
// to this item or a descendent, then clear it. |
|
1081 |
QGraphicsItem *fsi = p->d_ptr->focusScopeItem; |
|
1082 |
if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) { |
|
1083 |
parentFocusScopeItem = fsi; |
|
1084 |
p->d_ptr->focusScopeItem = 0; |
|
1085 |
} |
|
1086 |
break; |
|
1087 |
} |
|
1088 |
p = p->d_ptr->parent; |
|
1089 |
} |
|
1090 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1091 |
// Update graphics effect optimization flag |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1092 |
if (newParent && (graphicsEffect || mayHaveChildWithGraphicsEffect)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1093 |
newParent->d_ptr->updateChildWithGraphicsEffectFlagRecursively(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1094 |
|
0 | 1095 |
// Update focus scope item ptr in new scope. |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
QGraphicsItem *newFocusScopeItem = subFocusItem ? subFocusItem : parentFocusScopeItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
if (newFocusScopeItem && newParent) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1098 |
if (subFocusItem) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1099 |
// Find the subFocusItem's topmost focus scope. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1100 |
QGraphicsItem *ancestorScope = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1101 |
QGraphicsItem *p = subFocusItem->d_ptr->parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1102 |
while (p) { |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1103 |
if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1104 |
ancestorScope = p; |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1105 |
if (p->d_ptr->flags & QGraphicsItem::ItemIsPanel) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
break; |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1107 |
p = p->d_ptr->parent; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1108 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1109 |
if (ancestorScope) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1110 |
newFocusScopeItem = ancestorScope; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1111 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1112 |
|
0 | 1113 |
QGraphicsItem *p = newParent; |
1114 |
while (p) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1115 |
if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
p->d_ptr->focusScopeItem = newFocusScopeItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
// Ensure the new item is no longer the subFocusItem. The |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
// only way to set focus on a child of a focus scope is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
// by setting focus on the scope itself. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
if (subFocusItem && !p->focusItem()) |
0 | 1121 |
subFocusItem->d_ptr->clearSubFocus(); |
1122 |
break; |
|
1123 |
} |
|
1124 |
p = p->d_ptr->parent; |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
if ((parent = newParent)) { |
|
1129 |
if (parent->d_func()->scene && parent->d_func()->scene != scene) { |
|
1130 |
// Move this item to its new parent's scene |
|
1131 |
parent->d_func()->scene->addItem(q); |
|
1132 |
} else if (!parent->d_func()->scene && scene) { |
|
1133 |
// Remove this item from its former scene |
|
1134 |
scene->removeItem(q); |
|
1135 |
} |
|
1136 |
||
1137 |
parent->d_ptr->addChild(q); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1138 |
if (thisPointerVariant) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1139 |
parent->itemChange(QGraphicsItem::ItemChildAddedChange, *thisPointerVariant); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1140 |
if (scene) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1141 |
// Re-enable scene pos notifications for new ancestors |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1142 |
if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
scene->d_func()->setScenePosItemEnabled(q, true); |
0 | 1144 |
} |
1145 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1146 |
// Propagate dirty flags to the new parent |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1147 |
markParentDirty(/*updateBoundingRect=*/true); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1148 |
|
0 | 1149 |
// Inherit ancestor flags from the new parent. |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1150 |
updateAncestorFlags(); |
0 | 1151 |
|
1152 |
// Update item visible / enabled. |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1153 |
if (parent->d_ptr->visible != visible) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1154 |
if (!parent->d_ptr->visible || !explicitlyHidden) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1155 |
setVisibleHelper(parent->d_ptr->visible, /* explicit = */ false, /* update = */ false); |
0 | 1156 |
} |
1157 |
if (parent->isEnabled() != enabled) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1158 |
if (!parent->d_ptr->enabled || !explicitlyDisabled) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1159 |
setEnabledHelper(parent->d_ptr->enabled, /* explicit = */ false, /* update = */ false); |
0 | 1160 |
} |
1161 |
||
1162 |
// Auto-activate if visible and the parent is active. |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1163 |
if (visible && parent->isActive()) |
0 | 1164 |
q->setActive(true); |
1165 |
} else { |
|
1166 |
// Inherit ancestor flags from the new parent. |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1167 |
updateAncestorFlags(); |
0 | 1168 |
|
1169 |
if (!inDestructor) { |
|
1170 |
// Update item visible / enabled. |
|
1171 |
if (!visible && !explicitlyHidden) |
|
1172 |
setVisibleHelper(true, /* explicit = */ false); |
|
1173 |
if (!enabled && !explicitlyDisabled) |
|
1174 |
setEnabledHelper(true, /* explicit = */ false); |
|
1175 |
} |
|
1176 |
} |
|
1177 |
||
1178 |
// Resolve depth. |
|
1179 |
invalidateDepthRecursively(); |
|
1180 |
dirtySceneTransform = 1; |
|
1181 |
||
1182 |
// Restore the sub focus chain. |
|
1183 |
if (subFocusItem) { |
|
1184 |
subFocusItem->d_ptr->setSubFocus(newParent); |
|
1185 |
if (parent && parent->isActive()) |
|
1186 |
subFocusItem->setFocus(); |
|
1187 |
} |
|
1188 |
||
1189 |
// Deliver post-change notification |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1190 |
if (newParentVariant) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1191 |
q->itemChange(QGraphicsItem::ItemParentHasChanged, *newParentVariant); |
0 | 1192 |
|
1193 |
if (isObject) |
|
1194 |
emit static_cast<QGraphicsObject *>(q)->parentChanged(); |
|
1195 |
} |
|
1196 |
||
1197 |
/*! |
|
1198 |
\internal |
|
1199 |
||
1200 |
Returns the bounding rect of this item's children (excluding itself). |
|
1201 |
*/ |
|
1202 |
void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect) |
|
1203 |
{ |
|
1204 |
for (int i = 0; i < children.size(); ++i) { |
|
1205 |
QGraphicsItem *child = children.at(i); |
|
1206 |
QGraphicsItemPrivate *childd = child->d_ptr.data(); |
|
1207 |
bool hasPos = !childd->pos.isNull(); |
|
1208 |
if (hasPos || childd->transformData) { |
|
1209 |
// COMBINE |
|
1210 |
QTransform matrix = childd->transformToParent(); |
|
1211 |
if (x) |
|
1212 |
matrix *= *x; |
|
1213 |
*rect |= matrix.mapRect(child->boundingRect()); |
|
1214 |
if (!childd->children.isEmpty()) |
|
1215 |
childd->childrenBoundingRectHelper(&matrix, rect); |
|
1216 |
} else { |
|
1217 |
if (x) |
|
1218 |
*rect |= x->mapRect(child->boundingRect()); |
|
1219 |
else |
|
1220 |
*rect |= child->boundingRect(); |
|
1221 |
if (!childd->children.isEmpty()) |
|
1222 |
childd->childrenBoundingRectHelper(x, rect); |
|
1223 |
} |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, |
|
1228 |
const QRegion &exposedRegion, bool allItems) const |
|
1229 |
{ |
|
1230 |
Q_ASSERT(option); |
|
1231 |
Q_Q(const QGraphicsItem); |
|
1232 |
||
1233 |
// Initialize standard QStyleOption values. |
|
1234 |
const QRectF brect = q->boundingRect(); |
|
1235 |
option->state = QStyle::State_None; |
|
1236 |
option->rect = brect.toRect(); |
|
1237 |
option->levelOfDetail = 1; |
|
1238 |
option->exposedRect = brect; |
|
1239 |
if (selected) |
|
1240 |
option->state |= QStyle::State_Selected; |
|
1241 |
if (enabled) |
|
1242 |
option->state |= QStyle::State_Enabled; |
|
1243 |
if (q->hasFocus()) |
|
1244 |
option->state |= QStyle::State_HasFocus; |
|
1245 |
if (scene) { |
|
1246 |
if (scene->d_func()->hoverItems.contains(q_ptr)) |
|
1247 |
option->state |= QStyle::State_MouseOver; |
|
1248 |
if (q == scene->mouseGrabberItem()) |
|
1249 |
option->state |= QStyle::State_Sunken; |
|
1250 |
} |
|
1251 |
||
1252 |
if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption)) |
|
1253 |
return; |
|
1254 |
||
1255 |
// Initialize QStyleOptionGraphicsItem specific values (matrix, exposedRect). |
|
1256 |
option->matrix = worldTransform.toAffine(); //### discards perspective |
|
1257 |
||
1258 |
if (!allItems) { |
|
1259 |
// Determine the item's exposed area |
|
1260 |
option->exposedRect = QRectF(); |
|
1261 |
const QTransform reverseMap = worldTransform.inverted(); |
|
1262 |
const QVector<QRect> exposedRects(exposedRegion.rects()); |
|
1263 |
for (int i = 0; i < exposedRects.size(); ++i) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i))); |
0 | 1265 |
if (option->exposedRect.contains(brect)) |
1266 |
break; |
|
1267 |
} |
|
1268 |
option->exposedRect &= brect; |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
/*! |
|
1273 |
\internal |
|
1274 |
||
1275 |
Empty all cached pixmaps from the pixmap cache. |
|
1276 |
*/ |
|
1277 |
void QGraphicsItemCache::purge() |
|
1278 |
{ |
|
1279 |
QPixmapCache::remove(key); |
|
1280 |
key = QPixmapCache::Key(); |
|
1281 |
QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData); |
|
1282 |
while (it.hasNext()) { |
|
1283 |
DeviceData &data = it.next().value(); |
|
1284 |
QPixmapCache::remove(data.key); |
|
1285 |
data.cacheIndent = QPoint(); |
|
1286 |
} |
|
1287 |
deviceData.clear(); |
|
1288 |
allExposed = true; |
|
1289 |
exposed.clear(); |
|
1290 |
} |
|
1291 |
||
1292 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1293 |
Constructs a QGraphicsItem with the given \a parent item. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
It does not modify the parent object returned by QObject::parent(). |
0 | 1295 |
|
1296 |
If \a parent is 0, you can add the item to a scene by calling |
|
1297 |
QGraphicsScene::addItem(). The item will then become a top-level item. |
|
1298 |
||
1299 |
\sa QGraphicsScene::addItem(), setParentItem() |
|
1300 |
*/ |
|
1301 |
QGraphicsItem::QGraphicsItem(QGraphicsItem *parent |
|
1302 |
#ifndef Q_QDOC |
|
1303 |
// obsolete argument |
|
1304 |
, QGraphicsScene *scene |
|
1305 |
#endif |
|
1306 |
) |
|
1307 |
: d_ptr(new QGraphicsItemPrivate) |
|
1308 |
{ |
|
1309 |
d_ptr->q_ptr = this; |
|
1310 |
setParentItem(parent); |
|
1311 |
||
1312 |
if (scene && parent && parent->scene() != scene) { |
|
1313 |
qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is" |
|
1314 |
" different from parent's scene (%p)", |
|
1315 |
scene, parent->scene()); |
|
1316 |
return; |
|
1317 |
} |
|
1318 |
if (scene && !parent) |
|
1319 |
scene->addItem(this); |
|
1320 |
} |
|
1321 |
||
1322 |
/*! |
|
1323 |
\internal |
|
1324 |
*/ |
|
1325 |
QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent, |
|
1326 |
QGraphicsScene *scene) |
|
1327 |
: d_ptr(&dd) |
|
1328 |
{ |
|
1329 |
d_ptr->q_ptr = this; |
|
1330 |
setParentItem(parent); |
|
1331 |
||
1332 |
if (scene && parent && parent->scene() != scene) { |
|
1333 |
qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is" |
|
1334 |
" different from parent's scene (%p)", |
|
1335 |
scene, parent->scene()); |
|
1336 |
return; |
|
1337 |
} |
|
1338 |
if (scene && !parent) |
|
1339 |
scene->addItem(this); |
|
1340 |
} |
|
1341 |
||
1342 |
/*! |
|
1343 |
Destroys the QGraphicsItem and all its children. If this item is currently |
|
1344 |
associated with a scene, the item will be removed from the scene before it |
|
1345 |
is deleted. |
|
1346 |
||
1347 |
\note It is more efficient to remove the item from the QGraphicsScene before |
|
1348 |
destroying the item. |
|
1349 |
*/ |
|
1350 |
QGraphicsItem::~QGraphicsItem() |
|
1351 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
if (d_ptr->isObject) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
QObjectPrivate::get(static_cast<QGraphicsObject *>(this))->wasDeleted = true; |
0 | 1354 |
d_ptr->inDestructor = 1; |
1355 |
d_ptr->removeExtraItemCache(); |
|
1356 |
||
1357 |
clearFocus(); |
|
1358 |
||
1359 |
// Update focus scope item ptr. |
|
1360 |
QGraphicsItem *p = d_ptr->parent; |
|
1361 |
while (p) { |
|
1362 |
if (p->flags() & ItemIsFocusScope) { |
|
1363 |
if (p->d_ptr->focusScopeItem == this) |
|
1364 |
p->d_ptr->focusScopeItem = 0; |
|
1365 |
break; |
|
1366 |
} |
|
1367 |
p = p->d_ptr->parent; |
|
1368 |
} |
|
1369 |
||
1370 |
if (!d_ptr->children.isEmpty()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1371 |
while (!d_ptr->children.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1372 |
delete d_ptr->children.first(); |
0 | 1373 |
Q_ASSERT(d_ptr->children.isEmpty()); |
1374 |
} |
|
1375 |
||
1376 |
if (d_ptr->scene) { |
|
1377 |
d_ptr->scene->d_func()->removeItemHelper(this); |
|
1378 |
} else { |
|
1379 |
d_ptr->resetFocusProxy(); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1380 |
setParentItem(0); |
0 | 1381 |
} |
1382 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1383 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 1384 |
delete d_ptr->graphicsEffect; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 1386 |
if (d_ptr->transformData) { |
1387 |
for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) { |
|
1388 |
QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i); |
|
1389 |
static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0; |
|
1390 |
delete t; |
|
1391 |
} |
|
1392 |
} |
|
1393 |
delete d_ptr->transformData; |
|
1394 |
||
1395 |
qt_dataStore()->data.remove(this); |
|
1396 |
} |
|
1397 |
||
1398 |
/*! |
|
1399 |
Returns the current scene for the item, or 0 if the item is not stored in |
|
1400 |
a scene. |
|
1401 |
||
1402 |
To add or move an item to a scene, call QGraphicsScene::addItem(). |
|
1403 |
*/ |
|
1404 |
QGraphicsScene *QGraphicsItem::scene() const |
|
1405 |
{ |
|
1406 |
return d_ptr->scene; |
|
1407 |
} |
|
1408 |
||
1409 |
/*! |
|
1410 |
Returns a pointer to this item's item group, or 0 if this item is not |
|
1411 |
member of a group. |
|
1412 |
||
1413 |
\sa QGraphicsItemGroup, QGraphicsScene::createItemGroup() |
|
1414 |
*/ |
|
1415 |
QGraphicsItemGroup *QGraphicsItem::group() const |
|
1416 |
{ |
|
1417 |
if (!d_ptr->isMemberOfGroup) |
|
1418 |
return 0; |
|
1419 |
QGraphicsItem *parent = const_cast<QGraphicsItem *>(this); |
|
1420 |
while ((parent = parent->d_ptr->parent)) { |
|
1421 |
if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent)) |
|
1422 |
return group; |
|
1423 |
} |
|
1424 |
// Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this |
|
1425 |
// item is a group item. |
|
1426 |
return 0; |
|
1427 |
} |
|
1428 |
||
1429 |
/*! |
|
1430 |
Adds this item to the item group \a group. If \a group is 0, this item is |
|
1431 |
removed from any current group and added as a child of the previous |
|
1432 |
group's parent. |
|
1433 |
||
1434 |
\sa group(), QGraphicsScene::createItemGroup() |
|
1435 |
*/ |
|
1436 |
void QGraphicsItem::setGroup(QGraphicsItemGroup *group) |
|
1437 |
{ |
|
1438 |
if (!group) { |
|
1439 |
if (QGraphicsItemGroup *group = this->group()) |
|
1440 |
group->removeFromGroup(this); |
|
1441 |
} else { |
|
1442 |
group->addToGroup(this); |
|
1443 |
} |
|
1444 |
} |
|
1445 |
||
1446 |
/*! |
|
1447 |
Returns a pointer to this item's parent item. If this item does not have a |
|
1448 |
parent, 0 is returned. |
|
1449 |
||
1450 |
\sa setParentItem(), childItems() |
|
1451 |
*/ |
|
1452 |
QGraphicsItem *QGraphicsItem::parentItem() const |
|
1453 |
{ |
|
1454 |
return d_ptr->parent; |
|
1455 |
} |
|
1456 |
||
1457 |
/*! |
|
1458 |
Returns this item's top-level item. The top-level item is the item's |
|
1459 |
topmost ancestor item whose parent is 0. If an item has no parent, its own |
|
1460 |
pointer is returned (i.e., a top-level item is its own top-level item). |
|
1461 |
||
1462 |
\sa parentItem() |
|
1463 |
*/ |
|
1464 |
QGraphicsItem *QGraphicsItem::topLevelItem() const |
|
1465 |
{ |
|
1466 |
QGraphicsItem *parent = const_cast<QGraphicsItem *>(this); |
|
1467 |
while (QGraphicsItem *grandPa = parent->parentItem()) |
|
1468 |
parent = grandPa; |
|
1469 |
return parent; |
|
1470 |
} |
|
1471 |
||
1472 |
/*! |
|
1473 |
\since 4.6 |
|
1474 |
||
1475 |
Returns a pointer to the item's parent, cast to a QGraphicsObject. returns 0 if the parent item |
|
1476 |
is not a QGraphicsObject. |
|
1477 |
||
1478 |
\sa parentItem(), childItems() |
|
1479 |
*/ |
|
1480 |
QGraphicsObject *QGraphicsItem::parentObject() const |
|
1481 |
{ |
|
1482 |
QGraphicsItem *p = d_ptr->parent; |
|
1483 |
return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0; |
|
1484 |
} |
|
1485 |
||
1486 |
/*! |
|
1487 |
\since 4.4 |
|
1488 |
||
1489 |
Returns a pointer to the item's parent widget. The item's parent widget is |
|
1490 |
the closest parent item that is a widget. |
|
1491 |
||
1492 |
\sa parentItem(), childItems() |
|
1493 |
*/ |
|
1494 |
QGraphicsWidget *QGraphicsItem::parentWidget() const |
|
1495 |
{ |
|
1496 |
QGraphicsItem *p = parentItem(); |
|
1497 |
while (p && !p->isWidget()) |
|
1498 |
p = p->parentItem(); |
|
1499 |
return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0; |
|
1500 |
} |
|
1501 |
||
1502 |
/*! |
|
1503 |
\since 4.4 |
|
1504 |
||
1505 |
Returns a pointer to the item's top level widget (i.e., the item's |
|
1506 |
ancestor whose parent is 0, or whose parent is not a widget), or 0 if this |
|
1507 |
item does not have a top level widget. If the item is its own top level |
|
1508 |
widget, this function returns a pointer to the item itself. |
|
1509 |
*/ |
|
1510 |
QGraphicsWidget *QGraphicsItem::topLevelWidget() const |
|
1511 |
{ |
|
1512 |
if (const QGraphicsWidget *p = parentWidget()) |
|
1513 |
return p->topLevelWidget(); |
|
1514 |
return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0; |
|
1515 |
} |
|
1516 |
||
1517 |
/*! |
|
1518 |
\since 4.4 |
|
1519 |
||
1520 |
Returns the item's window, or 0 if this item does not have a window. If |
|
1521 |
the item is a window, it will return itself. Otherwise it will return the |
|
1522 |
closest ancestor that is a window. |
|
1523 |
||
1524 |
\sa QGraphicsWidget::isWindow() |
|
1525 |
*/ |
|
1526 |
QGraphicsWidget *QGraphicsItem::window() const |
|
1527 |
{ |
|
1528 |
QGraphicsItem *p = panel(); |
|
1529 |
if (p && p->isWindow()) |
|
1530 |
return static_cast<QGraphicsWidget *>(p); |
|
1531 |
return 0; |
|
1532 |
} |
|
1533 |
||
1534 |
/*! |
|
1535 |
\since 4.6 |
|
1536 |
||
1537 |
Returns the item's panel, or 0 if this item does not have a panel. If the |
|
1538 |
item is a panel, it will return itself. Otherwise it will return the |
|
1539 |
closest ancestor that is a panel. |
|
1540 |
||
1541 |
\sa isPanel(), ItemIsPanel |
|
1542 |
*/ |
|
1543 |
QGraphicsItem *QGraphicsItem::panel() const |
|
1544 |
{ |
|
1545 |
if (d_ptr->flags & ItemIsPanel) |
|
1546 |
return const_cast<QGraphicsItem *>(this); |
|
1547 |
return d_ptr->parent ? d_ptr->parent->panel() : 0; |
|
1548 |
} |
|
1549 |
||
1550 |
/*! |
|
1551 |
\since 4.6 |
|
1552 |
||
1553 |
Return the graphics item cast to a QGraphicsObject, if the class is actually a |
|
1554 |
graphics object, 0 otherwise. |
|
1555 |
*/ |
|
1556 |
QGraphicsObject *QGraphicsItem::toGraphicsObject() |
|
1557 |
{ |
|
1558 |
return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0; |
|
1559 |
} |
|
1560 |
||
1561 |
/*! |
|
1562 |
\since 4.6 |
|
1563 |
||
1564 |
Return the graphics item cast to a QGraphicsObject, if the class is actually a |
|
1565 |
graphics object, 0 otherwise. |
|
1566 |
*/ |
|
1567 |
const QGraphicsObject *QGraphicsItem::toGraphicsObject() const |
|
1568 |
{ |
|
1569 |
return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0; |
|
1570 |
} |
|
1571 |
||
1572 |
/*! |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1573 |
Sets this item's parent item to \a newParent. If this item already |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1574 |
has a parent, it is first removed from the previous parent. If \a |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1575 |
newParent is 0, this item will become a top-level item. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1576 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1577 |
Note that this implicitly adds this graphics item to the scene of |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1578 |
the parent. You should not \l{QGraphicsScene::addItem()}{add} the |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1579 |
item to the scene yourself. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1580 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1581 |
Calling this function on an item that is an ancestor of \a newParent |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1582 |
have undefined behaviour. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1583 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1584 |
\sa parentItem(), childItems() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1585 |
*/ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1586 |
void QGraphicsItem::setParentItem(QGraphicsItem *newParent) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1587 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1588 |
if (newParent == this) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1589 |
qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1590 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1591 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1592 |
if (newParent == d_ptr->parent) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1593 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1594 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1595 |
const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1596 |
qVariantFromValue<QGraphicsItem *>(newParent))); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1597 |
newParent = qVariantValue<QGraphicsItem *>(newParentVariant); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1598 |
if (newParent == d_ptr->parent) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1599 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1600 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1601 |
const QVariant thisPointerVariant(qVariantFromValue<QGraphicsItem *>(this)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1602 |
d_ptr->setParentItemHelper(newParent, &newParentVariant, &thisPointerVariant); |
0 | 1603 |
} |
1604 |
||
1605 |
/*! |
|
1606 |
\obsolete |
|
1607 |
||
1608 |
Use childItems() instead. |
|
1609 |
||
1610 |
\sa setParentItem() |
|
1611 |
*/ |
|
1612 |
QList<QGraphicsItem *> QGraphicsItem::children() const |
|
1613 |
{ |
|
1614 |
return childItems(); |
|
1615 |
} |
|
1616 |
||
1617 |
/*! |
|
1618 |
\since 4.4 |
|
1619 |
||
1620 |
Returns a list of this item's children. |
|
1621 |
||
1622 |
The items are sorted by stacking order. This takes into account both the |
|
1623 |
items' insertion order and their Z-values. |
|
1624 |
||
1625 |
\sa setParentItem(), zValue(), {QGraphicsItem#Sorting}{Sorting} |
|
1626 |
*/ |
|
1627 |
QList<QGraphicsItem *> QGraphicsItem::childItems() const |
|
1628 |
{ |
|
1629 |
const_cast<QGraphicsItem *>(this)->d_ptr->ensureSortedChildren(); |
|
1630 |
return d_ptr->children; |
|
1631 |
} |
|
1632 |
||
1633 |
/*! |
|
1634 |
\since 4.4 |
|
1635 |
Returns true if this item is a widget (i.e., QGraphicsWidget); otherwise, |
|
1636 |
returns false. |
|
1637 |
*/ |
|
1638 |
bool QGraphicsItem::isWidget() const |
|
1639 |
{ |
|
1640 |
return d_ptr->isWidget; |
|
1641 |
} |
|
1642 |
||
1643 |
/*! |
|
1644 |
\since 4.4 |
|
1645 |
Returns true if the item is a QGraphicsWidget window, otherwise returns |
|
1646 |
false. |
|
1647 |
||
1648 |
\sa QGraphicsWidget::windowFlags() |
|
1649 |
*/ |
|
1650 |
bool QGraphicsItem::isWindow() const |
|
1651 |
{ |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1652 |
return d_ptr->isWidget && (static_cast<const QGraphicsWidget *>(this)->windowType() & Qt::Window); |
0 | 1653 |
} |
1654 |
||
1655 |
/*! |
|
1656 |
\since 4.6 |
|
1657 |
Returns true if the item is a panel; otherwise returns false. |
|
1658 |
||
1659 |
\sa QGraphicsItem::panel(), ItemIsPanel |
|
1660 |
*/ |
|
1661 |
bool QGraphicsItem::isPanel() const |
|
1662 |
{ |
|
1663 |
return d_ptr->flags & ItemIsPanel; |
|
1664 |
} |
|
1665 |
||
1666 |
/*! |
|
1667 |
Returns this item's flags. The flags describe what configurable features |
|
1668 |
of the item are enabled and not. For example, if the flags include |
|
1669 |
ItemIsFocusable, the item can accept input focus. |
|
1670 |
||
1671 |
By default, no flags are enabled. |
|
1672 |
||
1673 |
\sa setFlags(), setFlag() |
|
1674 |
*/ |
|
1675 |
QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags() const |
|
1676 |
{ |
|
1677 |
return GraphicsItemFlags(d_ptr->flags); |
|
1678 |
} |
|
1679 |
||
1680 |
/*! |
|
1681 |
If \a enabled is true, the item flag \a flag is enabled; otherwise, it is |
|
1682 |
disabled. |
|
1683 |
||
1684 |
\sa flags(), setFlags() |
|
1685 |
*/ |
|
1686 |
void QGraphicsItem::setFlag(GraphicsItemFlag flag, bool enabled) |
|
1687 |
{ |
|
1688 |
if (enabled) |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1689 |
setFlags(GraphicsItemFlags(d_ptr->flags) | flag); |
0 | 1690 |
else |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1691 |
setFlags(GraphicsItemFlags(d_ptr->flags) & ~flag); |
0 | 1692 |
} |
1693 |
||
1694 |
/*! |
|
1695 |
\internal |
|
1696 |
||
1697 |
Sets the flag \a flag on \a item and all its children, to \a enabled. |
|
1698 |
*/ |
|
1699 |
static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag, |
|
1700 |
bool enabled) |
|
1701 |
{ |
|
1702 |
if (item->flags() & flag) { |
|
1703 |
// If this item already has the correct flag set, we don't have to |
|
1704 |
// propagate it. |
|
1705 |
return; |
|
1706 |
} |
|
1707 |
item->setFlag(flag, enabled); |
|
1708 |
foreach (QGraphicsItem *child, item->children()) |
|
1709 |
_q_qgraphicsItemSetFlag(child, flag, enabled); |
|
1710 |
} |
|
1711 |
||
1712 |
/*! |
|
1713 |
Sets the item flags to \a flags. All flags in \a flags are enabled; all |
|
1714 |
flags not in \a flags are disabled. |
|
1715 |
||
1716 |
If the item had focus and \a flags does not enable ItemIsFocusable, the |
|
1717 |
item loses focus as a result of calling this function. Similarly, if the |
|
1718 |
item was selected, and \a flags does not enabled ItemIsSelectable, the |
|
1719 |
item is automatically unselected. |
|
1720 |
||
1721 |
By default, no flags are enabled. (QGraphicsWidget enables the |
|
1722 |
ItemSendsGeometryChanges flag by default in order to track position |
|
1723 |
changes.) |
|
1724 |
||
1725 |
\sa flags(), setFlag() |
|
1726 |
*/ |
|
1727 |
void QGraphicsItem::setFlags(GraphicsItemFlags flags) |
|
1728 |
{ |
|
1729 |
if (isWindow()) |
|
1730 |
flags |= ItemIsPanel; |
|
1731 |
||
1732 |
// Notify change and check for adjustment. |
|
1733 |
if (quint32(d_ptr->flags) == quint32(flags)) |
|
1734 |
return; |
|
1735 |
flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt()); |
|
1736 |
if (quint32(d_ptr->flags) == quint32(flags)) |
|
1737 |
return; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1738 |
if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1739 |
d_ptr->scene->d_func()->index->itemChange(this, ItemFlagsChange, &flags); |
0 | 1740 |
|
1741 |
// Flags that alter the geometry of the item (or its children). |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1742 |
const quint32 geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations | ItemIsSelectable); |
0 | 1743 |
bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask); |
1744 |
if (fullUpdate) |
|
1745 |
d_ptr->paintedViewBoundingRectsNeedRepaint = 1; |
|
1746 |
||
1747 |
// Keep the old flags to compare the diff. |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1748 |
GraphicsItemFlags oldFlags = GraphicsItemFlags(d_ptr->flags); |
0 | 1749 |
|
1750 |
// Update flags. |
|
1751 |
d_ptr->flags = flags; |
|
1752 |
||
1753 |
if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) { |
|
1754 |
// Clear focus on the item if it has focus when the focusable flag |
|
1755 |
// is unset. |
|
1756 |
clearFocus(); |
|
1757 |
} |
|
1758 |
||
1759 |
if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) { |
|
1760 |
// Unselect the item if it is selected when the selectable flag is |
|
1761 |
// unset. |
|
1762 |
setSelected(false); |
|
1763 |
} |
|
1764 |
||
1765 |
if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) { |
|
1766 |
// Item children clipping changes. Propagate the ancestor flag to |
|
1767 |
// all children. |
|
1768 |
d_ptr->updateAncestorFlag(ItemClipsChildrenToShape); |
|
1769 |
} |
|
1770 |
||
1771 |
if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) { |
|
1772 |
// Item children clipping changes. Propagate the ancestor flag to |
|
1773 |
// all children. |
|
1774 |
d_ptr->updateAncestorFlag(ItemIgnoresTransformations); |
|
1775 |
} |
|
1776 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1777 |
if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1778 |
// NB! We change the flags directly here, so we must also update d_ptr->flags. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1779 |
// Note that this has do be done before the ItemStacksBehindParent check |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1780 |
// below; otherwise we will loose the change. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1781 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1782 |
// Update stack-behind. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1783 |
if (d_ptr->z < qreal(0.0)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1784 |
flags |= ItemStacksBehindParent; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1785 |
else |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1786 |
flags &= ~ItemStacksBehindParent; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1787 |
d_ptr->flags = flags; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1788 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1789 |
|
0 | 1790 |
if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) { |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1791 |
// NB! This check has to come after the ItemNegativeZStacksBehindParent |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1792 |
// check above. Be careful. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1793 |
|
0 | 1794 |
// Ensure child item sorting is up to date when toggling this flag. |
1795 |
if (d_ptr->parent) |
|
1796 |
d_ptr->parent->d_ptr->needSortChildren = 1; |
|
1797 |
else if (d_ptr->scene) |
|
1798 |
d_ptr->scene->d_func()->needSortTopLevelItems = 1; |
|
1799 |
} |
|
1800 |
||
1801 |
if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) { |
|
1802 |
// Update input method sensitivity in any views. |
|
1803 |
if (d_ptr->scene) |
|
1804 |
d_ptr->scene->d_func()->updateInputMethodSensitivityInViews(); |
|
1805 |
} |
|
1806 |
||
1807 |
||
1808 |
if ((d_ptr->panelModality != NonModal) |
|
1809 |
&& d_ptr->scene |
|
1810 |
&& (flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) { |
|
1811 |
// update the panel's modal state |
|
1812 |
if (flags & ItemIsPanel) |
|
1813 |
d_ptr->scene->d_func()->enterModal(this); |
|
1814 |
else |
|
1815 |
d_ptr->scene->d_func()->leaveModal(this); |
|
1816 |
} |
|
1817 |
||
1818 |
if (d_ptr->scene) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1819 |
if ((flags & ItemSendsScenePositionChanges) != (oldFlags & ItemSendsScenePositionChanges)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1820 |
if (flags & ItemSendsScenePositionChanges) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1821 |
d_ptr->scene->d_func()->registerScenePosItem(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1822 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1823 |
d_ptr->scene->d_func()->unregisterScenePosItem(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1824 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1825 |
d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true); |
0 | 1826 |
} |
1827 |
||
1828 |
// Notify change. |
|
1829 |
itemChange(ItemFlagsHaveChanged, quint32(flags)); |
|
1830 |
} |
|
1831 |
||
1832 |
/*! |
|
1833 |
\since 4.4 |
|
1834 |
Returns the cache mode for this item. The default mode is NoCache (i.e., |
|
1835 |
cache is disabled and all painting is immediate). |
|
1836 |
||
1837 |
\sa setCacheMode() |
|
1838 |
*/ |
|
1839 |
QGraphicsItem::CacheMode QGraphicsItem::cacheMode() const |
|
1840 |
{ |
|
1841 |
return QGraphicsItem::CacheMode(d_ptr->cacheMode); |
|
1842 |
} |
|
1843 |
||
1844 |
/*! |
|
1845 |
\since 4.4 |
|
1846 |
Sets the item's cache mode to \a mode. |
|
1847 |
||
1848 |
The optional \a logicalCacheSize argument is used only by |
|
1849 |
ItemCoordinateCache mode, and describes the resolution of the cache |
|
1850 |
buffer; if \a logicalCacheSize is (100, 100), QGraphicsItem will fit the |
|
1851 |
item into 100x100 pixels in graphics memory, regardless of the logical |
|
1852 |
size of the item itself. By default QGraphicsItem uses the size of |
|
1853 |
boundingRect(). For all other cache modes than ItemCoordinateCache, \a |
|
1854 |
logicalCacheSize is ignored. |
|
1855 |
||
1856 |
Caching can speed up rendering if your item spends a significant time |
|
1857 |
redrawing itself. In some cases the cache can also slow down rendering, in |
|
1858 |
particular when the item spends less time redrawing than QGraphicsItem |
|
1859 |
spends redrawing from the cache. When enabled, the item's paint() function |
|
1860 |
will be called only once for each call to update(); for any subsequent |
|
1861 |
repaint requests, the Graphics View framework will redraw from the |
|
1862 |
cache. This approach works particularly well with QGLWidget, which stores |
|
1863 |
all the cache as OpenGL textures. |
|
1864 |
||
1865 |
Be aware that QPixmapCache's cache limit may need to be changed to obtain |
|
1866 |
optimal performance. |
|
1867 |
||
1868 |
You can read more about the different cache modes in the CacheMode |
|
1869 |
documentation. |
|
1870 |
||
1871 |
\sa CacheMode, QPixmapCache::setCacheLimit() |
|
1872 |
*/ |
|
1873 |
void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize) |
|
1874 |
{ |
|
1875 |
CacheMode lastMode = CacheMode(d_ptr->cacheMode); |
|
1876 |
d_ptr->cacheMode = mode; |
|
1877 |
bool noVisualChange = (mode == NoCache && lastMode == NoCache) |
|
1878 |
|| (mode == NoCache && lastMode == DeviceCoordinateCache) |
|
1879 |
|| (mode == DeviceCoordinateCache && lastMode == NoCache); |
|
1880 |
if (mode == NoCache) { |
|
1881 |
d_ptr->removeExtraItemCache(); |
|
1882 |
} else { |
|
1883 |
QGraphicsItemCache *cache = d_ptr->extraItemCache(); |
|
1884 |
||
1885 |
// Reset old cache |
|
1886 |
cache->purge(); |
|
1887 |
||
1888 |
if (mode == ItemCoordinateCache) { |
|
1889 |
if (lastMode == mode && cache->fixedSize == logicalCacheSize) |
|
1890 |
noVisualChange = true; |
|
1891 |
cache->fixedSize = logicalCacheSize; |
|
1892 |
} |
|
1893 |
} |
|
1894 |
if (!noVisualChange) |
|
1895 |
update(); |
|
1896 |
} |
|
1897 |
||
1898 |
/*! |
|
1899 |
\since 4.6 |
|
1900 |
||
1901 |
Returns the modality for this item. |
|
1902 |
*/ |
|
1903 |
QGraphicsItem::PanelModality QGraphicsItem::panelModality() const |
|
1904 |
{ |
|
1905 |
return d_ptr->panelModality; |
|
1906 |
} |
|
1907 |
||
1908 |
/*! |
|
1909 |
\since 4.6 |
|
1910 |
||
1911 |
Sets the modality for this item to \a panelModality. |
|
1912 |
||
1913 |
Changing the modality of a visible item takes effect immediately. |
|
1914 |
*/ |
|
1915 |
void QGraphicsItem::setPanelModality(PanelModality panelModality) |
|
1916 |
{ |
|
1917 |
if (d_ptr->panelModality == panelModality) |
|
1918 |
return; |
|
1919 |
||
1920 |
PanelModality previousModality = d_ptr->panelModality; |
|
1921 |
bool enterLeaveModal = (isPanel() && d_ptr->scene && isVisible()); |
|
1922 |
if (enterLeaveModal && panelModality == NonModal) |
|
1923 |
d_ptr->scene->d_func()->leaveModal(this); |
|
1924 |
d_ptr->panelModality = panelModality; |
|
1925 |
if (enterLeaveModal && d_ptr->panelModality != NonModal) |
|
1926 |
d_ptr->scene->d_func()->enterModal(this, previousModality); |
|
1927 |
} |
|
1928 |
||
1929 |
/*! |
|
1930 |
\since 4.6 |
|
1931 |
||
1932 |
Returns true if this item is blocked by a modal panel, false otherwise. If \a blockingPanel is |
|
1933 |
non-zero, \a blockingPanel will be set to the modal panel that is blocking this item. If this |
|
1934 |
item is not blocked, \a blockingPanel will not be set by this function. |
|
1935 |
||
1936 |
This function always returns false for items not in a scene. |
|
1937 |
||
1938 |
\sa panelModality() setPanelModality() PanelModality |
|
1939 |
*/ |
|
1940 |
bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel) const |
|
1941 |
{ |
|
1942 |
if (!d_ptr->scene) |
|
1943 |
return false; |
|
1944 |
||
1945 |
||
1946 |
QGraphicsItem *dummy = 0; |
|
1947 |
if (!blockingPanel) |
|
1948 |
blockingPanel = &dummy; |
|
1949 |
||
1950 |
QGraphicsScenePrivate *scene_d = d_ptr->scene->d_func(); |
|
1951 |
if (scene_d->modalPanels.isEmpty()) |
|
1952 |
return false; |
|
1953 |
||
1954 |
// ### |
|
1955 |
if (!scene_d->popupWidgets.isEmpty() && scene_d->popupWidgets.first() == this) |
|
1956 |
return false; |
|
1957 |
||
1958 |
for (int i = 0; i < scene_d->modalPanels.count(); ++i) { |
|
1959 |
QGraphicsItem *modalPanel = scene_d->modalPanels.at(i); |
|
1960 |
if (modalPanel->panelModality() == QGraphicsItem::SceneModal) { |
|
1961 |
// Scene modal panels block all non-descendents. |
|
1962 |
if (modalPanel != this && !modalPanel->isAncestorOf(this)) { |
|
1963 |
*blockingPanel = modalPanel; |
|
1964 |
return true; |
|
1965 |
} |
|
1966 |
} else { |
|
1967 |
// Window modal panels block ancestors and siblings/cousins. |
|
1968 |
if (modalPanel != this |
|
1969 |
&& !modalPanel->isAncestorOf(this) |
|
1970 |
&& commonAncestorItem(modalPanel)) { |
|
1971 |
*blockingPanel = modalPanel; |
|
1972 |
return true; |
|
1973 |
} |
|
1974 |
} |
|
1975 |
} |
|
1976 |
return false; |
|
1977 |
} |
|
1978 |
||
1979 |
#ifndef QT_NO_TOOLTIP |
|
1980 |
/*! |
|
1981 |
Returns the item's tool tip, or an empty QString if no tool tip has been |
|
1982 |
set. |
|
1983 |
||
1984 |
\sa setToolTip(), QToolTip |
|
1985 |
*/ |
|
1986 |
QString QGraphicsItem::toolTip() const |
|
1987 |
{ |
|
1988 |
return d_ptr->extra(QGraphicsItemPrivate::ExtraToolTip).toString(); |
|
1989 |
} |
|
1990 |
||
1991 |
/*! |
|
1992 |
Sets the item's tool tip to \a toolTip. If \a toolTip is empty, the item's |
|
1993 |
tool tip is cleared. |
|
1994 |
||
1995 |
\sa toolTip(), QToolTip |
|
1996 |
*/ |
|
1997 |
void QGraphicsItem::setToolTip(const QString &toolTip) |
|
1998 |
{ |
|
1999 |
const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip)); |
|
2000 |
d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString()); |
|
2001 |
itemChange(ItemToolTipHasChanged, toolTipVariant); |
|
2002 |
} |
|
2003 |
#endif // QT_NO_TOOLTIP |
|
2004 |
||
2005 |
#ifndef QT_NO_CURSOR |
|
2006 |
/*! |
|
2007 |
Returns the current cursor shape for the item. The mouse cursor |
|
2008 |
will assume this shape when it's over this item. See the \link |
|
2009 |
Qt::CursorShape list of predefined cursor objects\endlink for a |
|
2010 |
range of useful shapes. |
|
2011 |
||
2012 |
An editor item might want to use an I-beam cursor: |
|
2013 |
||
2014 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 2 |
|
2015 |
||
2016 |
If no cursor has been set, the parent's cursor is used. |
|
2017 |
||
2018 |
\sa setCursor(), hasCursor(), unsetCursor(), QWidget::cursor, |
|
2019 |
QApplication::overrideCursor() |
|
2020 |
*/ |
|
2021 |
QCursor QGraphicsItem::cursor() const |
|
2022 |
{ |
|
2023 |
return qVariantValue<QCursor>(d_ptr->extra(QGraphicsItemPrivate::ExtraCursor)); |
|
2024 |
} |
|
2025 |
||
2026 |
/*! |
|
2027 |
Sets the current cursor shape for the item to \a cursor. The mouse cursor |
|
2028 |
will assume this shape when it's over this item. See the \link |
|
2029 |
Qt::CursorShape list of predefined cursor objects\endlink for a range of |
|
2030 |
useful shapes. |
|
2031 |
||
2032 |
An editor item might want to use an I-beam cursor: |
|
2033 |
||
2034 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 3 |
|
2035 |
||
2036 |
If no cursor has been set, the cursor of the item beneath is used. |
|
2037 |
||
2038 |
\sa cursor(), hasCursor(), unsetCursor(), QWidget::cursor, |
|
2039 |
QApplication::overrideCursor() |
|
2040 |
*/ |
|
2041 |
void QGraphicsItem::setCursor(const QCursor &cursor) |
|
2042 |
{ |
|
2043 |
const QVariant cursorVariant(itemChange(ItemCursorChange, qVariantFromValue<QCursor>(cursor))); |
|
2044 |
d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qVariantValue<QCursor>(cursorVariant)); |
|
2045 |
d_ptr->hasCursor = 1; |
|
2046 |
if (d_ptr->scene) { |
|
2047 |
d_ptr->scene->d_func()->allItemsUseDefaultCursor = false; |
|
2048 |
foreach (QGraphicsView *view, d_ptr->scene->views()) { |
|
2049 |
view->viewport()->setMouseTracking(true); |
|
2050 |
// Note: Some of this logic is duplicated in QGraphicsView's mouse events. |
|
2051 |
if (view->underMouse()) { |
|
2052 |
foreach (QGraphicsItem *itemUnderCursor, view->items(view->mapFromGlobal(QCursor::pos()))) { |
|
2053 |
if (itemUnderCursor->hasCursor()) { |
|
2054 |
QMetaObject::invokeMethod(view, "_q_setViewportCursor", |
|
2055 |
Q_ARG(QCursor, itemUnderCursor->cursor())); |
|
2056 |
break; |
|
2057 |
} |
|
2058 |
} |
|
2059 |
break; |
|
2060 |
} |
|
2061 |
} |
|
2062 |
} |
|
2063 |
itemChange(ItemCursorHasChanged, cursorVariant); |
|
2064 |
} |
|
2065 |
||
2066 |
/*! |
|
2067 |
Returns true if this item has a cursor set; otherwise, false is returned. |
|
2068 |
||
2069 |
By default, items don't have any cursor set. cursor() will return a |
|
2070 |
standard pointing arrow cursor. |
|
2071 |
||
2072 |
\sa unsetCursor() |
|
2073 |
*/ |
|
2074 |
bool QGraphicsItem::hasCursor() const |
|
2075 |
{ |
|
2076 |
return d_ptr->hasCursor; |
|
2077 |
} |
|
2078 |
||
2079 |
/*! |
|
2080 |
Clears the cursor from this item. |
|
2081 |
||
2082 |
\sa hasCursor(), setCursor() |
|
2083 |
*/ |
|
2084 |
void QGraphicsItem::unsetCursor() |
|
2085 |
{ |
|
2086 |
d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraCursor); |
|
2087 |
d_ptr->hasCursor = 0; |
|
2088 |
if (d_ptr->scene) { |
|
2089 |
foreach (QGraphicsView *view, d_ptr->scene->views()) { |
|
2090 |
if (view->underMouse() && view->itemAt(view->mapFromGlobal(QCursor::pos())) == this) { |
|
2091 |
QMetaObject::invokeMethod(view, "_q_unsetViewportCursor"); |
|
2092 |
break; |
|
2093 |
} |
|
2094 |
} |
|
2095 |
} |
|
2096 |
} |
|
2097 |
||
2098 |
#endif // QT_NO_CURSOR |
|
2099 |
||
2100 |
/*! |
|
2101 |
Returns true if the item is visible; otherwise, false is returned. |
|
2102 |
||
2103 |
Note that the item's general visibility is unrelated to whether or not it |
|
2104 |
is actually being visualized by a QGraphicsView. |
|
2105 |
||
2106 |
\sa setVisible() |
|
2107 |
*/ |
|
2108 |
bool QGraphicsItem::isVisible() const |
|
2109 |
{ |
|
2110 |
return d_ptr->visible; |
|
2111 |
} |
|
2112 |
||
2113 |
/*! |
|
2114 |
\since 4.4 |
|
2115 |
Returns true if the item is visible to \a parent; otherwise, false is |
|
2116 |
returned. \a parent can be 0, in which case this function will return |
|
2117 |
whether the item is visible to the scene or not. |
|
2118 |
||
2119 |
An item may not be visible to its ancestors even if isVisible() is true. If |
|
2120 |
any ancestor is hidden, the item itself will be implicitly hidden, in which |
|
2121 |
case this function will return false. |
|
2122 |
||
2123 |
\sa isVisible(), setVisible() |
|
2124 |
*/ |
|
2125 |
bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const |
|
2126 |
{ |
|
2127 |
if (!d_ptr->visible) |
|
2128 |
return false; |
|
2129 |
if (parent == this) |
|
2130 |
return true; |
|
2131 |
if (parentItem() && parentItem()->isVisibleTo(parent)) |
|
2132 |
return true; |
|
2133 |
if (!parent && !parentItem()) |
|
2134 |
return true; |
|
2135 |
return false; |
|
2136 |
} |
|
2137 |
||
2138 |
/*! |
|
2139 |
\internal |
|
2140 |
||
2141 |
Sets this item's visibility to \a newVisible. If \a explicitly is true, |
|
2142 |
this item will be "explicitly" \a newVisible; otherwise, it.. will not be. |
|
2143 |
*/ |
|
2144 |
void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bool update) |
|
2145 |
{ |
|
2146 |
Q_Q(QGraphicsItem); |
|
2147 |
||
2148 |
// Update explicit bit. |
|
2149 |
if (explicitly) |
|
2150 |
explicitlyHidden = newVisible ? 0 : 1; |
|
2151 |
||
2152 |
// Check if there's nothing to do. |
|
2153 |
if (visible == quint32(newVisible)) |
|
2154 |
return; |
|
2155 |
||
2156 |
// Don't show child if parent is not visible |
|
2157 |
if (parent && newVisible && !parent->d_ptr->visible) |
|
2158 |
return; |
|
2159 |
||
2160 |
// Modify the property. |
|
2161 |
const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange, |
|
2162 |
quint32(newVisible))); |
|
2163 |
newVisible = newVisibleVariant.toBool(); |
|
2164 |
if (visible == quint32(newVisible)) |
|
2165 |
return; |
|
2166 |
visible = newVisible; |
|
2167 |
||
2168 |
// Schedule redrawing |
|
2169 |
if (update) { |
|
2170 |
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); |
|
2171 |
if (c) |
|
2172 |
c->purge(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2173 |
if (scene) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2174 |
scene->d_func()->markDirty(q_ptr, QRectF(), /*invalidateChildren=*/false, /*force=*/true); |
0 | 2175 |
} |
2176 |
||
2177 |
// Certain properties are dropped as an item becomes invisible. |
|
2178 |
if (!newVisible) { |
|
2179 |
if (scene) { |
|
2180 |
if (scene->d_func()->mouseGrabberItems.contains(q)) |
|
2181 |
q->ungrabMouse(); |
|
2182 |
if (scene->d_func()->keyboardGrabberItems.contains(q)) |
|
2183 |
q->ungrabKeyboard(); |
|
2184 |
if (q->isPanel() && panelModality != QGraphicsItem::NonModal) |
|
2185 |
scene->d_func()->leaveModal(q_ptr); |
|
2186 |
} |
|
2187 |
if (q_ptr->hasFocus() && scene) { |
|
2188 |
// Hiding the closest non-panel ancestor of the focus item |
|
2189 |
QGraphicsItem *focusItem = scene->focusItem(); |
|
2190 |
bool clear = true; |
|
2191 |
if (isWidget && !focusItem->isPanel()) { |
|
2192 |
do { |
|
2193 |
if (focusItem == q_ptr) { |
|
2194 |
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true); |
|
2195 |
break; |
|
2196 |
} |
|
2197 |
} while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel()); |
|
2198 |
} |
|
2199 |
if (clear) |
|
2200 |
q_ptr->clearFocus(); |
|
2201 |
} |
|
2202 |
if (q_ptr->isSelected()) |
|
2203 |
q_ptr->setSelected(false); |
|
2204 |
} else { |
|
2205 |
geometryChanged = 1; |
|
2206 |
paintedViewBoundingRectsNeedRepaint = 1; |
|
2207 |
if (scene) { |
|
2208 |
if (isWidget) { |
|
2209 |
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr); |
|
2210 |
if (widget->windowType() == Qt::Popup) |
|
2211 |
scene->d_func()->addPopup(widget); |
|
2212 |
} |
|
2213 |
if (q->isPanel() && panelModality != QGraphicsItem::NonModal) { |
|
2214 |
scene->d_func()->enterModal(q_ptr); |
|
2215 |
} |
|
2216 |
} |
|
2217 |
} |
|
2218 |
||
2219 |
// Update children with explicitly = false. |
|
2220 |
const bool updateChildren = update && !(flags & QGraphicsItem::ItemClipsChildrenToShape); |
|
2221 |
foreach (QGraphicsItem *child, children) { |
|
2222 |
if (!newVisible || !child->d_ptr->explicitlyHidden) |
|
2223 |
child->d_ptr->setVisibleHelper(newVisible, false, updateChildren); |
|
2224 |
} |
|
2225 |
||
2226 |
// Update activation |
|
2227 |
if (scene && q->isPanel()) { |
|
2228 |
if (newVisible) { |
|
2229 |
if (parent && parent->isActive()) |
|
2230 |
q->setActive(true); |
|
2231 |
} else { |
|
2232 |
if (q->isActive()) |
|
2233 |
scene->setActivePanel(parent); |
|
2234 |
} |
|
2235 |
} |
|
2236 |
||
2237 |
// Enable subfocus |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2238 |
if (scene && newVisible) { |
0 | 2239 |
QGraphicsItem *p = parent; |
2240 |
bool done = false; |
|
2241 |
while (p) { |
|
2242 |
if (p->flags() & QGraphicsItem::ItemIsFocusScope) { |
|
2243 |
QGraphicsItem *fsi = p->d_ptr->focusScopeItem; |
|
2244 |
if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) { |
|
2245 |
done = true; |
|
2246 |
while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible()) |
|
2247 |
fsi = fsi->d_ptr->focusScopeItem; |
|
2248 |
scene->setFocusItem(fsi); |
|
2249 |
} |
|
2250 |
break; |
|
2251 |
} |
|
2252 |
p = p->d_ptr->parent; |
|
2253 |
} |
|
2254 |
if (!done) { |
|
2255 |
QGraphicsItem *fi = subFocusItem; |
|
2256 |
if (fi && fi != scene->focusItem()) { |
|
2257 |
scene->setFocusItem(fi); |
|
2258 |
} |
|
2259 |
} |
|
2260 |
} |
|
2261 |
||
2262 |
// Deliver post-change notification. |
|
2263 |
q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant); |
|
2264 |
||
2265 |
if (isObject) |
|
2266 |
emit static_cast<QGraphicsObject *>(q_ptr)->visibleChanged(); |
|
2267 |
} |
|
2268 |
||
2269 |
/*! |
|
2270 |
If \a visible is true, the item is made visible. Otherwise, the item is |
|
2271 |
made invisible. Invisible items are not painted, nor do they receive any |
|
2272 |
events. In particular, mouse events pass right through invisible items, |
|
2273 |
and are delivered to any item that may be behind. Invisible items are also |
|
2274 |
unselectable, they cannot take input focus, and are not detected by |
|
2275 |
QGraphicsScene's item location functions. |
|
2276 |
||
2277 |
If an item becomes invisible while grabbing the mouse, (i.e., while it is |
|
2278 |
receiving mouse events,) it will automatically lose the mouse grab, and |
|
2279 |
the grab is not regained by making the item visible again; it must receive |
|
2280 |
a new mouse press to regain the mouse grab. |
|
2281 |
||
2282 |
Similarly, an invisible item cannot have focus, so if the item has focus |
|
2283 |
when it becomes invisible, it will lose focus, and the focus is not |
|
2284 |
regained by simply making the item visible again. |
|
2285 |
||
2286 |
If you hide a parent item, all its children will also be hidden. If you |
|
2287 |
show a parent item, all children will be shown, unless they have been |
|
2288 |
explicitly hidden (i.e., if you call setVisible(false) on a child, it will |
|
2289 |
not be reshown even if its parent is hidden, and then shown again). |
|
2290 |
||
2291 |
Items are visible by default; it is unnecessary to call |
|
2292 |
setVisible() on a new item. |
|
2293 |
||
2294 |
\sa isVisible(), show(), hide() |
|
2295 |
*/ |
|
2296 |
void QGraphicsItem::setVisible(bool visible) |
|
2297 |
{ |
|
2298 |
d_ptr->setVisibleHelper(visible, /* explicit = */ true); |
|
2299 |
} |
|
2300 |
||
2301 |
/*! |
|
2302 |
\fn void QGraphicsItem::hide() |
|
2303 |
||
2304 |
Hides the item. (Items are visible by default.) |
|
2305 |
||
2306 |
This convenience function is equivalent to calling \c setVisible(false). |
|
2307 |
||
2308 |
\sa show(), setVisible() |
|
2309 |
*/ |
|
2310 |
||
2311 |
/*! |
|
2312 |
\fn void QGraphicsItem::show() |
|
2313 |
||
2314 |
Shows the item. (Items are visible by default.) |
|
2315 |
||
2316 |
This convenience function is equivalent to calling \c setVisible(true). |
|
2317 |
||
2318 |
\sa hide(), setVisible() |
|
2319 |
*/ |
|
2320 |
||
2321 |
/*! |
|
2322 |
Returns true if the item is enabled; otherwise, false is returned. |
|
2323 |
||
2324 |
\sa setEnabled() |
|
2325 |
*/ |
|
2326 |
bool QGraphicsItem::isEnabled() const |
|
2327 |
{ |
|
2328 |
return d_ptr->enabled; |
|
2329 |
} |
|
2330 |
||
2331 |
/*! |
|
2332 |
\internal |
|
2333 |
||
2334 |
Sets this item's visibility to \a newEnabled. If \a explicitly is true, |
|
2335 |
this item will be "explicitly" \a newEnabled; otherwise, it.. will not be. |
|
2336 |
*/ |
|
2337 |
void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bool update) |
|
2338 |
{ |
|
2339 |
// Update explicit bit. |
|
2340 |
if (explicitly) |
|
2341 |
explicitlyDisabled = newEnabled ? 0 : 1; |
|
2342 |
||
2343 |
// Check if there's nothing to do. |
|
2344 |
if (enabled == quint32(newEnabled)) |
|
2345 |
return; |
|
2346 |
||
2347 |
// Certain properties are dropped when an item is disabled. |
|
2348 |
if (!newEnabled) { |
|
2349 |
if (scene && scene->mouseGrabberItem() == q_ptr) |
|
2350 |
q_ptr->ungrabMouse(); |
|
2351 |
if (q_ptr->hasFocus()) { |
|
2352 |
// Disabling the closest non-panel ancestor of the focus item |
|
2353 |
// causes focus to pop to the next item, otherwise it's cleared. |
|
2354 |
QGraphicsItem *focusItem = scene->focusItem(); |
|
2355 |
bool clear = true; |
|
2356 |
if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) { |
|
2357 |
do { |
|
2358 |
if (focusItem == q_ptr) { |
|
2359 |
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true); |
|
2360 |
break; |
|
2361 |
} |
|
2362 |
} while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel()); |
|
2363 |
} |
|
2364 |
if (clear) |
|
2365 |
q_ptr->clearFocus(); |
|
2366 |
} |
|
2367 |
if (q_ptr->isSelected()) |
|
2368 |
q_ptr->setSelected(false); |
|
2369 |
} |
|
2370 |
||
2371 |
// Modify the property. |
|
2372 |
const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange, |
|
2373 |
quint32(newEnabled))); |
|
2374 |
enabled = newEnabledVariant.toBool(); |
|
2375 |
||
2376 |
// Schedule redraw. |
|
2377 |
if (update) |
|
2378 |
q_ptr->update(); |
|
2379 |
||
2380 |
foreach (QGraphicsItem *child, children) { |
|
2381 |
if (!newEnabled || !child->d_ptr->explicitlyDisabled) |
|
2382 |
child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false); |
|
2383 |
} |
|
2384 |
||
2385 |
// Deliver post-change notification. |
|
2386 |
q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant); |
|
2387 |
||
2388 |
if (isObject) |
|
2389 |
emit static_cast<QGraphicsObject *>(q_ptr)->enabledChanged(); |
|
2390 |
} |
|
2391 |
||
2392 |
/*! |
|
2393 |
If \a enabled is true, the item is enabled; otherwise, it is disabled. |
|
2394 |
||
2395 |
Disabled items are visible, but they do not receive any events, and cannot |
|
2396 |
take focus nor be selected. Mouse events are discarded; they are not |
|
2397 |
propagated unless the item is also invisible, or if it does not accept |
|
2398 |
mouse events (see acceptedMouseButtons()). A disabled item cannot become the |
|
2399 |
mouse grabber, and as a result of this, an item loses the grab if it |
|
2400 |
becomes disabled when grabbing the mouse, just like it loses focus if it |
|
2401 |
had focus when it was disabled. |
|
2402 |
||
2403 |
Disabled items are traditionally drawn using grayed-out colors (see \l |
|
2404 |
QPalette::Disabled). |
|
2405 |
||
2406 |
If you disable a parent item, all its children will also be disabled. If |
|
2407 |
you enable a parent item, all children will be enabled, unless they have |
|
2408 |
been explicitly disabled (i.e., if you call setEnabled(false) on a child, |
|
2409 |
it will not be reenabled if its parent is disabled, and then enabled |
|
2410 |
again). |
|
2411 |
||
2412 |
Items are enabled by default. |
|
2413 |
||
2414 |
\note If you install an event filter, you can still intercept events |
|
2415 |
before they are delivered to items; this mechanism disregards the item's |
|
2416 |
enabled state. |
|
2417 |
||
2418 |
\sa isEnabled() |
|
2419 |
*/ |
|
2420 |
void QGraphicsItem::setEnabled(bool enabled) |
|
2421 |
{ |
|
2422 |
d_ptr->setEnabledHelper(enabled, /* explicitly = */ true); |
|
2423 |
} |
|
2424 |
||
2425 |
/*! |
|
2426 |
Returns true if this item is selected; otherwise, false is returned. |
|
2427 |
||
2428 |
Items that are in a group inherit the group's selected state. |
|
2429 |
||
2430 |
Items are not selected by default. |
|
2431 |
||
2432 |
\sa setSelected(), QGraphicsScene::setSelectionArea() |
|
2433 |
*/ |
|
2434 |
bool QGraphicsItem::isSelected() const |
|
2435 |
{ |
|
2436 |
if (QGraphicsItemGroup *group = this->group()) |
|
2437 |
return group->isSelected(); |
|
2438 |
return d_ptr->selected; |
|
2439 |
} |
|
2440 |
||
2441 |
/*! |
|
2442 |
If \a selected is true and this item is selectable, this item is selected; |
|
2443 |
otherwise, it is unselected. |
|
2444 |
||
2445 |
If the item is in a group, the whole group's selected state is toggled by |
|
2446 |
this function. If the group is selected, all items in the group are also |
|
2447 |
selected, and if the group is not selected, no item in the group is |
|
2448 |
selected. |
|
2449 |
||
2450 |
Only visible, enabled, selectable items can be selected. If \a selected |
|
2451 |
is true and this item is either invisible or disabled or unselectable, |
|
2452 |
this function does nothing. |
|
2453 |
||
2454 |
By default, items cannot be selected. To enable selection, set the |
|
2455 |
ItemIsSelectable flag. |
|
2456 |
||
2457 |
This function is provided for convenience, allowing individual toggling of |
|
2458 |
the selected state of an item. However, a more common way of selecting |
|
2459 |
items is to call QGraphicsScene::setSelectionArea(), which will call this |
|
2460 |
function for all visible, enabled, and selectable items within a specified |
|
2461 |
area on the scene. |
|
2462 |
||
2463 |
\sa isSelected(), QGraphicsScene::selectedItems() |
|
2464 |
*/ |
|
2465 |
void QGraphicsItem::setSelected(bool selected) |
|
2466 |
{ |
|
2467 |
if (QGraphicsItemGroup *group = this->group()) { |
|
2468 |
group->setSelected(selected); |
|
2469 |
return; |
|
2470 |
} |
|
2471 |
||
2472 |
if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible) |
|
2473 |
selected = false; |
|
2474 |
if (d_ptr->selected == selected) |
|
2475 |
return; |
|
2476 |
const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected))); |
|
2477 |
bool newSelected = newSelectedVariant.toBool(); |
|
2478 |
if (d_ptr->selected == newSelected) |
|
2479 |
return; |
|
2480 |
d_ptr->selected = newSelected; |
|
2481 |
||
2482 |
update(); |
|
2483 |
if (d_ptr->scene) { |
|
2484 |
QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func(); |
|
2485 |
if (selected) { |
|
2486 |
sceneD->selectedItems << this; |
|
2487 |
} else { |
|
2488 |
// QGraphicsScene::selectedItems() lazily pulls out all items that are |
|
2489 |
// no longer selected. |
|
2490 |
} |
|
2491 |
if (!sceneD->selectionChanging) |
|
2492 |
emit d_ptr->scene->selectionChanged(); |
|
2493 |
} |
|
2494 |
||
2495 |
// Deliver post-change notification. |
|
2496 |
itemChange(QGraphicsItem::ItemSelectedHasChanged, newSelectedVariant); |
|
2497 |
} |
|
2498 |
||
2499 |
/*! |
|
2500 |
\since 4.5 |
|
2501 |
||
2502 |
Returns this item's local opacity, which is between 0.0 (transparent) and |
|
2503 |
1.0 (opaque). This value is combined with parent and ancestor values into |
|
2504 |
the effectiveOpacity(). The effective opacity decides how the item is |
|
2505 |
rendered. |
|
2506 |
||
2507 |
The opacity property decides the state of the painter passed to the |
|
2508 |
paint() function. If the item is cached, i.e., ItemCoordinateCache or |
|
2509 |
DeviceCoordinateCache, the effective property will be applied to the item's |
|
2510 |
cache as it is rendered. |
|
2511 |
||
2512 |
The default opacity is 1.0; fully opaque. |
|
2513 |
||
2514 |
\sa setOpacity(), paint(), ItemIgnoresParentOpacity, |
|
2515 |
ItemDoesntPropagateOpacityToChildren |
|
2516 |
*/ |
|
2517 |
qreal QGraphicsItem::opacity() const |
|
2518 |
{ |
|
2519 |
return d_ptr->opacity; |
|
2520 |
} |
|
2521 |
||
2522 |
/*! |
|
2523 |
\since 4.5 |
|
2524 |
||
2525 |
Returns this item's \e effective opacity, which is between 0.0 |
|
2526 |
(transparent) and 1.0 (opaque). This value is a combination of this item's |
|
2527 |
local opacity, and its parent and ancestors' opacities. The effective |
|
2528 |
opacity decides how the item is rendered. |
|
2529 |
||
2530 |
\sa opacity(), setOpacity(), paint(), ItemIgnoresParentOpacity, |
|
2531 |
ItemDoesntPropagateOpacityToChildren |
|
2532 |
*/ |
|
2533 |
qreal QGraphicsItem::effectiveOpacity() const |
|
2534 |
{ |
|
2535 |
return d_ptr->effectiveOpacity(); |
|
2536 |
} |
|
2537 |
||
2538 |
/*! |
|
2539 |
\since 4.5 |
|
2540 |
||
2541 |
Sets this item's local \a opacity, between 0.0 (transparent) and 1.0 |
|
2542 |
(opaque). The item's local opacity is combined with parent and ancestor |
|
2543 |
opacities into the effectiveOpacity(). |
|
2544 |
||
2545 |
By default, opacity propagates from parent to child, so if a parent's |
|
2546 |
opacity is 0.5 and the child is also 0.5, the child's effective opacity |
|
2547 |
will be 0.25. |
|
2548 |
||
2549 |
The opacity property decides the state of the painter passed to the |
|
2550 |
paint() function. If the item is cached, i.e., ItemCoordinateCache or |
|
2551 |
DeviceCoordinateCache, the effective property will be applied to the |
|
2552 |
item's cache as it is rendered. |
|
2553 |
||
2554 |
There are two item flags that affect how the item's opacity is combined |
|
2555 |
with the parent: ItemIgnoresParentOpacity and |
|
2556 |
ItemDoesntPropagateOpacityToChildren. |
|
2557 |
||
2558 |
\sa opacity(), effectiveOpacity() |
|
2559 |
*/ |
|
2560 |
void QGraphicsItem::setOpacity(qreal opacity) |
|
2561 |
{ |
|
2562 |
// Notify change. |
|
2563 |
const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity)); |
|
2564 |
||
2565 |
// Normalized opacity |
|
2566 |
qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1)); |
|
2567 |
||
2568 |
// No change? Done. |
|
2569 |
if (newOpacity == d_ptr->opacity) |
|
2570 |
return; |
|
2571 |
||
2572 |
d_ptr->opacity = newOpacity; |
|
2573 |
||
2574 |
// Notify change. |
|
2575 |
itemChange(ItemOpacityHasChanged, newOpacityVariant); |
|
2576 |
||
2577 |
// Update. |
|
2578 |
if (d_ptr->scene) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2579 |
#ifndef QT_NO_GRAPHICSEFFECT |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2580 |
d_ptr->invalidateParentGraphicsEffectsRecursively(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2581 |
if (!(d_ptr->flags & ItemDoesntPropagateOpacityToChildren)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2582 |
d_ptr->invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::OpacityChanged); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2583 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 2584 |
d_ptr->scene->d_func()->markDirty(this, QRectF(), |
2585 |
/*invalidateChildren=*/true, |
|
2586 |
/*force=*/false, |
|
2587 |
/*ignoreOpacity=*/true); |
|
2588 |
} |
|
2589 |
||
2590 |
if (d_ptr->isObject) |
|
2591 |
emit static_cast<QGraphicsObject *>(this)->opacityChanged(); |
|
2592 |
} |
|
2593 |
||
2594 |
/*! |
|
2595 |
Returns a pointer to this item's effect if it has one; otherwise 0. |
|
2596 |
||
2597 |
\since 4.6 |
|
2598 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2599 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 2600 |
QGraphicsEffect *QGraphicsItem::graphicsEffect() const |
2601 |
{ |
|
2602 |
return d_ptr->graphicsEffect; |
|
2603 |
} |
|
2604 |
||
2605 |
/*! |
|
2606 |
Sets \a effect as the item's effect. If there already is an effect installed |
|
2607 |
on this item, QGraphicsItem will delete the existing effect before installing |
|
2608 |
the new \a effect. |
|
2609 |
||
2610 |
If \a effect is the installed on a different item, setGraphicsEffect() will remove |
|
2611 |
the effect from the item and install it on this item. |
|
2612 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2613 |
QGraphicsItem takes ownership of \a effect. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2614 |
|
0 | 2615 |
\note This function will apply the effect on itself and all its children. |
2616 |
||
2617 |
\since 4.6 |
|
2618 |
*/ |
|
2619 |
void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect) |
|
2620 |
{ |
|
2621 |
if (d_ptr->graphicsEffect == effect) |
|
2622 |
return; |
|
2623 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2624 |
if (d_ptr->graphicsEffect) { |
0 | 2625 |
delete d_ptr->graphicsEffect; |
2626 |
d_ptr->graphicsEffect = 0; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2627 |
} else if (d_ptr->parent) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2628 |
d_ptr->parent->d_ptr->updateChildWithGraphicsEffectFlagRecursively(); |
0 | 2629 |
} |
2630 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2631 |
if (effect) { |
0 | 2632 |
// Set new effect. |
2633 |
QGraphicsEffectSourcePrivate *sourced = new QGraphicsItemEffectSourcePrivate(this); |
|
2634 |
QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); |
|
2635 |
d_ptr->graphicsEffect = effect; |
|
2636 |
effect->d_func()->setGraphicsEffectSource(source); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2637 |
prepareGeometryChange(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2638 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2639 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2640 |
#endif //QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2641 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2642 |
void QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2643 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2644 |
#ifndef QT_NO_GRAPHICSEFFECT |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2645 |
QGraphicsItemPrivate *itemPrivate = this; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2646 |
do { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2647 |
// parent chain already notified? |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2648 |
if (itemPrivate->mayHaveChildWithGraphicsEffect) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2649 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2650 |
itemPrivate->mayHaveChildWithGraphicsEffect = 1; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2651 |
} while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2652 |
#endif |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2653 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2654 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2655 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2656 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2657 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2658 |
Returns the effective bounding rect of the given item space rect. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2659 |
If the item has no effect, the rect is returned unmodified. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2660 |
If the item has an effect, the effective rect can be extend beyond the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2661 |
item's bounding rect, depending on the effect. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2662 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2663 |
\sa boundingRect() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2664 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2665 |
QRectF QGraphicsItemPrivate::effectiveBoundingRect(const QRectF &rect) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2666 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2667 |
#ifndef QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2668 |
Q_Q(const QGraphicsItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2669 |
QGraphicsEffect *effect = graphicsEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2670 |
if (scene && effect && effect->isEnabled()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2671 |
QRectF sceneRect = q->mapRectToScene(rect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2672 |
QRectF sceneEffectRect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2673 |
foreach (QGraphicsView *view, scene->views()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2674 |
QRectF deviceRect = view->d_func()->mapRectFromScene(sceneRect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2675 |
QRect deviceEffectRect = effect->boundingRectFor(deviceRect).toAlignedRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2676 |
sceneEffectRect |= view->d_func()->mapRectToScene(deviceEffectRect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2677 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2678 |
return q->mapRectFromScene(sceneEffectRect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2679 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2680 |
#endif //QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2681 |
return rect; |
0 | 2682 |
} |
2683 |
||
2684 |
/*! |
|
2685 |
\internal |
|
2686 |
\since 4.6 |
|
2687 |
Returns the effective bounding rect of the item. |
|
2688 |
If the item has no effect, this is the same as the item's bounding rect. |
|
2689 |
If the item has an effect, the effective rect can be larger than the item's |
|
2690 |
bouding rect, depending on the effect. |
|
2691 |
||
2692 |
\sa boundingRect() |
|
2693 |
*/ |
|
2694 |
QRectF QGraphicsItemPrivate::effectiveBoundingRect() const |
|
2695 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2696 |
#ifndef QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2697 |
Q_Q(const QGraphicsItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2698 |
QRectF brect = effectiveBoundingRect(q_ptr->boundingRect()); |
0 | 2699 |
if (ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) |
2700 |
return brect; |
|
2701 |
||
2702 |
const QGraphicsItem *effectParent = parent; |
|
2703 |
while (effectParent) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2704 |
QGraphicsEffect *effect = effectParent->d_ptr->graphicsEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2705 |
if (scene && effect && effect->isEnabled()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2706 |
const QRectF brectInParentSpace = q->mapRectToItem(effectParent, brect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2707 |
const QRectF effectRectInParentSpace = effectParent->d_ptr->effectiveBoundingRect(brectInParentSpace); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2708 |
brect = effectParent->mapRectToItem(q, effectRectInParentSpace); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2709 |
} |
0 | 2710 |
if (effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) |
2711 |
return brect; |
|
2712 |
effectParent = effectParent->d_ptr->parent; |
|
2713 |
} |
|
2714 |
||
2715 |
return brect; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2716 |
#else //QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2717 |
return q_ptr->boundingRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2718 |
#endif //QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2719 |
|
0 | 2720 |
} |
2721 |
||
2722 |
/*! |
|
2723 |
\internal |
|
2724 |
\since 4.6 |
|
2725 |
Returns the effective bounding rect of this item in scene coordinates, |
|
2726 |
by combining sceneTransform() with boundingRect(), taking into account |
|
2727 |
the effect that the item might have. |
|
2728 |
||
2729 |
If the item has no effect, this is the same as sceneBoundingRect(). |
|
2730 |
||
2731 |
\sa effectiveBoundingRect(), sceneBoundingRect() |
|
2732 |
*/ |
|
2733 |
QRectF QGraphicsItemPrivate::sceneEffectiveBoundingRect() const |
|
2734 |
{ |
|
2735 |
// Find translate-only offset |
|
2736 |
// COMBINE |
|
2737 |
QPointF offset; |
|
2738 |
const QGraphicsItem *parentItem = q_ptr; |
|
2739 |
const QGraphicsItemPrivate *itemd; |
|
2740 |
do { |
|
2741 |
itemd = parentItem->d_ptr.data(); |
|
2742 |
if (itemd->transformData) |
|
2743 |
break; |
|
2744 |
offset += itemd->pos; |
|
2745 |
} while ((parentItem = itemd->parent)); |
|
2746 |
||
2747 |
QRectF br = effectiveBoundingRect(); |
|
2748 |
br.translate(offset); |
|
2749 |
return !parentItem ? br : parentItem->sceneTransform().mapRect(br); |
|
2750 |
} |
|
2751 |
||
2752 |
/*! |
|
2753 |
Returns true if this item can accept drag and drop events; otherwise, |
|
2754 |
returns false. By default, items do not accept drag and drop events; items |
|
2755 |
are transparent to drag and drop. |
|
2756 |
||
2757 |
\sa setAcceptDrops() |
|
2758 |
*/ |
|
2759 |
bool QGraphicsItem::acceptDrops() const |
|
2760 |
{ |
|
2761 |
return d_ptr->acceptDrops; |
|
2762 |
} |
|
2763 |
||
2764 |
/*! |
|
2765 |
If \a on is true, this item will accept drag and drop events; otherwise, |
|
2766 |
it is transparent for drag and drop events. By default, items do not |
|
2767 |
accept drag and drop events. |
|
2768 |
||
2769 |
\sa acceptDrops() |
|
2770 |
*/ |
|
2771 |
void QGraphicsItem::setAcceptDrops(bool on) |
|
2772 |
{ |
|
2773 |
d_ptr->acceptDrops = on; |
|
2774 |
} |
|
2775 |
||
2776 |
/*! |
|
2777 |
Returns the mouse buttons that this item accepts mouse events for. By |
|
2778 |
default, all mouse buttons are accepted. |
|
2779 |
||
2780 |
If an item accepts a mouse button, it will become the mouse |
|
2781 |
grabber item when a mouse press event is delivered for that mouse |
|
2782 |
button. However, if the item does not accept the button, |
|
2783 |
QGraphicsScene will forward the mouse events to the first item |
|
2784 |
beneath it that does. |
|
2785 |
||
2786 |
\sa setAcceptedMouseButtons(), mousePressEvent() |
|
2787 |
*/ |
|
2788 |
Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const |
|
2789 |
{ |
|
2790 |
return Qt::MouseButtons(d_ptr->acceptedMouseButtons); |
|
2791 |
} |
|
2792 |
||
2793 |
/*! |
|
2794 |
Sets the mouse \a buttons that this item accepts mouse events for. |
|
2795 |
||
2796 |
By default, all mouse buttons are accepted. If an item accepts a |
|
2797 |
mouse button, it will become the mouse grabber item when a mouse |
|
2798 |
press event is delivered for that button. However, if the item |
|
2799 |
does not accept the mouse button, QGraphicsScene will forward the |
|
2800 |
mouse events to the first item beneath it that does. |
|
2801 |
||
2802 |
To disable mouse events for an item (i.e., make it transparent for mouse |
|
2803 |
events), call setAcceptedMouseButtons(0). |
|
2804 |
||
2805 |
\sa acceptedMouseButtons(), mousePressEvent() |
|
2806 |
*/ |
|
2807 |
void QGraphicsItem::setAcceptedMouseButtons(Qt::MouseButtons buttons) |
|
2808 |
{ |
|
2809 |
if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) { |
|
2810 |
if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this |
|
2811 |
&& d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) { |
|
2812 |
ungrabMouse(); |
|
2813 |
} |
|
2814 |
d_ptr->acceptedMouseButtons = quint32(buttons); |
|
2815 |
} |
|
2816 |
} |
|
2817 |
||
2818 |
/*! |
|
2819 |
\since 4.4 |
|
2820 |
||
2821 |
Returns true if an item accepts hover events |
|
2822 |
(QGraphicsSceneHoverEvent); otherwise, returns false. By default, |
|
2823 |
items do not accept hover events. |
|
2824 |
||
2825 |
\sa setAcceptedMouseButtons() |
|
2826 |
*/ |
|
2827 |
bool QGraphicsItem::acceptHoverEvents() const |
|
2828 |
{ |
|
2829 |
return d_ptr->acceptsHover; |
|
2830 |
} |
|
2831 |
||
2832 |
/*! |
|
2833 |
\obsolete |
|
2834 |
||
2835 |
Call acceptHoverEvents() instead. |
|
2836 |
*/ |
|
2837 |
bool QGraphicsItem::acceptsHoverEvents() const |
|
2838 |
{ |
|
2839 |
return d_ptr->acceptsHover; |
|
2840 |
} |
|
2841 |
||
2842 |
/*! |
|
2843 |
\since 4.4 |
|
2844 |
||
2845 |
If \a enabled is true, this item will accept hover events; |
|
2846 |
otherwise, it will ignore them. By default, items do not accept |
|
2847 |
hover events. |
|
2848 |
||
2849 |
Hover events are delivered when there is no current mouse grabber |
|
2850 |
item. They are sent when the mouse cursor enters an item, when it |
|
2851 |
moves around inside the item, and when the cursor leaves an |
|
2852 |
item. Hover events are commonly used to highlight an item when |
|
2853 |
it's entered, and for tracking the mouse cursor as it hovers over |
|
2854 |
the item (equivalent to QWidget::mouseTracking). |
|
2855 |
||
2856 |
Parent items receive hover enter events before their children, and |
|
2857 |
leave events after their children. The parent does not receive a |
|
2858 |
hover leave event if the cursor enters a child, though; the parent |
|
2859 |
stays "hovered" until the cursor leaves its area, including its |
|
2860 |
children's areas. |
|
2861 |
||
2862 |
If a parent item handles child events, it will receive hover move, |
|
2863 |
drag move, and drop events as the cursor passes through its |
|
2864 |
children, but it does not receive hover enter and hover leave, nor |
|
2865 |
drag enter and drag leave events on behalf of its children. |
|
2866 |
||
2867 |
A QGraphicsWidget with window decorations will accept hover events |
|
2868 |
regardless of the value of acceptHoverEvents(). |
|
2869 |
||
2870 |
\sa acceptHoverEvents(), hoverEnterEvent(), hoverMoveEvent(), |
|
2871 |
hoverLeaveEvent() |
|
2872 |
*/ |
|
2873 |
void QGraphicsItem::setAcceptHoverEvents(bool enabled) |
|
2874 |
{ |
|
2875 |
if (d_ptr->acceptsHover == quint32(enabled)) |
|
2876 |
return; |
|
2877 |
d_ptr->acceptsHover = quint32(enabled); |
|
2878 |
if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) { |
|
2879 |
d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false; |
|
2880 |
d_ptr->scene->d_func()->enableMouseTrackingOnViews(); |
|
2881 |
} |
|
2882 |
} |
|
2883 |
||
2884 |
/*! |
|
2885 |
\obsolete |
|
2886 |
||
2887 |
Use setAcceptHoverEvents(\a enabled) instead. |
|
2888 |
*/ |
|
2889 |
void QGraphicsItem::setAcceptsHoverEvents(bool enabled) |
|
2890 |
{ |
|
2891 |
setAcceptHoverEvents(enabled); |
|
2892 |
} |
|
2893 |
||
2894 |
/*! \since 4.6 |
|
2895 |
||
2896 |
Returns true if an item accepts \l{QTouchEvent}{touch events}; |
|
2897 |
otherwise, returns false. By default, items do not accept touch events. |
|
2898 |
||
2899 |
\sa setAcceptTouchEvents() |
|
2900 |
*/ |
|
2901 |
bool QGraphicsItem::acceptTouchEvents() const |
|
2902 |
{ |
|
2903 |
return d_ptr->acceptTouchEvents; |
|
2904 |
} |
|
2905 |
||
2906 |
/*! |
|
2907 |
\since 4.6 |
|
2908 |
||
2909 |
If \a enabled is true, this item will accept \l{QTouchEvent}{touch events}; |
|
2910 |
otherwise, it will ignore them. By default, items do not accept |
|
2911 |
touch events. |
|
2912 |
*/ |
|
2913 |
void QGraphicsItem::setAcceptTouchEvents(bool enabled) |
|
2914 |
{ |
|
2915 |
if (d_ptr->acceptTouchEvents == quint32(enabled)) |
|
2916 |
return; |
|
2917 |
d_ptr->acceptTouchEvents = quint32(enabled); |
|
2918 |
if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) { |
|
2919 |
d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false; |
|
2920 |
d_ptr->scene->d_func()->enableTouchEventsOnViews(); |
|
2921 |
} |
|
2922 |
} |
|
2923 |
||
2924 |
/*! |
|
2925 |
\since 4.6 |
|
2926 |
||
2927 |
Returns true if this item filters child events (i.e., all events |
|
2928 |
intended for any of its children are instead sent to this item); |
|
2929 |
otherwise, false is returned. |
|
2930 |
||
2931 |
The default value is false; child events are not filtered. |
|
2932 |
||
2933 |
\sa setFiltersChildEvents() |
|
2934 |
*/ |
|
2935 |
bool QGraphicsItem::filtersChildEvents() const |
|
2936 |
{ |
|
2937 |
return d_ptr->filtersDescendantEvents; |
|
2938 |
} |
|
2939 |
||
2940 |
/*! |
|
2941 |
\since 4.6 |
|
2942 |
||
2943 |
If \a enabled is true, this item is set to filter all events for |
|
2944 |
all its children (i.e., all events intented for any of its |
|
2945 |
children are instead sent to this item); otherwise, if \a enabled |
|
2946 |
is false, this item will only handle its own events. The default |
|
2947 |
value is false. |
|
2948 |
||
2949 |
\sa filtersChildEvents() |
|
2950 |
*/ |
|
2951 |
void QGraphicsItem::setFiltersChildEvents(bool enabled) |
|
2952 |
{ |
|
2953 |
if (d_ptr->filtersDescendantEvents == enabled) |
|
2954 |
return; |
|
2955 |
||
2956 |
d_ptr->filtersDescendantEvents = enabled; |
|
2957 |
d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2)); |
|
2958 |
} |
|
2959 |
||
2960 |
/*! |
|
2961 |
\obsolete |
|
2962 |
||
2963 |
Returns true if this item handles child events (i.e., all events |
|
2964 |
intended for any of its children are instead sent to this item); |
|
2965 |
otherwise, false is returned. |
|
2966 |
||
2967 |
This property is useful for item groups; it allows one item to |
|
2968 |
handle events on behalf of its children, as opposed to its |
|
2969 |
children handling their events individually. |
|
2970 |
||
2971 |
The default is to return false; children handle their own events. |
|
2972 |
The exception for this is if the item is a QGraphicsItemGroup, then |
|
2973 |
it defaults to return true. |
|
2974 |
||
2975 |
\sa setHandlesChildEvents() |
|
2976 |
*/ |
|
2977 |
bool QGraphicsItem::handlesChildEvents() const |
|
2978 |
{ |
|
2979 |
return d_ptr->handlesChildEvents; |
|
2980 |
} |
|
2981 |
||
2982 |
/*! |
|
2983 |
\obsolete |
|
2984 |
||
2985 |
If \a enabled is true, this item is set to handle all events for |
|
2986 |
all its children (i.e., all events intented for any of its |
|
2987 |
children are instead sent to this item); otherwise, if \a enabled |
|
2988 |
is false, this item will only handle its own events. The default |
|
2989 |
value is false. |
|
2990 |
||
2991 |
This property is useful for item groups; it allows one item to |
|
2992 |
handle events on behalf of its children, as opposed to its |
|
2993 |
children handling their events individually. |
|
2994 |
||
2995 |
If a child item accepts hover events, its parent will receive |
|
2996 |
hover move events as the cursor passes through the child, but it |
|
2997 |
does not receive hover enter and hover leave events on behalf of |
|
2998 |
its child. |
|
2999 |
||
3000 |
\sa handlesChildEvents() |
|
3001 |
*/ |
|
3002 |
void QGraphicsItem::setHandlesChildEvents(bool enabled) |
|
3003 |
{ |
|
3004 |
if (d_ptr->handlesChildEvents == enabled) |
|
3005 |
return; |
|
3006 |
||
3007 |
d_ptr->handlesChildEvents = enabled; |
|
3008 |
d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1)); |
|
3009 |
} |
|
3010 |
/*! |
|
3011 |
\since 4.6 |
|
3012 |
Returns true if this item is active; otherwise returns false. |
|
3013 |
||
3014 |
An item can only be active if the scene is active. An item is active |
|
3015 |
if it is, or is a descendent of, an active panel. Items in non-active |
|
3016 |
panels are not active. |
|
3017 |
||
3018 |
Items that are not part of a panel follow scene activation when the |
|
3019 |
scene has no active panel. |
|
3020 |
||
3021 |
Only active items can gain input focus. |
|
3022 |
||
3023 |
\sa QGraphicsScene::isActive(), QGraphicsScene::activePanel(), panel(), isPanel() |
|
3024 |
*/ |
|
3025 |
bool QGraphicsItem::isActive() const |
|
3026 |
{ |
|
3027 |
if (!d_ptr->scene || !d_ptr->scene->isActive()) |
|
3028 |
return false; |
|
3029 |
return panel() == d_ptr->scene->activePanel(); |
|
3030 |
} |
|
3031 |
||
3032 |
/*! |
|
3033 |
\since 4.6 |
|
3034 |
||
3035 |
If \a active is true, and the scene is active, this item's panel will be |
|
3036 |
activated. Otherwise, the panel is deactivated. |
|
3037 |
||
3038 |
If the item is not part of an active scene, \a active will decide what |
|
3039 |
happens to the panel when the scene becomes active or the item is added to |
|
3040 |
the scene. If true, the item's panel will be activated when the item is |
|
3041 |
either added to the scene or the scene is activated. Otherwise, the item |
|
3042 |
will stay inactive independent of the scene's activated state. |
|
3043 |
||
3044 |
\sa isPanel(), QGraphicsScene::setActivePanel(), QGraphicsScene::isActive() |
|
3045 |
*/ |
|
3046 |
void QGraphicsItem::setActive(bool active) |
|
3047 |
{ |
|
3048 |
d_ptr->explicitActivate = 1; |
|
3049 |
d_ptr->wantsActive = active; |
|
3050 |
if (d_ptr->scene) { |
|
3051 |
if (active) { |
|
3052 |
// Activate this item. |
|
3053 |
d_ptr->scene->setActivePanel(this); |
|
3054 |
} else { |
|
3055 |
// Deactivate this item, and reactivate the last active item |
|
3056 |
// (if any). |
|
3057 |
QGraphicsItem *lastActive = d_ptr->scene->d_func()->lastActivePanel; |
|
3058 |
d_ptr->scene->setActivePanel(lastActive != this ? lastActive : 0); |
|
3059 |
} |
|
3060 |
} |
|
3061 |
} |
|
3062 |
||
3063 |
/*! |
|
3064 |
Returns true if this item is active, and it or its \l{focusProxy()}{focus |
|
3065 |
proxy} has keyboard input focus; otherwise, returns false. |
|
3066 |
||
3067 |
\sa focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive() |
|
3068 |
*/ |
|
3069 |
bool QGraphicsItem::hasFocus() const |
|
3070 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3071 |
if (!d_ptr->scene || !d_ptr->scene->isActive()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3072 |
return false; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3073 |
|
0 | 3074 |
if (d_ptr->focusProxy) |
3075 |
return d_ptr->focusProxy->hasFocus(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3076 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3077 |
if (d_ptr->scene->d_func()->focusItem != this) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3078 |
return false; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3079 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3080 |
return panel() == d_ptr->scene->d_func()->activePanel; |
0 | 3081 |
} |
3082 |
||
3083 |
/*! |
|
3084 |
Gives keyboard input focus to this item. The \a focusReason argument will |
|
3085 |
be passed into any \l{QFocusEvent}{focus event} generated by this function; |
|
3086 |
it is used to give an explanation of what caused the item to get focus. |
|
3087 |
||
3088 |
Only enabled items that set the ItemIsFocusable flag can accept keyboard |
|
3089 |
focus. |
|
3090 |
||
3091 |
If this item is not visible, not active, or not associated with a scene, |
|
3092 |
it will not gain immediate input focus. However, it will be registered as |
|
3093 |
the preferred focus item for its subtree of items, should it later become |
|
3094 |
visible. |
|
3095 |
||
3096 |
As a result of calling this function, this item will receive a |
|
3097 |
\l{focusInEvent()}{focus in event} with \a focusReason. If another item |
|
3098 |
already has focus, that item will first receive a \l{focusOutEvent()} |
|
3099 |
{focus out event} indicating that it has lost input focus. |
|
3100 |
||
3101 |
\sa clearFocus(), hasFocus(), focusItem(), focusProxy() |
|
3102 |
*/ |
|
3103 |
void QGraphicsItem::setFocus(Qt::FocusReason focusReason) |
|
3104 |
{ |
|
3105 |
d_ptr->setFocusHelper(focusReason, /* climb = */ true); |
|
3106 |
} |
|
3107 |
||
3108 |
/*! |
|
3109 |
\internal |
|
3110 |
*/ |
|
3111 |
void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb) |
|
3112 |
{ |
|
3113 |
// Disabled / unfocusable items cannot accept focus. |
|
3114 |
if (!q_ptr->isEnabled() || !(flags & QGraphicsItem::ItemIsFocusable)) |
|
3115 |
return; |
|
3116 |
||
3117 |
// Find focus proxy. |
|
3118 |
QGraphicsItem *f = q_ptr; |
|
3119 |
while (f->d_ptr->focusProxy) |
|
3120 |
f = f->d_ptr->focusProxy; |
|
3121 |
||
3122 |
// Return if it already has focus. |
|
3123 |
if (scene && scene->focusItem() == f) |
|
3124 |
return; |
|
3125 |
||
3126 |
// Update focus scope item ptr. |
|
3127 |
QGraphicsItem *p = parent; |
|
3128 |
while (p) { |
|
3129 |
if (p->flags() & QGraphicsItem::ItemIsFocusScope) { |
|
3130 |
p->d_ptr->focusScopeItem = q_ptr; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3131 |
if (!p->focusItem()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3132 |
// If you call setFocus on a child of a focus scope that |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3133 |
// doesn't currently have a focus item, then stop. |
0 | 3134 |
return; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3135 |
} |
0 | 3136 |
break; |
3137 |
} |
|
3138 |
p = p->d_ptr->parent; |
|
3139 |
} |
|
3140 |
||
3141 |
if (climb) { |
|
3142 |
while (f->d_ptr->focusScopeItem && f->d_ptr->focusScopeItem->isVisible()) |
|
3143 |
f = f->d_ptr->focusScopeItem; |
|
3144 |
} |
|
3145 |
||
3146 |
// Update the child focus chain. |
|
3147 |
f->d_ptr->setSubFocus(); |
|
3148 |
||
3149 |
// Update the scene's focus item. |
|
3150 |
if (scene) { |
|
3151 |
QGraphicsItem *p = q_ptr->panel(); |
|
3152 |
if ((!p && scene->isActive()) || (p && p->isActive())) { |
|
3153 |
// Visible items immediately gain focus from scene. |
|
3154 |
scene->d_func()->setFocusItemHelper(f, focusReason); |
|
3155 |
} |
|
3156 |
} |
|
3157 |
} |
|
3158 |
||
3159 |
/*! |
|
3160 |
Takes keyboard input focus from the item. |
|
3161 |
||
3162 |
If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this |
|
3163 |
item to tell it that it is about to lose the focus. |
|
3164 |
||
3165 |
Only items that set the ItemIsFocusable flag, or widgets that set an |
|
3166 |
appropriate focus policy, can accept keyboard focus. |
|
3167 |
||
3168 |
\sa setFocus(), hasFocus(), QGraphicsWidget::focusPolicy |
|
3169 |
*/ |
|
3170 |
void QGraphicsItem::clearFocus() |
|
3171 |
{ |
|
3172 |
// Pass focus to the closest parent focus scope. |
|
3173 |
if (!d_ptr->inDestructor) { |
|
3174 |
QGraphicsItem *p = d_ptr->parent; |
|
3175 |
while (p) { |
|
3176 |
if (p->flags() & ItemIsFocusScope) { |
|
3177 |
p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false); |
|
3178 |
return; |
|
3179 |
} |
|
3180 |
p = p->d_ptr->parent; |
|
3181 |
} |
|
3182 |
} |
|
3183 |
||
3184 |
// Invisible items with focus must explicitly clear subfocus. |
|
3185 |
d_ptr->clearSubFocus(this); |
|
3186 |
||
3187 |
if (hasFocus()) { |
|
3188 |
// If this item has the scene's input focus, clear it. |
|
3189 |
d_ptr->scene->setFocusItem(0); |
|
3190 |
} |
|
3191 |
} |
|
3192 |
||
3193 |
/*! |
|
3194 |
\since 4.6 |
|
3195 |
||
3196 |
Returns this item's focus proxy, or 0 if this item has no |
|
3197 |
focus proxy. |
|
3198 |
||
3199 |
\sa setFocusProxy(), setFocus(), hasFocus() |
|
3200 |
*/ |
|
3201 |
QGraphicsItem *QGraphicsItem::focusProxy() const |
|
3202 |
{ |
|
3203 |
return d_ptr->focusProxy; |
|
3204 |
} |
|
3205 |
||
3206 |
/*! |
|
3207 |
\since 4.6 |
|
3208 |
||
3209 |
Sets the item's focus proxy to \a item. |
|
3210 |
||
3211 |
If an item has a focus proxy, the focus proxy will receive |
|
3212 |
input focus when the item gains input focus. The item itself |
|
3213 |
will still have focus (i.e., hasFocus() will return true), |
|
3214 |
but only the focus proxy will receive the keyboard input. |
|
3215 |
||
3216 |
A focus proxy can itself have a focus proxy, and so on. In |
|
3217 |
such case, keyboard input will be handled by the outermost |
|
3218 |
focus proxy. |
|
3219 |
||
3220 |
The focus proxy \a item must belong to the same scene as |
|
3221 |
this item. |
|
3222 |
||
3223 |
\sa focusProxy(), setFocus(), hasFocus() |
|
3224 |
*/ |
|
3225 |
void QGraphicsItem::setFocusProxy(QGraphicsItem *item) |
|
3226 |
{ |
|
3227 |
if (item == d_ptr->focusProxy) |
|
3228 |
return; |
|
3229 |
if (item == this) { |
|
3230 |
qWarning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy"); |
|
3231 |
return; |
|
3232 |
} |
|
3233 |
if (item) { |
|
3234 |
if (item->d_ptr->scene != d_ptr->scene) { |
|
3235 |
qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene"); |
|
3236 |
return; |
|
3237 |
} |
|
3238 |
for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) { |
|
3239 |
if (f == this) { |
|
3240 |
qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item); |
|
3241 |
return; |
|
3242 |
} |
|
3243 |
} |
|
3244 |
} |
|
3245 |
||
3246 |
QGraphicsItem *lastFocusProxy = d_ptr->focusProxy; |
|
3247 |
if (lastFocusProxy) |
|
3248 |
lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy); |
|
3249 |
d_ptr->focusProxy = item; |
|
3250 |
if (item) |
|
3251 |
item->d_ptr->focusProxyRefs << &d_ptr->focusProxy; |
|
3252 |
} |
|
3253 |
||
3254 |
/*! |
|
3255 |
\since 4.6 |
|
3256 |
||
3257 |
If this item, a child or descendant of this item currently has input |
|
3258 |
focus, this function will return a pointer to that item. If |
|
3259 |
no descendant has input focus, 0 is returned. |
|
3260 |
||
3261 |
\sa hasFocus(), setFocus(), QWidget::focusWidget() |
|
3262 |
*/ |
|
3263 |
QGraphicsItem *QGraphicsItem::focusItem() const |
|
3264 |
{ |
|
3265 |
return d_ptr->subFocusItem; |
|
3266 |
} |
|
3267 |
||
3268 |
/*! |
|
3269 |
\internal |
|
3270 |
||
3271 |
Returns this item's focus scope item. |
|
3272 |
*/ |
|
3273 |
QGraphicsItem *QGraphicsItem::focusScopeItem() const |
|
3274 |
{ |
|
3275 |
return d_ptr->focusScopeItem; |
|
3276 |
} |
|
3277 |
||
3278 |
/*! |
|
3279 |
\since 4.4 |
|
3280 |
Grabs the mouse input. |
|
3281 |
||
3282 |
This item will receive all mouse events for the scene until any of the |
|
3283 |
following events occurs: |
|
3284 |
||
3285 |
\list |
|
3286 |
\o The item becomes invisible |
|
3287 |
\o The item is removed from the scene |
|
3288 |
\o The item is deleted |
|
3289 |
\o The item call ungrabMouse() |
|
3290 |
\o Another item calls grabMouse(); the item will regain the mouse grab |
|
3291 |
when the other item calls ungrabMouse(). |
|
3292 |
\endlist |
|
3293 |
||
3294 |
When an item gains the mouse grab, it receives a QEvent::GrabMouse |
|
3295 |
event. When it loses the mouse grab, it receives a QEvent::UngrabMouse |
|
3296 |
event. These events can be used to detect when your item gains or loses |
|
3297 |
the mouse grab through other means than receiving mouse button events. |
|
3298 |
||
3299 |
It is almost never necessary to explicitly grab the mouse in Qt, as Qt |
|
3300 |
grabs and releases it sensibly. In particular, Qt grabs the mouse when you |
|
3301 |
press a mouse button, and keeps the mouse grabbed until you release the |
|
3302 |
last mouse button. Also, Qt::Popup widgets implicitly call grabMouse() |
|
3303 |
when shown, and ungrabMouse() when hidden. |
|
3304 |
||
3305 |
Note that only visible items can grab mouse input. Calling grabMouse() on |
|
3306 |
an invisible item has no effect. |
|
3307 |
||
3308 |
Keyboard events are not affected. |
|
3309 |
||
3310 |
\sa QGraphicsScene::mouseGrabberItem(), ungrabMouse(), grabKeyboard() |
|
3311 |
*/ |
|
3312 |
void QGraphicsItem::grabMouse() |
|
3313 |
{ |
|
3314 |
if (!d_ptr->scene) { |
|
3315 |
qWarning("QGraphicsItem::grabMouse: cannot grab mouse without scene"); |
|
3316 |
return; |
|
3317 |
} |
|
3318 |
if (!d_ptr->visible) { |
|
3319 |
qWarning("QGraphicsItem::grabMouse: cannot grab mouse while invisible"); |
|
3320 |
return; |
|
3321 |
} |
|
3322 |
d_ptr->scene->d_func()->grabMouse(this); |
|
3323 |
} |
|
3324 |
||
3325 |
/*! |
|
3326 |
\since 4.4 |
|
3327 |
Releases the mouse grab. |
|
3328 |
||
3329 |
\sa grabMouse(), ungrabKeyboard() |
|
3330 |
*/ |
|
3331 |
void QGraphicsItem::ungrabMouse() |
|
3332 |
{ |
|
3333 |
if (!d_ptr->scene) { |
|
3334 |
qWarning("QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene"); |
|
3335 |
return; |
|
3336 |
} |
|
3337 |
d_ptr->scene->d_func()->ungrabMouse(this); |
|
3338 |
} |
|
3339 |
||
3340 |
/*! |
|
3341 |
\since 4.4 |
|
3342 |
Grabs the keyboard input. |
|
3343 |
||
3344 |
The item will receive all keyboard input to the scene until one of the |
|
3345 |
following events occur: |
|
3346 |
||
3347 |
\list |
|
3348 |
\o The item becomes invisible |
|
3349 |
\o The item is removed from the scene |
|
3350 |
\o The item is deleted |
|
3351 |
\o The item calls ungrabKeyboard() |
|
3352 |
\o Another item calls grabKeyboard(); the item will regain the keyboard grab |
|
3353 |
when the other item calls ungrabKeyboard(). |
|
3354 |
\endlist |
|
3355 |
||
3356 |
When an item gains the keyboard grab, it receives a QEvent::GrabKeyboard |
|
3357 |
event. When it loses the keyboard grab, it receives a |
|
3358 |
QEvent::UngrabKeyboard event. These events can be used to detect when your |
|
3359 |
item gains or loses the keyboard grab through other means than gaining |
|
3360 |
input focus. |
|
3361 |
||
3362 |
It is almost never necessary to explicitly grab the keyboard in Qt, as Qt |
|
3363 |
grabs and releases it sensibly. In particular, Qt grabs the keyboard when |
|
3364 |
your item gains input focus, and releases it when your item loses input |
|
3365 |
focus, or when the item is hidden. |
|
3366 |
||
3367 |
Note that only visible items can grab keyboard input. Calling |
|
3368 |
grabKeyboard() on an invisible item has no effect. |
|
3369 |
||
3370 |
Keyboard events are not affected. |
|
3371 |
||
3372 |
\sa ungrabKeyboard(), grabMouse(), setFocus() |
|
3373 |
*/ |
|
3374 |
void QGraphicsItem::grabKeyboard() |
|
3375 |
{ |
|
3376 |
if (!d_ptr->scene) { |
|
3377 |
qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard without scene"); |
|
3378 |
return; |
|
3379 |
} |
|
3380 |
if (!d_ptr->visible) { |
|
3381 |
qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible"); |
|
3382 |
return; |
|
3383 |
} |
|
3384 |
d_ptr->scene->d_func()->grabKeyboard(this); |
|
3385 |
} |
|
3386 |
||
3387 |
/*! |
|
3388 |
\since 4.4 |
|
3389 |
Releases the keyboard grab. |
|
3390 |
||
3391 |
\sa grabKeyboard(), ungrabMouse() |
|
3392 |
*/ |
|
3393 |
void QGraphicsItem::ungrabKeyboard() |
|
3394 |
{ |
|
3395 |
if (!d_ptr->scene) { |
|
3396 |
qWarning("QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene"); |
|
3397 |
return; |
|
3398 |
} |
|
3399 |
d_ptr->scene->d_func()->ungrabKeyboard(this); |
|
3400 |
} |
|
3401 |
||
3402 |
/*! |
|
3403 |
Returns the position of the item in parent coordinates. If the item has no |
|
3404 |
parent, its position is given in scene coordinates. |
|
3405 |
||
3406 |
The position of the item describes its origin (local coordinate |
|
3407 |
(0, 0)) in parent coordinates; this function returns the same as |
|
3408 |
mapToParent(0, 0). |
|
3409 |
||
3410 |
For convenience, you can also call scenePos() to determine the |
|
3411 |
item's position in scene coordinates, regardless of its parent. |
|
3412 |
||
3413 |
\sa x(), y(), setPos(), transform(), {The Graphics View Coordinate System} |
|
3414 |
*/ |
|
3415 |
QPointF QGraphicsItem::pos() const |
|
3416 |
{ |
|
3417 |
return d_ptr->pos; |
|
3418 |
} |
|
3419 |
||
3420 |
/*! |
|
3421 |
\fn QGraphicsItem::x() const |
|
3422 |
||
3423 |
This convenience function is equivalent to calling pos().x(). |
|
3424 |
||
3425 |
\sa y() |
|
3426 |
*/ |
|
3427 |
||
3428 |
/*! |
|
3429 |
\since 4.6 |
|
3430 |
||
3431 |
Set's the \a x coordinate of the item's position. Equivalent to |
|
3432 |
calling setPos(x, y()). |
|
3433 |
||
3434 |
\sa x(), setPos() |
|
3435 |
*/ |
|
3436 |
void QGraphicsItem::setX(qreal x) |
|
3437 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3438 |
if (d_ptr->inDestructor) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3439 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3440 |
|
0 | 3441 |
d_ptr->setPosHelper(QPointF(x, d_ptr->pos.y())); |
3442 |
} |
|
3443 |
||
3444 |
/*! |
|
3445 |
\fn QGraphicsItem::y() const |
|
3446 |
||
3447 |
This convenience function is equivalent to calling pos().y(). |
|
3448 |
||
3449 |
\sa x() |
|
3450 |
*/ |
|
3451 |
||
3452 |
/*! |
|
3453 |
\since 4.6 |
|
3454 |
||
3455 |
Set's the \a y coordinate of the item's position. Equivalent to |
|
3456 |
calling setPos(x(), y). |
|
3457 |
||
3458 |
\sa x(), setPos() |
|
3459 |
*/ |
|
3460 |
void QGraphicsItem::setY(qreal y) |
|
3461 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3462 |
if (d_ptr->inDestructor) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3463 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3464 |
|
0 | 3465 |
d_ptr->setPosHelper(QPointF(d_ptr->pos.x(), y)); |
3466 |
} |
|
3467 |
||
3468 |
/*! |
|
3469 |
Returns the item's position in scene coordinates. This is |
|
3470 |
equivalent to calling \c mapToScene(0, 0). |
|
3471 |
||
3472 |
\sa pos(), sceneTransform(), {The Graphics View Coordinate System} |
|
3473 |
*/ |
|
3474 |
QPointF QGraphicsItem::scenePos() const |
|
3475 |
{ |
|
3476 |
return mapToScene(0, 0); |
|
3477 |
} |
|
3478 |
||
3479 |
/*! |
|
3480 |
\internal |
|
3481 |
||
3482 |
Sets the position \a pos. |
|
3483 |
*/ |
|
3484 |
void QGraphicsItemPrivate::setPosHelper(const QPointF &pos) |
|
3485 |
{ |
|
3486 |
Q_Q(QGraphicsItem); |
|
3487 |
inSetPosHelper = 1; |
|
3488 |
if (scene) |
|
3489 |
q->prepareGeometryChange(); |
|
3490 |
QPointF oldPos = this->pos; |
|
3491 |
this->pos = pos; |
|
3492 |
dirtySceneTransform = 1; |
|
3493 |
inSetPosHelper = 0; |
|
3494 |
if (isObject) { |
|
3495 |
if (pos.x() != oldPos.x()) |
|
3496 |
emit static_cast<QGraphicsObject *>(q_ptr)->xChanged(); |
|
3497 |
if (pos.y() != oldPos.y()) |
|
3498 |
emit static_cast<QGraphicsObject *>(q_ptr)->yChanged(); |
|
3499 |
} |
|
3500 |
} |
|
3501 |
||
3502 |
/*! |
|
3503 |
\internal |
|
3504 |
||
3505 |
Sets the transform \a transform. |
|
3506 |
*/ |
|
3507 |
void QGraphicsItemPrivate::setTransformHelper(const QTransform &transform) |
|
3508 |
{ |
|
3509 |
q_ptr->prepareGeometryChange(); |
|
3510 |
transformData->transform = transform; |
|
3511 |
dirtySceneTransform = 1; |
|
3512 |
} |
|
3513 |
||
3514 |
/*! |
|
3515 |
Sets the position of the item to \a pos, which is in parent |
|
3516 |
coordinates. For items with no parent, \a pos is in scene |
|
3517 |
coordinates. |
|
3518 |
||
3519 |
The position of the item describes its origin (local coordinate |
|
3520 |
(0, 0)) in parent coordinates. |
|
3521 |
||
3522 |
\sa pos(), scenePos(), {The Graphics View Coordinate System} |
|
3523 |
*/ |
|
3524 |
void QGraphicsItem::setPos(const QPointF &pos) |
|
3525 |
{ |
|
3526 |
if (d_ptr->pos == pos) |
|
3527 |
return; |
|
3528 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3529 |
if (d_ptr->inDestructor) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3530 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3531 |
|
0 | 3532 |
// Update and repositition. |
3533 |
if (!(d_ptr->flags & ItemSendsGeometryChanges)) { |
|
3534 |
d_ptr->setPosHelper(pos); |
|
3535 |
return; |
|
3536 |
} |
|
3537 |
||
3538 |
// Notify the item that the position is changing. |
|
3539 |
const QVariant newPosVariant(itemChange(ItemPositionChange, qVariantFromValue<QPointF>(pos))); |
|
3540 |
QPointF newPos = newPosVariant.toPointF(); |
|
3541 |
if (newPos == d_ptr->pos) |
|
3542 |
return; |
|
3543 |
||
3544 |
// Update and repositition. |
|
3545 |
d_ptr->setPosHelper(newPos); |
|
3546 |
||
3547 |
// Send post-notification. |
|
3548 |
itemChange(QGraphicsItem::ItemPositionHasChanged, newPosVariant); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3549 |
d_ptr->sendScenePosChange(); |
0 | 3550 |
} |
3551 |
||
3552 |
/*! |
|
3553 |
\fn void QGraphicsItem::setPos(qreal x, qreal y) |
|
3554 |
\overload |
|
3555 |
||
3556 |
This convenience function is equivalent to calling setPos(QPointF(\a x, \a |
|
3557 |
y)). |
|
3558 |
*/ |
|
3559 |
||
3560 |
/*! |
|
3561 |
\fn void QGraphicsItem::moveBy(qreal dx, qreal dy) |
|
3562 |
||
3563 |
Moves the item by \a dx points horizontally, and \a dy point |
|
3564 |
vertically. This function is equivalent to calling setPos(pos() + |
|
3565 |
QPointF(\a dx, \a dy)). |
|
3566 |
*/ |
|
3567 |
||
3568 |
/*! |
|
3569 |
If this item is part of a scene that is viewed by a QGraphicsView, this |
|
3570 |
convenience function will attempt to scroll the view to ensure that \a |
|
3571 |
rect is visible inside the view's viewport. If \a rect is a null rect (the |
|
3572 |
default), QGraphicsItem will default to the item's bounding rect. \a xmargin |
|
3573 |
and \a ymargin are the number of pixels the view should use for margins. |
|
3574 |
||
3575 |
If the specified rect cannot be reached, the contents are scrolled to the |
|
3576 |
nearest valid position. |
|
3577 |
||
3578 |
If this item is not viewed by a QGraphicsView, this function does nothing. |
|
3579 |
||
3580 |
\sa QGraphicsView::ensureVisible() |
|
3581 |
*/ |
|
3582 |
void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin) |
|
3583 |
{ |
|
3584 |
if (d_ptr->scene) { |
|
3585 |
QRectF sceneRect; |
|
3586 |
if (!rect.isNull()) |
|
3587 |
sceneRect = sceneTransform().mapRect(rect); |
|
3588 |
else |
|
3589 |
sceneRect = sceneBoundingRect(); |
|
3590 |
foreach (QGraphicsView *view, d_ptr->scene->d_func()->views) |
|
3591 |
view->ensureVisible(sceneRect, xmargin, ymargin); |
|
3592 |
} |
|
3593 |
} |
|
3594 |
||
3595 |
/*! |
|
3596 |
\fn void QGraphicsItem::ensureVisible(qreal x, qreal y, qreal w, qreal h, |
|
3597 |
int xmargin = 50, int ymargin = 50) |
|
3598 |
||
3599 |
This convenience function is equivalent to calling |
|
3600 |
ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin): |
|
3601 |
*/ |
|
3602 |
||
3603 |
/*! |
|
3604 |
\obsolete |
|
3605 |
||
3606 |
Returns the item's affine transformation matrix. This is a subset or the |
|
3607 |
item's full transformation matrix, and might not represent the item's full |
|
3608 |
transformation. |
|
3609 |
||
3610 |
Use transform() instead. |
|
3611 |
||
3612 |
\sa setTransform(), sceneTransform() |
|
3613 |
*/ |
|
3614 |
QMatrix QGraphicsItem::matrix() const |
|
3615 |
{ |
|
3616 |
return transform().toAffine(); |
|
3617 |
} |
|
3618 |
||
3619 |
/*! |
|
3620 |
\since 4.3 |
|
3621 |
||
3622 |
Returns this item's transformation matrix. |
|
3623 |
||
3624 |
The transformation matrix is combined with the item's rotation(), scale() |
|
3625 |
and transformations() into a combined transformations for the item. |
|
3626 |
||
3627 |
The default transformation matrix is an identity matrix. |
|
3628 |
||
3629 |
\sa setTransform(), sceneTransform() |
|
3630 |
*/ |
|
3631 |
QTransform QGraphicsItem::transform() const |
|
3632 |
{ |
|
3633 |
if (!d_ptr->transformData) |
|
3634 |
return QTransform(); |
|
3635 |
return d_ptr->transformData->transform; |
|
3636 |
} |
|
3637 |
||
3638 |
/*! |
|
3639 |
\since 4.6 |
|
3640 |
||
3641 |
Returns the clockwise rotation, in degrees, around the Z axis. The default |
|
3642 |
value is 0 (i.e., the item is not rotated). |
|
3643 |
||
3644 |
The rotation is combined with the item's scale(), transform() and |
|
3645 |
transformations() to map the item's coordinate system to the parent item. |
|
3646 |
||
3647 |
\sa setRotation(), transformOriginPoint(), {Transformations} |
|
3648 |
*/ |
|
3649 |
qreal QGraphicsItem::rotation() const |
|
3650 |
{ |
|
3651 |
if (!d_ptr->transformData) |
|
3652 |
return 0; |
|
3653 |
return d_ptr->transformData->rotation; |
|
3654 |
} |
|
3655 |
||
3656 |
/*! |
|
3657 |
\since 4.6 |
|
3658 |
||
3659 |
Sets the clockwise rotation \a angle, in degrees, around the Z axis. The |
|
3660 |
default value is 0 (i.e., the item is not rotated). Assigning a negative |
|
3661 |
value will rotate the item counter-clockwise. Normally the rotation angle |
|
3662 |
is in the range (-360, 360), but it's also possible to assign values |
|
3663 |
outside of this range (e.g., a rotation of 370 degrees is the same as a |
|
3664 |
rotation of 10 degrees). |
|
3665 |
||
3666 |
The item is rotated around its transform origin point, which by default |
|
3667 |
is (0, 0). You can select a different transformation origin by calling |
|
3668 |
setTransformOriginPoint(). |
|
3669 |
||
3670 |
The rotation is combined with the item's scale(), transform() and |
|
3671 |
transformations() to map the item's coordinate system to the parent item. |
|
3672 |
||
3673 |
\sa rotation(), setTransformOriginPoint(), {Transformations} |
|
3674 |
*/ |
|
3675 |
void QGraphicsItem::setRotation(qreal angle) |
|
3676 |
{ |
|
3677 |
prepareGeometryChange(); |
|
3678 |
if (!d_ptr->transformData) |
|
3679 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
3680 |
d_ptr->transformData->rotation = angle; |
|
3681 |
d_ptr->transformData->onlyTransform = false; |
|
3682 |
d_ptr->dirtySceneTransform = 1; |
|
3683 |
||
3684 |
if (d_ptr->isObject) |
|
3685 |
emit static_cast<QGraphicsObject *>(this)->rotationChanged(); |
|
3686 |
} |
|
3687 |
||
3688 |
/*! |
|
3689 |
\since 4.6 |
|
3690 |
||
3691 |
Returns the scale factor of the item. The default scale factor is 1.0 |
|
3692 |
(i.e., the item is not scaled). |
|
3693 |
||
3694 |
The scale is combined with the item's rotation(), transform() and |
|
3695 |
transformations() to map the item's coordinate system to the parent item. |
|
3696 |
||
3697 |
\sa setScale(), rotation(), {Transformations} |
|
3698 |
*/ |
|
3699 |
qreal QGraphicsItem::scale() const |
|
3700 |
{ |
|
3701 |
if (!d_ptr->transformData) |
|
3702 |
return 1.; |
|
3703 |
return d_ptr->transformData->scale; |
|
3704 |
} |
|
3705 |
||
3706 |
/*! |
|
3707 |
\since 4.6 |
|
3708 |
||
3709 |
Sets the scale \a factor of the item. The default scale factor is 1.0 |
|
3710 |
(i.e., the item is not scaled). A scale factor of 0.0 will collapse the |
|
3711 |
item to a single point. If you provide a negative scale factor, the |
|
3712 |
item will be flipped and mirrored (i.e., rotated 180 degrees). |
|
3713 |
||
3714 |
The item is scaled around its transform origin point, which by default |
|
3715 |
is (0, 0). You can select a different transformation origin by calling |
|
3716 |
setTransformOriginPoint(). |
|
3717 |
||
3718 |
The scale is combined with the item's rotation(), transform() and |
|
3719 |
transformations() to map the item's coordinate system to the parent item. |
|
3720 |
||
3721 |
\sa scale(), setTransformOriginPoint(), {Transformations} |
|
3722 |
*/ |
|
3723 |
void QGraphicsItem::setScale(qreal factor) |
|
3724 |
{ |
|
3725 |
prepareGeometryChange(); |
|
3726 |
if (!d_ptr->transformData) |
|
3727 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
3728 |
d_ptr->transformData->scale = factor; |
|
3729 |
d_ptr->transformData->onlyTransform = false; |
|
3730 |
d_ptr->dirtySceneTransform = 1; |
|
3731 |
||
3732 |
if (d_ptr->isObject) |
|
3733 |
emit static_cast<QGraphicsObject *>(this)->scaleChanged(); |
|
3734 |
} |
|
3735 |
||
3736 |
||
3737 |
/*! |
|
3738 |
\since 4.6 |
|
3739 |
||
3740 |
Returns a list of graphics transforms that currently apply to this item. |
|
3741 |
||
3742 |
QGraphicsTransform is for applying and controlling a chain of individual |
|
3743 |
transformation operations on an item. It's particularily useful in |
|
3744 |
animations, where each transform operation needs to be interpolated |
|
3745 |
independently, or differently. |
|
3746 |
||
3747 |
The transformations are combined with the item's rotation(), scale() and |
|
3748 |
transform() to map the item's coordinate system to the parent item. |
|
3749 |
||
3750 |
\sa scale(), rotation(), transformOriginPoint(), {Transformations} |
|
3751 |
*/ |
|
3752 |
QList<QGraphicsTransform *> QGraphicsItem::transformations() const |
|
3753 |
{ |
|
3754 |
if (!d_ptr->transformData) |
|
3755 |
return QList<QGraphicsTransform *>(); |
|
3756 |
return d_ptr->transformData->graphicsTransforms; |
|
3757 |
} |
|
3758 |
||
3759 |
/*! |
|
3760 |
\since 4.6 |
|
3761 |
||
3762 |
Sets a list of graphics \a transformations (QGraphicsTransform) that |
|
3763 |
currently apply to this item. |
|
3764 |
||
3765 |
If all you want is to rotate or scale an item, you should call setRotation() |
|
3766 |
or setScale() instead. If you want to set an arbitrary transformation on |
|
3767 |
an item, you can call setTransform(). |
|
3768 |
||
3769 |
QGraphicsTransform is for applying and controlling a chain of individual |
|
3770 |
transformation operations on an item. It's particularily useful in |
|
3771 |
animations, where each transform operation needs to be interpolated |
|
3772 |
independently, or differently. |
|
3773 |
||
3774 |
The transformations are combined with the item's rotation(), scale() and |
|
3775 |
transform() to map the item's coordinate system to the parent item. |
|
3776 |
||
3777 |
\sa scale(), setTransformOriginPoint(), {Transformations} |
|
3778 |
*/ |
|
3779 |
void QGraphicsItem::setTransformations(const QList<QGraphicsTransform *> &transformations) |
|
3780 |
{ |
|
3781 |
prepareGeometryChange(); |
|
3782 |
if (!d_ptr->transformData) |
|
3783 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
3784 |
d_ptr->transformData->graphicsTransforms = transformations; |
|
3785 |
for (int i = 0; i < transformations.size(); ++i) |
|
3786 |
transformations.at(i)->d_func()->setItem(this); |
|
3787 |
d_ptr->transformData->onlyTransform = false; |
|
3788 |
d_ptr->dirtySceneTransform = 1; |
|
3789 |
} |
|
3790 |
||
3791 |
/*! |
|
3792 |
\internal |
|
3793 |
*/ |
|
3794 |
void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t) |
|
3795 |
{ |
|
3796 |
if (!transformData) |
|
3797 |
transformData = new QGraphicsItemPrivate::TransformData; |
|
3798 |
if (!transformData->graphicsTransforms.contains(t)) |
|
3799 |
transformData->graphicsTransforms.append(t); |
|
3800 |
||
3801 |
Q_Q(QGraphicsItem); |
|
3802 |
t->d_func()->setItem(q); |
|
3803 |
transformData->onlyTransform = false; |
|
3804 |
dirtySceneTransform = 1; |
|
3805 |
} |
|
3806 |
||
3807 |
/*! |
|
3808 |
\since 4.6 |
|
3809 |
||
3810 |
Returns the origin point for the transformation in item coordinates. |
|
3811 |
||
3812 |
The default is QPointF(0,0). |
|
3813 |
||
3814 |
\sa setTransformOriginPoint(), {Transformations} |
|
3815 |
*/ |
|
3816 |
QPointF QGraphicsItem::transformOriginPoint() const |
|
3817 |
{ |
|
3818 |
if (!d_ptr->transformData) |
|
3819 |
return QPointF(0,0); |
|
3820 |
return QPointF(d_ptr->transformData->xOrigin, d_ptr->transformData->yOrigin); |
|
3821 |
} |
|
3822 |
||
3823 |
/*! |
|
3824 |
\since 4.6 |
|
3825 |
||
3826 |
Sets the \a origin point for the transformation in item coordinates. |
|
3827 |
||
3828 |
\sa transformOriginPoint(), {Transformations} |
|
3829 |
*/ |
|
3830 |
void QGraphicsItem::setTransformOriginPoint(const QPointF &origin) |
|
3831 |
{ |
|
3832 |
prepareGeometryChange(); |
|
3833 |
if (!d_ptr->transformData) |
|
3834 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
3835 |
d_ptr->transformData->xOrigin = origin.x(); |
|
3836 |
d_ptr->transformData->yOrigin = origin.y(); |
|
3837 |
d_ptr->transformData->onlyTransform = false; |
|
3838 |
d_ptr->dirtySceneTransform = 1; |
|
3839 |
} |
|
3840 |
||
3841 |
/*! |
|
3842 |
\fn void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y) |
|
3843 |
||
3844 |
\since 4.6 |
|
3845 |
\overload |
|
3846 |
||
3847 |
Sets the origin point for the transformation in item coordinates. |
|
3848 |
This is equivalent to calling setTransformOriginPoint(QPointF(\a x, \a y)). |
|
3849 |
||
3850 |
\sa setTransformOriginPoint(), {Transformations} |
|
3851 |
*/ |
|
3852 |
||
3853 |
||
3854 |
/*! |
|
3855 |
\obsolete |
|
3856 |
||
3857 |
Use sceneTransform() instead. |
|
3858 |
||
3859 |
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System} |
|
3860 |
*/ |
|
3861 |
QMatrix QGraphicsItem::sceneMatrix() const |
|
3862 |
{ |
|
3863 |
d_ptr->ensureSceneTransform(); |
|
3864 |
return d_ptr->sceneTransform.toAffine(); |
|
3865 |
} |
|
3866 |
||
3867 |
||
3868 |
/*! |
|
3869 |
\since 4.3 |
|
3870 |
||
3871 |
Returns this item's scene transformation matrix. This matrix can be used |
|
3872 |
to map coordinates and geometrical shapes from this item's local |
|
3873 |
coordinate system to the scene's coordinate system. To map coordinates |
|
3874 |
from the scene, you must first invert the returned matrix. |
|
3875 |
||
3876 |
Example: |
|
3877 |
||
3878 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 4 |
|
3879 |
||
3880 |
Unlike transform(), which returns only an item's local transformation, this |
|
3881 |
function includes the item's (and any parents') position, and all the transfomation properties. |
|
3882 |
||
3883 |
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}, {Transformations} |
|
3884 |
*/ |
|
3885 |
QTransform QGraphicsItem::sceneTransform() const |
|
3886 |
{ |
|
3887 |
d_ptr->ensureSceneTransform(); |
|
3888 |
return d_ptr->sceneTransform; |
|
3889 |
} |
|
3890 |
||
3891 |
/*! |
|
3892 |
\since 4.3 |
|
3893 |
||
3894 |
Returns this item's device transformation matrix, using \a |
|
3895 |
viewportTransform to map from scene to device coordinates. This matrix can |
|
3896 |
be used to map coordinates and geometrical shapes from this item's local |
|
3897 |
coordinate system to the viewport's (or any device's) coordinate |
|
3898 |
system. To map coordinates from the viewport, you must first invert the |
|
3899 |
returned matrix. |
|
3900 |
||
3901 |
Example: |
|
3902 |
||
3903 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 5 |
|
3904 |
||
3905 |
This function is the same as combining this item's scene transform with |
|
3906 |
the view's viewport transform, but it also understands the |
|
3907 |
ItemIgnoresTransformations flag. The device transform can be used to do |
|
3908 |
accurate coordinate mapping (and collision detection) for untransformable |
|
3909 |
items. |
|
3910 |
||
3911 |
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate |
|
3912 |
System}, itemTransform() |
|
3913 |
*/ |
|
3914 |
QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) const |
|
3915 |
{ |
|
3916 |
// Ensure we return the standard transform if we're not untransformable. |
|
3917 |
if (!d_ptr->itemIsUntransformable()) { |
|
3918 |
d_ptr->ensureSceneTransform(); |
|
3919 |
return d_ptr->sceneTransform * viewportTransform; |
|
3920 |
} |
|
3921 |
||
3922 |
// Find the topmost item that ignores view transformations. |
|
3923 |
const QGraphicsItem *untransformedAncestor = this; |
|
3924 |
QList<const QGraphicsItem *> parents; |
|
3925 |
while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags |
|
3926 |
& QGraphicsItemPrivate::AncestorIgnoresTransformations))) { |
|
3927 |
parents.prepend(untransformedAncestor); |
|
3928 |
untransformedAncestor = untransformedAncestor->parentItem(); |
|
3929 |
} |
|
3930 |
||
3931 |
if (!untransformedAncestor) { |
|
3932 |
// Assert in debug mode, continue in release. |
|
3933 |
Q_ASSERT_X(untransformedAncestor, "QGraphicsItem::deviceTransform", |
|
3934 |
"Invalid object structure!"); |
|
3935 |
return QTransform(); |
|
3936 |
} |
|
3937 |
||
3938 |
// First translate the base untransformable item. |
|
3939 |
untransformedAncestor->d_ptr->ensureSceneTransform(); |
|
3940 |
QPointF mappedPoint = (untransformedAncestor->d_ptr->sceneTransform * viewportTransform).map(QPointF(0, 0)); |
|
3941 |
||
3942 |
// COMBINE |
|
3943 |
QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y()); |
|
3944 |
if (untransformedAncestor->d_ptr->transformData) |
|
3945 |
matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix); |
|
3946 |
||
3947 |
// Then transform and translate all children. |
|
3948 |
for (int i = 0; i < parents.size(); ++i) { |
|
3949 |
const QGraphicsItem *parent = parents.at(i); |
|
3950 |
parent->d_ptr->combineTransformFromParent(&matrix); |
|
3951 |
} |
|
3952 |
||
3953 |
return matrix; |
|
3954 |
} |
|
3955 |
||
3956 |
/*! |
|
3957 |
\since 4.5 |
|
3958 |
||
3959 |
Returns a QTransform that maps coordinates from this item to \a other. If |
|
3960 |
\a ok is not null, and if there is no such transform, the boolean pointed |
|
3961 |
to by \a ok will be set to false; otherwise it will be set to true. |
|
3962 |
||
3963 |
This transform provides an alternative to the mapToItem() or mapFromItem() |
|
3964 |
functions, by returning the appropriate transform so that you can map |
|
3965 |
shapes and coordinates yourself. It also helps you write more efficient |
|
3966 |
code when repeatedly mapping between the same two items. |
|
3967 |
||
3968 |
\note In rare circumstances, there is no transform that maps between two |
|
3969 |
items. |
|
3970 |
||
3971 |
\sa mapToItem(), mapFromItem(), deviceTransform() |
|
3972 |
*/ |
|
3973 |
QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) const |
|
3974 |
{ |
|
3975 |
// Catch simple cases first. |
|
3976 |
if (other == 0) { |
|
3977 |
qWarning("QGraphicsItem::itemTransform: null pointer passed"); |
|
3978 |
return QTransform(); |
|
3979 |
} |
|
3980 |
if (other == this) { |
|
3981 |
if (ok) |
|
3982 |
*ok = true; |
|
3983 |
return QTransform(); |
|
3984 |
} |
|
3985 |
||
3986 |
QGraphicsItem *parent = d_ptr->parent; |
|
3987 |
const QGraphicsItem *otherParent = other->d_ptr->parent; |
|
3988 |
||
3989 |
// This is other's child |
|
3990 |
if (parent == other) { |
|
3991 |
if (ok) |
|
3992 |
*ok = true; |
|
3993 |
QTransform x; |
|
3994 |
d_ptr->combineTransformFromParent(&x); |
|
3995 |
return x; |
|
3996 |
} |
|
3997 |
||
3998 |
// This is other's parent |
|
3999 |
if (otherParent == this) { |
|
4000 |
const QPointF &otherPos = other->d_ptr->pos; |
|
4001 |
if (other->d_ptr->transformData) { |
|
4002 |
QTransform otherToParent; |
|
4003 |
other->d_ptr->combineTransformFromParent(&otherToParent); |
|
4004 |
return otherToParent.inverted(ok); |
|
4005 |
} |
|
4006 |
if (ok) |
|
4007 |
*ok = true; |
|
4008 |
return QTransform::fromTranslate(-otherPos.x(), -otherPos.y()); |
|
4009 |
} |
|
4010 |
||
4011 |
// Siblings |
|
4012 |
if (parent == otherParent) { |
|
4013 |
// COMBINE |
|
4014 |
const QPointF &itemPos = d_ptr->pos; |
|
4015 |
const QPointF &otherPos = other->d_ptr->pos; |
|
4016 |
if (!d_ptr->transformData && !other->d_ptr->transformData) { |
|
4017 |
QPointF delta = itemPos - otherPos; |
|
4018 |
if (ok) |
|
4019 |
*ok = true; |
|
4020 |
return QTransform::fromTranslate(delta.x(), delta.y()); |
|
4021 |
} |
|
4022 |
||
4023 |
QTransform itemToParent; |
|
4024 |
d_ptr->combineTransformFromParent(&itemToParent); |
|
4025 |
QTransform otherToParent; |
|
4026 |
other->d_ptr->combineTransformFromParent(&otherToParent); |
|
4027 |
return itemToParent * otherToParent.inverted(ok); |
|
4028 |
} |
|
4029 |
||
4030 |
// Find the closest common ancestor. If the two items don't share an |
|
4031 |
// ancestor, then the only way is to combine their scene transforms. |
|
4032 |
const QGraphicsItem *commonAncestor = commonAncestorItem(other); |
|
4033 |
if (!commonAncestor) { |
|
4034 |
d_ptr->ensureSceneTransform(); |
|
4035 |
other->d_ptr->ensureSceneTransform(); |
|
4036 |
return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok); |
|
4037 |
} |
|
4038 |
||
4039 |
// If the two items are cousins (in sibling branches), map both to the |
|
4040 |
// common ancestor, and combine the two transforms. |
|
4041 |
bool cousins = other != commonAncestor && this != commonAncestor; |
|
4042 |
if (cousins) { |
|
4043 |
bool good = false; |
|
4044 |
QTransform thisToScene = itemTransform(commonAncestor, &good); |
|
4045 |
QTransform otherToScene(Qt::Uninitialized); |
|
4046 |
if (good) |
|
4047 |
otherToScene = other->itemTransform(commonAncestor, &good); |
|
4048 |
if (!good) { |
|
4049 |
if (ok) |
|
4050 |
*ok = false; |
|
4051 |
return QTransform(); |
|
4052 |
} |
|
4053 |
return thisToScene * otherToScene.inverted(ok); |
|
4054 |
} |
|
4055 |
||
4056 |
// One is an ancestor of the other; walk the chain. |
|
4057 |
bool parentOfOther = isAncestorOf(other); |
|
4058 |
const QGraphicsItem *child = parentOfOther ? other : this; |
|
4059 |
const QGraphicsItem *root = parentOfOther ? this : other; |
|
4060 |
||
4061 |
QTransform x; |
|
4062 |
const QGraphicsItem *p = child; |
|
4063 |
do { |
|
4064 |
p->d_ptr.data()->combineTransformToParent(&x); |
|
4065 |
} while ((p = p->d_ptr->parent) && p != root); |
|
4066 |
if (parentOfOther) |
|
4067 |
return x.inverted(ok); |
|
4068 |
if (ok) |
|
4069 |
*ok = true; |
|
4070 |
return x; |
|
4071 |
} |
|
4072 |
||
4073 |
/*! |
|
4074 |
\obsolete |
|
4075 |
||
4076 |
Sets the item's affine transformation matrix. This is a subset or the |
|
4077 |
item's full transformation matrix, and might not represent the item's full |
|
4078 |
transformation. |
|
4079 |
||
4080 |
Use setTransform() instead. |
|
4081 |
||
4082 |
\sa transform(), {The Graphics View Coordinate System} |
|
4083 |
*/ |
|
4084 |
void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) |
|
4085 |
{ |
|
4086 |
if (!d_ptr->transformData) |
|
4087 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
4088 |
||
4089 |
QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix)); |
|
4090 |
if (d_ptr->transformData->transform == newTransform) |
|
4091 |
return; |
|
4092 |
||
4093 |
// Update and set the new transformation. |
|
4094 |
if (!(d_ptr->flags & ItemSendsGeometryChanges)) { |
|
4095 |
d_ptr->setTransformHelper(newTransform); |
|
4096 |
return; |
|
4097 |
} |
|
4098 |
||
4099 |
// Notify the item that the transformation matrix is changing. |
|
4100 |
const QVariant newMatrixVariant = qVariantFromValue<QMatrix>(newTransform.toAffine()); |
|
4101 |
newTransform = QTransform(qVariantValue<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant))); |
|
4102 |
if (d_ptr->transformData->transform == newTransform) |
|
4103 |
return; |
|
4104 |
||
4105 |
// Update and set the new transformation. |
|
4106 |
d_ptr->setTransformHelper(newTransform); |
|
4107 |
||
4108 |
// Send post-notification. |
|
4109 |
itemChange(ItemTransformHasChanged, qVariantFromValue<QTransform>(newTransform)); |
|
4110 |
} |
|
4111 |
||
4112 |
/*! |
|
4113 |
\since 4.3 |
|
4114 |
||
4115 |
Sets the item's current transformation matrix to \a matrix. |
|
4116 |
||
4117 |
If \a combine is true, then \a matrix is combined with the current matrix; |
|
4118 |
otherwise, \a matrix \e replaces the current matrix. \a combine is false |
|
4119 |
by default. |
|
4120 |
||
4121 |
To simplify interation with items using a transformed view, QGraphicsItem |
|
4122 |
provides mapTo... and mapFrom... functions that can translate between |
|
4123 |
items' and the scene's coordinates. For example, you can call mapToScene() |
|
4124 |
to map an item coordiate to a scene coordinate, or mapFromScene() to map |
|
4125 |
from scene coordinates to item coordinates. |
|
4126 |
||
4127 |
The transformation matrix is combined with the item's rotation(), scale() |
|
4128 |
and transformations() into a combined transformation that maps the item's |
|
4129 |
coordinate system to its parent. |
|
4130 |
||
4131 |
\sa transform(), setRotation(), setScale(), setTransformOriginPoint(), {The Graphics View Coordinate System}, {Transformations} |
|
4132 |
*/ |
|
4133 |
void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) |
|
4134 |
{ |
|
4135 |
if (!d_ptr->transformData) |
|
4136 |
d_ptr->transformData = new QGraphicsItemPrivate::TransformData; |
|
4137 |
||
4138 |
QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix); |
|
4139 |
if (d_ptr->transformData->transform == newTransform) |
|
4140 |
return; |
|
4141 |
||
4142 |
// Update and set the new transformation. |
|
4143 |
if (!(d_ptr->flags & ItemSendsGeometryChanges)) { |
|
4144 |
d_ptr->setTransformHelper(newTransform); |
|
4145 |
return; |
|
4146 |
} |
|
4147 |
||
4148 |
// Notify the item that the transformation matrix is changing. |
|
4149 |
const QVariant newTransformVariant(itemChange(ItemTransformChange, |
|
4150 |
qVariantFromValue<QTransform>(newTransform))); |
|
4151 |
newTransform = qVariantValue<QTransform>(newTransformVariant); |
|
4152 |
if (d_ptr->transformData->transform == newTransform) |
|
4153 |
return; |
|
4154 |
||
4155 |
// Update and set the new transformation. |
|
4156 |
d_ptr->setTransformHelper(newTransform); |
|
4157 |
||
4158 |
// Send post-notification. |
|
4159 |
itemChange(ItemTransformHasChanged, newTransformVariant); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4160 |
d_ptr->sendScenePosChange(); |
0 | 4161 |
} |
4162 |
||
4163 |
/*! |
|
4164 |
\obsolete |
|
4165 |
||
4166 |
Use resetTransform() instead. |
|
4167 |
*/ |
|
4168 |
void QGraphicsItem::resetMatrix() |
|
4169 |
{ |
|
4170 |
resetTransform(); |
|
4171 |
} |
|
4172 |
||
4173 |
/*! |
|
4174 |
\since 4.3 |
|
4175 |
||
4176 |
Resets this item's transformation matrix to the identity matrix or |
|
4177 |
all the transformation properties to their default values. |
|
4178 |
This is equivalent to calling \c setTransform(QTransform()). |
|
4179 |
||
4180 |
\sa setTransform(), transform() |
|
4181 |
*/ |
|
4182 |
void QGraphicsItem::resetTransform() |
|
4183 |
{ |
|
4184 |
setTransform(QTransform(), false); |
|
4185 |
} |
|
4186 |
||
4187 |
/*! |
|
4188 |
\obsolete |
|
4189 |
||
4190 |
Use |
|
4191 |
||
4192 |
\code |
|
4193 |
setRotation(rotation() + angle); |
|
4194 |
\endcode |
|
4195 |
||
4196 |
instead. |
|
4197 |
||
4198 |
Rotates the current item transformation \a angle degrees clockwise around |
|
4199 |
its origin. To translate around an arbitrary point (x, y), you need to |
|
4200 |
combine translation and rotation with setTransform(). |
|
4201 |
||
4202 |
Example: |
|
4203 |
||
4204 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 6 |
|
4205 |
||
4206 |
\sa setTransform(), transform(), scale(), shear(), translate() |
|
4207 |
*/ |
|
4208 |
void QGraphicsItem::rotate(qreal angle) |
|
4209 |
{ |
|
4210 |
setTransform(QTransform().rotate(angle), true); |
|
4211 |
} |
|
4212 |
||
4213 |
/*! |
|
4214 |
\obsolete |
|
4215 |
||
4216 |
Use |
|
4217 |
||
4218 |
\code |
|
4219 |
setTransform(QTransform::fromScale(sx, sy), true); |
|
4220 |
\endcode |
|
4221 |
||
4222 |
instead. |
|
4223 |
||
4224 |
Scales the current item transformation by (\a sx, \a sy) around its |
|
4225 |
origin. To scale from an arbitrary point (x, y), you need to combine |
|
4226 |
translation and scaling with setTransform(). |
|
4227 |
||
4228 |
Example: |
|
4229 |
||
4230 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 7 |
|
4231 |
||
4232 |
\sa setTransform(), transform() |
|
4233 |
*/ |
|
4234 |
void QGraphicsItem::scale(qreal sx, qreal sy) |
|
4235 |
{ |
|
4236 |
setTransform(QTransform::fromScale(sx, sy), true); |
|
4237 |
} |
|
4238 |
||
4239 |
/*! |
|
4240 |
\obsolete |
|
4241 |
||
4242 |
Use |
|
4243 |
||
4244 |
\code |
|
4245 |
setTransform(QTransform().shear(sh, sv), true); |
|
4246 |
\endcode |
|
4247 |
||
4248 |
instead. |
|
4249 |
||
4250 |
Shears the current item transformation by (\a sh, \a sv). |
|
4251 |
||
4252 |
\sa setTransform(), transform() |
|
4253 |
*/ |
|
4254 |
void QGraphicsItem::shear(qreal sh, qreal sv) |
|
4255 |
{ |
|
4256 |
setTransform(QTransform().shear(sh, sv), true); |
|
4257 |
} |
|
4258 |
||
4259 |
/*! |
|
4260 |
\obsolete |
|
4261 |
||
4262 |
Use setPos() or setTransformOriginPoint() instead. For identical |
|
4263 |
behavior, use |
|
4264 |
||
4265 |
\code |
|
4266 |
setTransform(QTransform::fromTranslate(dx, dy), true); |
|
4267 |
\endcode |
|
4268 |
||
4269 |
Translates the current item transformation by (\a dx, \a dy). |
|
4270 |
||
4271 |
If all you want is to move an item, you should call moveBy() or |
|
4272 |
setPos() instead; this function changes the item's translation, |
|
4273 |
which is conceptually separate from its position. |
|
4274 |
||
4275 |
\sa setTransform(), transform() |
|
4276 |
*/ |
|
4277 |
void QGraphicsItem::translate(qreal dx, qreal dy) |
|
4278 |
{ |
|
4279 |
setTransform(QTransform::fromTranslate(dx, dy), true); |
|
4280 |
} |
|
4281 |
||
4282 |
/*! |
|
4283 |
This virtual function is called twice for all items by the |
|
4284 |
QGraphicsScene::advance() slot. In the first phase, all items are called |
|
4285 |
with \a phase == 0, indicating that items on the scene are about to |
|
4286 |
advance, and then all items are called with \a phase == 1. Reimplement |
|
4287 |
this function to update your item if you need simple scene-controlled |
|
4288 |
animation. |
|
4289 |
||
4290 |
The default implementation does nothing. |
|
4291 |
||
4292 |
For individual item animation, an alternative to this function is to |
|
4293 |
either use QGraphicsItemAnimation, or to multiple-inherit from QObject and |
|
4294 |
QGraphicsItem, and animate your item using QObject::startTimer() and |
|
4295 |
QObject::timerEvent(). |
|
4296 |
||
4297 |
\sa QGraphicsItemAnimation, QTimeLine |
|
4298 |
*/ |
|
4299 |
void QGraphicsItem::advance(int phase) |
|
4300 |
{ |
|
4301 |
Q_UNUSED(phase); |
|
4302 |
} |
|
4303 |
||
4304 |
/*! |
|
4305 |
Returns the Z-value of the item. The Z-value affects the stacking order of |
|
4306 |
sibling (neighboring) items. |
|
4307 |
||
4308 |
The default Z-value is 0. |
|
4309 |
||
4310 |
\sa setZValue(), {QGraphicsItem#Sorting}{Sorting}, stackBefore(), ItemStacksBehindParent |
|
4311 |
*/ |
|
4312 |
qreal QGraphicsItem::zValue() const |
|
4313 |
{ |
|
4314 |
return d_ptr->z; |
|
4315 |
} |
|
4316 |
||
4317 |
/*! |
|
4318 |
Sets the Z-value of the item to \a z. The Z value decides the stacking |
|
4319 |
order of sibling (neighboring) items. A sibling item of high Z value will |
|
4320 |
always be drawn on top of another sibling item with a lower Z value. |
|
4321 |
||
4322 |
If you restore the Z value, the item's insertion order will decide its |
|
4323 |
stacking order. |
|
4324 |
||
4325 |
The Z-value does not affect the item's size in any way. |
|
4326 |
||
4327 |
The default Z-value is 0. |
|
4328 |
||
4329 |
\sa zValue(), {QGraphicsItem#Sorting}{Sorting}, stackBefore(), ItemStacksBehindParent |
|
4330 |
*/ |
|
4331 |
void QGraphicsItem::setZValue(qreal z) |
|
4332 |
{ |
|
4333 |
const QVariant newZVariant(itemChange(ItemZValueChange, z)); |
|
4334 |
qreal newZ = newZVariant.toReal(); |
|
4335 |
if (newZ == d_ptr->z) |
|
4336 |
return; |
|
4337 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4338 |
if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) { |
0 | 4339 |
// Z Value has changed, we have to notify the index. |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
4340 |
d_ptr->scene->d_func()->index->itemChange(this, ItemZValueChange, &newZ); |
0 | 4341 |
} |
4342 |
||
4343 |
d_ptr->z = newZ; |
|
4344 |
if (d_ptr->parent) |
|
4345 |
d_ptr->parent->d_ptr->needSortChildren = 1; |
|
4346 |
else if (d_ptr->scene) |
|
4347 |
d_ptr->scene->d_func()->needSortTopLevelItems = 1; |
|
4348 |
||
4349 |
if (d_ptr->scene) |
|
4350 |
d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true); |
|
4351 |
||
4352 |
itemChange(ItemZValueHasChanged, newZVariant); |
|
4353 |
||
4354 |
if (d_ptr->flags & ItemNegativeZStacksBehindParent) |
|
4355 |
setFlag(QGraphicsItem::ItemStacksBehindParent, z < qreal(0.0)); |
|
4356 |
||
4357 |
if (d_ptr->isObject) |
|
4358 |
emit static_cast<QGraphicsObject *>(this)->zChanged(); |
|
4359 |
} |
|
4360 |
||
4361 |
/*! |
|
4362 |
\internal |
|
4363 |
||
4364 |
Ensures that the list of children is sorted by insertion order, and that |
|
4365 |
the siblingIndexes are packed (no gaps), and start at 0. |
|
4366 |
||
4367 |
### This function is almost identical to |
|
4368 |
QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes(). |
|
4369 |
*/ |
|
4370 |
void QGraphicsItemPrivate::ensureSequentialSiblingIndex() |
|
4371 |
{ |
|
4372 |
if (!sequentialOrdering) { |
|
4373 |
qSort(children.begin(), children.end(), insertionOrder); |
|
4374 |
sequentialOrdering = 1; |
|
4375 |
needSortChildren = 1; |
|
4376 |
} |
|
4377 |
if (holesInSiblingIndex) { |
|
4378 |
holesInSiblingIndex = 0; |
|
4379 |
for (int i = 0; i < children.size(); ++i) |
|
4380 |
children[i]->d_ptr->siblingIndex = i; |
|
4381 |
} |
|
4382 |
} |
|
4383 |
||
4384 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4385 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4386 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4387 |
inline void QGraphicsItemPrivate::sendScenePosChange() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4388 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4389 |
Q_Q(QGraphicsItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4390 |
if (scene) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4391 |
if (flags & QGraphicsItem::ItemSendsScenePositionChanges) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4392 |
q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4393 |
if (scenePosDescendants) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4394 |
foreach (QGraphicsItem *item, scene->d_func()->scenePosItems) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4395 |
if (q->isAncestorOf(item)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4396 |
item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4397 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4398 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4399 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4400 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4401 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4402 |
/*! |
0 | 4403 |
\since 4.6 |
4404 |
||
4405 |
Stacks this item before \a sibling, which must be a sibling item (i.e., the |
|
4406 |
two items must share the same parent item, or must both be toplevel items). |
|
4407 |
The \a sibling must have the same Z value as this item, otherwise calling |
|
4408 |
this function will have no effect. |
|
4409 |
||
4410 |
By default, all sibling items are stacked by insertion order (i.e., the |
|
4411 |
first item you add is drawn before the next item you add). If two items' Z |
|
4412 |
values are different, then the item with the highest Z value is drawn on |
|
4413 |
top. When the Z values are the same, the insertion order will decide the |
|
4414 |
stacking order. |
|
4415 |
||
4416 |
\sa setZValue(), ItemStacksBehindParent, {QGraphicsItem#Sorting}{Sorting} |
|
4417 |
*/ |
|
4418 |
void QGraphicsItem::stackBefore(const QGraphicsItem *sibling) |
|
4419 |
{ |
|
4420 |
if (sibling == this) |
|
4421 |
return; |
|
4422 |
if (!sibling || d_ptr->parent != sibling->parentItem()) { |
|
4423 |
qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling); |
|
4424 |
return; |
|
4425 |
} |
|
4426 |
QList<QGraphicsItem *> *siblings = d_ptr->parent |
|
4427 |
? &d_ptr->parent->d_ptr->children |
|
4428 |
: (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : 0); |
|
4429 |
if (!siblings) { |
|
4430 |
qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling); |
|
4431 |
return; |
|
4432 |
} |
|
4433 |
||
4434 |
// First, make sure that the sibling indexes have no holes. This also |
|
4435 |
// marks the children list for sorting. |
|
4436 |
if (d_ptr->parent) |
|
4437 |
d_ptr->parent->d_ptr->ensureSequentialSiblingIndex(); |
|
4438 |
else |
|
4439 |
d_ptr->scene->d_func()->ensureSequentialTopLevelSiblingIndexes(); |
|
4440 |
||
4441 |
// Only move items with the same Z value, and that need moving. |
|
4442 |
int siblingIndex = sibling->d_ptr->siblingIndex; |
|
4443 |
int myIndex = d_ptr->siblingIndex; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4444 |
if (myIndex >= siblingIndex) { |
0 | 4445 |
siblings->move(myIndex, siblingIndex); |
4446 |
// Fixup the insertion ordering. |
|
4447 |
for (int i = 0; i < siblings->size(); ++i) { |
|
4448 |
int &index = siblings->at(i)->d_ptr->siblingIndex; |
|
4449 |
if (i != siblingIndex && index >= siblingIndex && index <= myIndex) |
|
4450 |
++index; |
|
4451 |
} |
|
4452 |
d_ptr->siblingIndex = siblingIndex; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4453 |
for (int i = 0; i < siblings->size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4454 |
int &index = siblings->at(i)->d_ptr->siblingIndex; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4455 |
if (i != siblingIndex && index >= siblingIndex && index <= myIndex) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4456 |
siblings->at(i)->d_ptr->siblingOrderChange(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4457 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4458 |
d_ptr->siblingOrderChange(); |
0 | 4459 |
} |
4460 |
} |
|
4461 |
||
4462 |
/*! |
|
4463 |
Returns the bounding rect of this item's descendants (i.e., its |
|
4464 |
children, their children, etc.) in local coordinates. The |
|
4465 |
rectangle will contain all descendants after they have been mapped |
|
4466 |
to local coordinates. If the item has no children, this function |
|
4467 |
returns an empty QRectF. |
|
4468 |
||
4469 |
This does not include this item's own bounding rect; it only returns |
|
4470 |
its descendants' accumulated bounding rect. If you need to include this |
|
4471 |
item's bounding rect, you can add boundingRect() to childrenBoundingRect() |
|
4472 |
using QRectF::operator|(). |
|
4473 |
||
4474 |
This function is linear in complexity; it determines the size of the |
|
4475 |
returned bounding rect by iterating through all descendants. |
|
4476 |
||
4477 |
\sa boundingRect(), sceneBoundingRect() |
|
4478 |
*/ |
|
4479 |
QRectF QGraphicsItem::childrenBoundingRect() const |
|
4480 |
{ |
|
4481 |
if (!d_ptr->dirtyChildrenBoundingRect) |
|
4482 |
return d_ptr->childrenBoundingRect; |
|
4483 |
||
4484 |
d_ptr->childrenBoundingRect = QRectF(); |
|
4485 |
d_ptr->childrenBoundingRectHelper(0, &d_ptr->childrenBoundingRect); |
|
4486 |
d_ptr->dirtyChildrenBoundingRect = 0; |
|
4487 |
return d_ptr->childrenBoundingRect; |
|
4488 |
} |
|
4489 |
||
4490 |
/*! |
|
4491 |
\fn virtual QRectF QGraphicsItem::boundingRect() const = 0 |
|
4492 |
||
4493 |
This pure virtual function defines the outer bounds of the item as |
|
4494 |
a rectangle; all painting must be restricted to inside an item's |
|
4495 |
bounding rect. QGraphicsView uses this to determine whether the |
|
4496 |
item requires redrawing. |
|
4497 |
||
4498 |
Although the item's shape can be arbitrary, the bounding rect is |
|
4499 |
always rectangular, and it is unaffected by the items' |
|
4500 |
transformation. |
|
4501 |
||
4502 |
If you want to change the item's bounding rectangle, you must first call |
|
4503 |
prepareGeometryChange(). This notifies the scene of the imminent change, |
|
4504 |
so that its can update its item geometry index; otherwise, the scene will |
|
4505 |
be unaware of the item's new geometry, and the results are undefined |
|
4506 |
(typically, rendering artifacts are left around in the view). |
|
4507 |
||
4508 |
Reimplement this function to let QGraphicsView determine what |
|
4509 |
parts of the widget, if any, need to be redrawn. |
|
4510 |
||
4511 |
Note: For shapes that paint an outline / stroke, it is important |
|
4512 |
to include half the pen width in the bounding rect. It is not |
|
4513 |
necessary to compensate for antialiasing, though. |
|
4514 |
||
4515 |
Example: |
|
4516 |
||
4517 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 8 |
|
4518 |
||
4519 |
\sa boundingRegion(), shape(), contains(), {The Graphics View Coordinate |
|
4520 |
System}, prepareGeometryChange() |
|
4521 |
*/ |
|
4522 |
||
4523 |
/*! |
|
4524 |
Returns the bounding rect of this item in scene coordinates, by combining |
|
4525 |
sceneTransform() with boundingRect(). |
|
4526 |
||
4527 |
\sa boundingRect(), {The Graphics View Coordinate System} |
|
4528 |
*/ |
|
4529 |
QRectF QGraphicsItem::sceneBoundingRect() const |
|
4530 |
{ |
|
4531 |
// Find translate-only offset |
|
4532 |
// COMBINE |
|
4533 |
QPointF offset; |
|
4534 |
const QGraphicsItem *parentItem = this; |
|
4535 |
const QGraphicsItemPrivate *itemd; |
|
4536 |
do { |
|
4537 |
itemd = parentItem->d_ptr.data(); |
|
4538 |
if (itemd->transformData) |
|
4539 |
break; |
|
4540 |
offset += itemd->pos; |
|
4541 |
} while ((parentItem = itemd->parent)); |
|
4542 |
||
4543 |
QRectF br = boundingRect(); |
|
4544 |
br.translate(offset); |
|
4545 |
if (!parentItem) |
|
4546 |
return br; |
|
4547 |
if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) { |
|
4548 |
br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy()); |
|
4549 |
return br; |
|
4550 |
} |
|
4551 |
return parentItem->d_ptr->sceneTransform.mapRect(br); |
|
4552 |
} |
|
4553 |
||
4554 |
/*! |
|
4555 |
Returns the shape of this item as a QPainterPath in local |
|
4556 |
coordinates. The shape is used for many things, including collision |
|
4557 |
detection, hit tests, and for the QGraphicsScene::items() functions. |
|
4558 |
||
4559 |
The default implementation calls boundingRect() to return a simple |
|
4560 |
rectangular shape, but subclasses can reimplement this function to return |
|
4561 |
a more accurate shape for non-rectangular items. For example, a round item |
|
4562 |
may choose to return an elliptic shape for better collision detection. For |
|
4563 |
example: |
|
4564 |
||
4565 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 9 |
|
4566 |
||
4567 |
The outline of a shape can vary depending on the width and style of the |
|
4568 |
pen used when drawing. If you want to include this outline in the item's |
|
4569 |
shape, you can create a shape from the stroke using QPainterPathStroker. |
|
4570 |
||
4571 |
This function is called by the default implementations of contains() and |
|
4572 |
collidesWithPath(). |
|
4573 |
||
4574 |
\sa boundingRect(), contains(), prepareGeometryChange(), QPainterPathStroker |
|
4575 |
*/ |
|
4576 |
QPainterPath QGraphicsItem::shape() const |
|
4577 |
{ |
|
4578 |
QPainterPath path; |
|
4579 |
path.addRect(boundingRect()); |
|
4580 |
return path; |
|
4581 |
} |
|
4582 |
||
4583 |
/*! |
|
4584 |
Returns true if this item is clipped. An item is clipped if it has either |
|
4585 |
set the \l ItemClipsToShape flag, or if it or any of its ancestors has set |
|
4586 |
the \l ItemClipsChildrenToShape flag. |
|
4587 |
||
4588 |
Clipping affects the item's appearance (i.e., painting), as well as mouse |
|
4589 |
and hover event delivery. |
|
4590 |
||
4591 |
\sa clipPath(), shape(), setFlags() |
|
4592 |
*/ |
|
4593 |
bool QGraphicsItem::isClipped() const |
|
4594 |
{ |
|
4595 |
Q_D(const QGraphicsItem); |
|
4596 |
return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) |
|
4597 |
|| (d->flags & QGraphicsItem::ItemClipsToShape); |
|
4598 |
} |
|
4599 |
||
4600 |
/*! |
|
4601 |
\since 4.5 |
|
4602 |
||
4603 |
Returns this item's clip path, or an empty QPainterPath if this item is |
|
4604 |
not clipped. The clip path constrains the item's appearance and |
|
4605 |
interaction (i.e., restricts the area the item can draw, and it also |
|
4606 |
restricts the area that the item receives events). |
|
4607 |
||
4608 |
You can enable clipping by setting the ItemClipsToShape or |
|
4609 |
ItemClipsChildrenToShape flags. The item's clip path is calculated by |
|
4610 |
intersecting all clipping ancestors' shapes. If the item sets |
|
4611 |
ItemClipsToShape, the final clip is intersected with the item's own shape. |
|
4612 |
||
4613 |
\note Clipping introduces a performance penalty for all items involved; |
|
4614 |
you should generally avoid using clipping if you can (e.g., if your items |
|
4615 |
always draw inside boundingRect() or shape() boundaries, clipping is not |
|
4616 |
necessary). |
|
4617 |
||
4618 |
\sa isClipped(), shape(), setFlags() |
|
4619 |
*/ |
|
4620 |
QPainterPath QGraphicsItem::clipPath() const |
|
4621 |
{ |
|
4622 |
Q_D(const QGraphicsItem); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4623 |
if (!isClipped()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4624 |
return QPainterPath(); |
0 | 4625 |
|
4626 |
const QRectF thisBoundingRect(boundingRect()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4627 |
if (thisBoundingRect.isEmpty()) |
0 | 4628 |
return QPainterPath(); |
4629 |
||
4630 |
QPainterPath clip; |
|
4631 |
// Start with the item's bounding rect. |
|
4632 |
clip.addRect(thisBoundingRect); |
|
4633 |
||
4634 |
if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) { |
|
4635 |
const QGraphicsItem *parent = this; |
|
4636 |
const QGraphicsItem *lastParent = this; |
|
4637 |
||
4638 |
// Intersect any in-between clips starting at the top and moving downwards. |
|
4639 |
while ((parent = parent->d_ptr->parent)) { |
|
4640 |
if (parent->d_ptr->flags & ItemClipsChildrenToShape) { |
|
4641 |
// Map clip to the current parent and intersect with its shape/clipPath |
|
4642 |
clip = lastParent->itemTransform(parent).map(clip); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4643 |
clip = clip.intersected(parent->shape()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4644 |
if (clip.isEmpty()) |
0 | 4645 |
return clip; |
4646 |
lastParent = parent; |
|
4647 |
} |
|
4648 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4649 |
if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)) |
0 | 4650 |
break; |
4651 |
} |
|
4652 |
||
4653 |
if (lastParent != this) { |
|
4654 |
// Map clip back to the item's transform. |
|
4655 |
// ### what if itemtransform fails |
|
4656 |
clip = lastParent->itemTransform(this).map(clip); |
|
4657 |
} |
|
4658 |
} |
|
4659 |
||
4660 |
if (d->flags & ItemClipsToShape) |
|
4661 |
clip = clip.intersected(shape()); |
|
4662 |
||
4663 |
return clip; |
|
4664 |
} |
|
4665 |
||
4666 |
/*! |
|
4667 |
Returns true if this item contains \a point, which is in local |
|
4668 |
coordinates; otherwise, false is returned. It is most often called from |
|
4669 |
QGraphicsView to determine what item is under the cursor, and for that |
|
4670 |
reason, the implementation of this function should be as light-weight as |
|
4671 |
possible. |
|
4672 |
||
4673 |
By default, this function calls shape(), but you can reimplement it in a |
|
4674 |
subclass to provide a (perhaps more efficient) implementation. |
|
4675 |
||
4676 |
\sa shape(), boundingRect(), collidesWithPath() |
|
4677 |
*/ |
|
4678 |
bool QGraphicsItem::contains(const QPointF &point) const |
|
4679 |
{ |
|
4680 |
return isClipped() ? clipPath().contains(point) : shape().contains(point); |
|
4681 |
} |
|
4682 |
||
4683 |
/*! |
|
4684 |
||
4685 |
Returns true if this item collides with \a other; otherwise |
|
4686 |
returns false. |
|
4687 |
||
4688 |
The \a mode is applied to \a other, and the resulting shape or |
|
4689 |
bounding rectangle is then compared to this item's shape. The |
|
4690 |
default value for \a mode is Qt::IntersectsItemShape; \a other |
|
4691 |
collides with this item if it either intersects, contains, or is |
|
4692 |
contained by this item's shape (see Qt::ItemSelectionMode for |
|
4693 |
details). |
|
4694 |
||
4695 |
The default implementation is based on shape intersection, and it calls |
|
4696 |
shape() on both items. Because the complexity of arbitrary shape-shape |
|
4697 |
intersection grows with an order of magnitude when the shapes are complex, |
|
4698 |
this operation can be noticably time consuming. You have the option of |
|
4699 |
reimplementing this function in a subclass of QGraphicsItem to provide a |
|
4700 |
custom algorithm. This allows you to make use of natural constraints in |
|
4701 |
the shapes of your own items, in order to improve the performance of the |
|
4702 |
collision detection. For instance, two untransformed perfectly circular |
|
4703 |
items' collision can be determined very efficiently by comparing their |
|
4704 |
positions and radii. |
|
4705 |
||
4706 |
Keep in mind that when reimplementing this function and calling shape() or |
|
4707 |
boundingRect() on \a other, the returned coordinates must be mapped to |
|
4708 |
this item's coordinate system before any intersection can take place. |
|
4709 |
||
4710 |
\sa contains(), shape() |
|
4711 |
*/ |
|
4712 |
bool QGraphicsItem::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const |
|
4713 |
{ |
|
4714 |
if (other == this) |
|
4715 |
return true; |
|
4716 |
if (!other) |
|
4717 |
return false; |
|
4718 |
// The items share the same clip if their closest clipper is the same, or |
|
4719 |
// if one clips the other. |
|
4720 |
bool clips = (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren); |
|
4721 |
bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren); |
|
4722 |
if (clips || otherClips) { |
|
4723 |
const QGraphicsItem *closestClipper = isAncestorOf(other) ? this : parentItem(); |
|
4724 |
while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape)) |
|
4725 |
closestClipper = closestClipper->parentItem(); |
|
4726 |
const QGraphicsItem *otherClosestClipper = other->isAncestorOf(this) ? other : other->parentItem(); |
|
4727 |
while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape)) |
|
4728 |
otherClosestClipper = otherClosestClipper->parentItem(); |
|
4729 |
if (closestClipper == otherClosestClipper) { |
|
4730 |
d_ptr->localCollisionHack = 1; |
|
4731 |
bool res = collidesWithPath(mapFromItem(other, other->shape()), mode); |
|
4732 |
d_ptr->localCollisionHack = 0; |
|
4733 |
return res; |
|
4734 |
} |
|
4735 |
} |
|
4736 |
||
4737 |
QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape(); |
|
4738 |
return collidesWithPath(mapFromItem(other, otherShape), mode); |
|
4739 |
} |
|
4740 |
||
4741 |
/*! |
|
4742 |
Returns true if this item collides with \a path. |
|
4743 |
||
4744 |
The collision is determined by \a mode. The default value for \a mode is |
|
4745 |
Qt::IntersectsItemShape; \a path collides with this item if it either |
|
4746 |
intersects, contains, or is contained by this item's shape. |
|
4747 |
||
4748 |
Note that this function checks whether the item's shape or |
|
4749 |
bounding rectangle (depending on \a mode) is contained within \a |
|
4750 |
path, and not whether \a path is contained within the items shape |
|
4751 |
or bounding rectangle. |
|
4752 |
||
4753 |
\sa collidesWithItem(), contains(), shape() |
|
4754 |
*/ |
|
4755 |
bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode) const |
|
4756 |
{ |
|
4757 |
if (path.isEmpty()) { |
|
4758 |
// No collision with empty paths. |
|
4759 |
return false; |
|
4760 |
} |
|
4761 |
||
4762 |
QRectF rectA(boundingRect()); |
|
4763 |
_q_adjustRect(&rectA); |
|
4764 |
QRectF rectB(path.controlPointRect()); |
|
4765 |
_q_adjustRect(&rectB); |
|
4766 |
if (!rectA.intersects(rectB)) { |
|
4767 |
// This we can determine efficiently. If the two rects neither |
|
4768 |
// intersect nor contain eachother, then the two items do not collide. |
|
4769 |
return false; |
|
4770 |
} |
|
4771 |
||
4772 |
// For further testing, we need this item's shape or bounding rect. |
|
4773 |
QPainterPath thisShape; |
|
4774 |
if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape) |
|
4775 |
thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape(); |
|
4776 |
else |
|
4777 |
thisShape.addRect(rectA); |
|
4778 |
||
4779 |
if (thisShape == QPainterPath()) { |
|
4780 |
// Empty shape? No collision. |
|
4781 |
return false; |
|
4782 |
} |
|
4783 |
||
4784 |
// Use QPainterPath boolean operations to determine the collision, O(N*logN). |
|
4785 |
if (mode == Qt::IntersectsItemShape || mode == Qt::IntersectsItemBoundingRect) |
|
4786 |
return path.intersects(thisShape); |
|
4787 |
return path.contains(thisShape); |
|
4788 |
} |
|
4789 |
||
4790 |
/*! |
|
4791 |
Returns a list of all items that collide with this item. |
|
4792 |
||
4793 |
The way collisions are detected is determined by applying \a mode |
|
4794 |
to items that are compared to this item, i.e., each item's shape |
|
4795 |
or bounding rectangle is checked against this item's shape. The |
|
4796 |
default value for \a mode is Qt::IntersectsItemShape. |
|
4797 |
||
4798 |
\sa collidesWithItem() |
|
4799 |
*/ |
|
4800 |
QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode) const |
|
4801 |
{ |
|
4802 |
if (d_ptr->scene) |
|
4803 |
return d_ptr->scene->collidingItems(this, mode); |
|
4804 |
return QList<QGraphicsItem *>(); |
|
4805 |
} |
|
4806 |
||
4807 |
/*! |
|
4808 |
Returns true if this item's bounding rect is completely obscured by the |
|
4809 |
opaque shape of any of colliding items above it (i.e., with a higher Z |
|
4810 |
value than this item). |
|
4811 |
||
4812 |
Its implementation is based on calling isObscuredBy(), which you can |
|
4813 |
reimplement to provide a custom obscurity algorithm. |
|
4814 |
||
4815 |
\sa opaqueArea() |
|
4816 |
*/ |
|
4817 |
bool QGraphicsItem::isObscured() const |
|
4818 |
{ |
|
4819 |
return isObscured(QRectF()); |
|
4820 |
} |
|
4821 |
||
4822 |
/*! |
|
4823 |
\internal |
|
4824 |
||
4825 |
Item obscurity helper function. |
|
4826 |
||
4827 |
Returns true if the subrect \a rect of \a item's bounding rect is obscured |
|
4828 |
by \a other (i.e., \a other's opaque area covers \a item's \a rect |
|
4829 |
completely. \a other is assumed to already be "on top of" \a item |
|
4830 |
wrt. stacking order. |
|
4831 |
*/ |
|
4832 |
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, |
|
4833 |
const QGraphicsItem *other, |
|
4834 |
const QRectF &rect) |
|
4835 |
{ |
|
4836 |
return other->mapToItem(item, other->opaqueArea()).contains(rect); |
|
4837 |
} |
|
4838 |
||
4839 |
/*! |
|
4840 |
\overload |
|
4841 |
\since 4.3 |
|
4842 |
||
4843 |
Returns true if \a rect is completely obscured by the opaque shape of any |
|
4844 |
of colliding items above it (i.e., with a higher Z value than this item). |
|
4845 |
||
4846 |
Unlike the default isObscured() function, this function does not call |
|
4847 |
isObscuredBy(). |
|
4848 |
||
4849 |
\sa opaqueArea() |
|
4850 |
*/ |
|
4851 |
bool QGraphicsItem::isObscured(const QRectF &rect) const |
|
4852 |
{ |
|
4853 |
Q_D(const QGraphicsItem); |
|
4854 |
if (!d->scene) |
|
4855 |
return false; |
|
4856 |
||
4857 |
QRectF br = boundingRect(); |
|
4858 |
QRectF testRect = rect.isNull() ? br : rect; |
|
4859 |
||
4860 |
foreach (QGraphicsItem *item, d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect)) { |
|
4861 |
if (item == this) |
|
4862 |
break; |
|
4863 |
if (qt_QGraphicsItem_isObscured(this, item, testRect)) |
|
4864 |
return true; |
|
4865 |
} |
|
4866 |
return false; |
|
4867 |
} |
|
4868 |
||
4869 |
/*! |
|
4870 |
\fn bool QGraphicsItem::isObscured(qreal x, qreal y, qreal w, qreal h) const |
|
4871 |
\since 4.3 |
|
4872 |
||
4873 |
This convenience function is equivalent to calling isObscured(QRectF(\a x, \a y, \a w, \a h)). |
|
4874 |
*/ |
|
4875 |
||
4876 |
/*! |
|
4877 |
Returns true if this item's bounding rect is completely obscured by the |
|
4878 |
opaque shape of \a item. |
|
4879 |
||
4880 |
The base implementation maps \a item's opaqueArea() to this item's |
|
4881 |
coordinate system, and then checks if this item's boundingRect() is fully |
|
4882 |
contained within the mapped shape. |
|
4883 |
||
4884 |
You can reimplement this function to provide a custom algorithm for |
|
4885 |
determining whether this item is obscured by \a item. |
|
4886 |
||
4887 |
\sa opaqueArea(), isObscured() |
|
4888 |
*/ |
|
4889 |
bool QGraphicsItem::isObscuredBy(const QGraphicsItem *item) const |
|
4890 |
{ |
|
4891 |
if (!item) |
|
4892 |
return false; |
|
4893 |
return qt_closestItemFirst(item, this) |
|
4894 |
&& qt_QGraphicsItem_isObscured(this, item, boundingRect()); |
|
4895 |
} |
|
4896 |
||
4897 |
/*! |
|
4898 |
This virtual function returns a shape representing the area where this |
|
4899 |
item is opaque. An area is opaque if it is filled using an opaque brush or |
|
4900 |
color (i.e., not transparent). |
|
4901 |
||
4902 |
This function is used by isObscuredBy(), which is called by underlying |
|
4903 |
items to determine if they are obscured by this item. |
|
4904 |
||
4905 |
The default implementation returns an empty QPainterPath, indicating that |
|
4906 |
this item is completely transparent and does not obscure any other items. |
|
4907 |
||
4908 |
\sa isObscuredBy(), isObscured(), shape() |
|
4909 |
*/ |
|
4910 |
QPainterPath QGraphicsItem::opaqueArea() const |
|
4911 |
{ |
|
4912 |
return QPainterPath(); |
|
4913 |
} |
|
4914 |
||
4915 |
/*! |
|
4916 |
\since 4.4 |
|
4917 |
||
4918 |
Returns the bounding region for this item. The coordinate space of the |
|
4919 |
returned region depends on \a itemToDeviceTransform. If you pass an |
|
4920 |
identity QTransform as a parameter, this function will return a local |
|
4921 |
coordinate region. |
|
4922 |
||
4923 |
The bounding region describes a coarse outline of the item's visual |
|
4924 |
contents. Although it's expensive to calculate, it's also more precise |
|
4925 |
than boundingRect(), and it can help to avoid unnecessary repainting when |
|
4926 |
an item is updated. This is particularily efficient for thin items (e.g., |
|
4927 |
lines or simple polygons). You can tune the granularity for the bounding |
|
4928 |
region by calling setBoundingRegionGranularity(). The default granularity |
|
4929 |
is 0; in which the item's bounding region is the same as its bounding |
|
4930 |
rect. |
|
4931 |
||
4932 |
\a itemToDeviceTransform is the transformation from item coordinates to |
|
4933 |
device coordinates. If you want this function to return a QRegion in scene |
|
4934 |
coordinates, you can pass sceneTransform() as an argument. |
|
4935 |
||
4936 |
\sa boundingRegionGranularity() |
|
4937 |
*/ |
|
4938 |
QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) const |
|
4939 |
{ |
|
4940 |
// ### Ideally we would have a better way to generate this region, |
|
4941 |
// preferably something in the lines of QPainterPath::toRegion(QTransform) |
|
4942 |
// coupled with a way to generate a painter path from a set of painter |
|
4943 |
// operations (e.g., QPicture::toPainterPath() or so). The current |
|
4944 |
// approach generates a bitmap with the size of the item's bounding rect |
|
4945 |
// in device coordinates, scaled by b.r.granularity, then paints the item |
|
4946 |
// into the bitmap, converts the result to a QRegion and scales the region |
|
4947 |
// back to device space with inverse granularity. |
|
4948 |
qreal granularity = boundingRegionGranularity(); |
|
4949 |
QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect(); |
|
4950 |
_q_adjustRect(&deviceRect); |
|
4951 |
if (granularity == 0.0) |
|
4952 |
return QRegion(deviceRect); |
|
4953 |
||
4954 |
int pad = 1; |
|
4955 |
QSize bitmapSize(qMax(1, int(deviceRect.width() * granularity) + pad * 2), |
|
4956 |
qMax(1, int(deviceRect.height() * granularity) + pad * 2)); |
|
4957 |
QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied); |
|
4958 |
mask.fill(0); |
|
4959 |
QPainter p(&mask); |
|
4960 |
p.setRenderHints(QPainter::Antialiasing); |
|
4961 |
||
4962 |
// Transform painter (### this code is from QGraphicsScene::drawItemHelper |
|
4963 |
// and doesn't work properly with perspective transformations). |
|
4964 |
QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0)); |
|
4965 |
QPointF offset = viewOrigo - deviceRect.topLeft(); |
|
4966 |
p.scale(granularity, granularity); |
|
4967 |
p.translate(offset); |
|
4968 |
p.translate(pad, pad); |
|
4969 |
p.setWorldTransform(itemToDeviceTransform, true); |
|
4970 |
p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0))); |
|
4971 |
||
4972 |
// Render |
|
4973 |
QStyleOptionGraphicsItem option; |
|
4974 |
const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0); |
|
4975 |
p.end(); |
|
4976 |
||
4977 |
// Transform QRegion back to device space |
|
4978 |
QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity); |
|
4979 |
QRegion r; |
|
4980 |
QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0)); |
|
4981 |
foreach (const QRect &rect, QRegion( colorMask ).rects()) { |
|
4982 |
QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad)); |
|
4983 |
r += xrect.adjusted(-1, -1, 1, 1) & deviceRect; |
|
4984 |
} |
|
4985 |
return r; |
|
4986 |
} |
|
4987 |
||
4988 |
/*! |
|
4989 |
\since 4.4 |
|
4990 |
||
4991 |
Returns the item's bounding region granularity; a value between and |
|
4992 |
including 0 and 1. The default value is 0 (i.e., the lowest granularity, |
|
4993 |
where the bounding region corresponds to the item's bounding rectangle). |
|
4994 |
||
4995 |
\omit |
|
4996 |
### NOTE |
|
4997 |
\endomit |
|
4998 |
||
4999 |
\sa setBoundingRegionGranularity() |
|
5000 |
*/ |
|
5001 |
qreal QGraphicsItem::boundingRegionGranularity() const |
|
5002 |
{ |
|
5003 |
return d_ptr->hasBoundingRegionGranularity |
|
5004 |
? qVariantValue<qreal>(d_ptr->extra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity)) |
|
5005 |
: 0; |
|
5006 |
} |
|
5007 |
||
5008 |
/*! |
|
5009 |
\since 4.4 |
|
5010 |
Sets the bounding region granularity to \a granularity; a value between |
|
5011 |
and including 0 and 1. The default value is 0 (i.e., the lowest |
|
5012 |
granularity, where the bounding region corresponds to the item's bounding |
|
5013 |
rectangle). |
|
5014 |
||
5015 |
The granularity is used by boundingRegion() to calculate how fine the |
|
5016 |
bounding region of the item should be. The highest achievable granularity |
|
5017 |
is 1, where boundingRegion() will return the finest outline possible for |
|
5018 |
the respective device (e.g., for a QGraphicsView viewport, this gives you |
|
5019 |
a pixel-perfect bounding region). The lowest possible granularity is |
|
5020 |
0. The value of \a granularity describes the ratio between device |
|
5021 |
resolution and the resolution of the bounding region (e.g., a value of |
|
5022 |
0.25 will provide a region where each chunk corresponds to 4x4 device |
|
5023 |
units / pixels). |
|
5024 |
||
5025 |
\sa boundingRegionGranularity() |
|
5026 |
*/ |
|
5027 |
void QGraphicsItem::setBoundingRegionGranularity(qreal granularity) |
|
5028 |
{ |
|
5029 |
if (granularity < 0.0 || granularity > 1.0) { |
|
5030 |
qWarning("QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity); |
|
5031 |
return; |
|
5032 |
} |
|
5033 |
if (granularity == 0.0) { |
|
5034 |
d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity); |
|
5035 |
d_ptr->hasBoundingRegionGranularity = 0; |
|
5036 |
return; |
|
5037 |
} |
|
5038 |
d_ptr->hasBoundingRegionGranularity = 1; |
|
5039 |
d_ptr->setExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity, |
|
5040 |
qVariantFromValue<qreal>(granularity)); |
|
5041 |
} |
|
5042 |
||
5043 |
/*! |
|
5044 |
\fn virtual void QGraphicsItem::paint(QPainter *painter, const |
|
5045 |
QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0 |
|
5046 |
||
5047 |
This function, which is usually called by QGraphicsView, paints the |
|
5048 |
contents of an item in local coordinates. |
|
5049 |
||
5050 |
Reimplement this function in a QGraphicsItem subclass to provide the |
|
5051 |
item's painting implementation, using \a painter. The \a option parameter |
|
5052 |
provides style options for the item, such as its state, exposed area and |
|
5053 |
its level-of-detail hints. The \a widget argument is optional. If |
|
5054 |
provided, it points to the widget that is being painted on; otherwise, it |
|
5055 |
is 0. For cached painting, \a widget is always 0. |
|
5056 |
||
5057 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 10 |
|
5058 |
||
5059 |
The painter's pen is 0-width by default, and its pen is initialized to the |
|
5060 |
QPalette::Text brush from the paint device's palette. The brush is |
|
5061 |
initialized to QPalette::Window. |
|
5062 |
||
5063 |
Make sure to constrain all painting inside the boundaries of |
|
5064 |
boundingRect() to avoid rendering artifacts (as QGraphicsView does not |
|
5065 |
clip the painter for you). In particular, when QPainter renders the |
|
5066 |
outline of a shape using an assigned QPen, half of the outline will be |
|
5067 |
drawn outside, and half inside, the shape you're rendering (e.g., with a |
|
5068 |
pen width of 2 units, you must draw outlines 1 unit inside |
|
5069 |
boundingRect()). QGraphicsItem does not support use of cosmetic pens with |
|
5070 |
a non-zero width. |
|
5071 |
||
5072 |
All painting is done in local coordinates. |
|
5073 |
||
5074 |
\sa setCacheMode(), QPen::width(), {Item Coordinates}, ItemUsesExtendedStyleOption |
|
5075 |
*/ |
|
5076 |
||
5077 |
/*! |
|
5078 |
\internal |
|
5079 |
Returns true if we can discard an update request; otherwise false. |
|
5080 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5081 |
bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreVisibleBit, bool ignoreDirtyBit, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5082 |
bool ignoreOpacity) const |
0 | 5083 |
{ |
5084 |
// No scene, or if the scene is updating everything, means we have nothing |
|
5085 |
// to do. The only exception is if the scene tracks the growing scene rect. |
|
5086 |
return !scene |
|
5087 |
|| (!visible && !ignoreVisibleBit && !this->ignoreVisible) |
|
5088 |
|| (!ignoreDirtyBit && fullUpdatePending) |
|
5089 |
|| (!ignoreOpacity && !this->ignoreOpacity && childrenCombineOpacity() && isFullyTransparent()); |
|
5090 |
} |
|
5091 |
||
5092 |
/*! |
|
5093 |
\internal |
|
5094 |
*/ |
|
5095 |
int QGraphicsItemPrivate::depth() const |
|
5096 |
{ |
|
5097 |
if (itemDepth == -1) |
|
5098 |
const_cast<QGraphicsItemPrivate *>(this)->resolveDepth(); |
|
5099 |
||
5100 |
return itemDepth; |
|
5101 |
} |
|
5102 |
||
5103 |
/*! |
|
5104 |
\internal |
|
5105 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5106 |
#ifndef QT_NO_GRAPHICSEFFECT |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5107 |
void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively() |
0 | 5108 |
{ |
5109 |
QGraphicsItemPrivate *itemPrivate = this; |
|
5110 |
do { |
|
5111 |
if (itemPrivate->graphicsEffect) { |
|
5112 |
itemPrivate->notifyInvalidated = 1; |
|
5113 |
||
5114 |
if (!itemPrivate->updateDueToGraphicsEffect) |
|
5115 |
static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache(); |
|
5116 |
} |
|
5117 |
} while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0)); |
|
5118 |
} |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5119 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5120 |
void QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::InvalidateReason reason) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5121 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5122 |
if (!mayHaveChildWithGraphicsEffect) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5123 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5124 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5125 |
for (int i = 0; i < children.size(); ++i) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5126 |
QGraphicsItemPrivate *childPrivate = children.at(i)->d_ptr.data(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5127 |
if (reason == OpacityChanged && (childPrivate->flags & QGraphicsItem::ItemIgnoresParentOpacity)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5128 |
continue; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5129 |
if (childPrivate->graphicsEffect) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5130 |
childPrivate->notifyInvalidated = 1; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5131 |
static_cast<QGraphicsItemEffectSourcePrivate *>(childPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5132 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5133 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5134 |
childPrivate->invalidateChildGraphicsEffectsRecursively(reason); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5135 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5136 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5137 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 5138 |
|
5139 |
/*! |
|
5140 |
\internal |
|
5141 |
*/ |
|
5142 |
void QGraphicsItemPrivate::invalidateDepthRecursively() |
|
5143 |
{ |
|
5144 |
if (itemDepth == -1) |
|
5145 |
return; |
|
5146 |
||
5147 |
itemDepth = -1; |
|
5148 |
for (int i = 0; i < children.size(); ++i) |
|
5149 |
children.at(i)->d_ptr->invalidateDepthRecursively(); |
|
5150 |
} |
|
5151 |
||
5152 |
/*! |
|
5153 |
\internal |
|
5154 |
||
5155 |
Resolves the stacking depth of this object and all its ancestors. |
|
5156 |
*/ |
|
5157 |
void QGraphicsItemPrivate::resolveDepth() |
|
5158 |
{ |
|
5159 |
if (!parent) |
|
5160 |
itemDepth = 0; |
|
5161 |
else { |
|
5162 |
if (parent->d_ptr->itemDepth == -1) |
|
5163 |
parent->d_ptr->resolveDepth(); |
|
5164 |
itemDepth = parent->d_ptr->itemDepth + 1; |
|
5165 |
} |
|
5166 |
} |
|
5167 |
||
5168 |
/*! |
|
5169 |
\internal |
|
5170 |
||
5171 |
### This function is almost identical to |
|
5172 |
QGraphicsScenePrivate::registerTopLevelItem(). |
|
5173 |
*/ |
|
5174 |
void QGraphicsItemPrivate::addChild(QGraphicsItem *child) |
|
5175 |
{ |
|
5176 |
// Remove all holes from the sibling index list. Now the max index |
|
5177 |
// number is equal to the size of the children list. |
|
5178 |
ensureSequentialSiblingIndex(); |
|
5179 |
needSortChildren = 1; // ### maybe 0 |
|
5180 |
child->d_ptr->siblingIndex = children.size(); |
|
5181 |
children.append(child); |
|
5182 |
} |
|
5183 |
||
5184 |
/*! |
|
5185 |
\internal |
|
5186 |
||
5187 |
### This function is almost identical to |
|
5188 |
QGraphicsScenePrivate::unregisterTopLevelItem(). |
|
5189 |
*/ |
|
5190 |
void QGraphicsItemPrivate::removeChild(QGraphicsItem *child) |
|
5191 |
{ |
|
5192 |
// When removing elements in the middle of the children list, |
|
5193 |
// there will be a "gap" in the list of sibling indexes (0,1,3,4). |
|
5194 |
if (!holesInSiblingIndex) |
|
5195 |
holesInSiblingIndex = child->d_ptr->siblingIndex != children.size() - 1; |
|
5196 |
if (sequentialOrdering && !holesInSiblingIndex) |
|
5197 |
children.removeAt(child->d_ptr->siblingIndex); |
|
5198 |
else |
|
5199 |
children.removeOne(child); |
|
5200 |
// NB! Do not use children.removeAt(child->d_ptr->siblingIndex) because |
|
5201 |
// the child is not guaranteed to be at the index after the list is sorted. |
|
5202 |
// (see ensureSortedChildren()). |
|
5203 |
child->d_ptr->siblingIndex = -1; |
|
5204 |
} |
|
5205 |
||
5206 |
/*! |
|
5207 |
\internal |
|
5208 |
*/ |
|
5209 |
QGraphicsItemCache *QGraphicsItemPrivate::maybeExtraItemCache() const |
|
5210 |
{ |
|
5211 |
return (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); |
|
5212 |
} |
|
5213 |
||
5214 |
/*! |
|
5215 |
\internal |
|
5216 |
*/ |
|
5217 |
QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache() const |
|
5218 |
{ |
|
5219 |
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); |
|
5220 |
if (!c) { |
|
5221 |
QGraphicsItemPrivate *that = const_cast<QGraphicsItemPrivate *>(this); |
|
5222 |
c = new QGraphicsItemCache; |
|
5223 |
that->setExtra(ExtraCacheData, qVariantFromValue<void *>(c)); |
|
5224 |
} |
|
5225 |
return c; |
|
5226 |
} |
|
5227 |
||
5228 |
/*! |
|
5229 |
\internal |
|
5230 |
*/ |
|
5231 |
void QGraphicsItemPrivate::removeExtraItemCache() |
|
5232 |
{ |
|
5233 |
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); |
|
5234 |
if (c) { |
|
5235 |
c->purge(); |
|
5236 |
delete c; |
|
5237 |
} |
|
5238 |
unsetExtra(ExtraCacheData); |
|
5239 |
} |
|
5240 |
||
5241 |
// Traverses all the ancestors up to the top-level and updates the pointer to |
|
5242 |
// always point to the top-most item that has a dirty scene transform. |
|
5243 |
// It then backtracks to the top-most dirty item and start calculating the |
|
5244 |
// scene transform by combining the item's transform (+pos) with the parent's |
|
5245 |
// cached scene transform (which we at this point know for sure is valid). |
|
5246 |
void QGraphicsItemPrivate::ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem) |
|
5247 |
{ |
|
5248 |
Q_ASSERT(topMostDirtyItem); |
|
5249 |
||
5250 |
if (dirtySceneTransform) |
|
5251 |
*topMostDirtyItem = q_ptr; |
|
5252 |
||
5253 |
if (parent) |
|
5254 |
parent->d_ptr->ensureSceneTransformRecursive(topMostDirtyItem); |
|
5255 |
||
5256 |
if (*topMostDirtyItem == q_ptr) { |
|
5257 |
if (!dirtySceneTransform) |
|
5258 |
return; // OK, neither my ancestors nor I have dirty scene transforms. |
|
5259 |
*topMostDirtyItem = 0; |
|
5260 |
} else if (*topMostDirtyItem) { |
|
5261 |
return; // Continue backtrack. |
|
5262 |
} |
|
5263 |
||
5264 |
// This item and all its descendants have dirty scene transforms. |
|
5265 |
// We're about to validate this item's scene transform, so we have to |
|
5266 |
// invalidate all the children; otherwise there's no way for the descendants |
|
5267 |
// to detect that the ancestor has changed. |
|
5268 |
invalidateChildrenSceneTransform(); |
|
5269 |
||
5270 |
// COMBINE my transform with the parent's scene transform. |
|
5271 |
updateSceneTransformFromParent(); |
|
5272 |
Q_ASSERT(!dirtySceneTransform); |
|
5273 |
} |
|
5274 |
||
5275 |
/*! |
|
5276 |
\internal |
|
5277 |
*/ |
|
5278 |
void QGraphicsItemPrivate::setSubFocus(QGraphicsItem *rootItem) |
|
5279 |
{ |
|
5280 |
// Update focus child chain. Stop at panels, or if this item |
|
5281 |
// is hidden, stop at the first item with a visible parent. |
|
5282 |
QGraphicsItem *parent = rootItem ? rootItem : q_ptr; |
|
5283 |
do { |
|
5284 |
// Clear any existing ancestor's subFocusItem. |
|
5285 |
if (parent != q_ptr && parent->d_ptr->subFocusItem) { |
|
5286 |
if (parent->d_ptr->subFocusItem == q_ptr) |
|
5287 |
break; |
|
5288 |
parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(); |
|
5289 |
} |
|
5290 |
parent->d_ptr->subFocusItem = q_ptr; |
|
5291 |
parent->d_ptr->subFocusItemChange(); |
|
5292 |
} while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (visible || !parent->d_ptr->visible)); |
|
5293 |
||
5294 |
if (scene && !scene->isActive()) |
|
5295 |
scene->d_func()->lastFocusItem = subFocusItem; |
|
5296 |
} |
|
5297 |
||
5298 |
/*! |
|
5299 |
\internal |
|
5300 |
*/ |
|
5301 |
void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem) |
|
5302 |
{ |
|
5303 |
// Reset sub focus chain. |
|
5304 |
QGraphicsItem *parent = rootItem ? rootItem : q_ptr; |
|
5305 |
do { |
|
5306 |
if (parent->d_ptr->subFocusItem != q_ptr) |
|
5307 |
break; |
|
5308 |
parent->d_ptr->subFocusItem = 0; |
|
5309 |
parent->d_ptr->subFocusItemChange(); |
|
5310 |
} while (!parent->isPanel() && (parent = parent->d_ptr->parent)); |
|
5311 |
} |
|
5312 |
||
5313 |
/*! |
|
5314 |
\internal |
|
5315 |
||
5316 |
Sets the focusProxy pointer to 0 for all items that have this item as their |
|
5317 |
focusProxy. ### Qt 5: Use QPointer instead. |
|
5318 |
*/ |
|
5319 |
void QGraphicsItemPrivate::resetFocusProxy() |
|
5320 |
{ |
|
5321 |
for (int i = 0; i < focusProxyRefs.size(); ++i) |
|
5322 |
*focusProxyRefs.at(i) = 0; |
|
5323 |
focusProxyRefs.clear(); |
|
5324 |
} |
|
5325 |
||
5326 |
/*! |
|
5327 |
\internal |
|
5328 |
||
5329 |
Subclasses can reimplement this function to be notified when subFocusItem |
|
5330 |
changes. |
|
5331 |
*/ |
|
5332 |
void QGraphicsItemPrivate::subFocusItemChange() |
|
5333 |
{ |
|
5334 |
} |
|
5335 |
||
5336 |
/*! |
|
5337 |
\internal |
|
5338 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5339 |
Subclasses can reimplement this function to be notified when its |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5340 |
siblingIndex order is changed. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5341 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5342 |
void QGraphicsItemPrivate::siblingOrderChange() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5343 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5344 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5345 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5346 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5347 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5348 |
|
0 | 5349 |
Tells us if it is a proxy widget |
5350 |
*/ |
|
5351 |
bool QGraphicsItemPrivate::isProxyWidget() const |
|
5352 |
{ |
|
5353 |
return false; |
|
5354 |
} |
|
5355 |
||
5356 |
/*! |
|
5357 |
Schedules a redraw of the area covered by \a rect in this item. You can |
|
5358 |
call this function whenever your item needs to be redrawn, such as if it |
|
5359 |
changes appearance or size. |
|
5360 |
||
5361 |
This function does not cause an immediate paint; instead it schedules a |
|
5362 |
paint request that is processed by QGraphicsView after control reaches the |
|
5363 |
event loop. The item will only be redrawn if it is visible in any |
|
5364 |
associated view. |
|
5365 |
||
5366 |
As a side effect of the item being repainted, other items that overlap the |
|
5367 |
area \a rect may also be repainted. |
|
5368 |
||
5369 |
If the item is invisible (i.e., isVisible() returns false), this function |
|
5370 |
does nothing. |
|
5371 |
||
5372 |
\sa paint(), boundingRect() |
|
5373 |
*/ |
|
5374 |
void QGraphicsItem::update(const QRectF &rect) |
|
5375 |
{ |
|
5376 |
if (rect.isEmpty() && !rect.isNull()) |
|
5377 |
return; |
|
5378 |
||
5379 |
// Make sure we notify effects about invalidated source. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5380 |
#ifndef QT_NO_GRAPHICSEFFECT |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5381 |
d_ptr->invalidateParentGraphicsEffectsRecursively(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5382 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 5383 |
|
5384 |
if (CacheMode(d_ptr->cacheMode) != NoCache) { |
|
5385 |
// Invalidate cache. |
|
5386 |
QGraphicsItemCache *cache = d_ptr->extraItemCache(); |
|
5387 |
if (!cache->allExposed) { |
|
5388 |
if (rect.isNull()) { |
|
5389 |
cache->allExposed = true; |
|
5390 |
cache->exposed.clear(); |
|
5391 |
} else { |
|
5392 |
cache->exposed.append(rect); |
|
5393 |
} |
|
5394 |
} |
|
5395 |
// Only invalidate cache; item is already dirty. |
|
5396 |
if (d_ptr->fullUpdatePending) |
|
5397 |
return; |
|
5398 |
} |
|
5399 |
||
5400 |
if (d_ptr->discardUpdateRequest()) |
|
5401 |
return; |
|
5402 |
||
5403 |
if (d_ptr->scene) |
|
5404 |
d_ptr->scene->d_func()->markDirty(this, rect); |
|
5405 |
} |
|
5406 |
||
5407 |
/*! |
|
5408 |
\since 4.4 |
|
5409 |
Scrolls the contents of \a rect by \a dx, \a dy. If \a rect is a null rect |
|
5410 |
(the default), the item's bounding rect is scrolled. |
|
5411 |
||
5412 |
Scrolling provides a fast alternative to simply redrawing when the |
|
5413 |
contents of the item (or parts of the item) are shifted vertically or |
|
5414 |
horizontally. Depending on the current transformation and the capabilities |
|
5415 |
of the paint device (i.e., the viewport), this operation may consist of |
|
5416 |
simply moving pixels from one location to another using memmove(). In most |
|
5417 |
cases this is faster than rerendering the entire area. |
|
5418 |
||
5419 |
After scrolling, the item will issue an update for the newly exposed |
|
5420 |
areas. If scrolling is not supported (e.g., you are rendering to an OpenGL |
|
5421 |
viewport, which does not benefit from scroll optimizations), this function |
|
5422 |
is equivalent to calling update(\a rect). |
|
5423 |
||
5424 |
\sa boundingRect() |
|
5425 |
*/ |
|
5426 |
void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) |
|
5427 |
{ |
|
5428 |
Q_D(QGraphicsItem); |
|
5429 |
if (dx == 0.0 && dy == 0.0) |
|
5430 |
return; |
|
5431 |
if (!d->scene) |
|
5432 |
return; |
|
5433 |
if (d->cacheMode != NoCache) { |
|
5434 |
QGraphicsItemCache *c; |
|
5435 |
bool scrollCache = qFuzzyIsNull(dx - int(dx)) && qFuzzyIsNull(dy - int(dy)) |
|
5436 |
&& (c = (QGraphicsItemCache *)qVariantValue<void *>(d_ptr->extra(QGraphicsItemPrivate::ExtraCacheData))) |
|
5437 |
&& (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid()); |
|
5438 |
if (scrollCache) { |
|
5439 |
QPixmap pix; |
|
5440 |
if (QPixmapCache::find(c->key, &pix)) { |
|
5441 |
// Adjust with 2 pixel margin. Notice the loss of precision |
|
5442 |
// when converting to QRect. |
|
5443 |
int adjust = 2; |
|
5444 |
QRectF br = boundingRect().adjusted(-adjust, -adjust, adjust, adjust); |
|
5445 |
QRect irect = rect.toRect().translated(-br.x(), -br.y()); |
|
5446 |
||
5447 |
pix.scroll(dx, dy, irect); |
|
5448 |
||
5449 |
QPixmapCache::replace(c->key, pix); |
|
5450 |
||
5451 |
// Translate the existing expose. |
|
5452 |
foreach (QRectF exposedRect, c->exposed) |
|
5453 |
c->exposed += exposedRect.translated(dx, dy) & rect; |
|
5454 |
||
5455 |
// Calculate exposure. |
|
5456 |
QRegion exposed; |
|
5457 |
QRect r = rect.toRect(); |
|
5458 |
exposed += r; |
|
5459 |
exposed -= r.translated(dx, dy); |
|
5460 |
foreach (QRect rect, exposed.rects()) |
|
5461 |
update(rect); |
|
5462 |
d->scene->d_func()->markDirty(this); |
|
5463 |
} else { |
|
5464 |
update(rect); |
|
5465 |
} |
|
5466 |
} else { |
|
5467 |
// ### This is very slow, and can be done much better. If the cache is |
|
5468 |
// local and matches the below criteria for rotation and scaling, we |
|
5469 |
// can easily scroll. And if the cache is in device coordinates, we |
|
5470 |
// can scroll both the viewport and the cache. |
|
5471 |
update(rect); |
|
5472 |
} |
|
5473 |
return; |
|
5474 |
} |
|
5475 |
||
5476 |
QRectF scrollRect = !rect.isNull() ? rect : boundingRect(); |
|
5477 |
int couldntScroll = d->scene->views().size(); |
|
5478 |
foreach (QGraphicsView *view, d->scene->views()) { |
|
5479 |
if (view->viewport()->inherits("QGLWidget")) { |
|
5480 |
// ### Please replace with a widget attribute; any widget that |
|
5481 |
// doesn't support partial updates / doesn't support scrolling |
|
5482 |
// should be skipped in this code. Qt::WA_NoPartialUpdates or so. |
|
5483 |
continue; |
|
5484 |
} |
|
5485 |
||
5486 |
static const QLineF up(0, 0, 0, -1); |
|
5487 |
static const QLineF down(0, 0, 0, 1); |
|
5488 |
static const QLineF left(0, 0, -1, 0); |
|
5489 |
static const QLineF right(0, 0, 1, 0); |
|
5490 |
||
5491 |
QTransform deviceTr = deviceTransform(view->viewportTransform()); |
|
5492 |
QRect deviceScrollRect = deviceTr.mapRect(scrollRect).toRect(); |
|
5493 |
QLineF v1 = deviceTr.map(right); |
|
5494 |
QLineF v2 = deviceTr.map(down); |
|
5495 |
QLineF u1 = v1.unitVector(); u1.translate(-v1.p1()); |
|
5496 |
QLineF u2 = v2.unitVector(); u2.translate(-v2.p1()); |
|
5497 |
bool noScroll = false; |
|
5498 |
||
5499 |
// Check if the delta resolves to ints in device space. |
|
5500 |
QPointF deviceDelta = deviceTr.map(QPointF(dx, dy)); |
|
5501 |
if ((deviceDelta.x() - int(deviceDelta.x())) |
|
5502 |
|| (deviceDelta.y() - int(deviceDelta.y()))) { |
|
5503 |
noScroll = true; |
|
5504 |
} else { |
|
5505 |
// Check if the unit vectors have no fraction in device space. |
|
5506 |
qreal v1l = v1.length(); |
|
5507 |
if (v1l - int(v1l)) { |
|
5508 |
noScroll = true; |
|
5509 |
} else { |
|
5510 |
dx *= v1.length(); |
|
5511 |
} |
|
5512 |
qreal v2l = v2.length(); |
|
5513 |
if (v2l - int(v2l)) { |
|
5514 |
noScroll = true; |
|
5515 |
} else { |
|
5516 |
dy *= v2.length(); |
|
5517 |
} |
|
5518 |
} |
|
5519 |
||
5520 |
if (!noScroll) { |
|
5521 |
if (u1 == right) { |
|
5522 |
if (u2 == up) { |
|
5523 |
// flipped |
|
5524 |
dy = -dy; |
|
5525 |
} else if (u2 == down) { |
|
5526 |
// normal |
|
5527 |
} else { |
|
5528 |
noScroll = true; |
|
5529 |
} |
|
5530 |
} else if (u1 == left) { |
|
5531 |
if (u2 == up) { |
|
5532 |
// mirrored & flipped / rotated 180 degrees |
|
5533 |
dx = -dx; |
|
5534 |
dy = -dy; |
|
5535 |
} else if (u2 == down) { |
|
5536 |
// mirrored |
|
5537 |
dx = -dx; |
|
5538 |
} else { |
|
5539 |
noScroll = true; |
|
5540 |
} |
|
5541 |
} else if (u1 == up) { |
|
5542 |
if (u2 == left) { |
|
5543 |
// rotated -90 & mirrored |
|
5544 |
qreal tmp = dy; |
|
5545 |
dy = -dx; |
|
5546 |
dx = -tmp; |
|
5547 |
} else if (u2 == right) { |
|
5548 |
// rotated -90 |
|
5549 |
qreal tmp = dy; |
|
5550 |
dy = -dx; |
|
5551 |
dx = tmp; |
|
5552 |
} else { |
|
5553 |
noScroll = true; |
|
5554 |
} |
|
5555 |
} else if (u1 == down) { |
|
5556 |
if (u2 == left) { |
|
5557 |
// rotated 90 |
|
5558 |
qreal tmp = dy; |
|
5559 |
dy = dx; |
|
5560 |
dx = -tmp; |
|
5561 |
} else if (u2 == right) { |
|
5562 |
// rotated 90 & mirrored |
|
5563 |
qreal tmp = dy; |
|
5564 |
dy = dx; |
|
5565 |
dx = tmp; |
|
5566 |
} else { |
|
5567 |
noScroll = true; |
|
5568 |
} |
|
5569 |
} |
|
5570 |
} |
|
5571 |
||
5572 |
if (!noScroll) { |
|
5573 |
view->viewport()->scroll(int(dx), int(dy), deviceScrollRect); |
|
5574 |
--couldntScroll; |
|
5575 |
} |
|
5576 |
} |
|
5577 |
if (couldntScroll) |
|
5578 |
update(rect); |
|
5579 |
} |
|
5580 |
||
5581 |
/*! |
|
5582 |
\fn void QGraphicsItem::update(qreal x, qreal y, qreal width, qreal height) |
|
5583 |
\overload |
|
5584 |
||
5585 |
This convenience function is equivalent to calling update(QRectF(\a x, \a |
|
5586 |
y, \a width, \a height)). |
|
5587 |
*/ |
|
5588 |
||
5589 |
/*! |
|
5590 |
Maps the point \a point, which is in this item's coordinate system, to \a |
|
5591 |
item's coordinate system, and returns the mapped coordinate. |
|
5592 |
||
5593 |
If \a item is 0, this function returns the same as mapToScene(). |
|
5594 |
||
5595 |
\sa itemTransform(), mapToParent(), mapToScene(), transform(), mapFromItem(), {The Graphics |
|
5596 |
View Coordinate System} |
|
5597 |
*/ |
|
5598 |
QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPointF &point) const |
|
5599 |
{ |
|
5600 |
if (item) |
|
5601 |
return itemTransform(item).map(point); |
|
5602 |
return mapToScene(point); |
|
5603 |
} |
|
5604 |
||
5605 |
/*! |
|
5606 |
\fn QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal x, qreal y) const |
|
5607 |
\overload |
|
5608 |
||
5609 |
This convenience function is equivalent to calling mapToItem(\a item, |
|
5610 |
QPointF(\a x, \a y)). |
|
5611 |
*/ |
|
5612 |
||
5613 |
/*! |
|
5614 |
Maps the point \a point, which is in this item's coordinate system, to its |
|
5615 |
parent's coordinate system, and returns the mapped coordinate. If the item |
|
5616 |
has no parent, \a point will be mapped to the scene's coordinate system. |
|
5617 |
||
5618 |
\sa mapToItem(), mapToScene(), transform(), mapFromParent(), {The Graphics |
|
5619 |
View Coordinate System} |
|
5620 |
*/ |
|
5621 |
QPointF QGraphicsItem::mapToParent(const QPointF &point) const |
|
5622 |
{ |
|
5623 |
// COMBINE |
|
5624 |
if (!d_ptr->transformData) |
|
5625 |
return point + d_ptr->pos; |
|
5626 |
return d_ptr->transformToParent().map(point); |
|
5627 |
} |
|
5628 |
||
5629 |
/*! |
|
5630 |
\fn QPointF QGraphicsItem::mapToParent(qreal x, qreal y) const |
|
5631 |
\overload |
|
5632 |
||
5633 |
This convenience function is equivalent to calling mapToParent(QPointF(\a |
|
5634 |
x, \a y)). |
|
5635 |
*/ |
|
5636 |
||
5637 |
/*! |
|
5638 |
Maps the point \a point, which is in this item's coordinate system, to the |
|
5639 |
scene's coordinate system, and returns the mapped coordinate. |
|
5640 |
||
5641 |
\sa mapToItem(), mapToParent(), transform(), mapFromScene(), {The Graphics |
|
5642 |
View Coordinate System} |
|
5643 |
*/ |
|
5644 |
QPointF QGraphicsItem::mapToScene(const QPointF &point) const |
|
5645 |
{ |
|
5646 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5647 |
return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy()); |
|
5648 |
return d_ptr->sceneTransform.map(point); |
|
5649 |
} |
|
5650 |
||
5651 |
/*! |
|
5652 |
\fn QPointF QGraphicsItem::mapToScene(qreal x, qreal y) const |
|
5653 |
\overload |
|
5654 |
||
5655 |
This convenience function is equivalent to calling mapToScene(QPointF(\a |
|
5656 |
x, \a y)). |
|
5657 |
*/ |
|
5658 |
||
5659 |
/*! |
|
5660 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5661 |
\a item's coordinate system, and returns the mapped rectangle as a polygon. |
|
5662 |
||
5663 |
If \a item is 0, this function returns the same as mapToScene(). |
|
5664 |
||
5665 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5666 |
Graphics View Coordinate System} |
|
5667 |
*/ |
|
5668 |
QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QRectF &rect) const |
|
5669 |
{ |
|
5670 |
if (item) |
|
5671 |
return itemTransform(item).map(rect); |
|
5672 |
return mapToScene(rect); |
|
5673 |
} |
|
5674 |
||
5675 |
/*! |
|
5676 |
\fn QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const |
|
5677 |
\since 4.3 |
|
5678 |
||
5679 |
This convenience function is equivalent to calling mapToItem(item, QRectF(\a x, \a y, \a w, \a h)). |
|
5680 |
*/ |
|
5681 |
||
5682 |
/*! |
|
5683 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5684 |
its parent's coordinate system, and returns the mapped rectangle as a |
|
5685 |
polygon. If the item has no parent, \a rect will be mapped to the scene's |
|
5686 |
coordinate system. |
|
5687 |
||
5688 |
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View |
|
5689 |
Coordinate System} |
|
5690 |
*/ |
|
5691 |
QPolygonF QGraphicsItem::mapToParent(const QRectF &rect) const |
|
5692 |
{ |
|
5693 |
// COMBINE |
|
5694 |
if (!d_ptr->transformData) |
|
5695 |
return rect.translated(d_ptr->pos); |
|
5696 |
return d_ptr->transformToParent().map(rect); |
|
5697 |
} |
|
5698 |
||
5699 |
/*! |
|
5700 |
\fn QPolygonF QGraphicsItem::mapToParent(qreal x, qreal y, qreal w, qreal h) const |
|
5701 |
\since 4.3 |
|
5702 |
||
5703 |
This convenience function is equivalent to calling mapToParent(QRectF(\a x, \a y, \a w, \a h)). |
|
5704 |
*/ |
|
5705 |
||
5706 |
/*! |
|
5707 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5708 |
the scene's coordinate system, and returns the mapped rectangle as a polygon. |
|
5709 |
||
5710 |
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View |
|
5711 |
Coordinate System} |
|
5712 |
*/ |
|
5713 |
QPolygonF QGraphicsItem::mapToScene(const QRectF &rect) const |
|
5714 |
{ |
|
5715 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5716 |
return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy()); |
|
5717 |
return d_ptr->sceneTransform.map(rect); |
|
5718 |
} |
|
5719 |
||
5720 |
/*! |
|
5721 |
\fn QPolygonF QGraphicsItem::mapToScene(qreal x, qreal y, qreal w, qreal h) const |
|
5722 |
\since 4.3 |
|
5723 |
||
5724 |
This convenience function is equivalent to calling mapToScene(QRectF(\a x, \a y, \a w, \a h)). |
|
5725 |
*/ |
|
5726 |
||
5727 |
/*! |
|
5728 |
\since 4.5 |
|
5729 |
||
5730 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5731 |
\a item's coordinate system, and returns the mapped rectangle as a new |
|
5732 |
rectangle (i.e., the bounding rectangle of the resulting polygon). |
|
5733 |
||
5734 |
If \a item is 0, this function returns the same as mapRectToScene(). |
|
5735 |
||
5736 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5737 |
Graphics View Coordinate System} |
|
5738 |
*/ |
|
5739 |
QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const |
|
5740 |
{ |
|
5741 |
if (item) |
|
5742 |
return itemTransform(item).mapRect(rect); |
|
5743 |
return mapRectToScene(rect); |
|
5744 |
} |
|
5745 |
||
5746 |
/*! |
|
5747 |
\fn QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const |
|
5748 |
\since 4.5 |
|
5749 |
||
5750 |
This convenience function is equivalent to calling mapRectToItem(item, QRectF(\a x, \a y, \a w, \a h)). |
|
5751 |
*/ |
|
5752 |
||
5753 |
/*! |
|
5754 |
\since 4.5 |
|
5755 |
||
5756 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5757 |
its parent's coordinate system, and returns the mapped rectangle as a new |
|
5758 |
rectangle (i.e., the bounding rectangle of the resulting polygon). |
|
5759 |
||
5760 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5761 |
Graphics View Coordinate System} |
|
5762 |
*/ |
|
5763 |
QRectF QGraphicsItem::mapRectToParent(const QRectF &rect) const |
|
5764 |
{ |
|
5765 |
// COMBINE |
|
5766 |
if (!d_ptr->transformData) |
|
5767 |
return rect.translated(d_ptr->pos); |
|
5768 |
return d_ptr->transformToParent().mapRect(rect); |
|
5769 |
} |
|
5770 |
||
5771 |
/*! |
|
5772 |
\fn QRectF QGraphicsItem::mapRectToParent(qreal x, qreal y, qreal w, qreal h) const |
|
5773 |
\since 4.5 |
|
5774 |
||
5775 |
This convenience function is equivalent to calling mapRectToParent(QRectF(\a x, \a y, \a w, \a h)). |
|
5776 |
*/ |
|
5777 |
||
5778 |
/*! |
|
5779 |
\since 4.5 |
|
5780 |
||
5781 |
Maps the rectangle \a rect, which is in this item's coordinate system, to |
|
5782 |
the scene coordinate system, and returns the mapped rectangle as a new |
|
5783 |
rectangle (i.e., the bounding rectangle of the resulting polygon). |
|
5784 |
||
5785 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5786 |
Graphics View Coordinate System} |
|
5787 |
*/ |
|
5788 |
QRectF QGraphicsItem::mapRectToScene(const QRectF &rect) const |
|
5789 |
{ |
|
5790 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5791 |
return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy()); |
|
5792 |
return d_ptr->sceneTransform.mapRect(rect); |
|
5793 |
} |
|
5794 |
||
5795 |
/*! |
|
5796 |
\fn QRectF QGraphicsItem::mapRectToScene(qreal x, qreal y, qreal w, qreal h) const |
|
5797 |
\since 4.5 |
|
5798 |
||
5799 |
This convenience function is equivalent to calling mapRectToScene(QRectF(\a x, \a y, \a w, \a h)). |
|
5800 |
*/ |
|
5801 |
||
5802 |
/*! |
|
5803 |
\since 4.5 |
|
5804 |
||
5805 |
Maps the rectangle \a rect, which is in \a item's coordinate system, to |
|
5806 |
this item's coordinate system, and returns the mapped rectangle as a new |
|
5807 |
rectangle (i.e., the bounding rectangle of the resulting polygon). |
|
5808 |
||
5809 |
If \a item is 0, this function returns the same as mapRectFromScene(). |
|
5810 |
||
5811 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5812 |
Graphics View Coordinate System} |
|
5813 |
*/ |
|
5814 |
QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const |
|
5815 |
{ |
|
5816 |
if (item) |
|
5817 |
return item->itemTransform(this).mapRect(rect); |
|
5818 |
return mapRectFromScene(rect); |
|
5819 |
} |
|
5820 |
||
5821 |
/*! |
|
5822 |
\fn QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const |
|
5823 |
\since 4.5 |
|
5824 |
||
5825 |
This convenience function is equivalent to calling mapRectFromItem(item, QRectF(\a x, \a y, \a w, \a h)). |
|
5826 |
*/ |
|
5827 |
||
5828 |
/*! |
|
5829 |
\since 4.5 |
|
5830 |
||
5831 |
Maps the rectangle \a rect, which is in this item's parent's coordinate |
|
5832 |
system, to this item's coordinate system, and returns the mapped rectangle |
|
5833 |
as a new rectangle (i.e., the bounding rectangle of the resulting |
|
5834 |
polygon). |
|
5835 |
||
5836 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5837 |
Graphics View Coordinate System} |
|
5838 |
*/ |
|
5839 |
QRectF QGraphicsItem::mapRectFromParent(const QRectF &rect) const |
|
5840 |
{ |
|
5841 |
// COMBINE |
|
5842 |
if (!d_ptr->transformData) |
|
5843 |
return rect.translated(-d_ptr->pos); |
|
5844 |
return d_ptr->transformToParent().inverted().mapRect(rect); |
|
5845 |
} |
|
5846 |
||
5847 |
/*! |
|
5848 |
\fn QRectF QGraphicsItem::mapRectFromParent(qreal x, qreal y, qreal w, qreal h) const |
|
5849 |
\since 4.5 |
|
5850 |
||
5851 |
This convenience function is equivalent to calling mapRectFromParent(QRectF(\a x, \a y, \a w, \a h)). |
|
5852 |
*/ |
|
5853 |
||
5854 |
/*! |
|
5855 |
\since 4.5 |
|
5856 |
||
5857 |
Maps the rectangle \a rect, which is in scene coordinates, to this item's |
|
5858 |
coordinate system, and returns the mapped rectangle as a new rectangle |
|
5859 |
(i.e., the bounding rectangle of the resulting polygon). |
|
5860 |
||
5861 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5862 |
Graphics View Coordinate System} |
|
5863 |
*/ |
|
5864 |
QRectF QGraphicsItem::mapRectFromScene(const QRectF &rect) const |
|
5865 |
{ |
|
5866 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5867 |
return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy()); |
|
5868 |
return d_ptr->sceneTransform.inverted().mapRect(rect); |
|
5869 |
} |
|
5870 |
||
5871 |
/*! |
|
5872 |
\fn QRectF QGraphicsItem::mapRectFromScene(qreal x, qreal y, qreal w, qreal h) const |
|
5873 |
\since 4.5 |
|
5874 |
||
5875 |
This convenience function is equivalent to calling mapRectFromScene(QRectF(\a x, \a y, \a w, \a h)). |
|
5876 |
*/ |
|
5877 |
||
5878 |
/*! |
|
5879 |
Maps the polygon \a polygon, which is in this item's coordinate system, to |
|
5880 |
\a item's coordinate system, and returns the mapped polygon. |
|
5881 |
||
5882 |
If \a item is 0, this function returns the same as mapToScene(). |
|
5883 |
||
5884 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5885 |
Graphics View Coordinate System} |
|
5886 |
*/ |
|
5887 |
QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const |
|
5888 |
{ |
|
5889 |
if (item) |
|
5890 |
return itemTransform(item).map(polygon); |
|
5891 |
return mapToScene(polygon); |
|
5892 |
} |
|
5893 |
||
5894 |
/*! |
|
5895 |
Maps the polygon \a polygon, which is in this item's coordinate system, to |
|
5896 |
its parent's coordinate system, and returns the mapped polygon. If the |
|
5897 |
item has no parent, \a polygon will be mapped to the scene's coordinate |
|
5898 |
system. |
|
5899 |
||
5900 |
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View |
|
5901 |
Coordinate System} |
|
5902 |
*/ |
|
5903 |
QPolygonF QGraphicsItem::mapToParent(const QPolygonF &polygon) const |
|
5904 |
{ |
|
5905 |
// COMBINE |
|
5906 |
if (!d_ptr->transformData) |
|
5907 |
return polygon.translated(d_ptr->pos); |
|
5908 |
return d_ptr->transformToParent().map(polygon); |
|
5909 |
} |
|
5910 |
||
5911 |
/*! |
|
5912 |
Maps the polygon \a polygon, which is in this item's coordinate system, to |
|
5913 |
the scene's coordinate system, and returns the mapped polygon. |
|
5914 |
||
5915 |
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View |
|
5916 |
Coordinate System} |
|
5917 |
*/ |
|
5918 |
QPolygonF QGraphicsItem::mapToScene(const QPolygonF &polygon) const |
|
5919 |
{ |
|
5920 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5921 |
return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy()); |
|
5922 |
return d_ptr->sceneTransform.map(polygon); |
|
5923 |
} |
|
5924 |
||
5925 |
/*! |
|
5926 |
Maps the path \a path, which is in this item's coordinate system, to |
|
5927 |
\a item's coordinate system, and returns the mapped path. |
|
5928 |
||
5929 |
If \a item is 0, this function returns the same as mapToScene(). |
|
5930 |
||
5931 |
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The |
|
5932 |
Graphics View Coordinate System} |
|
5933 |
*/ |
|
5934 |
QPainterPath QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPainterPath &path) const |
|
5935 |
{ |
|
5936 |
if (item) |
|
5937 |
return itemTransform(item).map(path); |
|
5938 |
return mapToScene(path); |
|
5939 |
} |
|
5940 |
||
5941 |
/*! |
|
5942 |
Maps the path \a path, which is in this item's coordinate system, to |
|
5943 |
its parent's coordinate system, and returns the mapped path. If the |
|
5944 |
item has no parent, \a path will be mapped to the scene's coordinate |
|
5945 |
system. |
|
5946 |
||
5947 |
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View |
|
5948 |
Coordinate System} |
|
5949 |
*/ |
|
5950 |
QPainterPath QGraphicsItem::mapToParent(const QPainterPath &path) const |
|
5951 |
{ |
|
5952 |
// COMBINE |
|
5953 |
if (!d_ptr->transformData) |
|
5954 |
return path.translated(d_ptr->pos); |
|
5955 |
return d_ptr->transformToParent().map(path); |
|
5956 |
} |
|
5957 |
||
5958 |
/*! |
|
5959 |
Maps the path \a path, which is in this item's coordinate system, to |
|
5960 |
the scene's coordinate system, and returns the mapped path. |
|
5961 |
||
5962 |
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View |
|
5963 |
Coordinate System} |
|
5964 |
*/ |
|
5965 |
QPainterPath QGraphicsItem::mapToScene(const QPainterPath &path) const |
|
5966 |
{ |
|
5967 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
5968 |
return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy()); |
|
5969 |
return d_ptr->sceneTransform.map(path); |
|
5970 |
} |
|
5971 |
||
5972 |
/*! |
|
5973 |
Maps the point \a point, which is in \a item's coordinate system, to this |
|
5974 |
item's coordinate system, and returns the mapped coordinate. |
|
5975 |
||
5976 |
If \a item is 0, this function returns the same as mapFromScene(). |
|
5977 |
||
5978 |
\sa itemTransform(), mapFromParent(), mapFromScene(), transform(), mapToItem(), {The Graphics |
|
5979 |
View Coordinate System} |
|
5980 |
*/ |
|
5981 |
QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPointF &point) const |
|
5982 |
{ |
|
5983 |
if (item) |
|
5984 |
return item->itemTransform(this).map(point); |
|
5985 |
return mapFromScene(point); |
|
5986 |
} |
|
5987 |
||
5988 |
/*! |
|
5989 |
\fn QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal x, qreal y) const |
|
5990 |
\overload |
|
5991 |
||
5992 |
This convenience function is equivalent to calling mapFromItem(\a item, |
|
5993 |
QPointF(\a x, \a y)). |
|
5994 |
*/ |
|
5995 |
||
5996 |
/*! |
|
5997 |
Maps the point \a point, which is in this item's parent's coordinate |
|
5998 |
system, to this item's coordinate system, and returns the mapped |
|
5999 |
coordinate. |
|
6000 |
||
6001 |
\sa mapFromItem(), mapFromScene(), transform(), mapToParent(), {The Graphics |
|
6002 |
View Coordinate System} |
|
6003 |
*/ |
|
6004 |
QPointF QGraphicsItem::mapFromParent(const QPointF &point) const |
|
6005 |
{ |
|
6006 |
// COMBINE |
|
6007 |
if (d_ptr->transformData) |
|
6008 |
return d_ptr->transformToParent().inverted().map(point); |
|
6009 |
return point - d_ptr->pos; |
|
6010 |
} |
|
6011 |
||
6012 |
/*! |
|
6013 |
\fn QPointF QGraphicsItem::mapFromParent(qreal x, qreal y) const |
|
6014 |
\overload |
|
6015 |
||
6016 |
This convenience function is equivalent to calling |
|
6017 |
mapFromParent(QPointF(\a x, \a y)). |
|
6018 |
*/ |
|
6019 |
||
6020 |
/*! |
|
6021 |
Maps the point \a point, which is in this item's scene's coordinate |
|
6022 |
system, to this item's coordinate system, and returns the mapped |
|
6023 |
coordinate. |
|
6024 |
||
6025 |
\sa mapFromItem(), mapFromParent(), transform(), mapToScene(), {The Graphics |
|
6026 |
View Coordinate System} |
|
6027 |
*/ |
|
6028 |
QPointF QGraphicsItem::mapFromScene(const QPointF &point) const |
|
6029 |
{ |
|
6030 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
6031 |
return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy()); |
|
6032 |
return d_ptr->sceneTransform.inverted().map(point); |
|
6033 |
} |
|
6034 |
||
6035 |
/*! |
|
6036 |
\fn QPointF QGraphicsItem::mapFromScene(qreal x, qreal y) const |
|
6037 |
\overload |
|
6038 |
||
6039 |
This convenience function is equivalent to calling mapFromScene(QPointF(\a |
|
6040 |
x, \a y)). |
|
6041 |
*/ |
|
6042 |
||
6043 |
/*! |
|
6044 |
Maps the rectangle \a rect, which is in \a item's coordinate system, to |
|
6045 |
this item's coordinate system, and returns the mapped rectangle as a |
|
6046 |
polygon. |
|
6047 |
||
6048 |
If \a item is 0, this function returns the same as mapFromScene() |
|
6049 |
||
6050 |
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate |
|
6051 |
System} |
|
6052 |
*/ |
|
6053 |
QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QRectF &rect) const |
|
6054 |
{ |
|
6055 |
if (item) |
|
6056 |
return item->itemTransform(this).map(rect); |
|
6057 |
return mapFromScene(rect); |
|
6058 |
} |
|
6059 |
||
6060 |
/*! |
|
6061 |
\fn QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const |
|
6062 |
\since 4.3 |
|
6063 |
||
6064 |
This convenience function is equivalent to calling mapFromItem(item, QRectF(\a x, \a y, \a w, \a h)). |
|
6065 |
*/ |
|
6066 |
||
6067 |
/*! |
|
6068 |
Maps the rectangle \a rect, which is in this item's parent's coordinate |
|
6069 |
system, to this item's coordinate system, and returns the mapped rectangle |
|
6070 |
as a polygon. |
|
6071 |
||
6072 |
\sa mapToParent(), mapFromItem(), transform(), {The Graphics View Coordinate |
|
6073 |
System} |
|
6074 |
*/ |
|
6075 |
QPolygonF QGraphicsItem::mapFromParent(const QRectF &rect) const |
|
6076 |
{ |
|
6077 |
// COMBINE |
|
6078 |
if (!d_ptr->transformData) |
|
6079 |
return rect.translated(-d_ptr->pos); |
|
6080 |
return d_ptr->transformToParent().inverted().map(rect); |
|
6081 |
} |
|
6082 |
||
6083 |
/*! |
|
6084 |
\fn QPolygonF QGraphicsItem::mapFromParent(qreal x, qreal y, qreal w, qreal h) const |
|
6085 |
\since 4.3 |
|
6086 |
||
6087 |
This convenience function is equivalent to calling mapFromItem(QRectF(\a x, \a y, \a w, \a h)). |
|
6088 |
*/ |
|
6089 |
||
6090 |
/*! |
|
6091 |
Maps the rectangle \a rect, which is in this item's scene's coordinate |
|
6092 |
system, to this item's coordinate system, and returns the mapped rectangle |
|
6093 |
as a polygon. |
|
6094 |
||
6095 |
\sa mapToScene(), mapFromItem(), transform(), {The Graphics View Coordinate |
|
6096 |
System} |
|
6097 |
*/ |
|
6098 |
QPolygonF QGraphicsItem::mapFromScene(const QRectF &rect) const |
|
6099 |
{ |
|
6100 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
6101 |
return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy()); |
|
6102 |
return d_ptr->sceneTransform.inverted().map(rect); |
|
6103 |
} |
|
6104 |
||
6105 |
/*! |
|
6106 |
\fn QPolygonF QGraphicsItem::mapFromScene(qreal x, qreal y, qreal w, qreal h) const |
|
6107 |
\since 4.3 |
|
6108 |
||
6109 |
This convenience function is equivalent to calling mapFromScene(QRectF(\a x, \a y, \a w, \a h)). |
|
6110 |
*/ |
|
6111 |
||
6112 |
/*! |
|
6113 |
Maps the polygon \a polygon, which is in \a item's coordinate system, to |
|
6114 |
this item's coordinate system, and returns the mapped polygon. |
|
6115 |
||
6116 |
If \a item is 0, this function returns the same as mapFromScene(). |
|
6117 |
||
6118 |
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The |
|
6119 |
Graphics View Coordinate System} |
|
6120 |
*/ |
|
6121 |
QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPolygonF &polygon) const |
|
6122 |
{ |
|
6123 |
if (item) |
|
6124 |
return item->itemTransform(this).map(polygon); |
|
6125 |
return mapFromScene(polygon); |
|
6126 |
} |
|
6127 |
||
6128 |
/*! |
|
6129 |
Maps the polygon \a polygon, which is in this item's parent's coordinate |
|
6130 |
system, to this item's coordinate system, and returns the mapped polygon. |
|
6131 |
||
6132 |
\sa mapToParent(), mapToItem(), transform(), {The Graphics View Coordinate |
|
6133 |
System} |
|
6134 |
*/ |
|
6135 |
QPolygonF QGraphicsItem::mapFromParent(const QPolygonF &polygon) const |
|
6136 |
{ |
|
6137 |
// COMBINE |
|
6138 |
if (!d_ptr->transformData) |
|
6139 |
return polygon.translated(-d_ptr->pos); |
|
6140 |
return d_ptr->transformToParent().inverted().map(polygon); |
|
6141 |
} |
|
6142 |
||
6143 |
/*! |
|
6144 |
Maps the polygon \a polygon, which is in this item's scene's coordinate |
|
6145 |
system, to this item's coordinate system, and returns the mapped polygon. |
|
6146 |
||
6147 |
\sa mapToScene(), mapFromParent(), transform(), {The Graphics View Coordinate |
|
6148 |
System} |
|
6149 |
*/ |
|
6150 |
QPolygonF QGraphicsItem::mapFromScene(const QPolygonF &polygon) const |
|
6151 |
{ |
|
6152 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
6153 |
return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy()); |
|
6154 |
return d_ptr->sceneTransform.inverted().map(polygon); |
|
6155 |
} |
|
6156 |
||
6157 |
/*! |
|
6158 |
Maps the path \a path, which is in \a item's coordinate system, to |
|
6159 |
this item's coordinate system, and returns the mapped path. |
|
6160 |
||
6161 |
If \a item is 0, this function returns the same as mapFromScene(). |
|
6162 |
||
6163 |
\sa itemTransform(), mapFromParent(), mapFromScene(), mapToItem(), {The |
|
6164 |
Graphics View Coordinate System} |
|
6165 |
*/ |
|
6166 |
QPainterPath QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPainterPath &path) const |
|
6167 |
{ |
|
6168 |
if (item) |
|
6169 |
return item->itemTransform(this).map(path); |
|
6170 |
return mapFromScene(path); |
|
6171 |
} |
|
6172 |
||
6173 |
/*! |
|
6174 |
Maps the path \a path, which is in this item's parent's coordinate |
|
6175 |
system, to this item's coordinate system, and returns the mapped path. |
|
6176 |
||
6177 |
\sa mapFromScene(), mapFromItem(), mapToParent(), {The Graphics View |
|
6178 |
Coordinate System} |
|
6179 |
*/ |
|
6180 |
QPainterPath QGraphicsItem::mapFromParent(const QPainterPath &path) const |
|
6181 |
{ |
|
6182 |
// COMBINE |
|
6183 |
if (!d_ptr->transformData) |
|
6184 |
return path.translated(-d_ptr->pos); |
|
6185 |
return d_ptr->transformToParent().inverted().map(path); |
|
6186 |
} |
|
6187 |
||
6188 |
/*! |
|
6189 |
Maps the path \a path, which is in this item's scene's coordinate |
|
6190 |
system, to this item's coordinate system, and returns the mapped path. |
|
6191 |
||
6192 |
\sa mapFromParent(), mapFromItem(), mapToScene(), {The Graphics View |
|
6193 |
Coordinate System} |
|
6194 |
*/ |
|
6195 |
QPainterPath QGraphicsItem::mapFromScene(const QPainterPath &path) const |
|
6196 |
{ |
|
6197 |
if (d_ptr->hasTranslateOnlySceneTransform()) |
|
6198 |
return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy()); |
|
6199 |
return d_ptr->sceneTransform.inverted().map(path); |
|
6200 |
} |
|
6201 |
||
6202 |
/*! |
|
6203 |
Returns true if this item is an ancestor of \a child (i.e., if this item |
|
6204 |
is \a child's parent, or one of \a child's parent's ancestors). |
|
6205 |
||
6206 |
\sa parentItem() |
|
6207 |
*/ |
|
6208 |
bool QGraphicsItem::isAncestorOf(const QGraphicsItem *child) const |
|
6209 |
{ |
|
6210 |
if (!child || child == this) |
|
6211 |
return false; |
|
6212 |
if (child->d_ptr->depth() < d_ptr->depth()) |
|
6213 |
return false; |
|
6214 |
const QGraphicsItem *ancestor = child; |
|
6215 |
while ((ancestor = ancestor->d_ptr->parent)) { |
|
6216 |
if (ancestor == this) |
|
6217 |
return true; |
|
6218 |
} |
|
6219 |
return false; |
|
6220 |
} |
|
6221 |
||
6222 |
/*! |
|
6223 |
\since 4.4 |
|
6224 |
||
6225 |
Returns the closest common ancestor item of this item and \a other, or 0 |
|
6226 |
if either \a other is 0, or there is no common ancestor. |
|
6227 |
||
6228 |
\sa isAncestorOf() |
|
6229 |
*/ |
|
6230 |
QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) const |
|
6231 |
{ |
|
6232 |
if (!other) |
|
6233 |
return 0; |
|
6234 |
if (other == this) |
|
6235 |
return const_cast<QGraphicsItem *>(this); |
|
6236 |
const QGraphicsItem *thisw = this; |
|
6237 |
const QGraphicsItem *otherw = other; |
|
6238 |
int thisDepth = d_ptr->depth(); |
|
6239 |
int otherDepth = other->d_ptr->depth(); |
|
6240 |
while (thisDepth > otherDepth) { |
|
6241 |
thisw = thisw->d_ptr->parent; |
|
6242 |
--thisDepth; |
|
6243 |
} |
|
6244 |
while (otherDepth > thisDepth) { |
|
6245 |
otherw = otherw->d_ptr->parent; |
|
6246 |
--otherDepth; |
|
6247 |
} |
|
6248 |
while (thisw && thisw != otherw) { |
|
6249 |
thisw = thisw->d_ptr->parent; |
|
6250 |
otherw = otherw->d_ptr->parent; |
|
6251 |
} |
|
6252 |
return const_cast<QGraphicsItem *>(thisw); |
|
6253 |
} |
|
6254 |
||
6255 |
/*! |
|
6256 |
\since 4,4 |
|
6257 |
Returns true if this item is currently under the mouse cursor in one of |
|
6258 |
the views; otherwise, false is returned. |
|
6259 |
||
6260 |
\sa QGraphicsScene::views(), QCursor::pos() |
|
6261 |
*/ |
|
6262 |
bool QGraphicsItem::isUnderMouse() const |
|
6263 |
{ |
|
6264 |
Q_D(const QGraphicsItem); |
|
6265 |
if (!d->scene) |
|
6266 |
return false; |
|
6267 |
||
6268 |
QPoint cursorPos = QCursor::pos(); |
|
6269 |
foreach (QGraphicsView *view, d->scene->views()) { |
|
6270 |
if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos))))) |
|
6271 |
return true; |
|
6272 |
} |
|
6273 |
return false; |
|
6274 |
} |
|
6275 |
||
6276 |
/*! |
|
6277 |
Returns this item's custom data for the key \a key as a QVariant. |
|
6278 |
||
6279 |
Custom item data is useful for storing arbitrary properties in any |
|
6280 |
item. Example: |
|
6281 |
||
6282 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 11 |
|
6283 |
||
6284 |
Qt does not use this feature for storing data; it is provided solely |
|
6285 |
for the convenience of the user. |
|
6286 |
||
6287 |
\sa setData() |
|
6288 |
*/ |
|
6289 |
QVariant QGraphicsItem::data(int key) const |
|
6290 |
{ |
|
6291 |
QGraphicsItemCustomDataStore *store = qt_dataStore(); |
|
6292 |
if (!store->data.contains(this)) |
|
6293 |
return QVariant(); |
|
6294 |
return store->data.value(this).value(key); |
|
6295 |
} |
|
6296 |
||
6297 |
/*! |
|
6298 |
Sets this item's custom data for the key \a key to \a value. |
|
6299 |
||
6300 |
Custom item data is useful for storing arbitrary properties for any |
|
6301 |
item. Qt does not use this feature for storing data; it is provided solely |
|
6302 |
for the convenience of the user. |
|
6303 |
||
6304 |
\sa data() |
|
6305 |
*/ |
|
6306 |
void QGraphicsItem::setData(int key, const QVariant &value) |
|
6307 |
{ |
|
6308 |
qt_dataStore()->data[this][key] = value; |
|
6309 |
} |
|
6310 |
||
6311 |
/*! |
|
6312 |
\fn T qgraphicsitem_cast(QGraphicsItem *item) |
|
6313 |
\relates QGraphicsItem |
|
6314 |
\since 4.2 |
|
6315 |
||
6316 |
Returns the given \a item cast to type T if \a item is of type T; |
|
6317 |
otherwise, 0 is returned. |
|
6318 |
||
6319 |
\note To make this function work correctly with custom items, reimplement |
|
6320 |
the \l{QGraphicsItem::}{type()} function for each custom QGraphicsItem |
|
6321 |
subclass. |
|
6322 |
||
6323 |
\sa QGraphicsItem::type(), QGraphicsItem::UserType |
|
6324 |
*/ |
|
6325 |
||
6326 |
/*! |
|
6327 |
Returns the type of an item as an int. All standard graphicsitem classes |
|
6328 |
are associated with a unique value; see QGraphicsItem::Type. This type |
|
6329 |
information is used by qgraphicsitem_cast() to distinguish between types. |
|
6330 |
||
6331 |
The default implementation (in QGraphicsItem) returns UserType. |
|
6332 |
||
6333 |
To enable use of qgraphicsitem_cast() with a custom item, reimplement this |
|
6334 |
function and declare a Type enum value equal to your custom item's type. |
|
6335 |
Custom items must return a value larger than or equal to UserType (65536). |
|
6336 |
||
6337 |
For example: |
|
6338 |
||
6339 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp QGraphicsItem type |
|
6340 |
||
6341 |
\sa UserType |
|
6342 |
*/ |
|
6343 |
int QGraphicsItem::type() const |
|
6344 |
{ |
|
6345 |
return (int)UserType; |
|
6346 |
} |
|
6347 |
||
6348 |
/*! |
|
6349 |
Installs an event filter for this item on \a filterItem, causing |
|
6350 |
all events for this item to first pass through \a filterItem's |
|
6351 |
sceneEventFilter() function. |
|
6352 |
||
6353 |
To filter another item's events, install this item as an event filter |
|
6354 |
for the other item. Example: |
|
6355 |
||
6356 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 12 |
|
6357 |
||
6358 |
An item can only filter events for other items in the same |
|
6359 |
scene. Also, an item cannot filter its own events; instead, you |
|
6360 |
can reimplement sceneEvent() directly. |
|
6361 |
||
6362 |
Items must belong to a scene for scene event filters to be installed and |
|
6363 |
used. |
|
6364 |
||
6365 |
\sa removeSceneEventFilter(), sceneEventFilter(), sceneEvent() |
|
6366 |
*/ |
|
6367 |
void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem) |
|
6368 |
{ |
|
6369 |
if (!d_ptr->scene) { |
|
6370 |
qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed" |
|
6371 |
" on items in a scene."); |
|
6372 |
return; |
|
6373 |
} |
|
6374 |
if (d_ptr->scene != filterItem->scene()) { |
|
6375 |
qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed" |
|
6376 |
" on items in the same scene."); |
|
6377 |
return; |
|
6378 |
} |
|
6379 |
d_ptr->scene->d_func()->installSceneEventFilter(this, filterItem); |
|
6380 |
} |
|
6381 |
||
6382 |
/*! |
|
6383 |
Removes an event filter on this item from \a filterItem. |
|
6384 |
||
6385 |
\sa installSceneEventFilter() |
|
6386 |
*/ |
|
6387 |
void QGraphicsItem::removeSceneEventFilter(QGraphicsItem *filterItem) |
|
6388 |
{ |
|
6389 |
if (!d_ptr->scene || d_ptr->scene != filterItem->scene()) |
|
6390 |
return; |
|
6391 |
d_ptr->scene->d_func()->removeSceneEventFilter(this, filterItem); |
|
6392 |
} |
|
6393 |
||
6394 |
/*! |
|
6395 |
Filters events for the item \a watched. \a event is the filtered |
|
6396 |
event. |
|
6397 |
||
6398 |
Reimplementing this function in a subclass makes it possible |
|
6399 |
for the item to be used as an event filter for other items, |
|
6400 |
intercepting all the events send to those items before they are |
|
6401 |
able to respond. |
|
6402 |
||
6403 |
Reimplementations must return true to prevent further processing of |
|
6404 |
a given event, ensuring that it will not be delivered to the watched |
|
6405 |
item, or return false to indicate that the event should be propagated |
|
6406 |
further by the event system. |
|
6407 |
||
6408 |
\sa installSceneEventFilter() |
|
6409 |
*/ |
|
6410 |
bool QGraphicsItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event) |
|
6411 |
{ |
|
6412 |
Q_UNUSED(watched); |
|
6413 |
Q_UNUSED(event); |
|
6414 |
return false; |
|
6415 |
} |
|
6416 |
||
6417 |
/*! |
|
6418 |
This virtual function receives events to this item. Reimplement |
|
6419 |
this function to intercept events before they are dispatched to |
|
6420 |
the specialized event handlers contextMenuEvent(), focusInEvent(), |
|
6421 |
focusOutEvent(), hoverEnterEvent(), hoverMoveEvent(), |
|
6422 |
hoverLeaveEvent(), keyPressEvent(), keyReleaseEvent(), |
|
6423 |
mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), and |
|
6424 |
mouseDoubleClickEvent(). |
|
6425 |
||
6426 |
Returns true if the event was recognized and handled; otherwise, (e.g., if |
|
6427 |
the event type was not recognized,) false is returned. |
|
6428 |
||
6429 |
\a event is the intercepted event. |
|
6430 |
*/ |
|
6431 |
bool QGraphicsItem::sceneEvent(QEvent *event) |
|
6432 |
{ |
|
6433 |
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents) { |
|
6434 |
if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave |
|
6435 |
|| event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) { |
|
6436 |
// Hover enter and hover leave events for children are ignored; |
|
6437 |
// hover move events are forwarded. |
|
6438 |
return true; |
|
6439 |
} |
|
6440 |
||
6441 |
QGraphicsItem *handler = this; |
|
6442 |
do { |
|
6443 |
handler = handler->d_ptr->parent; |
|
6444 |
Q_ASSERT(handler); |
|
6445 |
} while (handler->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents); |
|
6446 |
// Forward the event to the closest parent that handles child |
|
6447 |
// events, mapping existing item-local coordinates to its |
|
6448 |
// coordinate system. |
|
6449 |
d_ptr->remapItemPos(event, handler); |
|
6450 |
handler->sceneEvent(event); |
|
6451 |
return true; |
|
6452 |
} |
|
6453 |
||
6454 |
if (!d_ptr->visible) { |
|
6455 |
// Eaten |
|
6456 |
return true; |
|
6457 |
} |
|
6458 |
||
6459 |
switch (event->type()) { |
|
6460 |
case QEvent::FocusIn: |
|
6461 |
focusInEvent(static_cast<QFocusEvent *>(event)); |
|
6462 |
break; |
|
6463 |
case QEvent::FocusOut: |
|
6464 |
focusOutEvent(static_cast<QFocusEvent *>(event)); |
|
6465 |
break; |
|
6466 |
case QEvent::GraphicsSceneContextMenu: |
|
6467 |
contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event)); |
|
6468 |
break; |
|
6469 |
case QEvent::GraphicsSceneDragEnter: |
|
6470 |
dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
6471 |
break; |
|
6472 |
case QEvent::GraphicsSceneDragMove: |
|
6473 |
dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
6474 |
break; |
|
6475 |
case QEvent::GraphicsSceneDragLeave: |
|
6476 |
dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
6477 |
break; |
|
6478 |
case QEvent::GraphicsSceneDrop: |
|
6479 |
dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
6480 |
break; |
|
6481 |
case QEvent::GraphicsSceneHoverEnter: |
|
6482 |
hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event)); |
|
6483 |
break; |
|
6484 |
case QEvent::GraphicsSceneHoverMove: |
|
6485 |
hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event)); |
|
6486 |
break; |
|
6487 |
case QEvent::GraphicsSceneHoverLeave: |
|
6488 |
hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event)); |
|
6489 |
break; |
|
6490 |
case QEvent::GraphicsSceneMouseMove: |
|
6491 |
mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
6492 |
break; |
|
6493 |
case QEvent::GraphicsSceneMousePress: |
|
6494 |
mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
6495 |
break; |
|
6496 |
case QEvent::GraphicsSceneMouseRelease: |
|
6497 |
mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
6498 |
break; |
|
6499 |
case QEvent::GraphicsSceneMouseDoubleClick: |
|
6500 |
mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
6501 |
break; |
|
6502 |
case QEvent::GraphicsSceneWheel: |
|
6503 |
wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event)); |
|
6504 |
break; |
|
6505 |
case QEvent::KeyPress: { |
|
6506 |
QKeyEvent *k = static_cast<QKeyEvent *>(event); |
|
6507 |
if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { |
|
6508 |
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? |
|
6509 |
bool res = false; |
|
6510 |
if (k->key() == Qt::Key_Backtab |
|
6511 |
|| (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) { |
|
6512 |
if (d_ptr->isWidget) { |
|
6513 |
res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(false); |
|
6514 |
} else if (d_ptr->scene) { |
|
6515 |
res = d_ptr->scene->focusNextPrevChild(false); |
|
6516 |
} |
|
6517 |
} else if (k->key() == Qt::Key_Tab) { |
|
6518 |
if (d_ptr->isWidget) { |
|
6519 |
res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(true); |
|
6520 |
} else if (d_ptr->scene) { |
|
6521 |
res = d_ptr->scene->focusNextPrevChild(true); |
|
6522 |
} |
|
6523 |
} |
|
6524 |
if (!res) |
|
6525 |
event->ignore(); |
|
6526 |
return true; |
|
6527 |
} |
|
6528 |
} |
|
6529 |
keyPressEvent(static_cast<QKeyEvent *>(event)); |
|
6530 |
break; |
|
6531 |
} |
|
6532 |
case QEvent::KeyRelease: |
|
6533 |
keyReleaseEvent(static_cast<QKeyEvent *>(event)); |
|
6534 |
break; |
|
6535 |
case QEvent::InputMethod: |
|
6536 |
inputMethodEvent(static_cast<QInputMethodEvent *>(event)); |
|
6537 |
break; |
|
6538 |
case QEvent::WindowActivate: |
|
6539 |
case QEvent::WindowDeactivate: |
|
6540 |
// Propagate panel activation. |
|
6541 |
if (d_ptr->scene) { |
|
6542 |
for (int i = 0; i < d_ptr->children.size(); ++i) { |
|
6543 |
QGraphicsItem *child = d_ptr->children.at(i); |
|
6544 |
if (child->isVisible() && !child->isPanel()) { |
|
6545 |
if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents)) |
|
6546 |
d_ptr->scene->sendEvent(child, event); |
|
6547 |
} |
|
6548 |
} |
|
6549 |
} |
|
6550 |
break; |
|
6551 |
default: |
|
6552 |
return false; |
|
6553 |
} |
|
6554 |
||
6555 |
return true; |
|
6556 |
} |
|
6557 |
||
6558 |
/*! |
|
6559 |
This event handler can be reimplemented in a subclass to process context |
|
6560 |
menu events. The \a event parameter contains details about the event to |
|
6561 |
be handled. |
|
6562 |
||
6563 |
If you ignore the event, (i.e., by calling QEvent::ignore(),) \a event |
|
6564 |
will propagate to any item beneath this item. If no items accept the |
|
6565 |
event, it will be ignored by the scene, and propagate to the view. |
|
6566 |
||
6567 |
It's common to open a QMenu in response to receiving a context menu |
|
6568 |
event. Example: |
|
6569 |
||
6570 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 13 |
|
6571 |
||
6572 |
The default implementation ignores the event. |
|
6573 |
||
6574 |
\sa sceneEvent() |
|
6575 |
*/ |
|
6576 |
void QGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) |
|
6577 |
{ |
|
6578 |
event->ignore(); |
|
6579 |
} |
|
6580 |
||
6581 |
/*! |
|
6582 |
This event handler, for event \a event, can be reimplemented to receive |
|
6583 |
drag enter events for this item. Drag enter events are generated as the |
|
6584 |
cursor enters the item's area. |
|
6585 |
||
6586 |
By accepting the event, (i.e., by calling QEvent::accept(),) the item will |
|
6587 |
accept drop events, in addition to receiving drag move and drag |
|
6588 |
leave. Otherwise, the event will be ignored and propagate to the item |
|
6589 |
beneath. If the event is accepted, the item will receive a drag move event |
|
6590 |
before control goes back to the event loop. |
|
6591 |
||
6592 |
A common implementation of dragEnterEvent accepts or ignores \a event |
|
6593 |
depending on the associated mime data in \a event. Example: |
|
6594 |
||
6595 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 14 |
|
6596 |
||
6597 |
Items do not receive drag and drop events by default; to enable this |
|
6598 |
feature, call \c setAcceptDrops(true). |
|
6599 |
||
6600 |
The default implementation does nothing. |
|
6601 |
||
6602 |
\sa dropEvent(), dragMoveEvent(), dragLeaveEvent() |
|
6603 |
*/ |
|
6604 |
void QGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) |
|
6605 |
{ |
|
6606 |
Q_D(QGraphicsItem); |
|
6607 |
// binary compatibility workaround between 4.4 and 4.5 |
|
6608 |
if (d->isProxyWidget()) |
|
6609 |
static_cast<QGraphicsProxyWidget*>(this)->dragEnterEvent(event); |
|
6610 |
} |
|
6611 |
||
6612 |
/*! |
|
6613 |
This event handler, for event \a event, can be reimplemented to receive |
|
6614 |
drag leave events for this item. Drag leave events are generated as the |
|
6615 |
cursor leaves the item's area. Most often you will not need to reimplement |
|
6616 |
this function, but it can be useful for resetting state in your item |
|
6617 |
(e.g., highlighting). |
|
6618 |
||
6619 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect. |
|
6620 |
||
6621 |
Items do not receive drag and drop events by default; to enable this |
|
6622 |
feature, call \c setAcceptDrops(true). |
|
6623 |
||
6624 |
The default implementation does nothing. |
|
6625 |
||
6626 |
\sa dragEnterEvent(), dropEvent(), dragMoveEvent() |
|
6627 |
*/ |
|
6628 |
void QGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) |
|
6629 |
{ |
|
6630 |
Q_D(QGraphicsItem); |
|
6631 |
// binary compatibility workaround between 4.4 and 4.5 |
|
6632 |
if (d->isProxyWidget()) |
|
6633 |
static_cast<QGraphicsProxyWidget*>(this)->dragLeaveEvent(event); |
|
6634 |
} |
|
6635 |
||
6636 |
/*! |
|
6637 |
This event handler, for event \a event, can be reimplemented to receive |
|
6638 |
drag move events for this item. Drag move events are generated as the |
|
6639 |
cursor moves around inside the item's area. Most often you will not need |
|
6640 |
to reimplement this function; it is used to indicate that only parts of |
|
6641 |
the item can accept drops. |
|
6642 |
||
6643 |
Calling QEvent::ignore() or QEvent::accept() on \a event toggles whether |
|
6644 |
or not the item will accept drops at the position from the event. By |
|
6645 |
default, \a event is accepted, indicating that the item allows drops at |
|
6646 |
the specified position. |
|
6647 |
||
6648 |
Items do not receive drag and drop events by default; to enable this |
|
6649 |
feature, call \c setAcceptDrops(true). |
|
6650 |
||
6651 |
The default implementation does nothing. |
|
6652 |
||
6653 |
\sa dropEvent(), dragEnterEvent(), dragLeaveEvent() |
|
6654 |
*/ |
|
6655 |
void QGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) |
|
6656 |
{ |
|
6657 |
Q_D(QGraphicsItem); |
|
6658 |
// binary compatibility workaround between 4.4 and 4.5 |
|
6659 |
if (d->isProxyWidget()) |
|
6660 |
static_cast<QGraphicsProxyWidget*>(this)->dragMoveEvent(event); |
|
6661 |
} |
|
6662 |
||
6663 |
/*! |
|
6664 |
This event handler, for event \a event, can be reimplemented to receive |
|
6665 |
drop events for this item. Items can only receive drop events if the last |
|
6666 |
drag move event was accepted. |
|
6667 |
||
6668 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect. |
|
6669 |
||
6670 |
Items do not receive drag and drop events by default; to enable this |
|
6671 |
feature, call \c setAcceptDrops(true). |
|
6672 |
||
6673 |
The default implementation does nothing. |
|
6674 |
||
6675 |
\sa dragEnterEvent(), dragMoveEvent(), dragLeaveEvent() |
|
6676 |
*/ |
|
6677 |
void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event) |
|
6678 |
{ |
|
6679 |
Q_D(QGraphicsItem); |
|
6680 |
// binary compatibility workaround between 4.4 and 4.5 |
|
6681 |
if (d->isProxyWidget()) |
|
6682 |
static_cast<QGraphicsProxyWidget*>(this)->dropEvent(event); |
|
6683 |
} |
|
6684 |
||
6685 |
/*! |
|
6686 |
This event handler, for event \a event, can be reimplemented to receive |
|
6687 |
focus in events for this item. The default implementation calls |
|
6688 |
ensureVisible(). |
|
6689 |
||
6690 |
\sa focusOutEvent(), sceneEvent(), setFocus() |
|
6691 |
*/ |
|
6692 |
void QGraphicsItem::focusInEvent(QFocusEvent *event) |
|
6693 |
{ |
|
6694 |
Q_UNUSED(event); |
|
6695 |
update(); |
|
6696 |
} |
|
6697 |
||
6698 |
/*! |
|
6699 |
This event handler, for event \a event, can be reimplemented to receive |
|
6700 |
focus out events for this item. The default implementation does nothing. |
|
6701 |
||
6702 |
\sa focusInEvent(), sceneEvent(), setFocus() |
|
6703 |
*/ |
|
6704 |
void QGraphicsItem::focusOutEvent(QFocusEvent *event) |
|
6705 |
{ |
|
6706 |
Q_UNUSED(event); |
|
6707 |
update(); |
|
6708 |
} |
|
6709 |
||
6710 |
/*! |
|
6711 |
This event handler, for event \a event, can be reimplemented to receive |
|
6712 |
hover enter events for this item. The default implementation calls |
|
6713 |
update(); otherwise it does nothing. |
|
6714 |
||
6715 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect. |
|
6716 |
||
6717 |
\sa hoverMoveEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents() |
|
6718 |
*/ |
|
6719 |
void QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
6720 |
{ |
|
6721 |
Q_UNUSED(event); |
|
6722 |
update(); |
|
6723 |
} |
|
6724 |
||
6725 |
/*! |
|
6726 |
This event handler, for event \a event, can be reimplemented to receive |
|
6727 |
hover move events for this item. The default implementation does nothing. |
|
6728 |
||
6729 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect. |
|
6730 |
||
6731 |
\sa hoverEnterEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents() |
|
6732 |
*/ |
|
6733 |
void QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) |
|
6734 |
{ |
|
6735 |
Q_UNUSED(event); |
|
6736 |
} |
|
6737 |
||
6738 |
/*! |
|
6739 |
This event handler, for event \a event, can be reimplemented to receive |
|
6740 |
hover leave events for this item. The default implementation calls |
|
6741 |
update(); otherwise it does nothing. |
|
6742 |
||
6743 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect. |
|
6744 |
||
6745 |
\sa hoverEnterEvent(), hoverMoveEvent(), sceneEvent(), setAcceptHoverEvents() |
|
6746 |
*/ |
|
6747 |
void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
6748 |
{ |
|
6749 |
Q_UNUSED(event); |
|
6750 |
update(); |
|
6751 |
} |
|
6752 |
||
6753 |
/*! |
|
6754 |
This event handler, for event \a event, can be reimplemented to |
|
6755 |
receive key press events for this item. The default implementation |
|
6756 |
ignores the event. If you reimplement this handler, the event will by |
|
6757 |
default be accepted. |
|
6758 |
||
6759 |
Note that key events are only received for items that set the |
|
6760 |
ItemIsFocusable flag, and that have keyboard input focus. |
|
6761 |
||
6762 |
\sa keyReleaseEvent(), setFocus(), QGraphicsScene::setFocusItem(), |
|
6763 |
sceneEvent() |
|
6764 |
*/ |
|
6765 |
void QGraphicsItem::keyPressEvent(QKeyEvent *event) |
|
6766 |
{ |
|
6767 |
event->ignore(); |
|
6768 |
} |
|
6769 |
||
6770 |
/*! |
|
6771 |
This event handler, for event \a event, can be reimplemented to receive |
|
6772 |
key release events for this item. The default implementation |
|
6773 |
ignores the event. If you reimplement this handler, the event will by |
|
6774 |
default be accepted. |
|
6775 |
||
6776 |
Note that key events are only received for items that set the |
|
6777 |
ItemIsFocusable flag, and that have keyboard input focus. |
|
6778 |
||
6779 |
\sa keyPressEvent(), setFocus(), QGraphicsScene::setFocusItem(), |
|
6780 |
sceneEvent() |
|
6781 |
*/ |
|
6782 |
void QGraphicsItem::keyReleaseEvent(QKeyEvent *event) |
|
6783 |
{ |
|
6784 |
event->ignore(); |
|
6785 |
} |
|
6786 |
||
6787 |
/*! |
|
6788 |
This event handler, for event \a event, can be reimplemented to |
|
6789 |
receive mouse press events for this item. Mouse press events are |
|
6790 |
only delivered to items that accept the mouse button that is |
|
6791 |
pressed. By default, an item accepts all mouse buttons, but you |
|
6792 |
can change this by calling setAcceptedMouseButtons(). |
|
6793 |
||
6794 |
The mouse press event decides which item should become the mouse |
|
6795 |
grabber (see QGraphicsScene::mouseGrabberItem()). If you do not |
|
6796 |
reimplement this function, the press event will propagate to any |
|
6797 |
topmost item beneath this item, and no other mouse events will be |
|
6798 |
delivered to this item. |
|
6799 |
||
6800 |
If you do reimplement this function, \a event will by default be |
|
6801 |
accepted (see QEvent::accept()), and this item is then the mouse |
|
6802 |
grabber. This allows the item to receive future move, release and |
|
6803 |
doubleclick events. If you call QEvent::ignore() on \a event, this |
|
6804 |
item will lose the mouse grab, and \a event will propagate to any |
|
6805 |
topmost item beneath. No further mouse events will be delivered to |
|
6806 |
this item unless a new mouse press event is received. |
|
6807 |
||
6808 |
The default implementation handles basic item interaction, such as |
|
6809 |
selection and moving. If you want to keep the base implementation |
|
6810 |
when reimplementing this function, call |
|
6811 |
QGraphicsItem::mousePressEvent() in your reimplementation. |
|
6812 |
||
6813 |
The event is \l{QEvent::ignore()}d for items that are neither |
|
6814 |
\l{QGraphicsItem::ItemIsMovable}{movable} nor |
|
6815 |
\l{QGraphicsItem::ItemIsSelectable}{selectable}. |
|
6816 |
||
6817 |
\sa mouseMoveEvent(), mouseReleaseEvent(), |
|
6818 |
mouseDoubleClickEvent(), sceneEvent() |
|
6819 |
*/ |
|
6820 |
void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
6821 |
{ |
|
6822 |
if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) { |
|
6823 |
bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0; |
|
6824 |
if (!multiSelect) { |
|
6825 |
if (!d_ptr->selected) { |
|
6826 |
if (QGraphicsScene *scene = d_ptr->scene) { |
|
6827 |
++scene->d_func()->selectionChanging; |
|
6828 |
scene->clearSelection(); |
|
6829 |
--scene->d_func()->selectionChanging; |
|
6830 |
} |
|
6831 |
setSelected(true); |
|
6832 |
} |
|
6833 |
} |
|
6834 |
} else if (!(flags() & ItemIsMovable)) { |
|
6835 |
event->ignore(); |
|
6836 |
} |
|
6837 |
if (d_ptr->isWidget) { |
|
6838 |
// Qt::Popup closes when you click outside. |
|
6839 |
QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this); |
|
6840 |
if ((w->windowFlags() & Qt::Popup) == Qt::Popup) { |
|
6841 |
event->accept(); |
|
6842 |
if (!w->rect().contains(event->pos())) |
|
6843 |
w->close(); |
|
6844 |
} |
|
6845 |
} |
|
6846 |
} |
|
6847 |
||
6848 |
/*! |
|
6849 |
obsolete |
|
6850 |
*/ |
|
6851 |
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item) |
|
6852 |
{ |
|
6853 |
const QGraphicsItem *parent = item->parentItem(); |
|
6854 |
return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent)); |
|
6855 |
} |
|
6856 |
||
6857 |
bool QGraphicsItemPrivate::movableAncestorIsSelected(const QGraphicsItem *item) |
|
6858 |
{ |
|
6859 |
const QGraphicsItem *parent = item->d_ptr->parent; |
|
6860 |
return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent)); |
|
6861 |
} |
|
6862 |
||
6863 |
/*! |
|
6864 |
This event handler, for event \a event, can be reimplemented to |
|
6865 |
receive mouse move events for this item. If you do receive this |
|
6866 |
event, you can be certain that this item also received a mouse |
|
6867 |
press event, and that this item is the current mouse grabber. |
|
6868 |
||
6869 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no |
|
6870 |
effect. |
|
6871 |
||
6872 |
The default implementation handles basic item interaction, such as |
|
6873 |
selection and moving. If you want to keep the base implementation |
|
6874 |
when reimplementing this function, call |
|
6875 |
QGraphicsItem::mouseMoveEvent() in your reimplementation. |
|
6876 |
||
6877 |
Please note that mousePressEvent() decides which graphics item it |
|
6878 |
is that receives mouse events. See the mousePressEvent() |
|
6879 |
description for details. |
|
6880 |
||
6881 |
\sa mousePressEvent(), mouseReleaseEvent(), |
|
6882 |
mouseDoubleClickEvent(), sceneEvent() |
|
6883 |
*/ |
|
6884 |
void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
6885 |
{ |
|
6886 |
if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) { |
|
6887 |
// Determine the list of items that need to be moved. |
|
6888 |
QList<QGraphicsItem *> selectedItems; |
|
6889 |
QMap<QGraphicsItem *, QPointF> initialPositions; |
|
6890 |
if (d_ptr->scene) { |
|
6891 |
selectedItems = d_ptr->scene->selectedItems(); |
|
6892 |
initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions; |
|
6893 |
if (initialPositions.isEmpty()) { |
|
6894 |
foreach (QGraphicsItem *item, selectedItems) |
|
6895 |
initialPositions[item] = item->pos(); |
|
6896 |
initialPositions[this] = pos(); |
|
6897 |
} |
|
6898 |
d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions; |
|
6899 |
} |
|
6900 |
||
6901 |
// Find the active view. |
|
6902 |
QGraphicsView *view = 0; |
|
6903 |
if (event->widget()) |
|
6904 |
view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget()); |
|
6905 |
||
6906 |
// Move all selected items |
|
6907 |
int i = 0; |
|
6908 |
bool movedMe = false; |
|
6909 |
while (i <= selectedItems.size()) { |
|
6910 |
QGraphicsItem *item = 0; |
|
6911 |
if (i < selectedItems.size()) |
|
6912 |
item = selectedItems.at(i); |
|
6913 |
else |
|
6914 |
item = this; |
|
6915 |
if (item == this) { |
|
6916 |
// Slightly clumsy-looking way to ensure that "this" is part |
|
6917 |
// of the list of items to move, this is to avoid allocations |
|
6918 |
// (appending this item to the list of selected items causes a |
|
6919 |
// detach). |
|
6920 |
if (movedMe) |
|
6921 |
break; |
|
6922 |
movedMe = true; |
|
6923 |
} |
|
6924 |
||
6925 |
if ((item->flags() & ItemIsMovable) && !QGraphicsItemPrivate::movableAncestorIsSelected(item)) { |
|
6926 |
QPointF currentParentPos; |
|
6927 |
QPointF buttonDownParentPos; |
|
6928 |
if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations) { |
|
6929 |
// Items whose ancestors ignore transformations need to |
|
6930 |
// map screen coordinates to local coordinates, then map |
|
6931 |
// those to the parent. |
|
6932 |
QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted(); |
|
6933 |
currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos())))); |
|
6934 |
buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))))); |
|
6935 |
} else if (item->flags() & ItemIgnoresTransformations) { |
|
6936 |
// Root items that ignore transformations need to |
|
6937 |
// calculate their diff by mapping viewport coordinates |
|
6938 |
// directly to parent coordinates. |
|
6939 |
QTransform viewToParentTransform = (item->transform().translate(item->d_ptr->pos.x(), item->d_ptr->pos.y())) |
|
6940 |
* (item->sceneTransform() * view->viewportTransform()).inverted(); |
|
6941 |
currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))); |
|
6942 |
buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))); |
|
6943 |
} else { |
|
6944 |
// All other items simply map from the scene. |
|
6945 |
currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos())); |
|
6946 |
buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton))); |
|
6947 |
} |
|
6948 |
||
6949 |
item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos); |
|
6950 |
||
6951 |
if (item->flags() & ItemIsSelectable) |
|
6952 |
item->setSelected(true); |
|
6953 |
} |
|
6954 |
++i; |
|
6955 |
} |
|
6956 |
||
6957 |
} else { |
|
6958 |
event->ignore(); |
|
6959 |
} |
|
6960 |
} |
|
6961 |
||
6962 |
/*! |
|
6963 |
This event handler, for event \a event, can be reimplemented to |
|
6964 |
receive mouse release events for this item. |
|
6965 |
||
6966 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no |
|
6967 |
effect. |
|
6968 |
||
6969 |
The default implementation handles basic item interaction, such as |
|
6970 |
selection and moving. If you want to keep the base implementation |
|
6971 |
when reimplementing this function, call |
|
6972 |
QGraphicsItem::mouseReleaseEvent() in your reimplementation. |
|
6973 |
||
6974 |
Please note that mousePressEvent() decides which graphics item it |
|
6975 |
is that receives mouse events. See the mousePressEvent() |
|
6976 |
description for details. |
|
6977 |
||
6978 |
\sa mousePressEvent(), mouseMoveEvent(), mouseDoubleClickEvent(), |
|
6979 |
sceneEvent() |
|
6980 |
*/ |
|
6981 |
void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
6982 |
{ |
|
6983 |
if (flags() & ItemIsSelectable) { |
|
6984 |
bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0; |
|
6985 |
if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) { |
|
6986 |
// The item didn't move |
|
6987 |
if (multiSelect) { |
|
6988 |
setSelected(!isSelected()); |
|
6989 |
} else { |
|
6990 |
bool selectionChanged = false; |
|
6991 |
if (QGraphicsScene *scene = d_ptr->scene) { |
|
6992 |
++scene->d_func()->selectionChanging; |
|
6993 |
// Clear everything but this item. Bypass |
|
6994 |
// QGraphicsScene::clearSelection()'s default behavior by |
|
6995 |
// temporarily removing this item from the selection list. |
|
6996 |
if (d_ptr->selected) { |
|
6997 |
scene->d_func()->selectedItems.remove(this); |
|
6998 |
foreach (QGraphicsItem *item, scene->d_func()->selectedItems) { |
|
6999 |
if (item->isSelected()) { |
|
7000 |
selectionChanged = true; |
|
7001 |
break; |
|
7002 |
} |
|
7003 |
} |
|
7004 |
} |
|
7005 |
scene->clearSelection(); |
|
7006 |
if (d_ptr->selected) |
|
7007 |
scene->d_func()->selectedItems.insert(this); |
|
7008 |
--scene->d_func()->selectionChanging; |
|
7009 |
if (selectionChanged) |
|
7010 |
emit d_ptr->scene->selectionChanged(); |
|
7011 |
} |
|
7012 |
setSelected(true); |
|
7013 |
} |
|
7014 |
} |
|
7015 |
} |
|
7016 |
if (d_ptr->scene && !event->buttons()) |
|
7017 |
d_ptr->scene->d_func()->movingItemsInitialPositions.clear(); |
|
7018 |
} |
|
7019 |
||
7020 |
/*! |
|
7021 |
This event handler, for event \a event, can be reimplemented to |
|
7022 |
receive mouse doubleclick events for this item. |
|
7023 |
||
7024 |
When doubleclicking an item, the item will first receive a mouse |
|
7025 |
press event, followed by a release event (i.e., a click), then a |
|
7026 |
doubleclick event, and finally a release event. |
|
7027 |
||
7028 |
Calling QEvent::ignore() or QEvent::accept() on \a event has no |
|
7029 |
effect. |
|
7030 |
||
7031 |
The default implementation calls mousePressEvent(). If you want to |
|
7032 |
keep the base implementation when reimplementing this function, |
|
7033 |
call QGraphicsItem::mouseDoubleClickEvent() in your |
|
7034 |
reimplementation. |
|
7035 |
||
7036 |
Note that an item will not receive double click events if it is |
|
7037 |
neither \l {QGraphicsItem::ItemIsSelectable}{selectable} nor |
|
7038 |
\l{QGraphicsItem::ItemIsMovable}{movable} (single mouse clicks are |
|
7039 |
ignored in this case, and that stops the generation of double |
|
7040 |
clicks). |
|
7041 |
||
7042 |
\sa mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), sceneEvent() |
|
7043 |
*/ |
|
7044 |
void QGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) |
|
7045 |
{ |
|
7046 |
mousePressEvent(event); |
|
7047 |
} |
|
7048 |
||
7049 |
/*! |
|
7050 |
This event handler, for event \a event, can be reimplemented to receive |
|
7051 |
wheel events for this item. If you reimplement this function, \a event |
|
7052 |
will be accepted by default. |
|
7053 |
||
7054 |
If you ignore the event, (i.e., by calling QEvent::ignore(),) it will |
|
7055 |
propagate to any item beneath this item. If no items accept the event, it |
|
7056 |
will be ignored by the scene, and propagate to the view (e.g., the view's |
|
7057 |
vertical scroll bar). |
|
7058 |
||
7059 |
The default implementation ignores the event. |
|
7060 |
||
7061 |
\sa sceneEvent() |
|
7062 |
*/ |
|
7063 |
void QGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent *event) |
|
7064 |
{ |
|
7065 |
event->ignore(); |
|
7066 |
} |
|
7067 |
||
7068 |
/*! |
|
7069 |
This event handler, for event \a event, can be reimplemented to receive |
|
7070 |
input method events for this item. The default implementation ignores the |
|
7071 |
event. |
|
7072 |
||
7073 |
\sa inputMethodQuery(), sceneEvent() |
|
7074 |
*/ |
|
7075 |
void QGraphicsItem::inputMethodEvent(QInputMethodEvent *event) |
|
7076 |
{ |
|
7077 |
event->ignore(); |
|
7078 |
} |
|
7079 |
||
7080 |
/*! |
|
7081 |
This method is only relevant for input items. It is used by the |
|
7082 |
input method to query a set of properties of the item to be able |
|
7083 |
to support complex input method operations, such as support for |
|
7084 |
surrounding text and reconversions. \a query specifies which |
|
7085 |
property is queried. |
|
7086 |
||
7087 |
\sa inputMethodEvent(), QInputMethodEvent, QInputContext |
|
7088 |
*/ |
|
7089 |
QVariant QGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const |
|
7090 |
{ |
|
7091 |
if (isWidget()) { |
|
7092 |
// ### Qt 5: Remove. The reimplementation in |
|
7093 |
// QGraphicsProxyWidget solves this problem (but requires a |
|
7094 |
// recompile to take effect). |
|
7095 |
return d_ptr->inputMethodQueryHelper(query); |
|
7096 |
} |
|
7097 |
||
7098 |
Q_UNUSED(query); |
|
7099 |
return QVariant(); |
|
7100 |
} |
|
7101 |
||
7102 |
/*! |
|
7103 |
Returns the current input method hints of this item. |
|
7104 |
||
7105 |
Input method hints are only relevant for input items. |
|
7106 |
The hints are used by the input method to indicate how it should operate. |
|
7107 |
For example, if the Qt::ImhNumbersOnly flag is set, the input method may change |
|
7108 |
its visual components to reflect that only numbers can be entered. |
|
7109 |
||
7110 |
The effect may vary between input method implementations. |
|
7111 |
||
7112 |
\since 4.6 |
|
7113 |
||
7114 |
\sa setInputMethodHints(), inputMethodQuery(), QInputContext |
|
7115 |
*/ |
|
7116 |
Qt::InputMethodHints QGraphicsItem::inputMethodHints() const |
|
7117 |
{ |
|
7118 |
Q_D(const QGraphicsItem); |
|
7119 |
return d->imHints; |
|
7120 |
} |
|
7121 |
||
7122 |
/*! |
|
7123 |
Sets the current input method hints of this item to \a hints. |
|
7124 |
||
7125 |
\since 4.6 |
|
7126 |
||
7127 |
\sa inputMethodHints(), inputMethodQuery(), QInputContext |
|
7128 |
*/ |
|
7129 |
void QGraphicsItem::setInputMethodHints(Qt::InputMethodHints hints) |
|
7130 |
{ |
|
7131 |
Q_D(QGraphicsItem); |
|
7132 |
d->imHints = hints; |
|
7133 |
} |
|
7134 |
||
7135 |
/*! |
|
7136 |
This virtual function is called by QGraphicsItem to notify custom items |
|
7137 |
that some part of the item's state changes. By reimplementing this |
|
7138 |
function, your can react to a change, and in some cases, (depending on \a |
|
7139 |
change,) adjustments can be made. |
|
7140 |
||
7141 |
\a change is the parameter of the item that is changing. \a value is the |
|
7142 |
new value; the type of the value depends on \a change. |
|
7143 |
||
7144 |
Example: |
|
7145 |
||
7146 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 15 |
|
7147 |
||
7148 |
The default implementation does nothing, and returns \a value. |
|
7149 |
||
7150 |
Note: Certain QGraphicsItem functions cannot be called in a |
|
7151 |
reimplementation of this function; see the GraphicsItemChange |
|
7152 |
documentation for details. |
|
7153 |
||
7154 |
\sa GraphicsItemChange |
|
7155 |
*/ |
|
7156 |
QVariant QGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value) |
|
7157 |
{ |
|
7158 |
Q_UNUSED(change); |
|
7159 |
return value; |
|
7160 |
} |
|
7161 |
||
7162 |
/*! |
|
7163 |
\internal |
|
7164 |
||
7165 |
Note: This is provided as a hook to avoid future problems related |
|
7166 |
to adding virtual functions. |
|
7167 |
*/ |
|
7168 |
bool QGraphicsItem::supportsExtension(Extension extension) const |
|
7169 |
{ |
|
7170 |
Q_UNUSED(extension); |
|
7171 |
return false; |
|
7172 |
} |
|
7173 |
||
7174 |
/*! |
|
7175 |
\internal |
|
7176 |
||
7177 |
Note: This is provided as a hook to avoid future problems related |
|
7178 |
to adding virtual functions. |
|
7179 |
*/ |
|
7180 |
void QGraphicsItem::setExtension(Extension extension, const QVariant &variant) |
|
7181 |
{ |
|
7182 |
Q_UNUSED(extension); |
|
7183 |
Q_UNUSED(variant); |
|
7184 |
} |
|
7185 |
||
7186 |
/*! |
|
7187 |
\internal |
|
7188 |
||
7189 |
Note: This is provided as a hook to avoid future problems related |
|
7190 |
to adding virtual functions. |
|
7191 |
*/ |
|
7192 |
QVariant QGraphicsItem::extension(const QVariant &variant) const |
|
7193 |
{ |
|
7194 |
Q_UNUSED(variant); |
|
7195 |
return QVariant(); |
|
7196 |
} |
|
7197 |
||
7198 |
/*! |
|
7199 |
\internal |
|
7200 |
||
7201 |
Adds this item to the scene's index. Called in conjunction with |
|
7202 |
removeFromIndex() to ensure the index bookkeeping is correct when |
|
7203 |
the item's position, transformation or shape changes. |
|
7204 |
*/ |
|
7205 |
void QGraphicsItem::addToIndex() |
|
7206 |
{ |
|
7207 |
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) { |
|
7208 |
// ### add to child index only if applicable |
|
7209 |
return; |
|
7210 |
} |
|
7211 |
if (d_ptr->scene) |
|
7212 |
d_ptr->scene->d_func()->index->addItem(this); |
|
7213 |
} |
|
7214 |
||
7215 |
/*! |
|
7216 |
\internal |
|
7217 |
||
7218 |
Removes this item from the scene's index. Called in conjunction |
|
7219 |
with addToIndex() to ensure the index bookkeeping is correct when |
|
7220 |
the item's position, transformation or shape changes. |
|
7221 |
*/ |
|
7222 |
void QGraphicsItem::removeFromIndex() |
|
7223 |
{ |
|
7224 |
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) { |
|
7225 |
// ### remove from child index only if applicable |
|
7226 |
return; |
|
7227 |
} |
|
7228 |
if (d_ptr->scene) |
|
7229 |
d_ptr->scene->d_func()->index->removeItem(this); |
|
7230 |
} |
|
7231 |
||
7232 |
/*! |
|
7233 |
Prepares the item for a geometry change. Call this function before |
|
7234 |
changing the bounding rect of an item to keep QGraphicsScene's index up to |
|
7235 |
date. |
|
7236 |
||
7237 |
prepareGeometryChange() will call update() if this is necessary. |
|
7238 |
||
7239 |
Example: |
|
7240 |
||
7241 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 16 |
|
7242 |
||
7243 |
\sa boundingRect() |
|
7244 |
*/ |
|
7245 |
void QGraphicsItem::prepareGeometryChange() |
|
7246 |
{ |
|
7247 |
if (d_ptr->inDestructor) |
|
7248 |
return; |
|
7249 |
if (d_ptr->scene) { |
|
7250 |
d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect = true; |
|
7251 |
d_ptr->geometryChanged = 1; |
|
7252 |
d_ptr->paintedViewBoundingRectsNeedRepaint = 1; |
|
7253 |
d_ptr->notifyBoundingRectChanged = !d_ptr->inSetPosHelper; |
|
7254 |
||
7255 |
QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func(); |
|
7256 |
scenePrivate->index->prepareBoundingRectChange(this); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
7257 |
scenePrivate->markDirty(this, QRectF(), /*invalidateChildren=*/true, /*force=*/false, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
7258 |
/*ignoreOpacity=*/ false, /*removingItemFromScene=*/ false, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
7259 |
/*updateBoundingRect=*/true); |
0 | 7260 |
|
7261 |
// For compatibility reasons, we have to update the item's old geometry |
|
7262 |
// if someone is connected to the changed signal or the scene has no views. |
|
7263 |
// Note that this has to be done *after* markDirty to ensure that |
|
7264 |
// _q_processDirtyItems is called before _q_emitUpdated. |
|
7265 |
if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex) |
|
7266 |
|| scenePrivate->views.isEmpty()) { |
|
7267 |
if (d_ptr->hasTranslateOnlySceneTransform()) { |
|
7268 |
d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(), |
|
7269 |
d_ptr->sceneTransform.dy())); |
|
7270 |
} else { |
|
7271 |
d_ptr->scene->update(d_ptr->sceneTransform.mapRect(boundingRect())); |
|
7272 |
} |
|
7273 |
} |
|
7274 |
} |
|
7275 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
7276 |
d_ptr->markParentDirty(/*updateBoundingRect=*/true); |
0 | 7277 |
} |
7278 |
||
7279 |
/*! |
|
7280 |
\internal |
|
7281 |
||
7282 |
Highlights \a item as selected. |
|
7283 |
||
7284 |
NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in |
|
7285 |
qgraphicssvgitem.cpp! |
|
7286 |
*/ |
|
7287 |
static void qt_graphicsItem_highlightSelected( |
|
7288 |
QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option) |
|
7289 |
{ |
|
7290 |
const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1)); |
|
7291 |
if (qFuzzyIsNull(qMax(murect.width(), murect.height()))) |
|
7292 |
return; |
|
7293 |
||
7294 |
const QRectF mbrect = painter->transform().mapRect(item->boundingRect()); |
|
7295 |
if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0)) |
|
7296 |
return; |
|
7297 |
||
7298 |
qreal itemPenWidth; |
|
7299 |
switch (item->type()) { |
|
7300 |
case QGraphicsEllipseItem::Type: |
|
7301 |
itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF(); |
|
7302 |
break; |
|
7303 |
case QGraphicsPathItem::Type: |
|
7304 |
itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF(); |
|
7305 |
break; |
|
7306 |
case QGraphicsPolygonItem::Type: |
|
7307 |
itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF(); |
|
7308 |
break; |
|
7309 |
case QGraphicsRectItem::Type: |
|
7310 |
itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF(); |
|
7311 |
break; |
|
7312 |
case QGraphicsSimpleTextItem::Type: |
|
7313 |
itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF(); |
|
7314 |
break; |
|
7315 |
case QGraphicsLineItem::Type: |
|
7316 |
itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF(); |
|
7317 |
break; |
|
7318 |
default: |
|
7319 |
itemPenWidth = 1.0; |
|
7320 |
} |
|
7321 |
const qreal pad = itemPenWidth / 2; |
|
7322 |
||
7323 |
const qreal penWidth = 0; // cosmetic pen |
|
7324 |
||
7325 |
const QColor fgcolor = option->palette.windowText().color(); |
|
7326 |
const QColor bgcolor( // ensure good contrast against fgcolor |
|
7327 |
fgcolor.red() > 127 ? 0 : 255, |
|
7328 |
fgcolor.green() > 127 ? 0 : 255, |
|
7329 |
fgcolor.blue() > 127 ? 0 : 255); |
|
7330 |
||
7331 |
painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine)); |
|
7332 |
painter->setBrush(Qt::NoBrush); |
|
7333 |
painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad)); |
|
7334 |
||
7335 |
painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine)); |
|
7336 |
painter->setBrush(Qt::NoBrush); |
|
7337 |
painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad)); |
|
7338 |
} |
|
7339 |
||
7340 |
/*! |
|
7341 |
\class QGraphicsObject |
|
7342 |
\brief The QGraphicsObject class provides a base class for all graphics items that |
|
7343 |
require signals, slots and properties. |
|
7344 |
\since 4.6 |
|
7345 |
\ingroup graphicsview-api |
|
7346 |
||
7347 |
The class extends a QGraphicsItem with QObject's signal/slot and property mechanisms. |
|
7348 |
It maps many of QGraphicsItem's basic setters and getters to properties and adds notification |
|
7349 |
signals for many of them. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7350 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7351 |
\section1 Parents and Children |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7352 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7353 |
Each graphics object can be constructed with a parent item. This ensures that the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7354 |
item will be destroyed when its parent item is destroyed. Although QGraphicsObject |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7355 |
inherits from both QObject and QGraphicsItem, you should use the functions provided |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7356 |
by QGraphicsItem, \e not QObject, to manage the relationships between parent and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7357 |
child items. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7358 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7359 |
The relationships between items can be explored using the parentItem() and childItems() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7360 |
functions. In the hierarchy of items in a scene, the parentObject() and parentWidget() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7361 |
functions are the equivalent of the QWidget::parent() and QWidget::parentWidget() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7362 |
functions for QWidget subclasses. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7363 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7364 |
\sa QGraphicsWidget |
0 | 7365 |
*/ |
7366 |
||
7367 |
/*! |
|
7368 |
Constructs a QGraphicsObject with \a parent. |
|
7369 |
*/ |
|
7370 |
QGraphicsObject::QGraphicsObject(QGraphicsItem *parent) |
|
7371 |
: QGraphicsItem(parent) |
|
7372 |
{ |
|
7373 |
QGraphicsItem::d_ptr->isObject = true; |
|
7374 |
} |
|
7375 |
||
7376 |
/*! |
|
7377 |
\internal |
|
7378 |
*/ |
|
7379 |
QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene) |
|
7380 |
: QGraphicsItem(dd, parent, scene) |
|
7381 |
{ |
|
7382 |
QGraphicsItem::d_ptr->isObject = true; |
|
7383 |
} |
|
7384 |
||
7385 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7386 |
Subscribes the graphics object to the given \a gesture with specific \a flags. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7387 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7388 |
\sa ungrabGesture(), QGestureEvent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7389 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7390 |
void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) |
0 | 7391 |
{ |
7392 |
QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7393 |
d->gestureContext.insert(gesture, flags); |
0 | 7394 |
(void)QGestureManager::instance(); // create a gesture manager |
7395 |
} |
|
7396 |
||
7397 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7398 |
Unsubscribes the graphics object from the given \a gesture. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7399 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7400 |
\sa grabGesture(), QGestureEvent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7401 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7402 |
void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7403 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7404 |
QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7405 |
if (d->gestureContext.remove(gesture)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7406 |
QGestureManager *manager = QGestureManager::instance(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7407 |
manager->cleanupCachedGestures(this, gesture); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7408 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7409 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7410 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7411 |
/*! |
0 | 7412 |
\property QGraphicsObject::parent |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7413 |
\brief the parent of the item |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7414 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7415 |
\note The item's parent is set independently of the parent object returned |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7416 |
by QObject::parent(). |
0 | 7417 |
|
7418 |
\sa QGraphicsItem::setParentItem(), QGraphicsItem::parentObject() |
|
7419 |
*/ |
|
7420 |
||
7421 |
/*! |
|
7422 |
\property QGraphicsObject::opacity |
|
7423 |
\brief the opacity of the item |
|
7424 |
||
7425 |
\sa QGraphicsItem::setOpacity(), QGraphicsItem::opacity() |
|
7426 |
*/ |
|
7427 |
||
7428 |
/*! |
|
7429 |
\fn QGraphicsObject::opacityChanged() |
|
7430 |
||
7431 |
This signal gets emitted whenever the opacity of the item changes |
|
7432 |
||
7433 |
\sa QGraphicsItem::opacity() |
|
7434 |
*/ |
|
7435 |
||
7436 |
/*! |
|
7437 |
\fn QGraphicsObject::parentChanged() |
|
7438 |
||
7439 |
This signal gets emitted whenever the parent of the item changes |
|
7440 |
*/ |
|
7441 |
||
7442 |
/*! |
|
7443 |
\property QGraphicsObject::pos |
|
7444 |
\brief the position of the item |
|
7445 |
||
7446 |
Describes the items position. |
|
7447 |
||
7448 |
\sa QGraphicsItem::setPos(), QGraphicsItem::pos() |
|
7449 |
*/ |
|
7450 |
||
7451 |
/*! |
|
7452 |
\property QGraphicsObject::x |
|
7453 |
\brief the x position of the item |
|
7454 |
||
7455 |
Describes the items x position. |
|
7456 |
||
7457 |
\sa QGraphicsItem::setX(), setPos(), xChanged() |
|
7458 |
*/ |
|
7459 |
||
7460 |
/*! |
|
7461 |
\fn QGraphicsObject::xChanged() |
|
7462 |
||
7463 |
This signal gets emitted whenever the x position of the item changes |
|
7464 |
||
7465 |
\sa pos() |
|
7466 |
*/ |
|
7467 |
||
7468 |
/*! |
|
7469 |
\property QGraphicsObject::y |
|
7470 |
\brief the y position of the item |
|
7471 |
||
7472 |
Describes the items y position. |
|
7473 |
||
7474 |
\sa QGraphicsItem::setY(), setPos(), yChanged() |
|
7475 |
*/ |
|
7476 |
||
7477 |
/*! |
|
7478 |
\fn QGraphicsObject::yChanged() |
|
7479 |
||
7480 |
This signal gets emitted whenever the y position of the item changes. |
|
7481 |
||
7482 |
\sa pos() |
|
7483 |
*/ |
|
7484 |
||
7485 |
/*! |
|
7486 |
\property QGraphicsObject::z |
|
7487 |
\brief the z value of the item |
|
7488 |
||
7489 |
Describes the items z value. |
|
7490 |
||
7491 |
\sa QGraphicsItem::setZValue(), zValue(), zChanged() |
|
7492 |
*/ |
|
7493 |
||
7494 |
/*! |
|
7495 |
\fn QGraphicsObject::zChanged() |
|
7496 |
||
7497 |
This signal gets emitted whenever the z value of the item changes. |
|
7498 |
||
7499 |
\sa pos() |
|
7500 |
*/ |
|
7501 |
||
7502 |
/*! |
|
7503 |
\property QGraphicsObject::rotation |
|
7504 |
This property holds the rotation of the item in degrees. |
|
7505 |
||
7506 |
This specifies how many degrees to rotate the item around its transformOrigin. |
|
7507 |
The default rotation is 0 degrees (i.e. not rotated at all). |
|
7508 |
*/ |
|
7509 |
||
7510 |
/*! |
|
7511 |
\fn QGraphicsObject::rotationChanged() |
|
7512 |
||
7513 |
This signal gets emitted whenever the roation of the item changes. |
|
7514 |
*/ |
|
7515 |
||
7516 |
/*! |
|
7517 |
\property QGraphicsObject::scale |
|
7518 |
This property holds the scale of the item. |
|
7519 |
||
7520 |
A scale of less than 1 means the item will be displayed smaller than |
|
7521 |
normal, and a scale of greater than 1 means the item will be |
|
7522 |
displayed larger than normal. A negative scale means the item will |
|
7523 |
be mirrored. |
|
7524 |
||
7525 |
By default, items are displayed at a scale of 1 (i.e. at their |
|
7526 |
normal size). |
|
7527 |
||
7528 |
Scaling is from the item's transformOrigin. |
|
7529 |
*/ |
|
7530 |
||
7531 |
/*! |
|
7532 |
\fn void QGraphicsObject::scaleChanged() |
|
7533 |
||
7534 |
This signal is emitted when the scale of the item changes. |
|
7535 |
*/ |
|
7536 |
||
7537 |
||
7538 |
/*! |
|
7539 |
\property QGraphicsObject::enabled |
|
7540 |
\brief whether the item is enabled or not |
|
7541 |
||
7542 |
This property is declared in QGraphicsItem. |
|
7543 |
||
7544 |
By default, this property is true. |
|
7545 |
||
7546 |
\sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled() |
|
7547 |
\sa QGraphicsObject::enabledChanged() |
|
7548 |
*/ |
|
7549 |
||
7550 |
/*! |
|
7551 |
\fn void QGraphicsObject::enabledChanged() |
|
7552 |
||
7553 |
This signal gets emitted whenever the item get's enabled or disabled. |
|
7554 |
||
7555 |
\sa isEnabled() |
|
7556 |
*/ |
|
7557 |
||
7558 |
/*! |
|
7559 |
\property QGraphicsObject::visible |
|
7560 |
\brief whether the item is visible or not |
|
7561 |
||
7562 |
This property is declared in QGraphicsItem. |
|
7563 |
||
7564 |
By default, this property is true. |
|
7565 |
||
7566 |
\sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), visibleChanged() |
|
7567 |
*/ |
|
7568 |
||
7569 |
/*! |
|
7570 |
\fn QGraphicsObject::visibleChanged() |
|
7571 |
||
7572 |
This signal gets emitted whenever the visibility of the item changes |
|
7573 |
||
7574 |
\sa visible |
|
7575 |
*/ |
|
7576 |
||
7577 |
/*! |
|
7578 |
\fn const QObjectList &QGraphicsObject::children() const |
|
7579 |
\internal |
|
7580 |
||
7581 |
This function returns the same value as QObject::children(). It's |
|
7582 |
provided to differentiate between the obsolete member |
|
7583 |
QGraphicsItem::children() and QObject::children(). QGraphicsItem now |
|
7584 |
provides childItems() instead. |
|
7585 |
*/ |
|
7586 |
||
7587 |
/*! |
|
7588 |
\property QGraphicsObject::transformOriginPoint |
|
7589 |
\brief the transformation origin |
|
7590 |
||
7591 |
This property sets a specific point in the items coordiante system as the |
|
7592 |
origin for scale and rotation. |
|
7593 |
||
7594 |
\sa scale, rotation, QGraphicsItem::transformOriginPoint() |
|
7595 |
*/ |
|
7596 |
||
7597 |
||
7598 |
/*! |
|
7599 |
\class QAbstractGraphicsShapeItem |
|
7600 |
\brief The QAbstractGraphicsShapeItem class provides a common base for |
|
7601 |
all path items. |
|
7602 |
\since 4.2 |
|
7603 |
\ingroup graphicsview-api |
|
7604 |
||
7605 |
This class does not fully implement an item by itself; in particular, it |
|
7606 |
does not implement boundingRect() and paint(), which are inherited by |
|
7607 |
QGraphicsItem. |
|
7608 |
||
7609 |
You can subclass this item to provide a simple base implementation of |
|
7610 |
accessors for the item's pen and brush. |
|
7611 |
||
7612 |
\sa QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPathItem, |
|
7613 |
QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, |
|
7614 |
QGraphicsPixmapItem, {The Graphics View Framework} |
|
7615 |
*/ |
|
7616 |
||
7617 |
class QAbstractGraphicsShapeItemPrivate : public QGraphicsItemPrivate |
|
7618 |
{ |
|
7619 |
Q_DECLARE_PUBLIC(QAbstractGraphicsShapeItem) |
|
7620 |
public: |
|
7621 |
||
7622 |
QBrush brush; |
|
7623 |
QPen pen; |
|
7624 |
||
7625 |
// Cached bounding rectangle |
|
7626 |
mutable QRectF boundingRect; |
|
7627 |
}; |
|
7628 |
||
7629 |
/*! |
|
7630 |
Constructs a QAbstractGraphicsShapeItem. \a parent is passed to |
|
7631 |
QGraphicsItem's constructor. |
|
7632 |
*/ |
|
7633 |
QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QGraphicsItem *parent |
|
7634 |
#ifndef Q_QDOC |
|
7635 |
// obsolete argument |
|
7636 |
, QGraphicsScene *scene |
|
7637 |
#endif |
|
7638 |
) |
|
7639 |
: QGraphicsItem(*new QAbstractGraphicsShapeItemPrivate, parent, scene) |
|
7640 |
{ |
|
7641 |
} |
|
7642 |
||
7643 |
/*! |
|
7644 |
\internal |
|
7645 |
*/ |
|
7646 |
QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd, |
|
7647 |
QGraphicsItem *parent, |
|
7648 |
QGraphicsScene *scene) |
|
7649 |
: QGraphicsItem(dd, parent, scene) |
|
7650 |
{ |
|
7651 |
} |
|
7652 |
||
7653 |
/*! |
|
7654 |
Destroys a QAbstractGraphicsShapeItem. |
|
7655 |
*/ |
|
7656 |
QAbstractGraphicsShapeItem::~QAbstractGraphicsShapeItem() |
|
7657 |
{ |
|
7658 |
} |
|
7659 |
||
7660 |
/*! |
|
7661 |
Returns the item's pen. If no pen has been set, this function returns |
|
7662 |
QPen(), a default black solid line pen with 0 width. |
|
7663 |
*/ |
|
7664 |
QPen QAbstractGraphicsShapeItem::pen() const |
|
7665 |
{ |
|
7666 |
Q_D(const QAbstractGraphicsShapeItem); |
|
7667 |
return d->pen; |
|
7668 |
} |
|
7669 |
||
7670 |
/*! |
|
7671 |
Sets the pen for this item to \a pen. |
|
7672 |
||
7673 |
The pen is used to draw the item's outline. |
|
7674 |
||
7675 |
\sa pen() |
|
7676 |
*/ |
|
7677 |
void QAbstractGraphicsShapeItem::setPen(const QPen &pen) |
|
7678 |
{ |
|
7679 |
Q_D(QAbstractGraphicsShapeItem); |
|
7680 |
prepareGeometryChange(); |
|
7681 |
d->pen = pen; |
|
7682 |
d->boundingRect = QRectF(); |
|
7683 |
update(); |
|
7684 |
} |
|
7685 |
||
7686 |
/*! |
|
7687 |
Returns the item's brush, or an empty brush if no brush has been set. |
|
7688 |
||
7689 |
\sa setBrush() |
|
7690 |
*/ |
|
7691 |
QBrush QAbstractGraphicsShapeItem::brush() const |
|
7692 |
{ |
|
7693 |
Q_D(const QAbstractGraphicsShapeItem); |
|
7694 |
return d->brush; |
|
7695 |
} |
|
7696 |
||
7697 |
/*! |
|
7698 |
Sets the item's brush to \a brush. |
|
7699 |
||
7700 |
The item's brush is used to fill the item. |
|
7701 |
||
7702 |
If you use a brush with a QGradient, the gradient |
|
7703 |
is relative to the item's coordinate system. |
|
7704 |
||
7705 |
\sa brush() |
|
7706 |
*/ |
|
7707 |
void QAbstractGraphicsShapeItem::setBrush(const QBrush &brush) |
|
7708 |
{ |
|
7709 |
Q_D(QAbstractGraphicsShapeItem); |
|
7710 |
d->brush = brush; |
|
7711 |
update(); |
|
7712 |
} |
|
7713 |
||
7714 |
/*! |
|
7715 |
\reimp |
|
7716 |
*/ |
|
7717 |
bool QAbstractGraphicsShapeItem::isObscuredBy(const QGraphicsItem *item) const |
|
7718 |
{ |
|
7719 |
return QGraphicsItem::isObscuredBy(item); |
|
7720 |
} |
|
7721 |
||
7722 |
/*! |
|
7723 |
\reimp |
|
7724 |
*/ |
|
7725 |
QPainterPath QAbstractGraphicsShapeItem::opaqueArea() const |
|
7726 |
{ |
|
7727 |
Q_D(const QAbstractGraphicsShapeItem); |
|
7728 |
if (d->brush.isOpaque()) |
|
7729 |
return isClipped() ? clipPath() : shape(); |
|
7730 |
return QGraphicsItem::opaqueArea(); |
|
7731 |
} |
|
7732 |
||
7733 |
/*! |
|
7734 |
\class QGraphicsPathItem |
|
7735 |
\brief The QGraphicsPathItem class provides a path item that you |
|
7736 |
can add to a QGraphicsScene. |
|
7737 |
\since 4.2 |
|
7738 |
\ingroup graphicsview-api |
|
7739 |
||
7740 |
To set the item's path, pass a QPainterPath to QGraphicsPathItem's |
|
7741 |
constructor, or call the setPath() function. The path() function |
|
7742 |
returns the current path. |
|
7743 |
||
7744 |
\image graphicsview-pathitem.png |
|
7745 |
||
7746 |
QGraphicsPathItem uses the path to provide a reasonable |
|
7747 |
implementation of boundingRect(), shape(), and contains(). The |
|
7748 |
paint() function draws the path using the item's associated pen |
|
7749 |
and brush, which you can set by calling the setPen() and |
|
7750 |
setBrush() functions. |
|
7751 |
||
7752 |
\sa QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem, |
|
7753 |
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics |
|
7754 |
View Framework} |
|
7755 |
*/ |
|
7756 |
||
7757 |
class QGraphicsPathItemPrivate : public QAbstractGraphicsShapeItemPrivate |
|
7758 |
{ |
|
7759 |
Q_DECLARE_PUBLIC(QGraphicsPathItem) |
|
7760 |
public: |
|
7761 |
QPainterPath path; |
|
7762 |
}; |
|
7763 |
||
7764 |
/*! |
|
7765 |
Constructs a QGraphicsPath item using \a path as the default path. \a |
|
7766 |
parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
7767 |
||
7768 |
\sa QGraphicsScene::addItem() |
|
7769 |
*/ |
|
7770 |
QGraphicsPathItem::QGraphicsPathItem(const QPainterPath &path, |
|
7771 |
QGraphicsItem *parent |
|
7772 |
#ifndef Q_QDOC |
|
7773 |
// obsolete argument |
|
7774 |
, QGraphicsScene *scene |
|
7775 |
#endif |
|
7776 |
) |
|
7777 |
: QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent, scene) |
|
7778 |
{ |
|
7779 |
if (!path.isEmpty()) |
|
7780 |
setPath(path); |
|
7781 |
} |
|
7782 |
||
7783 |
/*! |
|
7784 |
Constructs a QGraphicsPath. \a parent is passed to |
|
7785 |
QAbstractGraphicsShapeItem's constructor. |
|
7786 |
||
7787 |
\sa QGraphicsScene::addItem() |
|
7788 |
*/ |
|
7789 |
QGraphicsPathItem::QGraphicsPathItem(QGraphicsItem *parent |
|
7790 |
#ifndef Q_QDOC |
|
7791 |
// obsolete argument |
|
7792 |
, QGraphicsScene *scene |
|
7793 |
#endif |
|
7794 |
) |
|
7795 |
: QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent, scene) |
|
7796 |
{ |
|
7797 |
} |
|
7798 |
||
7799 |
/*! |
|
7800 |
Destroys the QGraphicsPathItem. |
|
7801 |
*/ |
|
7802 |
QGraphicsPathItem::~QGraphicsPathItem() |
|
7803 |
{ |
|
7804 |
} |
|
7805 |
||
7806 |
/*! |
|
7807 |
Returns the item's path as a QPainterPath. If no item has been set, an |
|
7808 |
empty QPainterPath is returned. |
|
7809 |
||
7810 |
\sa setPath() |
|
7811 |
*/ |
|
7812 |
QPainterPath QGraphicsPathItem::path() const |
|
7813 |
{ |
|
7814 |
Q_D(const QGraphicsPathItem); |
|
7815 |
return d->path; |
|
7816 |
} |
|
7817 |
||
7818 |
/*! |
|
7819 |
Sets the item's path to be the given \a path. |
|
7820 |
||
7821 |
\sa path() |
|
7822 |
*/ |
|
7823 |
void QGraphicsPathItem::setPath(const QPainterPath &path) |
|
7824 |
{ |
|
7825 |
Q_D(QGraphicsPathItem); |
|
7826 |
if (d->path == path) |
|
7827 |
return; |
|
7828 |
prepareGeometryChange(); |
|
7829 |
d->path = path; |
|
7830 |
d->boundingRect = QRectF(); |
|
7831 |
update(); |
|
7832 |
} |
|
7833 |
||
7834 |
/*! |
|
7835 |
\reimp |
|
7836 |
*/ |
|
7837 |
QRectF QGraphicsPathItem::boundingRect() const |
|
7838 |
{ |
|
7839 |
Q_D(const QGraphicsPathItem); |
|
7840 |
if (d->boundingRect.isNull()) { |
|
7841 |
qreal pw = pen().widthF(); |
|
7842 |
if (pw == 0.0) |
|
7843 |
d->boundingRect = d->path.controlPointRect(); |
|
7844 |
else { |
|
7845 |
d->boundingRect = shape().controlPointRect(); |
|
7846 |
} |
|
7847 |
} |
|
7848 |
return d->boundingRect; |
|
7849 |
} |
|
7850 |
||
7851 |
/*! |
|
7852 |
\reimp |
|
7853 |
*/ |
|
7854 |
QPainterPath QGraphicsPathItem::shape() const |
|
7855 |
{ |
|
7856 |
Q_D(const QGraphicsPathItem); |
|
7857 |
return qt_graphicsItem_shapeFromPath(d->path, d->pen); |
|
7858 |
} |
|
7859 |
||
7860 |
/*! |
|
7861 |
\reimp |
|
7862 |
*/ |
|
7863 |
bool QGraphicsPathItem::contains(const QPointF &point) const |
|
7864 |
{ |
|
7865 |
return QAbstractGraphicsShapeItem::contains(point); |
|
7866 |
} |
|
7867 |
||
7868 |
/*! |
|
7869 |
\reimp |
|
7870 |
*/ |
|
7871 |
void QGraphicsPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
7872 |
QWidget *widget) |
|
7873 |
{ |
|
7874 |
Q_D(QGraphicsPathItem); |
|
7875 |
Q_UNUSED(widget); |
|
7876 |
painter->setPen(d->pen); |
|
7877 |
painter->setBrush(d->brush); |
|
7878 |
painter->drawPath(d->path); |
|
7879 |
||
7880 |
if (option->state & QStyle::State_Selected) |
|
7881 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
7882 |
} |
|
7883 |
||
7884 |
/*! |
|
7885 |
\reimp |
|
7886 |
*/ |
|
7887 |
bool QGraphicsPathItem::isObscuredBy(const QGraphicsItem *item) const |
|
7888 |
{ |
|
7889 |
return QAbstractGraphicsShapeItem::isObscuredBy(item); |
|
7890 |
} |
|
7891 |
||
7892 |
/*! |
|
7893 |
\reimp |
|
7894 |
*/ |
|
7895 |
QPainterPath QGraphicsPathItem::opaqueArea() const |
|
7896 |
{ |
|
7897 |
return QAbstractGraphicsShapeItem::opaqueArea(); |
|
7898 |
} |
|
7899 |
||
7900 |
/*! |
|
7901 |
\reimp |
|
7902 |
*/ |
|
7903 |
int QGraphicsPathItem::type() const |
|
7904 |
{ |
|
7905 |
return Type; |
|
7906 |
} |
|
7907 |
||
7908 |
/*! |
|
7909 |
\internal |
|
7910 |
*/ |
|
7911 |
bool QGraphicsPathItem::supportsExtension(Extension extension) const |
|
7912 |
{ |
|
7913 |
Q_UNUSED(extension); |
|
7914 |
return false; |
|
7915 |
} |
|
7916 |
||
7917 |
/*! |
|
7918 |
\internal |
|
7919 |
*/ |
|
7920 |
void QGraphicsPathItem::setExtension(Extension extension, const QVariant &variant) |
|
7921 |
{ |
|
7922 |
Q_UNUSED(extension); |
|
7923 |
Q_UNUSED(variant); |
|
7924 |
} |
|
7925 |
||
7926 |
/*! |
|
7927 |
\internal |
|
7928 |
*/ |
|
7929 |
QVariant QGraphicsPathItem::extension(const QVariant &variant) const |
|
7930 |
{ |
|
7931 |
Q_UNUSED(variant); |
|
7932 |
return QVariant(); |
|
7933 |
} |
|
7934 |
||
7935 |
/*! |
|
7936 |
\class QGraphicsRectItem |
|
7937 |
\brief The QGraphicsRectItem class provides a rectangle item that you |
|
7938 |
can add to a QGraphicsScene. |
|
7939 |
\since 4.2 |
|
7940 |
\ingroup graphicsview-api |
|
7941 |
||
7942 |
To set the item's rectangle, pass a QRectF to QGraphicsRectItem's |
|
7943 |
constructor, or call the setRect() function. The rect() function |
|
7944 |
returns the current rectangle. |
|
7945 |
||
7946 |
\image graphicsview-rectitem.png |
|
7947 |
||
7948 |
QGraphicsRectItem uses the rectangle and the pen width to provide |
|
7949 |
a reasonable implementation of boundingRect(), shape(), and |
|
7950 |
contains(). The paint() function draws the rectangle using the |
|
7951 |
item's associated pen and brush, which you can set by calling the |
|
7952 |
setPen() and setBrush() functions. |
|
7953 |
||
7954 |
\note The rendering of invalid rectangles, such as those with negative |
|
7955 |
widths or heights, is undefined. If you cannot be sure that you are |
|
7956 |
using valid rectangles (for example, if you are creating |
|
7957 |
rectangles using data from an unreliable source) then you should |
|
7958 |
use QRectF::normalized() to create normalized rectangles, and use |
|
7959 |
those instead. |
|
7960 |
||
7961 |
\sa QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem, |
|
7962 |
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics |
|
7963 |
View Framework} |
|
7964 |
*/ |
|
7965 |
||
7966 |
class QGraphicsRectItemPrivate : public QAbstractGraphicsShapeItemPrivate |
|
7967 |
{ |
|
7968 |
Q_DECLARE_PUBLIC(QGraphicsRectItem) |
|
7969 |
public: |
|
7970 |
QRectF rect; |
|
7971 |
}; |
|
7972 |
||
7973 |
/*! |
|
7974 |
Constructs a QGraphicsRectItem, using \a rect as the default rectangle. |
|
7975 |
\a parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
7976 |
||
7977 |
\sa QGraphicsScene::addItem() |
|
7978 |
*/ |
|
7979 |
QGraphicsRectItem::QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent |
|
7980 |
#ifndef Q_QDOC |
|
7981 |
// obsolete argument |
|
7982 |
, QGraphicsScene *scene |
|
7983 |
#endif |
|
7984 |
) |
|
7985 |
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene) |
|
7986 |
{ |
|
7987 |
setRect(rect); |
|
7988 |
} |
|
7989 |
||
7990 |
/*! |
|
7991 |
\fn QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, |
|
7992 |
QGraphicsItem *parent) |
|
7993 |
||
7994 |
Constructs a QGraphicsRectItem with a default rectangle defined |
|
7995 |
by (\a x, \a y) and the given \a width and \a height. |
|
7996 |
||
7997 |
\a parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
7998 |
||
7999 |
\sa QGraphicsScene::addItem() |
|
8000 |
*/ |
|
8001 |
QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h, |
|
8002 |
QGraphicsItem *parent |
|
8003 |
#ifndef Q_QDOC |
|
8004 |
// obsolete argument |
|
8005 |
, QGraphicsScene *scene |
|
8006 |
#endif |
|
8007 |
) |
|
8008 |
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene) |
|
8009 |
{ |
|
8010 |
setRect(QRectF(x, y, w, h)); |
|
8011 |
} |
|
8012 |
||
8013 |
/*! |
|
8014 |
Constructs a QGraphicsRectItem. \a parent is passed to |
|
8015 |
QAbstractGraphicsShapeItem's constructor. |
|
8016 |
||
8017 |
\sa QGraphicsScene::addItem() |
|
8018 |
*/ |
|
8019 |
QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent |
|
8020 |
#ifndef Q_QDOC |
|
8021 |
// obsolete argument |
|
8022 |
, QGraphicsScene *scene |
|
8023 |
#endif |
|
8024 |
) |
|
8025 |
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene) |
|
8026 |
{ |
|
8027 |
} |
|
8028 |
||
8029 |
/*! |
|
8030 |
Destroys the QGraphicsRectItem. |
|
8031 |
*/ |
|
8032 |
QGraphicsRectItem::~QGraphicsRectItem() |
|
8033 |
{ |
|
8034 |
} |
|
8035 |
||
8036 |
/*! |
|
8037 |
Returns the item's rectangle. |
|
8038 |
||
8039 |
\sa setRect() |
|
8040 |
*/ |
|
8041 |
QRectF QGraphicsRectItem::rect() const |
|
8042 |
{ |
|
8043 |
Q_D(const QGraphicsRectItem); |
|
8044 |
return d->rect; |
|
8045 |
} |
|
8046 |
||
8047 |
/*! |
|
8048 |
\fn void QGraphicsRectItem::setRect(const QRectF &rectangle) |
|
8049 |
||
8050 |
Sets the item's rectangle to be the given \a rectangle. |
|
8051 |
||
8052 |
\sa rect() |
|
8053 |
*/ |
|
8054 |
void QGraphicsRectItem::setRect(const QRectF &rect) |
|
8055 |
{ |
|
8056 |
Q_D(QGraphicsRectItem); |
|
8057 |
if (d->rect == rect) |
|
8058 |
return; |
|
8059 |
prepareGeometryChange(); |
|
8060 |
d->rect = rect; |
|
8061 |
d->boundingRect = QRectF(); |
|
8062 |
update(); |
|
8063 |
} |
|
8064 |
||
8065 |
/*! |
|
8066 |
\fn void QGraphicsRectItem::setRect(qreal x, qreal y, qreal width, qreal height) |
|
8067 |
\fn void QGraphicsEllipseItem::setRect(qreal x, qreal y, qreal width, qreal height) |
|
8068 |
||
8069 |
Sets the item's rectangle to the rectangle defined by (\a x, \a y) |
|
8070 |
and the given \a width and \a height. |
|
8071 |
||
8072 |
This convenience function is equivalent to calling \c |
|
8073 |
{setRect(QRectF(x, y, width, height))} |
|
8074 |
||
8075 |
\sa rect() |
|
8076 |
*/ |
|
8077 |
||
8078 |
/*! |
|
8079 |
\reimp |
|
8080 |
*/ |
|
8081 |
QRectF QGraphicsRectItem::boundingRect() const |
|
8082 |
{ |
|
8083 |
Q_D(const QGraphicsRectItem); |
|
8084 |
if (d->boundingRect.isNull()) { |
|
8085 |
qreal halfpw = pen().widthF() / 2; |
|
8086 |
d->boundingRect = d->rect; |
|
8087 |
if (halfpw > 0.0) |
|
8088 |
d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw); |
|
8089 |
} |
|
8090 |
return d->boundingRect; |
|
8091 |
} |
|
8092 |
||
8093 |
/*! |
|
8094 |
\reimp |
|
8095 |
*/ |
|
8096 |
QPainterPath QGraphicsRectItem::shape() const |
|
8097 |
{ |
|
8098 |
Q_D(const QGraphicsRectItem); |
|
8099 |
QPainterPath path; |
|
8100 |
path.addRect(d->rect); |
|
8101 |
return qt_graphicsItem_shapeFromPath(path, d->pen); |
|
8102 |
} |
|
8103 |
||
8104 |
/*! |
|
8105 |
\reimp |
|
8106 |
*/ |
|
8107 |
bool QGraphicsRectItem::contains(const QPointF &point) const |
|
8108 |
{ |
|
8109 |
return QAbstractGraphicsShapeItem::contains(point); |
|
8110 |
} |
|
8111 |
||
8112 |
/*! |
|
8113 |
\reimp |
|
8114 |
*/ |
|
8115 |
void QGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
8116 |
QWidget *widget) |
|
8117 |
{ |
|
8118 |
Q_D(QGraphicsRectItem); |
|
8119 |
Q_UNUSED(widget); |
|
8120 |
painter->setPen(d->pen); |
|
8121 |
painter->setBrush(d->brush); |
|
8122 |
painter->drawRect(d->rect); |
|
8123 |
||
8124 |
if (option->state & QStyle::State_Selected) |
|
8125 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
8126 |
} |
|
8127 |
||
8128 |
/*! |
|
8129 |
\reimp |
|
8130 |
*/ |
|
8131 |
bool QGraphicsRectItem::isObscuredBy(const QGraphicsItem *item) const |
|
8132 |
{ |
|
8133 |
return QAbstractGraphicsShapeItem::isObscuredBy(item); |
|
8134 |
} |
|
8135 |
||
8136 |
/*! |
|
8137 |
\reimp |
|
8138 |
*/ |
|
8139 |
QPainterPath QGraphicsRectItem::opaqueArea() const |
|
8140 |
{ |
|
8141 |
return QAbstractGraphicsShapeItem::opaqueArea(); |
|
8142 |
} |
|
8143 |
||
8144 |
/*! |
|
8145 |
\reimp |
|
8146 |
*/ |
|
8147 |
int QGraphicsRectItem::type() const |
|
8148 |
{ |
|
8149 |
return Type; |
|
8150 |
} |
|
8151 |
||
8152 |
/*! |
|
8153 |
\internal |
|
8154 |
*/ |
|
8155 |
bool QGraphicsRectItem::supportsExtension(Extension extension) const |
|
8156 |
{ |
|
8157 |
Q_UNUSED(extension); |
|
8158 |
return false; |
|
8159 |
} |
|
8160 |
||
8161 |
/*! |
|
8162 |
\internal |
|
8163 |
*/ |
|
8164 |
void QGraphicsRectItem::setExtension(Extension extension, const QVariant &variant) |
|
8165 |
{ |
|
8166 |
Q_UNUSED(extension); |
|
8167 |
Q_UNUSED(variant); |
|
8168 |
} |
|
8169 |
||
8170 |
/*! |
|
8171 |
\internal |
|
8172 |
*/ |
|
8173 |
QVariant QGraphicsRectItem::extension(const QVariant &variant) const |
|
8174 |
{ |
|
8175 |
Q_UNUSED(variant); |
|
8176 |
return QVariant(); |
|
8177 |
} |
|
8178 |
||
8179 |
/*! |
|
8180 |
\class QGraphicsEllipseItem |
|
8181 |
\brief The QGraphicsEllipseItem class provides an ellipse item that you |
|
8182 |
can add to a QGraphicsScene. |
|
8183 |
\since 4.2 |
|
8184 |
\ingroup graphicsview-api |
|
8185 |
||
8186 |
QGraphicsEllipseItem respresents an ellipse with a fill and an outline, |
|
8187 |
and you can also use it for ellipse segments (see startAngle(), |
|
8188 |
spanAngle()). |
|
8189 |
||
8190 |
\table |
|
8191 |
\row |
|
8192 |
\o \inlineimage graphicsview-ellipseitem.png |
|
8193 |
\o \inlineimage graphicsview-ellipseitem-pie.png |
|
8194 |
\endtable |
|
8195 |
||
8196 |
To set the item's ellipse, pass a QRectF to QGraphicsEllipseItem's |
|
8197 |
constructor, or call setRect(). The rect() function returns the |
|
8198 |
current ellipse geometry. |
|
8199 |
||
8200 |
QGraphicsEllipseItem uses the rect and the pen width to provide a |
|
8201 |
reasonable implementation of boundingRect(), shape(), and contains(). The |
|
8202 |
paint() function draws the ellipse using the item's associated pen and |
|
8203 |
brush, which you can set by calling setPen() and setBrush(). |
|
8204 |
||
8205 |
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsPolygonItem, |
|
8206 |
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics |
|
8207 |
View Framework} |
|
8208 |
*/ |
|
8209 |
||
8210 |
class QGraphicsEllipseItemPrivate : public QAbstractGraphicsShapeItemPrivate |
|
8211 |
{ |
|
8212 |
Q_DECLARE_PUBLIC(QGraphicsEllipseItem) |
|
8213 |
public: |
|
8214 |
inline QGraphicsEllipseItemPrivate() |
|
8215 |
: startAngle(0), spanAngle(360 * 16) |
|
8216 |
{ } |
|
8217 |
||
8218 |
QRectF rect; |
|
8219 |
int startAngle; |
|
8220 |
int spanAngle; |
|
8221 |
}; |
|
8222 |
||
8223 |
/*! |
|
8224 |
Constructs a QGraphicsEllipseItem using \a rect as the default rectangle. |
|
8225 |
\a parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
8226 |
||
8227 |
\sa QGraphicsScene::addItem() |
|
8228 |
*/ |
|
8229 |
QGraphicsEllipseItem::QGraphicsEllipseItem(const QRectF &rect, QGraphicsItem *parent |
|
8230 |
#ifndef Q_QDOC |
|
8231 |
// obsolete argument |
|
8232 |
, QGraphicsScene *scene |
|
8233 |
#endif |
|
8234 |
) |
|
8235 |
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene) |
|
8236 |
{ |
|
8237 |
setRect(rect); |
|
8238 |
} |
|
8239 |
||
8240 |
/*! |
|
8241 |
\fn QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent) |
|
8242 |
\since 4.3 |
|
8243 |
||
8244 |
Constructs a QGraphicsEllipseItem using the rectangle defined by (\a x, \a |
|
8245 |
y) and the given \a width and \a height, as the default rectangle. \a |
|
8246 |
parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
8247 |
||
8248 |
\sa QGraphicsScene::addItem() |
|
8249 |
*/ |
|
8250 |
QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h, |
|
8251 |
QGraphicsItem *parent |
|
8252 |
#ifndef Q_QDOC |
|
8253 |
// obsolete argument |
|
8254 |
, QGraphicsScene *scene |
|
8255 |
#endif |
|
8256 |
) |
|
8257 |
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene) |
|
8258 |
{ |
|
8259 |
setRect(x,y,w,h); |
|
8260 |
} |
|
8261 |
||
8262 |
||
8263 |
||
8264 |
/*! |
|
8265 |
Constructs a QGraphicsEllipseItem. \a parent is passed to |
|
8266 |
QAbstractGraphicsShapeItem's constructor. |
|
8267 |
||
8268 |
\sa QGraphicsScene::addItem() |
|
8269 |
*/ |
|
8270 |
QGraphicsEllipseItem::QGraphicsEllipseItem(QGraphicsItem *parent |
|
8271 |
#ifndef Q_QDOC |
|
8272 |
// obsolete argument |
|
8273 |
, QGraphicsScene *scene |
|
8274 |
#endif |
|
8275 |
) |
|
8276 |
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene) |
|
8277 |
{ |
|
8278 |
} |
|
8279 |
||
8280 |
/*! |
|
8281 |
Destroys the QGraphicsEllipseItem. |
|
8282 |
*/ |
|
8283 |
QGraphicsEllipseItem::~QGraphicsEllipseItem() |
|
8284 |
{ |
|
8285 |
} |
|
8286 |
||
8287 |
/*! |
|
8288 |
Returns the item's ellipse geometry as a QRectF. |
|
8289 |
||
8290 |
\sa setRect(), QPainter::drawEllipse() |
|
8291 |
*/ |
|
8292 |
QRectF QGraphicsEllipseItem::rect() const |
|
8293 |
{ |
|
8294 |
Q_D(const QGraphicsEllipseItem); |
|
8295 |
return d->rect; |
|
8296 |
} |
|
8297 |
||
8298 |
/*! |
|
8299 |
Sets the item's ellipse geometry to \a rect. The rectangle's left edge |
|
8300 |
defines the left edge of the ellipse, and the rectangle's top edge |
|
8301 |
describes the top of the ellipse. The height and width of the rectangle |
|
8302 |
describe the height and width of the ellipse. |
|
8303 |
||
8304 |
\sa rect(), QPainter::drawEllipse() |
|
8305 |
*/ |
|
8306 |
void QGraphicsEllipseItem::setRect(const QRectF &rect) |
|
8307 |
{ |
|
8308 |
Q_D(QGraphicsEllipseItem); |
|
8309 |
if (d->rect == rect) |
|
8310 |
return; |
|
8311 |
prepareGeometryChange(); |
|
8312 |
d->rect = rect; |
|
8313 |
d->boundingRect = QRectF(); |
|
8314 |
update(); |
|
8315 |
} |
|
8316 |
||
8317 |
/*! |
|
8318 |
Returns the start angle for an ellipse segment in 16ths of a degree. This |
|
8319 |
angle is used together with spanAngle() for representing an ellipse |
|
8320 |
segment (a pie). By default, the start angle is 0. |
|
8321 |
||
8322 |
\sa setStartAngle(), spanAngle() |
|
8323 |
*/ |
|
8324 |
int QGraphicsEllipseItem::startAngle() const |
|
8325 |
{ |
|
8326 |
Q_D(const QGraphicsEllipseItem); |
|
8327 |
return d->startAngle; |
|
8328 |
} |
|
8329 |
||
8330 |
/*! |
|
8331 |
Sets the start angle for an ellipse segment to \a angle, which is in 16ths |
|
8332 |
of a degree. This angle is used together with spanAngle() for representing |
|
8333 |
an ellipse segment (a pie). By default, the start angle is 0. |
|
8334 |
||
8335 |
\sa startAngle(), setSpanAngle(), QPainter::drawPie() |
|
8336 |
*/ |
|
8337 |
void QGraphicsEllipseItem::setStartAngle(int angle) |
|
8338 |
{ |
|
8339 |
Q_D(QGraphicsEllipseItem); |
|
8340 |
if (angle != d->startAngle) { |
|
8341 |
prepareGeometryChange(); |
|
8342 |
d->boundingRect = QRectF(); |
|
8343 |
d->startAngle = angle; |
|
8344 |
update(); |
|
8345 |
} |
|
8346 |
} |
|
8347 |
||
8348 |
/*! |
|
8349 |
Returns the span angle of an ellipse segment in 16ths of a degree. This |
|
8350 |
angle is used together with startAngle() for representing an ellipse |
|
8351 |
segment (a pie). By default, this function returns 5760 (360 * 16, a full |
|
8352 |
ellipse). |
|
8353 |
||
8354 |
\sa setSpanAngle(), startAngle() |
|
8355 |
*/ |
|
8356 |
int QGraphicsEllipseItem::spanAngle() const |
|
8357 |
{ |
|
8358 |
Q_D(const QGraphicsEllipseItem); |
|
8359 |
return d->spanAngle; |
|
8360 |
} |
|
8361 |
||
8362 |
/*! |
|
8363 |
Sets the span angle for an ellipse segment to \a angle, which is in 16ths |
|
8364 |
of a degree. This angle is used together with startAngle() to represent an |
|
8365 |
ellipse segment (a pie). By default, the span angle is 5760 (360 * 16, a |
|
8366 |
full ellipse). |
|
8367 |
||
8368 |
\sa spanAngle(), setStartAngle(), QPainter::drawPie() |
|
8369 |
*/ |
|
8370 |
void QGraphicsEllipseItem::setSpanAngle(int angle) |
|
8371 |
{ |
|
8372 |
Q_D(QGraphicsEllipseItem); |
|
8373 |
if (angle != d->spanAngle) { |
|
8374 |
prepareGeometryChange(); |
|
8375 |
d->boundingRect = QRectF(); |
|
8376 |
d->spanAngle = angle; |
|
8377 |
update(); |
|
8378 |
} |
|
8379 |
} |
|
8380 |
||
8381 |
/*! |
|
8382 |
\reimp |
|
8383 |
*/ |
|
8384 |
QRectF QGraphicsEllipseItem::boundingRect() const |
|
8385 |
{ |
|
8386 |
Q_D(const QGraphicsEllipseItem); |
|
8387 |
if (d->boundingRect.isNull()) { |
|
8388 |
qreal pw = pen().widthF(); |
|
8389 |
if (pw == 0.0 && d->spanAngle == 360 * 16) |
|
8390 |
d->boundingRect = d->rect; |
|
8391 |
else |
|
8392 |
d->boundingRect = shape().controlPointRect(); |
|
8393 |
} |
|
8394 |
return d->boundingRect; |
|
8395 |
} |
|
8396 |
||
8397 |
/*! |
|
8398 |
\reimp |
|
8399 |
*/ |
|
8400 |
QPainterPath QGraphicsEllipseItem::shape() const |
|
8401 |
{ |
|
8402 |
Q_D(const QGraphicsEllipseItem); |
|
8403 |
QPainterPath path; |
|
8404 |
if (d->rect.isNull()) |
|
8405 |
return path; |
|
8406 |
if (d->spanAngle != 360 * 16) { |
|
8407 |
path.moveTo(d->rect.center()); |
|
8408 |
path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0); |
|
8409 |
} else { |
|
8410 |
path.addEllipse(d->rect); |
|
8411 |
} |
|
8412 |
||
8413 |
return qt_graphicsItem_shapeFromPath(path, d->pen); |
|
8414 |
} |
|
8415 |
||
8416 |
/*! |
|
8417 |
\reimp |
|
8418 |
*/ |
|
8419 |
bool QGraphicsEllipseItem::contains(const QPointF &point) const |
|
8420 |
{ |
|
8421 |
return QAbstractGraphicsShapeItem::contains(point); |
|
8422 |
} |
|
8423 |
||
8424 |
/*! |
|
8425 |
\reimp |
|
8426 |
*/ |
|
8427 |
void QGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
8428 |
QWidget *widget) |
|
8429 |
{ |
|
8430 |
Q_D(QGraphicsEllipseItem); |
|
8431 |
Q_UNUSED(widget); |
|
8432 |
painter->setPen(d->pen); |
|
8433 |
painter->setBrush(d->brush); |
|
8434 |
if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0)) |
|
8435 |
painter->drawEllipse(d->rect); |
|
8436 |
else |
|
8437 |
painter->drawPie(d->rect, d->startAngle, d->spanAngle); |
|
8438 |
||
8439 |
if (option->state & QStyle::State_Selected) |
|
8440 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
8441 |
} |
|
8442 |
||
8443 |
/*! |
|
8444 |
\reimp |
|
8445 |
*/ |
|
8446 |
bool QGraphicsEllipseItem::isObscuredBy(const QGraphicsItem *item) const |
|
8447 |
{ |
|
8448 |
return QAbstractGraphicsShapeItem::isObscuredBy(item); |
|
8449 |
} |
|
8450 |
||
8451 |
/*! |
|
8452 |
\reimp |
|
8453 |
*/ |
|
8454 |
QPainterPath QGraphicsEllipseItem::opaqueArea() const |
|
8455 |
{ |
|
8456 |
return QAbstractGraphicsShapeItem::opaqueArea(); |
|
8457 |
} |
|
8458 |
||
8459 |
/*! |
|
8460 |
\reimp |
|
8461 |
*/ |
|
8462 |
int QGraphicsEllipseItem::type() const |
|
8463 |
{ |
|
8464 |
return Type; |
|
8465 |
} |
|
8466 |
||
8467 |
||
8468 |
/*! |
|
8469 |
\internal |
|
8470 |
*/ |
|
8471 |
bool QGraphicsEllipseItem::supportsExtension(Extension extension) const |
|
8472 |
{ |
|
8473 |
Q_UNUSED(extension); |
|
8474 |
return false; |
|
8475 |
} |
|
8476 |
||
8477 |
/*! |
|
8478 |
\internal |
|
8479 |
*/ |
|
8480 |
void QGraphicsEllipseItem::setExtension(Extension extension, const QVariant &variant) |
|
8481 |
{ |
|
8482 |
Q_UNUSED(extension); |
|
8483 |
Q_UNUSED(variant); |
|
8484 |
} |
|
8485 |
||
8486 |
/*! |
|
8487 |
\internal |
|
8488 |
*/ |
|
8489 |
QVariant QGraphicsEllipseItem::extension(const QVariant &variant) const |
|
8490 |
{ |
|
8491 |
Q_UNUSED(variant); |
|
8492 |
return QVariant(); |
|
8493 |
} |
|
8494 |
||
8495 |
/*! |
|
8496 |
\class QGraphicsPolygonItem |
|
8497 |
\brief The QGraphicsPolygonItem class provides a polygon item that you |
|
8498 |
can add to a QGraphicsScene. |
|
8499 |
\since 4.2 |
|
8500 |
\ingroup graphicsview-api |
|
8501 |
||
8502 |
To set the item's polygon, pass a QPolygonF to |
|
8503 |
QGraphicsPolygonItem's constructor, or call the setPolygon() |
|
8504 |
function. The polygon() function returns the current polygon. |
|
8505 |
||
8506 |
\image graphicsview-polygonitem.png |
|
8507 |
||
8508 |
QGraphicsPolygonItem uses the polygon and the pen width to provide |
|
8509 |
a reasonable implementation of boundingRect(), shape(), and |
|
8510 |
contains(). The paint() function draws the polygon using the |
|
8511 |
item's associated pen and brush, which you can set by calling the |
|
8512 |
setPen() and setBrush() functions. |
|
8513 |
||
8514 |
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, |
|
8515 |
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics |
|
8516 |
View Framework} |
|
8517 |
*/ |
|
8518 |
||
8519 |
class QGraphicsPolygonItemPrivate : public QAbstractGraphicsShapeItemPrivate |
|
8520 |
{ |
|
8521 |
Q_DECLARE_PUBLIC(QGraphicsPolygonItem) |
|
8522 |
public: |
|
8523 |
inline QGraphicsPolygonItemPrivate() |
|
8524 |
: fillRule(Qt::OddEvenFill) |
|
8525 |
{ } |
|
8526 |
||
8527 |
QPolygonF polygon; |
|
8528 |
Qt::FillRule fillRule; |
|
8529 |
}; |
|
8530 |
||
8531 |
/*! |
|
8532 |
Constructs a QGraphicsPolygonItem with \a polygon as the default |
|
8533 |
polygon. \a parent is passed to QAbstractGraphicsShapeItem's constructor. |
|
8534 |
||
8535 |
\sa QGraphicsScene::addItem() |
|
8536 |
*/ |
|
8537 |
QGraphicsPolygonItem::QGraphicsPolygonItem(const QPolygonF &polygon, |
|
8538 |
QGraphicsItem *parent |
|
8539 |
#ifndef Q_QDOC |
|
8540 |
// obsolete argument |
|
8541 |
, QGraphicsScene *scene |
|
8542 |
#endif |
|
8543 |
) |
|
8544 |
: QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent, scene) |
|
8545 |
{ |
|
8546 |
setPolygon(polygon); |
|
8547 |
} |
|
8548 |
||
8549 |
/*! |
|
8550 |
Constructs a QGraphicsPolygonItem. \a parent is passed to |
|
8551 |
QAbstractGraphicsShapeItem's constructor. |
|
8552 |
||
8553 |
\sa QGraphicsScene::addItem() |
|
8554 |
*/ |
|
8555 |
QGraphicsPolygonItem::QGraphicsPolygonItem(QGraphicsItem *parent |
|
8556 |
#ifndef Q_QDOC |
|
8557 |
// obsolete argument |
|
8558 |
, QGraphicsScene *scene |
|
8559 |
#endif |
|
8560 |
) |
|
8561 |
: QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent, scene) |
|
8562 |
{ |
|
8563 |
} |
|
8564 |
||
8565 |
/*! |
|
8566 |
Destroys the QGraphicsPolygonItem. |
|
8567 |
*/ |
|
8568 |
QGraphicsPolygonItem::~QGraphicsPolygonItem() |
|
8569 |
{ |
|
8570 |
} |
|
8571 |
||
8572 |
/*! |
|
8573 |
Returns the item's polygon, or an empty polygon if no polygon |
|
8574 |
has been set. |
|
8575 |
||
8576 |
\sa setPolygon() |
|
8577 |
*/ |
|
8578 |
QPolygonF QGraphicsPolygonItem::polygon() const |
|
8579 |
{ |
|
8580 |
Q_D(const QGraphicsPolygonItem); |
|
8581 |
return d->polygon; |
|
8582 |
} |
|
8583 |
||
8584 |
/*! |
|
8585 |
Sets the item's polygon to be the given \a polygon. |
|
8586 |
||
8587 |
\sa polygon() |
|
8588 |
*/ |
|
8589 |
void QGraphicsPolygonItem::setPolygon(const QPolygonF &polygon) |
|
8590 |
{ |
|
8591 |
Q_D(QGraphicsPolygonItem); |
|
8592 |
if (d->polygon == polygon) |
|
8593 |
return; |
|
8594 |
prepareGeometryChange(); |
|
8595 |
d->polygon = polygon; |
|
8596 |
d->boundingRect = QRectF(); |
|
8597 |
update(); |
|
8598 |
} |
|
8599 |
||
8600 |
/*! |
|
8601 |
Returns the fill rule of the polygon. The default fill rule is |
|
8602 |
Qt::OddEvenFill. |
|
8603 |
||
8604 |
\sa setFillRule(), QPainterPath::fillRule(), QPainter::drawPolygon() |
|
8605 |
*/ |
|
8606 |
Qt::FillRule QGraphicsPolygonItem::fillRule() const |
|
8607 |
{ |
|
8608 |
Q_D(const QGraphicsPolygonItem); |
|
8609 |
return d->fillRule; |
|
8610 |
} |
|
8611 |
||
8612 |
/*! |
|
8613 |
Sets the fill rule of the polygon to \a rule. The default fill rule is |
|
8614 |
Qt::OddEvenFill. |
|
8615 |
||
8616 |
\sa fillRule(), QPainterPath::fillRule(), QPainter::drawPolygon() |
|
8617 |
*/ |
|
8618 |
void QGraphicsPolygonItem::setFillRule(Qt::FillRule rule) |
|
8619 |
{ |
|
8620 |
Q_D(QGraphicsPolygonItem); |
|
8621 |
if (rule != d->fillRule) { |
|
8622 |
d->fillRule = rule; |
|
8623 |
update(); |
|
8624 |
} |
|
8625 |
} |
|
8626 |
||
8627 |
/*! |
|
8628 |
\reimp |
|
8629 |
*/ |
|
8630 |
QRectF QGraphicsPolygonItem::boundingRect() const |
|
8631 |
{ |
|
8632 |
Q_D(const QGraphicsPolygonItem); |
|
8633 |
if (d->boundingRect.isNull()) { |
|
8634 |
qreal pw = pen().widthF(); |
|
8635 |
if (pw == 0.0) |
|
8636 |
d->boundingRect = d->polygon.boundingRect(); |
|
8637 |
else |
|
8638 |
d->boundingRect = shape().controlPointRect(); |
|
8639 |
} |
|
8640 |
return d->boundingRect; |
|
8641 |
} |
|
8642 |
||
8643 |
/*! |
|
8644 |
\reimp |
|
8645 |
*/ |
|
8646 |
QPainterPath QGraphicsPolygonItem::shape() const |
|
8647 |
{ |
|
8648 |
Q_D(const QGraphicsPolygonItem); |
|
8649 |
QPainterPath path; |
|
8650 |
path.addPolygon(d->polygon); |
|
8651 |
return qt_graphicsItem_shapeFromPath(path, d->pen); |
|
8652 |
} |
|
8653 |
||
8654 |
/*! |
|
8655 |
\reimp |
|
8656 |
*/ |
|
8657 |
bool QGraphicsPolygonItem::contains(const QPointF &point) const |
|
8658 |
{ |
|
8659 |
return QAbstractGraphicsShapeItem::contains(point); |
|
8660 |
} |
|
8661 |
||
8662 |
/*! |
|
8663 |
\reimp |
|
8664 |
*/ |
|
8665 |
void QGraphicsPolygonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
8666 |
{ |
|
8667 |
Q_D(QGraphicsPolygonItem); |
|
8668 |
Q_UNUSED(widget); |
|
8669 |
painter->setPen(d->pen); |
|
8670 |
painter->setBrush(d->brush); |
|
8671 |
painter->drawPolygon(d->polygon, d->fillRule); |
|
8672 |
||
8673 |
if (option->state & QStyle::State_Selected) |
|
8674 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
8675 |
} |
|
8676 |
||
8677 |
/*! |
|
8678 |
\reimp |
|
8679 |
*/ |
|
8680 |
bool QGraphicsPolygonItem::isObscuredBy(const QGraphicsItem *item) const |
|
8681 |
{ |
|
8682 |
return QAbstractGraphicsShapeItem::isObscuredBy(item); |
|
8683 |
} |
|
8684 |
||
8685 |
/*! |
|
8686 |
\reimp |
|
8687 |
*/ |
|
8688 |
QPainterPath QGraphicsPolygonItem::opaqueArea() const |
|
8689 |
{ |
|
8690 |
return QAbstractGraphicsShapeItem::opaqueArea(); |
|
8691 |
} |
|
8692 |
||
8693 |
/*! |
|
8694 |
\reimp |
|
8695 |
*/ |
|
8696 |
int QGraphicsPolygonItem::type() const |
|
8697 |
{ |
|
8698 |
return Type; |
|
8699 |
} |
|
8700 |
||
8701 |
/*! |
|
8702 |
\internal |
|
8703 |
*/ |
|
8704 |
bool QGraphicsPolygonItem::supportsExtension(Extension extension) const |
|
8705 |
{ |
|
8706 |
Q_UNUSED(extension); |
|
8707 |
return false; |
|
8708 |
} |
|
8709 |
||
8710 |
/*! |
|
8711 |
\internal |
|
8712 |
*/ |
|
8713 |
void QGraphicsPolygonItem::setExtension(Extension extension, const QVariant &variant) |
|
8714 |
{ |
|
8715 |
Q_UNUSED(extension); |
|
8716 |
Q_UNUSED(variant); |
|
8717 |
} |
|
8718 |
||
8719 |
/*! |
|
8720 |
\internal |
|
8721 |
*/ |
|
8722 |
QVariant QGraphicsPolygonItem::extension(const QVariant &variant) const |
|
8723 |
{ |
|
8724 |
Q_UNUSED(variant); |
|
8725 |
return QVariant(); |
|
8726 |
} |
|
8727 |
||
8728 |
/*! |
|
8729 |
\class QGraphicsLineItem |
|
8730 |
\brief The QGraphicsLineItem class provides a line item that you can add to a |
|
8731 |
QGraphicsScene. |
|
8732 |
\since 4.2 |
|
8733 |
\ingroup graphicsview-api |
|
8734 |
||
8735 |
To set the item's line, pass a QLineF to QGraphicsLineItem's |
|
8736 |
constructor, or call the setLine() function. The line() function |
|
8737 |
returns the current line. By default the line is black with a |
|
8738 |
width of 0, but you can change this by calling setPen(). |
|
8739 |
||
8740 |
\img graphicsview-lineitem.png |
|
8741 |
||
8742 |
QGraphicsLineItem uses the line and the pen width to provide a reasonable |
|
8743 |
implementation of boundingRect(), shape(), and contains(). The paint() |
|
8744 |
function draws the line using the item's associated pen. |
|
8745 |
||
8746 |
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, |
|
8747 |
QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsPixmapItem, {The |
|
8748 |
Graphics View Framework} |
|
8749 |
*/ |
|
8750 |
||
8751 |
class QGraphicsLineItemPrivate : public QGraphicsItemPrivate |
|
8752 |
{ |
|
8753 |
Q_DECLARE_PUBLIC(QGraphicsLineItem) |
|
8754 |
public: |
|
8755 |
QLineF line; |
|
8756 |
QPen pen; |
|
8757 |
}; |
|
8758 |
||
8759 |
/*! |
|
8760 |
Constructs a QGraphicsLineItem, using \a line as the default line. \a |
|
8761 |
parent is passed to QGraphicsItem's constructor. |
|
8762 |
||
8763 |
\sa QGraphicsScene::addItem() |
|
8764 |
*/ |
|
8765 |
QGraphicsLineItem::QGraphicsLineItem(const QLineF &line, QGraphicsItem *parent |
|
8766 |
#ifndef Q_QDOC |
|
8767 |
// obsolete argument |
|
8768 |
, QGraphicsScene *scene |
|
8769 |
#endif |
|
8770 |
) |
|
8771 |
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene) |
|
8772 |
{ |
|
8773 |
setLine(line); |
|
8774 |
} |
|
8775 |
||
8776 |
/*! |
|
8777 |
Constructs a QGraphicsLineItem, using the line between (\a x1, \a y1) and |
|
8778 |
(\a x2, \a y2) as the default line. \a parent is passed to |
|
8779 |
QGraphicsItem's constructor. |
|
8780 |
||
8781 |
\sa QGraphicsScene::addItem() |
|
8782 |
*/ |
|
8783 |
QGraphicsLineItem::QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent |
|
8784 |
#ifndef Q_QDOC |
|
8785 |
// obsolete argument |
|
8786 |
, QGraphicsScene *scene |
|
8787 |
#endif |
|
8788 |
) |
|
8789 |
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene) |
|
8790 |
{ |
|
8791 |
setLine(x1, y1, x2, y2); |
|
8792 |
} |
|
8793 |
||
8794 |
||
8795 |
||
8796 |
/*! |
|
8797 |
Constructs a QGraphicsLineItem. \a parent is passed to QGraphicsItem's |
|
8798 |
constructor. |
|
8799 |
||
8800 |
\sa QGraphicsScene::addItem() |
|
8801 |
*/ |
|
8802 |
QGraphicsLineItem::QGraphicsLineItem(QGraphicsItem *parent |
|
8803 |
#ifndef Q_QDOC |
|
8804 |
// obsolete argument |
|
8805 |
, QGraphicsScene *scene |
|
8806 |
#endif |
|
8807 |
) |
|
8808 |
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene) |
|
8809 |
{ |
|
8810 |
} |
|
8811 |
||
8812 |
/*! |
|
8813 |
Destroys the QGraphicsLineItem. |
|
8814 |
*/ |
|
8815 |
QGraphicsLineItem::~QGraphicsLineItem() |
|
8816 |
{ |
|
8817 |
} |
|
8818 |
||
8819 |
/*! |
|
8820 |
Returns the item's pen, or a black solid 0-width pen if no pen has |
|
8821 |
been set. |
|
8822 |
||
8823 |
\sa setPen() |
|
8824 |
*/ |
|
8825 |
QPen QGraphicsLineItem::pen() const |
|
8826 |
{ |
|
8827 |
Q_D(const QGraphicsLineItem); |
|
8828 |
return d->pen; |
|
8829 |
} |
|
8830 |
||
8831 |
/*! |
|
8832 |
Sets the item's pen to \a pen. If no pen is set, the line will be painted |
|
8833 |
using a black solid 0-width pen. |
|
8834 |
||
8835 |
\sa pen() |
|
8836 |
*/ |
|
8837 |
void QGraphicsLineItem::setPen(const QPen &pen) |
|
8838 |
{ |
|
8839 |
Q_D(QGraphicsLineItem); |
|
8840 |
prepareGeometryChange(); |
|
8841 |
d->pen = pen; |
|
8842 |
update(); |
|
8843 |
} |
|
8844 |
||
8845 |
/*! |
|
8846 |
Returns the item's line, or a null line if no line has been set. |
|
8847 |
||
8848 |
\sa setLine() |
|
8849 |
*/ |
|
8850 |
QLineF QGraphicsLineItem::line() const |
|
8851 |
{ |
|
8852 |
Q_D(const QGraphicsLineItem); |
|
8853 |
return d->line; |
|
8854 |
} |
|
8855 |
||
8856 |
/*! |
|
8857 |
Sets the item's line to be the given \a line. |
|
8858 |
||
8859 |
\sa line() |
|
8860 |
*/ |
|
8861 |
void QGraphicsLineItem::setLine(const QLineF &line) |
|
8862 |
{ |
|
8863 |
Q_D(QGraphicsLineItem); |
|
8864 |
if (d->line == line) |
|
8865 |
return; |
|
8866 |
prepareGeometryChange(); |
|
8867 |
d->line = line; |
|
8868 |
update(); |
|
8869 |
} |
|
8870 |
||
8871 |
/*! |
|
8872 |
\fn void QGraphicsLineItem::setLine(qreal x1, qreal y1, qreal x2, qreal y2) |
|
8873 |
\overload |
|
8874 |
||
8875 |
Sets the item's line to be the line between (\a x1, \a y1) and (\a |
|
8876 |
x2, \a y2). |
|
8877 |
||
8878 |
This is the same as calling \c {setLine(QLineF(x1, y1, x2, y2))}. |
|
8879 |
*/ |
|
8880 |
||
8881 |
/*! |
|
8882 |
\reimp |
|
8883 |
*/ |
|
8884 |
QRectF QGraphicsLineItem::boundingRect() const |
|
8885 |
{ |
|
8886 |
Q_D(const QGraphicsLineItem); |
|
8887 |
if (d->pen.widthF() == 0.0) { |
|
8888 |
const qreal x1 = d->line.p1().x(); |
|
8889 |
const qreal x2 = d->line.p2().x(); |
|
8890 |
const qreal y1 = d->line.p1().y(); |
|
8891 |
const qreal y2 = d->line.p2().y(); |
|
8892 |
qreal lx = qMin(x1, x2); |
|
8893 |
qreal rx = qMax(x1, x2); |
|
8894 |
qreal ty = qMin(y1, y2); |
|
8895 |
qreal by = qMax(y1, y2); |
|
8896 |
return QRectF(lx, ty, rx - lx, by - ty); |
|
8897 |
} |
|
8898 |
return shape().controlPointRect(); |
|
8899 |
} |
|
8900 |
||
8901 |
/*! |
|
8902 |
\reimp |
|
8903 |
*/ |
|
8904 |
QPainterPath QGraphicsLineItem::shape() const |
|
8905 |
{ |
|
8906 |
Q_D(const QGraphicsLineItem); |
|
8907 |
QPainterPath path; |
|
8908 |
if (d->line == QLineF()) |
|
8909 |
return path; |
|
8910 |
||
8911 |
path.moveTo(d->line.p1()); |
|
8912 |
path.lineTo(d->line.p2()); |
|
8913 |
return qt_graphicsItem_shapeFromPath(path, d->pen); |
|
8914 |
} |
|
8915 |
||
8916 |
/*! |
|
8917 |
\reimp |
|
8918 |
*/ |
|
8919 |
bool QGraphicsLineItem::contains(const QPointF &point) const |
|
8920 |
{ |
|
8921 |
return QGraphicsItem::contains(point); |
|
8922 |
} |
|
8923 |
||
8924 |
/*! |
|
8925 |
\reimp |
|
8926 |
*/ |
|
8927 |
void QGraphicsLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
8928 |
{ |
|
8929 |
Q_D(QGraphicsLineItem); |
|
8930 |
Q_UNUSED(widget); |
|
8931 |
painter->setPen(d->pen); |
|
8932 |
painter->drawLine(d->line); |
|
8933 |
||
8934 |
if (option->state & QStyle::State_Selected) |
|
8935 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
8936 |
} |
|
8937 |
||
8938 |
/*! |
|
8939 |
\reimp |
|
8940 |
*/ |
|
8941 |
bool QGraphicsLineItem::isObscuredBy(const QGraphicsItem *item) const |
|
8942 |
{ |
|
8943 |
return QGraphicsItem::isObscuredBy(item); |
|
8944 |
} |
|
8945 |
||
8946 |
/*! |
|
8947 |
\reimp |
|
8948 |
*/ |
|
8949 |
QPainterPath QGraphicsLineItem::opaqueArea() const |
|
8950 |
{ |
|
8951 |
return QGraphicsItem::opaqueArea(); |
|
8952 |
} |
|
8953 |
||
8954 |
/*! |
|
8955 |
\reimp |
|
8956 |
*/ |
|
8957 |
int QGraphicsLineItem::type() const |
|
8958 |
{ |
|
8959 |
return Type; |
|
8960 |
} |
|
8961 |
||
8962 |
/*! |
|
8963 |
\internal |
|
8964 |
*/ |
|
8965 |
bool QGraphicsLineItem::supportsExtension(Extension extension) const |
|
8966 |
{ |
|
8967 |
Q_UNUSED(extension); |
|
8968 |
return false; |
|
8969 |
} |
|
8970 |
||
8971 |
/*! |
|
8972 |
\internal |
|
8973 |
*/ |
|
8974 |
void QGraphicsLineItem::setExtension(Extension extension, const QVariant &variant) |
|
8975 |
{ |
|
8976 |
Q_UNUSED(extension); |
|
8977 |
Q_UNUSED(variant); |
|
8978 |
} |
|
8979 |
||
8980 |
/*! |
|
8981 |
\internal |
|
8982 |
*/ |
|
8983 |
QVariant QGraphicsLineItem::extension(const QVariant &variant) const |
|
8984 |
{ |
|
8985 |
Q_UNUSED(variant); |
|
8986 |
return QVariant(); |
|
8987 |
} |
|
8988 |
||
8989 |
/*! |
|
8990 |
\class QGraphicsPixmapItem |
|
8991 |
\brief The QGraphicsPixmapItem class provides a pixmap item that you can add to |
|
8992 |
a QGraphicsScene. |
|
8993 |
\since 4.2 |
|
8994 |
\ingroup graphicsview-api |
|
8995 |
||
8996 |
To set the item's pixmap, pass a QPixmap to QGraphicsPixmapItem's |
|
8997 |
constructor, or call the setPixmap() function. The pixmap() |
|
8998 |
function returns the current pixmap. |
|
8999 |
||
9000 |
QGraphicsPixmapItem uses pixmap's optional alpha mask to provide a |
|
9001 |
reasonable implementation of boundingRect(), shape(), and contains(). |
|
9002 |
||
9003 |
\image graphicsview-pixmapitem.png |
|
9004 |
||
9005 |
The pixmap is drawn at the item's (0, 0) coordinate, as returned by |
|
9006 |
offset(). You can change the drawing offset by calling setOffset(). |
|
9007 |
||
9008 |
You can set the pixmap's transformation mode by calling |
|
9009 |
setTransformationMode(). By default, Qt::FastTransformation is used, which |
|
9010 |
provides fast, non-smooth scaling. Qt::SmoothTransformation enables |
|
9011 |
QPainter::SmoothPixmapTransform on the painter, and the quality depends on |
|
9012 |
the platform and viewport. The result is usually not as good as calling |
|
9013 |
QPixmap::scale() directly. Call transformationMode() to get the current |
|
9014 |
transformation mode for the item. |
|
9015 |
||
9016 |
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, |
|
9017 |
QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsLineItem, {The |
|
9018 |
Graphics View Framework} |
|
9019 |
*/ |
|
9020 |
||
9021 |
/*! |
|
9022 |
\enum QGraphicsPixmapItem::ShapeMode |
|
9023 |
||
9024 |
This enum describes how QGraphicsPixmapItem calculates its shape and |
|
9025 |
opaque area. |
|
9026 |
||
9027 |
The default value is MaskShape. |
|
9028 |
||
9029 |
\value MaskShape The shape is determined by calling QPixmap::mask(). |
|
9030 |
This shape includes only the opaque pixels of the pixmap. |
|
9031 |
Because the shape is more complex, however, it can be slower than the other modes, |
|
9032 |
and uses more memory. |
|
9033 |
||
9034 |
\value BoundingRectShape The shape is determined by tracing the outline of |
|
9035 |
the pixmap. This is the fastest shape mode, but it does not take into account |
|
9036 |
any transparent areas on the pixmap. |
|
9037 |
||
9038 |
\value HeuristicMaskShape The shape is determine by calling |
|
9039 |
QPixmap::createHeuristicMask(). The performance and memory consumption |
|
9040 |
is similar to MaskShape. |
|
9041 |
*/ |
|
9042 |
extern QPainterPath qt_regionToPath(const QRegion ®ion); |
|
9043 |
||
9044 |
class QGraphicsPixmapItemPrivate : public QGraphicsItemPrivate |
|
9045 |
{ |
|
9046 |
Q_DECLARE_PUBLIC(QGraphicsPixmapItem) |
|
9047 |
public: |
|
9048 |
QGraphicsPixmapItemPrivate() |
|
9049 |
: transformationMode(Qt::FastTransformation), |
|
9050 |
shapeMode(QGraphicsPixmapItem::MaskShape), |
|
9051 |
hasShape(false) |
|
9052 |
{} |
|
9053 |
||
9054 |
QPixmap pixmap; |
|
9055 |
Qt::TransformationMode transformationMode; |
|
9056 |
QPointF offset; |
|
9057 |
QGraphicsPixmapItem::ShapeMode shapeMode; |
|
9058 |
QPainterPath shape; |
|
9059 |
bool hasShape; |
|
9060 |
||
9061 |
void updateShape() |
|
9062 |
{ |
|
9063 |
shape = QPainterPath(); |
|
9064 |
switch (shapeMode) { |
|
9065 |
case QGraphicsPixmapItem::MaskShape: { |
|
9066 |
QBitmap mask = pixmap.mask(); |
|
9067 |
if (!mask.isNull()) { |
|
9068 |
shape = qt_regionToPath(QRegion(mask).translated(offset.toPoint())); |
|
9069 |
break; |
|
9070 |
} |
|
9071 |
// FALL THROUGH |
|
9072 |
} |
|
9073 |
case QGraphicsPixmapItem::BoundingRectShape: |
|
9074 |
shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height())); |
|
9075 |
break; |
|
9076 |
case QGraphicsPixmapItem::HeuristicMaskShape: |
|
9077 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK |
|
9078 |
shape = qt_regionToPath(QRegion(pixmap.createHeuristicMask()).translated(offset.toPoint())); |
|
9079 |
#else |
|
9080 |
shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height())); |
|
9081 |
#endif |
|
9082 |
break; |
|
9083 |
} |
|
9084 |
} |
|
9085 |
}; |
|
9086 |
||
9087 |
/*! |
|
9088 |
Constructs a QGraphicsPixmapItem, using \a pixmap as the default pixmap. |
|
9089 |
\a parent is passed to QGraphicsItem's constructor. |
|
9090 |
||
9091 |
\sa QGraphicsScene::addItem() |
|
9092 |
*/ |
|
9093 |
QGraphicsPixmapItem::QGraphicsPixmapItem(const QPixmap &pixmap, |
|
9094 |
QGraphicsItem *parent |
|
9095 |
#ifndef Q_QDOC |
|
9096 |
// obsolete argument |
|
9097 |
, QGraphicsScene *scene |
|
9098 |
#endif |
|
9099 |
) |
|
9100 |
: QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent, scene) |
|
9101 |
{ |
|
9102 |
setPixmap(pixmap); |
|
9103 |
} |
|
9104 |
||
9105 |
/*! |
|
9106 |
Constructs a QGraphicsPixmapItem. \a parent is passed to QGraphicsItem's |
|
9107 |
constructor. |
|
9108 |
||
9109 |
\sa QGraphicsScene::addItem() |
|
9110 |
*/ |
|
9111 |
QGraphicsPixmapItem::QGraphicsPixmapItem(QGraphicsItem *parent |
|
9112 |
#ifndef Q_QDOC |
|
9113 |
// obsolete argument |
|
9114 |
, QGraphicsScene *scene |
|
9115 |
#endif |
|
9116 |
) |
|
9117 |
: QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent, scene) |
|
9118 |
{ |
|
9119 |
} |
|
9120 |
||
9121 |
/*! |
|
9122 |
Destroys the QGraphicsPixmapItem. |
|
9123 |
*/ |
|
9124 |
QGraphicsPixmapItem::~QGraphicsPixmapItem() |
|
9125 |
{ |
|
9126 |
} |
|
9127 |
||
9128 |
/*! |
|
9129 |
Sets the item's pixmap to \a pixmap. |
|
9130 |
||
9131 |
\sa pixmap() |
|
9132 |
*/ |
|
9133 |
void QGraphicsPixmapItem::setPixmap(const QPixmap &pixmap) |
|
9134 |
{ |
|
9135 |
Q_D(QGraphicsPixmapItem); |
|
9136 |
prepareGeometryChange(); |
|
9137 |
d->pixmap = pixmap; |
|
9138 |
d->hasShape = false; |
|
9139 |
update(); |
|
9140 |
} |
|
9141 |
||
9142 |
/*! |
|
9143 |
Returns the item's pixmap, or an invalid QPixmap if no pixmap has been |
|
9144 |
set. |
|
9145 |
||
9146 |
\sa setPixmap() |
|
9147 |
*/ |
|
9148 |
QPixmap QGraphicsPixmapItem::pixmap() const |
|
9149 |
{ |
|
9150 |
Q_D(const QGraphicsPixmapItem); |
|
9151 |
return d->pixmap; |
|
9152 |
} |
|
9153 |
||
9154 |
/*! |
|
9155 |
Returns the transformation mode of the pixmap. The default mode is |
|
9156 |
Qt::FastTransformation, which provides quick transformation with no |
|
9157 |
smoothing. |
|
9158 |
||
9159 |
\sa setTransformationMode() |
|
9160 |
*/ |
|
9161 |
Qt::TransformationMode QGraphicsPixmapItem::transformationMode() const |
|
9162 |
{ |
|
9163 |
Q_D(const QGraphicsPixmapItem); |
|
9164 |
return d->transformationMode; |
|
9165 |
} |
|
9166 |
||
9167 |
/*! |
|
9168 |
Sets the pixmap item's transformation mode to \a mode, and toggles an |
|
9169 |
update of the item. The default mode is Qt::FastTransformation, which |
|
9170 |
provides quick transformation with no smoothing. |
|
9171 |
||
9172 |
Qt::SmoothTransformation enables QPainter::SmoothPixmapTransform on the |
|
9173 |
painter, and the quality depends on the platform and viewport. The result |
|
9174 |
is usually not as good as calling QPixmap::scale() directly. |
|
9175 |
||
9176 |
\sa transformationMode() |
|
9177 |
*/ |
|
9178 |
void QGraphicsPixmapItem::setTransformationMode(Qt::TransformationMode mode) |
|
9179 |
{ |
|
9180 |
Q_D(QGraphicsPixmapItem); |
|
9181 |
if (mode != d->transformationMode) { |
|
9182 |
d->transformationMode = mode; |
|
9183 |
update(); |
|
9184 |
} |
|
9185 |
} |
|
9186 |
||
9187 |
/*! |
|
9188 |
Returns the pixmap item's \e offset, which defines the point of the |
|
9189 |
top-left corner of the pixmap, in local coordinates. |
|
9190 |
||
9191 |
\sa setOffset() |
|
9192 |
*/ |
|
9193 |
QPointF QGraphicsPixmapItem::offset() const |
|
9194 |
{ |
|
9195 |
Q_D(const QGraphicsPixmapItem); |
|
9196 |
return d->offset; |
|
9197 |
} |
|
9198 |
||
9199 |
/*! |
|
9200 |
Sets the pixmap item's offset to \a offset. QGraphicsPixmapItem will draw |
|
9201 |
its pixmap using \a offset for its top-left corner. |
|
9202 |
||
9203 |
\sa offset() |
|
9204 |
*/ |
|
9205 |
void QGraphicsPixmapItem::setOffset(const QPointF &offset) |
|
9206 |
{ |
|
9207 |
Q_D(QGraphicsPixmapItem); |
|
9208 |
if (d->offset == offset) |
|
9209 |
return; |
|
9210 |
prepareGeometryChange(); |
|
9211 |
d->offset = offset; |
|
9212 |
d->hasShape = false; |
|
9213 |
update(); |
|
9214 |
} |
|
9215 |
||
9216 |
/*! |
|
9217 |
\fn void QGraphicsPixmapItem::setOffset(qreal x, qreal y) |
|
9218 |
\since 4.3 |
|
9219 |
||
9220 |
This convenience function is equivalent to calling setOffset(QPointF(\a x, \a y)). |
|
9221 |
*/ |
|
9222 |
||
9223 |
/*! |
|
9224 |
\reimp |
|
9225 |
*/ |
|
9226 |
QRectF QGraphicsPixmapItem::boundingRect() const |
|
9227 |
{ |
|
9228 |
Q_D(const QGraphicsPixmapItem); |
|
9229 |
if (d->pixmap.isNull()) |
|
9230 |
return QRectF(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9231 |
if (d->flags & ItemIsSelectable) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9232 |
qreal pw = 1.0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9233 |
return QRectF(d->offset, d->pixmap.size()).adjusted(-pw/2, -pw/2, pw/2, pw/2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9234 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9235 |
return QRectF(d->offset, d->pixmap.size()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9236 |
} |
0 | 9237 |
} |
9238 |
||
9239 |
/*! |
|
9240 |
\reimp |
|
9241 |
*/ |
|
9242 |
QPainterPath QGraphicsPixmapItem::shape() const |
|
9243 |
{ |
|
9244 |
Q_D(const QGraphicsPixmapItem); |
|
9245 |
if (!d->hasShape) { |
|
9246 |
QGraphicsPixmapItemPrivate *thatD = const_cast<QGraphicsPixmapItemPrivate *>(d); |
|
9247 |
thatD->updateShape(); |
|
9248 |
thatD->hasShape = true; |
|
9249 |
} |
|
9250 |
return d_func()->shape; |
|
9251 |
} |
|
9252 |
||
9253 |
/*! |
|
9254 |
\reimp |
|
9255 |
*/ |
|
9256 |
bool QGraphicsPixmapItem::contains(const QPointF &point) const |
|
9257 |
{ |
|
9258 |
return QGraphicsItem::contains(point); |
|
9259 |
} |
|
9260 |
||
9261 |
/*! |
|
9262 |
\reimp |
|
9263 |
*/ |
|
9264 |
void QGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
9265 |
QWidget *widget) |
|
9266 |
{ |
|
9267 |
Q_D(QGraphicsPixmapItem); |
|
9268 |
Q_UNUSED(widget); |
|
9269 |
||
9270 |
painter->setRenderHint(QPainter::SmoothPixmapTransform, |
|
9271 |
(d->transformationMode == Qt::SmoothTransformation)); |
|
9272 |
||
9273 |
painter->drawPixmap(d->offset, d->pixmap); |
|
9274 |
||
9275 |
if (option->state & QStyle::State_Selected) |
|
9276 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
9277 |
} |
|
9278 |
||
9279 |
/*! |
|
9280 |
\reimp |
|
9281 |
*/ |
|
9282 |
bool QGraphicsPixmapItem::isObscuredBy(const QGraphicsItem *item) const |
|
9283 |
{ |
|
9284 |
return QGraphicsItem::isObscuredBy(item); |
|
9285 |
} |
|
9286 |
||
9287 |
/*! |
|
9288 |
\reimp |
|
9289 |
*/ |
|
9290 |
QPainterPath QGraphicsPixmapItem::opaqueArea() const |
|
9291 |
{ |
|
9292 |
return shape(); |
|
9293 |
} |
|
9294 |
||
9295 |
/*! |
|
9296 |
\reimp |
|
9297 |
*/ |
|
9298 |
int QGraphicsPixmapItem::type() const |
|
9299 |
{ |
|
9300 |
return Type; |
|
9301 |
} |
|
9302 |
||
9303 |
/*! |
|
9304 |
Returns the item's shape mode. The shape mode describes how |
|
9305 |
QGraphicsPixmapItem calculates its shape. The default mode is MaskShape. |
|
9306 |
||
9307 |
\sa setShapeMode(), ShapeMode |
|
9308 |
*/ |
|
9309 |
QGraphicsPixmapItem::ShapeMode QGraphicsPixmapItem::shapeMode() const |
|
9310 |
{ |
|
9311 |
return d_func()->shapeMode; |
|
9312 |
} |
|
9313 |
||
9314 |
/*! |
|
9315 |
Sets the item's shape mode to \a mode. The shape mode describes how |
|
9316 |
QGraphicsPixmapItem calculates its shape. The default mode is MaskShape. |
|
9317 |
||
9318 |
\sa shapeMode(), ShapeMode |
|
9319 |
*/ |
|
9320 |
void QGraphicsPixmapItem::setShapeMode(ShapeMode mode) |
|
9321 |
{ |
|
9322 |
Q_D(QGraphicsPixmapItem); |
|
9323 |
if (d->shapeMode == mode) |
|
9324 |
return; |
|
9325 |
d->shapeMode = mode; |
|
9326 |
d->hasShape = false; |
|
9327 |
} |
|
9328 |
||
9329 |
/*! |
|
9330 |
\internal |
|
9331 |
*/ |
|
9332 |
bool QGraphicsPixmapItem::supportsExtension(Extension extension) const |
|
9333 |
{ |
|
9334 |
Q_UNUSED(extension); |
|
9335 |
return false; |
|
9336 |
} |
|
9337 |
||
9338 |
/*! |
|
9339 |
\internal |
|
9340 |
*/ |
|
9341 |
void QGraphicsPixmapItem::setExtension(Extension extension, const QVariant &variant) |
|
9342 |
{ |
|
9343 |
Q_UNUSED(extension); |
|
9344 |
Q_UNUSED(variant); |
|
9345 |
} |
|
9346 |
||
9347 |
/*! |
|
9348 |
\internal |
|
9349 |
*/ |
|
9350 |
QVariant QGraphicsPixmapItem::extension(const QVariant &variant) const |
|
9351 |
{ |
|
9352 |
Q_UNUSED(variant); |
|
9353 |
return QVariant(); |
|
9354 |
} |
|
9355 |
||
9356 |
/*! |
|
9357 |
\class QGraphicsTextItem |
|
9358 |
\brief The QGraphicsTextItem class provides a text item that you can add to |
|
9359 |
a QGraphicsScene to display formatted text. |
|
9360 |
\since 4.2 |
|
9361 |
\ingroup graphicsview-api |
|
9362 |
||
9363 |
If you only need to show plain text in an item, consider using QGraphicsSimpleTextItem |
|
9364 |
instead. |
|
9365 |
||
9366 |
To set the item's text, pass a QString to QGraphicsTextItem's |
|
9367 |
constructor, or call setHtml()/setPlainText(). |
|
9368 |
||
9369 |
QGraphicsTextItem uses the text's formatted size and the associated font |
|
9370 |
to provide a reasonable implementation of boundingRect(), shape(), |
|
9371 |
and contains(). You can set the font by calling setFont(). |
|
9372 |
||
9373 |
It is possible to make the item editable by setting the Qt::TextEditorInteraction flag |
|
9374 |
using setTextInteractionFlags(). |
|
9375 |
||
9376 |
The item's preferred text width can be set using setTextWidth() and obtained |
|
9377 |
using textWidth(). |
|
9378 |
||
9379 |
\note In order to align HTML text in the center, the item's text width must be set. |
|
9380 |
||
9381 |
\img graphicsview-textitem.png |
|
9382 |
||
9383 |
\note QGraphicsTextItem accepts \l{QGraphicsItem::acceptHoverEvents()}{hover events} |
|
9384 |
by default. You can change this with \l{QGraphicsItem::}{setAcceptHoverEvents()}. |
|
9385 |
||
9386 |
\sa QGraphicsSimpleTextItem, QGraphicsPathItem, QGraphicsRectItem, |
|
9387 |
QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem, |
|
9388 |
QGraphicsLineItem, {The Graphics View Framework} |
|
9389 |
*/ |
|
9390 |
||
9391 |
class QGraphicsTextItemPrivate |
|
9392 |
{ |
|
9393 |
public: |
|
9394 |
QGraphicsTextItemPrivate() |
|
9395 |
: control(0), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0) |
|
9396 |
{ } |
|
9397 |
||
9398 |
mutable QTextControl *control; |
|
9399 |
QTextControl *textControl() const; |
|
9400 |
||
9401 |
inline QPointF controlOffset() const |
|
9402 |
{ return QPointF(0., pageNumber * control->document()->pageSize().height()); } |
|
9403 |
inline void sendControlEvent(QEvent *e) |
|
9404 |
{ if (control) control->processEvent(e, controlOffset()); } |
|
9405 |
||
9406 |
void _q_updateBoundingRect(const QSizeF &); |
|
9407 |
void _q_update(QRectF); |
|
9408 |
void _q_ensureVisible(QRectF); |
|
9409 |
bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *); |
|
9410 |
||
9411 |
QRectF boundingRect; |
|
9412 |
int pageNumber; |
|
9413 |
bool useDefaultImpl; |
|
9414 |
bool tabChangesFocus; |
|
9415 |
||
9416 |
uint clickCausedFocus : 1; |
|
9417 |
||
9418 |
QGraphicsTextItem *qq; |
|
9419 |
}; |
|
9420 |
||
9421 |
||
9422 |
/*! |
|
9423 |
Constructs a QGraphicsTextItem, using \a text as the default plain |
|
9424 |
text. \a parent is passed to QGraphicsItem's constructor. |
|
9425 |
||
9426 |
\sa QGraphicsScene::addItem() |
|
9427 |
*/ |
|
9428 |
QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent |
|
9429 |
#ifndef Q_QDOC |
|
9430 |
// obsolete argument |
|
9431 |
, QGraphicsScene *scene |
|
9432 |
#endif |
|
9433 |
) |
|
9434 |
: QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate) |
|
9435 |
{ |
|
9436 |
dd->qq = this; |
|
9437 |
if (!text.isEmpty()) |
|
9438 |
setPlainText(text); |
|
9439 |
setAcceptDrops(true); |
|
9440 |
setAcceptHoverEvents(true); |
|
9441 |
setFlags(ItemUsesExtendedStyleOption); |
|
9442 |
} |
|
9443 |
||
9444 |
/*! |
|
9445 |
Constructs a QGraphicsTextItem. \a parent is passed to QGraphicsItem's |
|
9446 |
constructor. |
|
9447 |
||
9448 |
\sa QGraphicsScene::addItem() |
|
9449 |
*/ |
|
9450 |
QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent |
|
9451 |
#ifndef Q_QDOC |
|
9452 |
// obsolete argument |
|
9453 |
, QGraphicsScene *scene |
|
9454 |
#endif |
|
9455 |
) |
|
9456 |
: QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate) |
|
9457 |
{ |
|
9458 |
dd->qq = this; |
|
9459 |
setAcceptDrops(true); |
|
9460 |
setAcceptHoverEvents(true); |
|
9461 |
setFlag(ItemUsesExtendedStyleOption); |
|
9462 |
} |
|
9463 |
||
9464 |
/*! |
|
9465 |
Destroys the QGraphicsTextItem. |
|
9466 |
*/ |
|
9467 |
QGraphicsTextItem::~QGraphicsTextItem() |
|
9468 |
{ |
|
9469 |
delete dd; |
|
9470 |
} |
|
9471 |
||
9472 |
/*! |
|
9473 |
Returns the item's text converted to HTML, or an empty QString if no text has been set. |
|
9474 |
||
9475 |
\sa setHtml() |
|
9476 |
*/ |
|
9477 |
QString QGraphicsTextItem::toHtml() const |
|
9478 |
{ |
|
9479 |
#ifndef QT_NO_TEXTHTMLPARSER |
|
9480 |
if (dd->control) |
|
9481 |
return dd->control->toHtml(); |
|
9482 |
#endif |
|
9483 |
return QString(); |
|
9484 |
} |
|
9485 |
||
9486 |
/*! |
|
9487 |
Sets the item's text to \a text, assuming that text is HTML formatted. If |
|
9488 |
the item has keyboard input focus, this function will also call |
|
9489 |
ensureVisible() to ensure that the text is visible in all viewports. |
|
9490 |
||
9491 |
\sa toHtml(), hasFocus(), QGraphicsSimpleTextItem |
|
9492 |
*/ |
|
9493 |
void QGraphicsTextItem::setHtml(const QString &text) |
|
9494 |
{ |
|
9495 |
dd->textControl()->setHtml(text); |
|
9496 |
} |
|
9497 |
||
9498 |
/*! |
|
9499 |
Returns the item's text converted to plain text, or an empty QString if no text has been set. |
|
9500 |
||
9501 |
\sa setPlainText() |
|
9502 |
*/ |
|
9503 |
QString QGraphicsTextItem::toPlainText() const |
|
9504 |
{ |
|
9505 |
if (dd->control) |
|
9506 |
return dd->control->toPlainText(); |
|
9507 |
return QString(); |
|
9508 |
} |
|
9509 |
||
9510 |
/*! |
|
9511 |
Sets the item's text to \a text. If the item has keyboard input focus, |
|
9512 |
this function will also call ensureVisible() to ensure that the text is |
|
9513 |
visible in all viewports. |
|
9514 |
||
9515 |
\sa toHtml(), hasFocus() |
|
9516 |
*/ |
|
9517 |
void QGraphicsTextItem::setPlainText(const QString &text) |
|
9518 |
{ |
|
9519 |
dd->textControl()->setPlainText(text); |
|
9520 |
} |
|
9521 |
||
9522 |
/*! |
|
9523 |
Returns the item's font, which is used to render the text. |
|
9524 |
||
9525 |
\sa setFont() |
|
9526 |
*/ |
|
9527 |
QFont QGraphicsTextItem::font() const |
|
9528 |
{ |
|
9529 |
if (!dd->control) |
|
9530 |
return QFont(); |
|
9531 |
return dd->control->document()->defaultFont(); |
|
9532 |
} |
|
9533 |
||
9534 |
/*! |
|
9535 |
Sets the font used to render the text item to \a font. |
|
9536 |
||
9537 |
\sa font() |
|
9538 |
*/ |
|
9539 |
void QGraphicsTextItem::setFont(const QFont &font) |
|
9540 |
{ |
|
9541 |
dd->textControl()->document()->setDefaultFont(font); |
|
9542 |
} |
|
9543 |
||
9544 |
/*! |
|
9545 |
Sets the color for unformatted text to \a col. |
|
9546 |
*/ |
|
9547 |
void QGraphicsTextItem::setDefaultTextColor(const QColor &col) |
|
9548 |
{ |
|
9549 |
QTextControl *c = dd->textControl(); |
|
9550 |
QPalette pal = c->palette(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9551 |
QColor old = pal.color(QPalette::Text); |
0 | 9552 |
pal.setColor(QPalette::Text, col); |
9553 |
c->setPalette(pal); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9554 |
if (old != col) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9555 |
update(); |
0 | 9556 |
} |
9557 |
||
9558 |
/*! |
|
9559 |
Returns the default text color that is used to for unformatted text. |
|
9560 |
*/ |
|
9561 |
QColor QGraphicsTextItem::defaultTextColor() const |
|
9562 |
{ |
|
9563 |
return dd->textControl()->palette().color(QPalette::Text); |
|
9564 |
} |
|
9565 |
||
9566 |
/*! |
|
9567 |
\reimp |
|
9568 |
*/ |
|
9569 |
QRectF QGraphicsTextItem::boundingRect() const |
|
9570 |
{ |
|
9571 |
return dd->boundingRect; |
|
9572 |
} |
|
9573 |
||
9574 |
/*! |
|
9575 |
\reimp |
|
9576 |
*/ |
|
9577 |
QPainterPath QGraphicsTextItem::shape() const |
|
9578 |
{ |
|
9579 |
if (!dd->control) |
|
9580 |
return QPainterPath(); |
|
9581 |
QPainterPath path; |
|
9582 |
path.addRect(dd->boundingRect); |
|
9583 |
return path; |
|
9584 |
} |
|
9585 |
||
9586 |
/*! |
|
9587 |
\reimp |
|
9588 |
*/ |
|
9589 |
bool QGraphicsTextItem::contains(const QPointF &point) const |
|
9590 |
{ |
|
9591 |
return dd->boundingRect.contains(point); |
|
9592 |
} |
|
9593 |
||
9594 |
/*! |
|
9595 |
\reimp |
|
9596 |
*/ |
|
9597 |
void QGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
9598 |
QWidget *widget) |
|
9599 |
{ |
|
9600 |
Q_UNUSED(widget); |
|
9601 |
if (dd->control) { |
|
9602 |
painter->save(); |
|
9603 |
QRectF r = option->exposedRect; |
|
9604 |
painter->translate(-dd->controlOffset()); |
|
9605 |
r.translate(dd->controlOffset()); |
|
9606 |
||
9607 |
QTextDocument *doc = dd->control->document(); |
|
9608 |
QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout()); |
|
9609 |
||
9610 |
// the layout might need to expand the root frame to |
|
9611 |
// the viewport if NoWrap is set |
|
9612 |
if (layout) |
|
9613 |
layout->setViewport(dd->boundingRect); |
|
9614 |
||
9615 |
dd->control->drawContents(painter, r); |
|
9616 |
||
9617 |
if (layout) |
|
9618 |
layout->setViewport(QRect()); |
|
9619 |
||
9620 |
painter->restore(); |
|
9621 |
} |
|
9622 |
||
9623 |
if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) |
|
9624 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
9625 |
} |
|
9626 |
||
9627 |
/*! |
|
9628 |
\reimp |
|
9629 |
*/ |
|
9630 |
bool QGraphicsTextItem::isObscuredBy(const QGraphicsItem *item) const |
|
9631 |
{ |
|
9632 |
return QGraphicsItem::isObscuredBy(item); |
|
9633 |
} |
|
9634 |
||
9635 |
/*! |
|
9636 |
\reimp |
|
9637 |
*/ |
|
9638 |
QPainterPath QGraphicsTextItem::opaqueArea() const |
|
9639 |
{ |
|
9640 |
return QGraphicsItem::opaqueArea(); |
|
9641 |
} |
|
9642 |
||
9643 |
/*! |
|
9644 |
\reimp |
|
9645 |
*/ |
|
9646 |
int QGraphicsTextItem::type() const |
|
9647 |
{ |
|
9648 |
return Type; |
|
9649 |
} |
|
9650 |
||
9651 |
/*! |
|
9652 |
Sets the preferred width for the item's text. If the actual text |
|
9653 |
is wider than the specified width then it will be broken into |
|
9654 |
multiple lines. |
|
9655 |
||
9656 |
If \a width is set to -1 then the text will not be broken into |
|
9657 |
multiple lines unless it is enforced through an explicit line |
|
9658 |
break or a new paragraph. |
|
9659 |
||
9660 |
The default value is -1. |
|
9661 |
||
9662 |
Note that QGraphicsTextItem keeps a QTextDocument internally, |
|
9663 |
which is used to calculate the text width. |
|
9664 |
||
9665 |
\sa textWidth(), QTextDocument::setTextWidth() |
|
9666 |
*/ |
|
9667 |
void QGraphicsTextItem::setTextWidth(qreal width) |
|
9668 |
{ |
|
9669 |
dd->textControl()->setTextWidth(width); |
|
9670 |
} |
|
9671 |
||
9672 |
/*! |
|
9673 |
Returns the text width. |
|
9674 |
||
9675 |
The width is calculated with the QTextDocument that |
|
9676 |
QGraphicsTextItem keeps internally. |
|
9677 |
||
9678 |
\sa setTextWidth(), QTextDocument::textWidth() |
|
9679 |
*/ |
|
9680 |
qreal QGraphicsTextItem::textWidth() const |
|
9681 |
{ |
|
9682 |
if (!dd->control) |
|
9683 |
return -1; |
|
9684 |
return dd->control->textWidth(); |
|
9685 |
} |
|
9686 |
||
9687 |
/*! |
|
9688 |
Adjusts the text item to a reasonable size. |
|
9689 |
*/ |
|
9690 |
void QGraphicsTextItem::adjustSize() |
|
9691 |
{ |
|
9692 |
if (dd->control) |
|
9693 |
dd->control->adjustSize(); |
|
9694 |
} |
|
9695 |
||
9696 |
/*! |
|
9697 |
Sets the text document \a document on the item. |
|
9698 |
*/ |
|
9699 |
void QGraphicsTextItem::setDocument(QTextDocument *document) |
|
9700 |
{ |
|
9701 |
dd->textControl()->setDocument(document); |
|
9702 |
dd->_q_updateBoundingRect(dd->control->size()); |
|
9703 |
} |
|
9704 |
||
9705 |
/*! |
|
9706 |
Returns the item's text document. |
|
9707 |
*/ |
|
9708 |
QTextDocument *QGraphicsTextItem::document() const |
|
9709 |
{ |
|
9710 |
return dd->textControl()->document(); |
|
9711 |
} |
|
9712 |
||
9713 |
/*! |
|
9714 |
\reimp |
|
9715 |
*/ |
|
9716 |
bool QGraphicsTextItem::sceneEvent(QEvent *event) |
|
9717 |
{ |
|
9718 |
QEvent::Type t = event->type(); |
|
9719 |
if (!dd->tabChangesFocus && (t == QEvent::KeyPress || t == QEvent::KeyRelease)) { |
|
9720 |
int k = ((QKeyEvent *)event)->key(); |
|
9721 |
if (k == Qt::Key_Tab || k == Qt::Key_Backtab) { |
|
9722 |
dd->sendControlEvent(event); |
|
9723 |
return true; |
|
9724 |
} |
|
9725 |
} |
|
9726 |
bool result = QGraphicsItem::sceneEvent(event); |
|
9727 |
||
9728 |
// Ensure input context is updated. |
|
9729 |
switch (event->type()) { |
|
9730 |
case QEvent::ContextMenu: |
|
9731 |
case QEvent::FocusIn: |
|
9732 |
case QEvent::FocusOut: |
|
9733 |
case QEvent::GraphicsSceneDragEnter: |
|
9734 |
case QEvent::GraphicsSceneDragLeave: |
|
9735 |
case QEvent::GraphicsSceneDragMove: |
|
9736 |
case QEvent::GraphicsSceneDrop: |
|
9737 |
case QEvent::GraphicsSceneHoverEnter: |
|
9738 |
case QEvent::GraphicsSceneHoverLeave: |
|
9739 |
case QEvent::GraphicsSceneHoverMove: |
|
9740 |
case QEvent::GraphicsSceneMouseDoubleClick: |
|
9741 |
case QEvent::GraphicsSceneMousePress: |
|
9742 |
case QEvent::GraphicsSceneMouseMove: |
|
9743 |
case QEvent::GraphicsSceneMouseRelease: |
|
9744 |
case QEvent::KeyPress: |
|
9745 |
case QEvent::KeyRelease: |
|
9746 |
// Reset the focus widget's input context, regardless |
|
9747 |
// of how this item gained or lost focus. |
|
9748 |
if (QWidget *fw = qApp->focusWidget()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9749 |
#ifndef QT_NO_IM |
0 | 9750 |
if (QInputContext *qic = fw->inputContext()) { |
9751 |
if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) |
|
9752 |
qic->reset(); |
|
9753 |
else |
|
9754 |
qic->update(); |
|
9755 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9756 |
#endif //QT_NO_IM |
0 | 9757 |
} |
9758 |
break; |
|
9759 |
default: |
|
9760 |
break; |
|
9761 |
} |
|
9762 |
||
9763 |
return result; |
|
9764 |
} |
|
9765 |
||
9766 |
/*! |
|
9767 |
\reimp |
|
9768 |
*/ |
|
9769 |
void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
9770 |
{ |
|
9771 |
if ((QGraphicsItem::d_ptr->flags & (ItemIsSelectable | ItemIsMovable)) |
|
9772 |
&& (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) { |
|
9773 |
// User left-pressed on edge of selectable/movable item, use |
|
9774 |
// base impl. |
|
9775 |
dd->useDefaultImpl = true; |
|
9776 |
} else if (event->buttons() == event->button() |
|
9777 |
&& dd->control->textInteractionFlags() == Qt::NoTextInteraction) { |
|
9778 |
// User pressed first button on non-interactive item. |
|
9779 |
dd->useDefaultImpl = true; |
|
9780 |
} |
|
9781 |
if (dd->useDefaultImpl) { |
|
9782 |
QGraphicsItem::mousePressEvent(event); |
|
9783 |
if (!event->isAccepted()) |
|
9784 |
dd->useDefaultImpl = false; |
|
9785 |
return; |
|
9786 |
} |
|
9787 |
||
9788 |
dd->sendControlEvent(event); |
|
9789 |
} |
|
9790 |
||
9791 |
/*! |
|
9792 |
\reimp |
|
9793 |
*/ |
|
9794 |
void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
9795 |
{ |
|
9796 |
if (dd->useDefaultImpl) { |
|
9797 |
QGraphicsItem::mouseMoveEvent(event); |
|
9798 |
return; |
|
9799 |
} |
|
9800 |
||
9801 |
dd->sendControlEvent(event); |
|
9802 |
} |
|
9803 |
||
9804 |
/*! |
|
9805 |
\reimp |
|
9806 |
*/ |
|
9807 |
void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
9808 |
{ |
|
9809 |
if (dd->useDefaultImpl) { |
|
9810 |
QGraphicsItem::mouseReleaseEvent(event); |
|
9811 |
if (dd->control->textInteractionFlags() == Qt::NoTextInteraction |
|
9812 |
&& !event->buttons()) { |
|
9813 |
// User released last button on non-interactive item. |
|
9814 |
dd->useDefaultImpl = false; |
|
9815 |
} else if ((event->buttons() & Qt::LeftButton) == 0) { |
|
9816 |
// User released the left button on an interactive item. |
|
9817 |
dd->useDefaultImpl = false; |
|
9818 |
} |
|
9819 |
return; |
|
9820 |
} |
|
9821 |
||
9822 |
QWidget *widget = event->widget(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9823 |
if (widget && (dd->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) { |
0 | 9824 |
qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), dd->clickCausedFocus); |
9825 |
} |
|
9826 |
dd->clickCausedFocus = 0; |
|
9827 |
dd->sendControlEvent(event); |
|
9828 |
} |
|
9829 |
||
9830 |
/*! |
|
9831 |
\reimp |
|
9832 |
*/ |
|
9833 |
void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) |
|
9834 |
{ |
|
9835 |
if (dd->useDefaultImpl) { |
|
9836 |
QGraphicsItem::mouseDoubleClickEvent(event); |
|
9837 |
return; |
|
9838 |
} |
|
9839 |
||
9840 |
if (!hasFocus()) { |
|
9841 |
QGraphicsItem::mouseDoubleClickEvent(event); |
|
9842 |
return; |
|
9843 |
} |
|
9844 |
||
9845 |
dd->sendControlEvent(event); |
|
9846 |
} |
|
9847 |
||
9848 |
/*! |
|
9849 |
\reimp |
|
9850 |
*/ |
|
9851 |
void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) |
|
9852 |
{ |
|
9853 |
dd->sendControlEvent(event); |
|
9854 |
} |
|
9855 |
||
9856 |
/*! |
|
9857 |
\reimp |
|
9858 |
*/ |
|
9859 |
void QGraphicsTextItem::keyPressEvent(QKeyEvent *event) |
|
9860 |
{ |
|
9861 |
dd->sendControlEvent(event); |
|
9862 |
} |
|
9863 |
||
9864 |
/*! |
|
9865 |
\reimp |
|
9866 |
*/ |
|
9867 |
void QGraphicsTextItem::keyReleaseEvent(QKeyEvent *event) |
|
9868 |
{ |
|
9869 |
dd->sendControlEvent(event); |
|
9870 |
} |
|
9871 |
||
9872 |
/*! |
|
9873 |
\reimp |
|
9874 |
*/ |
|
9875 |
void QGraphicsTextItem::focusInEvent(QFocusEvent *event) |
|
9876 |
{ |
|
9877 |
dd->sendControlEvent(event); |
|
9878 |
if (event->reason() == Qt::MouseFocusReason) { |
|
9879 |
dd->clickCausedFocus = 1; |
|
9880 |
} |
|
9881 |
update(); |
|
9882 |
} |
|
9883 |
||
9884 |
/*! |
|
9885 |
\reimp |
|
9886 |
*/ |
|
9887 |
void QGraphicsTextItem::focusOutEvent(QFocusEvent *event) |
|
9888 |
{ |
|
9889 |
dd->sendControlEvent(event); |
|
9890 |
update(); |
|
9891 |
} |
|
9892 |
||
9893 |
/*! |
|
9894 |
\reimp |
|
9895 |
*/ |
|
9896 |
void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) |
|
9897 |
{ |
|
9898 |
dd->sendControlEvent(event); |
|
9899 |
} |
|
9900 |
||
9901 |
/*! |
|
9902 |
\reimp |
|
9903 |
*/ |
|
9904 |
void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) |
|
9905 |
{ |
|
9906 |
dd->sendControlEvent(event); |
|
9907 |
} |
|
9908 |
||
9909 |
/*! |
|
9910 |
\reimp |
|
9911 |
*/ |
|
9912 |
void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) |
|
9913 |
{ |
|
9914 |
dd->sendControlEvent(event); |
|
9915 |
} |
|
9916 |
||
9917 |
/*! |
|
9918 |
\reimp |
|
9919 |
*/ |
|
9920 |
void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent *event) |
|
9921 |
{ |
|
9922 |
dd->sendControlEvent(event); |
|
9923 |
} |
|
9924 |
||
9925 |
/*! |
|
9926 |
\reimp |
|
9927 |
*/ |
|
9928 |
void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent *event) |
|
9929 |
{ |
|
9930 |
dd->sendControlEvent(event); |
|
9931 |
} |
|
9932 |
||
9933 |
/*! |
|
9934 |
\reimp |
|
9935 |
*/ |
|
9936 |
void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
9937 |
{ |
|
9938 |
dd->sendControlEvent(event); |
|
9939 |
} |
|
9940 |
||
9941 |
/*! |
|
9942 |
\reimp |
|
9943 |
*/ |
|
9944 |
void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) |
|
9945 |
{ |
|
9946 |
dd->sendControlEvent(event); |
|
9947 |
} |
|
9948 |
||
9949 |
/*! |
|
9950 |
\reimp |
|
9951 |
*/ |
|
9952 |
void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
9953 |
{ |
|
9954 |
dd->sendControlEvent(event); |
|
9955 |
} |
|
9956 |
||
9957 |
/*! |
|
9958 |
\reimp |
|
9959 |
*/ |
|
9960 |
QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const |
|
9961 |
{ |
|
9962 |
QVariant v; |
|
9963 |
if (dd->control) |
|
9964 |
v = dd->control->inputMethodQuery(query); |
|
9965 |
if (v.type() == QVariant::RectF) |
|
9966 |
v = v.toRectF().translated(-dd->controlOffset()); |
|
9967 |
else if (v.type() == QVariant::PointF) |
|
9968 |
v = v.toPointF() - dd->controlOffset(); |
|
9969 |
else if (v.type() == QVariant::Rect) |
|
9970 |
v = v.toRect().translated(-dd->controlOffset().toPoint()); |
|
9971 |
else if (v.type() == QVariant::Point) |
|
9972 |
v = v.toPoint() - dd->controlOffset().toPoint(); |
|
9973 |
return v; |
|
9974 |
} |
|
9975 |
||
9976 |
/*! |
|
9977 |
\internal |
|
9978 |
*/ |
|
9979 |
bool QGraphicsTextItem::supportsExtension(Extension extension) const |
|
9980 |
{ |
|
9981 |
Q_UNUSED(extension); |
|
9982 |
return false; |
|
9983 |
} |
|
9984 |
||
9985 |
/*! |
|
9986 |
\internal |
|
9987 |
*/ |
|
9988 |
void QGraphicsTextItem::setExtension(Extension extension, const QVariant &variant) |
|
9989 |
{ |
|
9990 |
Q_UNUSED(extension); |
|
9991 |
Q_UNUSED(variant); |
|
9992 |
} |
|
9993 |
||
9994 |
/*! |
|
9995 |
\internal |
|
9996 |
*/ |
|
9997 |
QVariant QGraphicsTextItem::extension(const QVariant &variant) const |
|
9998 |
{ |
|
9999 |
Q_UNUSED(variant); |
|
10000 |
return QVariant(); |
|
10001 |
} |
|
10002 |
||
10003 |
/*! |
|
10004 |
\internal |
|
10005 |
*/ |
|
10006 |
void QGraphicsTextItemPrivate::_q_update(QRectF rect) |
|
10007 |
{ |
|
10008 |
if (rect.isValid()) { |
|
10009 |
rect.translate(-controlOffset()); |
|
10010 |
} else { |
|
10011 |
rect = boundingRect; |
|
10012 |
} |
|
10013 |
if (rect.intersects(boundingRect)) |
|
10014 |
qq->update(rect); |
|
10015 |
} |
|
10016 |
||
10017 |
/*! |
|
10018 |
\internal |
|
10019 |
*/ |
|
10020 |
void QGraphicsTextItemPrivate::_q_updateBoundingRect(const QSizeF &size) |
|
10021 |
{ |
|
10022 |
if (!control) return; // can't happen |
|
10023 |
const QSizeF pageSize = control->document()->pageSize(); |
|
10024 |
// paged items have a constant (page) size |
|
10025 |
if (size == boundingRect.size() || pageSize.height() != -1) |
|
10026 |
return; |
|
10027 |
qq->prepareGeometryChange(); |
|
10028 |
boundingRect.setSize(size); |
|
10029 |
qq->update(); |
|
10030 |
} |
|
10031 |
||
10032 |
/*! |
|
10033 |
\internal |
|
10034 |
*/ |
|
10035 |
void QGraphicsTextItemPrivate::_q_ensureVisible(QRectF rect) |
|
10036 |
{ |
|
10037 |
if (qq->hasFocus()) { |
|
10038 |
rect.translate(-controlOffset()); |
|
10039 |
qq->ensureVisible(rect, /*xmargin=*/0, /*ymargin=*/0); |
|
10040 |
} |
|
10041 |
} |
|
10042 |
||
10043 |
QTextControl *QGraphicsTextItemPrivate::textControl() const |
|
10044 |
{ |
|
10045 |
if (!control) { |
|
10046 |
QGraphicsTextItem *that = const_cast<QGraphicsTextItem *>(qq); |
|
10047 |
control = new QTextControl(that); |
|
10048 |
control->setTextInteractionFlags(Qt::NoTextInteraction); |
|
10049 |
||
10050 |
QObject::connect(control, SIGNAL(updateRequest(QRectF)), |
|
10051 |
qq, SLOT(_q_update(QRectF))); |
|
10052 |
QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), |
|
10053 |
qq, SLOT(_q_updateBoundingRect(QSizeF))); |
|
10054 |
QObject::connect(control, SIGNAL(visibilityRequest(QRectF)), |
|
10055 |
qq, SLOT(_q_ensureVisible(QRectF))); |
|
10056 |
QObject::connect(control, SIGNAL(linkActivated(QString)), |
|
10057 |
qq, SIGNAL(linkActivated(QString))); |
|
10058 |
QObject::connect(control, SIGNAL(linkHovered(QString)), |
|
10059 |
qq, SIGNAL(linkHovered(QString))); |
|
10060 |
||
10061 |
const QSizeF pgSize = control->document()->pageSize(); |
|
10062 |
if (pgSize.height() != -1) { |
|
10063 |
qq->prepareGeometryChange(); |
|
10064 |
that->dd->boundingRect.setSize(pgSize); |
|
10065 |
qq->update(); |
|
10066 |
} else { |
|
10067 |
that->dd->_q_updateBoundingRect(control->size()); |
|
10068 |
} |
|
10069 |
} |
|
10070 |
return control; |
|
10071 |
} |
|
10072 |
||
10073 |
/*! |
|
10074 |
\internal |
|
10075 |
*/ |
|
10076 |
bool QGraphicsTextItemPrivate::_q_mouseOnEdge(QGraphicsSceneMouseEvent *event) |
|
10077 |
{ |
|
10078 |
QPainterPath path; |
|
10079 |
path.addRect(qq->boundingRect()); |
|
10080 |
||
10081 |
QPainterPath docPath; |
|
10082 |
const QTextFrameFormat format = control->document()->rootFrame()->frameFormat(); |
|
10083 |
docPath.addRect( |
|
10084 |
qq->boundingRect().adjusted( |
|
10085 |
format.leftMargin(), |
|
10086 |
format.topMargin(), |
|
10087 |
-format.rightMargin(), |
|
10088 |
-format.bottomMargin())); |
|
10089 |
||
10090 |
return path.subtracted(docPath).contains(event->pos()); |
|
10091 |
} |
|
10092 |
||
10093 |
/*! |
|
10094 |
\fn QGraphicsTextItem::linkActivated(const QString &link) |
|
10095 |
||
10096 |
This signal is emitted when the user clicks on a link on a text item |
|
10097 |
that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard. |
|
10098 |
\a link is the link that was clicked. |
|
10099 |
||
10100 |
\sa setTextInteractionFlags() |
|
10101 |
*/ |
|
10102 |
||
10103 |
/*! |
|
10104 |
\fn QGraphicsTextItem::linkHovered(const QString &link) |
|
10105 |
||
10106 |
This signal is emitted when the user hovers over a link on a text item |
|
10107 |
that enables Qt::LinksAccessibleByMouse. \a link is |
|
10108 |
the link that was hovered over. |
|
10109 |
||
10110 |
\sa setTextInteractionFlags() |
|
10111 |
*/ |
|
10112 |
||
10113 |
/*! |
|
10114 |
Sets the flags \a flags to specify how the text item should react to user |
|
10115 |
input. |
|
10116 |
||
10117 |
The default for a QGraphicsTextItem is Qt::NoTextInteraction. This function |
|
10118 |
also affects the ItemIsFocusable QGraphicsItem flag by setting it if \a flags |
|
10119 |
is different from Qt::NoTextInteraction and clearing it otherwise. |
|
10120 |
||
10121 |
By default, the text is read-only. To transform the item into an editor, |
|
10122 |
set the Qt::TextEditable flag. |
|
10123 |
*/ |
|
10124 |
void QGraphicsTextItem::setTextInteractionFlags(Qt::TextInteractionFlags flags) |
|
10125 |
{ |
|
10126 |
if (flags == Qt::NoTextInteraction) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10127 |
setFlags(this->flags() & ~(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod)); |
0 | 10128 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10129 |
setFlags(this->flags() | QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10130 |
|
0 | 10131 |
dd->textControl()->setTextInteractionFlags(flags); |
10132 |
} |
|
10133 |
||
10134 |
/*! |
|
10135 |
Returns the current text interaction flags. |
|
10136 |
||
10137 |
\sa setTextInteractionFlags() |
|
10138 |
*/ |
|
10139 |
Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const |
|
10140 |
{ |
|
10141 |
if (!dd->control) |
|
10142 |
return Qt::NoTextInteraction; |
|
10143 |
return dd->control->textInteractionFlags(); |
|
10144 |
} |
|
10145 |
||
10146 |
/*! |
|
10147 |
\since 4.5 |
|
10148 |
||
10149 |
If \a b is true, the \gui Tab key will cause the widget to change focus; |
|
10150 |
otherwise, the tab key will insert a tab into the document. |
|
10151 |
||
10152 |
In some occasions text edits should not allow the user to input tabulators |
|
10153 |
or change indentation using the \gui Tab key, as this breaks the focus |
|
10154 |
chain. The default is false. |
|
10155 |
||
10156 |
\sa tabChangesFocus(), ItemIsFocusable, textInteractionFlags() |
|
10157 |
*/ |
|
10158 |
void QGraphicsTextItem::setTabChangesFocus(bool b) |
|
10159 |
{ |
|
10160 |
dd->tabChangesFocus = b; |
|
10161 |
} |
|
10162 |
||
10163 |
/*! |
|
10164 |
\since 4.5 |
|
10165 |
||
10166 |
Returns true if the \gui Tab key will cause the widget to change focus; |
|
10167 |
otherwise, false is returned. |
|
10168 |
||
10169 |
By default, this behavior is disabled, and this function will return false. |
|
10170 |
||
10171 |
\sa setTabChangesFocus() |
|
10172 |
*/ |
|
10173 |
bool QGraphicsTextItem::tabChangesFocus() const |
|
10174 |
{ |
|
10175 |
return dd->tabChangesFocus; |
|
10176 |
} |
|
10177 |
||
10178 |
/*! |
|
10179 |
\property QGraphicsTextItem::openExternalLinks |
|
10180 |
||
10181 |
Specifies whether QGraphicsTextItem should automatically open links using |
|
10182 |
QDesktopServices::openUrl() instead of emitting the |
|
10183 |
linkActivated signal. |
|
10184 |
||
10185 |
The default value is false. |
|
10186 |
*/ |
|
10187 |
void QGraphicsTextItem::setOpenExternalLinks(bool open) |
|
10188 |
{ |
|
10189 |
dd->textControl()->setOpenExternalLinks(open); |
|
10190 |
} |
|
10191 |
||
10192 |
bool QGraphicsTextItem::openExternalLinks() const |
|
10193 |
{ |
|
10194 |
if (!dd->control) |
|
10195 |
return false; |
|
10196 |
return dd->control->openExternalLinks(); |
|
10197 |
} |
|
10198 |
||
10199 |
/*! |
|
10200 |
\property QGraphicsTextItem::textCursor |
|
10201 |
||
10202 |
This property represents the visible text cursor in an editable |
|
10203 |
text item. |
|
10204 |
||
10205 |
By default, if the item's text has not been set, this property |
|
10206 |
contains a null text cursor; otherwise it contains a text cursor |
|
10207 |
placed at the start of the item's document. |
|
10208 |
*/ |
|
10209 |
void QGraphicsTextItem::setTextCursor(const QTextCursor &cursor) |
|
10210 |
{ |
|
10211 |
dd->textControl()->setTextCursor(cursor); |
|
10212 |
} |
|
10213 |
||
10214 |
QTextCursor QGraphicsTextItem::textCursor() const |
|
10215 |
{ |
|
10216 |
if (!dd->control) |
|
10217 |
return QTextCursor(); |
|
10218 |
return dd->control->textCursor(); |
|
10219 |
} |
|
10220 |
||
10221 |
class QGraphicsSimpleTextItemPrivate : public QAbstractGraphicsShapeItemPrivate |
|
10222 |
{ |
|
10223 |
Q_DECLARE_PUBLIC(QGraphicsSimpleTextItem) |
|
10224 |
public: |
|
10225 |
inline QGraphicsSimpleTextItemPrivate() { |
|
10226 |
pen.setStyle(Qt::NoPen); |
|
10227 |
brush.setStyle(Qt::SolidPattern); |
|
10228 |
} |
|
10229 |
QString text; |
|
10230 |
QFont font; |
|
10231 |
QRectF boundingRect; |
|
10232 |
||
10233 |
void updateBoundingRect(); |
|
10234 |
}; |
|
10235 |
||
10236 |
static QRectF setupTextLayout(QTextLayout *layout) |
|
10237 |
{ |
|
10238 |
layout->setCacheEnabled(true); |
|
10239 |
layout->beginLayout(); |
|
10240 |
while (layout->createLine().isValid()) |
|
10241 |
; |
|
10242 |
layout->endLayout(); |
|
10243 |
qreal maxWidth = 0; |
|
10244 |
qreal y = 0; |
|
10245 |
for (int i = 0; i < layout->lineCount(); ++i) { |
|
10246 |
QTextLine line = layout->lineAt(i); |
|
10247 |
maxWidth = qMax(maxWidth, line.naturalTextWidth()); |
|
10248 |
line.setPosition(QPointF(0, y)); |
|
10249 |
y += line.height(); |
|
10250 |
} |
|
10251 |
return QRectF(0, 0, maxWidth, y); |
|
10252 |
} |
|
10253 |
||
10254 |
void QGraphicsSimpleTextItemPrivate::updateBoundingRect() |
|
10255 |
{ |
|
10256 |
Q_Q(QGraphicsSimpleTextItem); |
|
10257 |
QRectF br; |
|
10258 |
if (text.isEmpty()) { |
|
10259 |
br = QRectF(); |
|
10260 |
} else { |
|
10261 |
QString tmp = text; |
|
10262 |
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); |
|
10263 |
QStackTextEngine engine(tmp, font); |
|
10264 |
QTextLayout layout(&engine); |
|
10265 |
br = setupTextLayout(&layout); |
|
10266 |
} |
|
10267 |
if (br != boundingRect) { |
|
10268 |
q->prepareGeometryChange(); |
|
10269 |
boundingRect = br; |
|
10270 |
q->update(); |
|
10271 |
} |
|
10272 |
} |
|
10273 |
||
10274 |
/*! |
|
10275 |
\class QGraphicsSimpleTextItem |
|
10276 |
\brief The QGraphicsSimpleTextItem class provides a simple text path item |
|
10277 |
that you can add to a QGraphicsScene. |
|
10278 |
\since 4.2 |
|
10279 |
\ingroup graphicsview-api |
|
10280 |
||
10281 |
To set the item's text, you can either pass a QString to |
|
10282 |
QGraphicsSimpleTextItem's constructor, or call setText() to change the |
|
10283 |
text later. To set the text fill color, call setBrush(). |
|
10284 |
||
10285 |
The simple text item can have both a fill and an outline; setBrush() will |
|
10286 |
set the text fill (i.e., text color), and setPen() sets the pen that will |
|
10287 |
be used to draw the text outline. (The latter can be slow, especially for |
|
10288 |
complex pens, and items with long text content.) If all you want is to |
|
10289 |
draw a simple line of text, you should call setBrush() only, and leave the |
|
10290 |
pen unset; QGraphicsSimpleTextItem's pen is by default Qt::NoPen. |
|
10291 |
||
10292 |
QGraphicsSimpleTextItem uses the text's formatted size and the associated |
|
10293 |
font to provide a reasonable implementation of boundingRect(), shape(), |
|
10294 |
and contains(). You can set the font by calling setFont(). |
|
10295 |
||
10296 |
QGraphicsSimpleText does not display rich text; instead, you can use |
|
10297 |
QGraphicsTextItem, which provides full text control capabilities. |
|
10298 |
||
10299 |
\img graphicsview-simpletextitem.png |
|
10300 |
||
10301 |
\sa QGraphicsTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, |
|
10302 |
QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem, {The |
|
10303 |
Graphics View Framework} |
|
10304 |
*/ |
|
10305 |
||
10306 |
/*! |
|
10307 |
Constructs a QGraphicsSimpleTextItem. |
|
10308 |
||
10309 |
\a parent is passed to QGraphicsItem's constructor. |
|
10310 |
||
10311 |
\sa QGraphicsScene::addItem() |
|
10312 |
*/ |
|
10313 |
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(QGraphicsItem *parent |
|
10314 |
#ifndef Q_QDOC |
|
10315 |
// obsolete argument |
|
10316 |
, QGraphicsScene *scene |
|
10317 |
#endif |
|
10318 |
) |
|
10319 |
: QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent, scene) |
|
10320 |
{ |
|
10321 |
} |
|
10322 |
||
10323 |
/*! |
|
10324 |
Constructs a QGraphicsSimpleTextItem, using \a text as the default plain text. |
|
10325 |
||
10326 |
\a parent is passed to QGraphicsItem's constructor. |
|
10327 |
||
10328 |
\sa QGraphicsScene::addItem() |
|
10329 |
*/ |
|
10330 |
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent |
|
10331 |
#ifndef Q_QDOC |
|
10332 |
// obsolete argument |
|
10333 |
, QGraphicsScene *scene |
|
10334 |
#endif |
|
10335 |
) |
|
10336 |
: QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent, scene) |
|
10337 |
{ |
|
10338 |
setText(text); |
|
10339 |
} |
|
10340 |
||
10341 |
/*! |
|
10342 |
Destroys the QGraphicsSimpleTextItem. |
|
10343 |
*/ |
|
10344 |
QGraphicsSimpleTextItem::~QGraphicsSimpleTextItem() |
|
10345 |
{ |
|
10346 |
} |
|
10347 |
||
10348 |
/*! |
|
10349 |
Sets the item's text to \a text. The text will be displayed as |
|
10350 |
plain text. Newline characters ('\n') as well as characters of |
|
10351 |
type QChar::LineSeparator will cause item to break the text into |
|
10352 |
multiple lines. |
|
10353 |
*/ |
|
10354 |
void QGraphicsSimpleTextItem::setText(const QString &text) |
|
10355 |
{ |
|
10356 |
Q_D(QGraphicsSimpleTextItem); |
|
10357 |
if (d->text == text) |
|
10358 |
return; |
|
10359 |
d->text = text; |
|
10360 |
d->updateBoundingRect(); |
|
10361 |
update(); |
|
10362 |
} |
|
10363 |
||
10364 |
/*! |
|
10365 |
Returns the item's text. |
|
10366 |
*/ |
|
10367 |
QString QGraphicsSimpleTextItem::text() const |
|
10368 |
{ |
|
10369 |
Q_D(const QGraphicsSimpleTextItem); |
|
10370 |
return d->text; |
|
10371 |
} |
|
10372 |
||
10373 |
/*! |
|
10374 |
Sets the font that is used to draw the item's text to \a font. |
|
10375 |
*/ |
|
10376 |
void QGraphicsSimpleTextItem::setFont(const QFont &font) |
|
10377 |
{ |
|
10378 |
Q_D(QGraphicsSimpleTextItem); |
|
10379 |
d->font = font; |
|
10380 |
d->updateBoundingRect(); |
|
10381 |
} |
|
10382 |
||
10383 |
/*! |
|
10384 |
Returns the font that is used to draw the item's text. |
|
10385 |
*/ |
|
10386 |
QFont QGraphicsSimpleTextItem::font() const |
|
10387 |
{ |
|
10388 |
Q_D(const QGraphicsSimpleTextItem); |
|
10389 |
return d->font; |
|
10390 |
} |
|
10391 |
||
10392 |
/*! |
|
10393 |
\reimp |
|
10394 |
*/ |
|
10395 |
QRectF QGraphicsSimpleTextItem::boundingRect() const |
|
10396 |
{ |
|
10397 |
Q_D(const QGraphicsSimpleTextItem); |
|
10398 |
return d->boundingRect; |
|
10399 |
} |
|
10400 |
||
10401 |
/*! |
|
10402 |
\reimp |
|
10403 |
*/ |
|
10404 |
QPainterPath QGraphicsSimpleTextItem::shape() const |
|
10405 |
{ |
|
10406 |
Q_D(const QGraphicsSimpleTextItem); |
|
10407 |
QPainterPath path; |
|
10408 |
path.addRect(d->boundingRect); |
|
10409 |
return path; |
|
10410 |
} |
|
10411 |
||
10412 |
/*! |
|
10413 |
\reimp |
|
10414 |
*/ |
|
10415 |
bool QGraphicsSimpleTextItem::contains(const QPointF &point) const |
|
10416 |
{ |
|
10417 |
Q_D(const QGraphicsSimpleTextItem); |
|
10418 |
return d->boundingRect.contains(point); |
|
10419 |
} |
|
10420 |
||
10421 |
/*! |
|
10422 |
\reimp |
|
10423 |
*/ |
|
10424 |
void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
10425 |
{ |
|
10426 |
Q_UNUSED(widget); |
|
10427 |
Q_D(QGraphicsSimpleTextItem); |
|
10428 |
||
10429 |
painter->setFont(d->font); |
|
10430 |
||
10431 |
QString tmp = d->text; |
|
10432 |
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); |
|
10433 |
QStackTextEngine engine(tmp, d->font); |
|
10434 |
QTextLayout layout(&engine); |
|
10435 |
setupTextLayout(&layout); |
|
10436 |
||
10437 |
QPen p; |
|
10438 |
p.setBrush(d->brush); |
|
10439 |
painter->setPen(p); |
|
10440 |
if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) { |
|
10441 |
painter->setBrush(Qt::NoBrush); |
|
10442 |
} else { |
|
10443 |
QTextLayout::FormatRange range; |
|
10444 |
range.start = 0; |
|
10445 |
range.length = layout.text().length(); |
|
10446 |
range.format.setTextOutline(d->pen); |
|
10447 |
QList<QTextLayout::FormatRange> formats; |
|
10448 |
formats.append(range); |
|
10449 |
layout.setAdditionalFormats(formats); |
|
10450 |
} |
|
10451 |
||
10452 |
layout.draw(painter, QPointF(0, 0)); |
|
10453 |
||
10454 |
if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) |
|
10455 |
qt_graphicsItem_highlightSelected(this, painter, option); |
|
10456 |
} |
|
10457 |
||
10458 |
/*! |
|
10459 |
\reimp |
|
10460 |
*/ |
|
10461 |
bool QGraphicsSimpleTextItem::isObscuredBy(const QGraphicsItem *item) const |
|
10462 |
{ |
|
10463 |
return QAbstractGraphicsShapeItem::isObscuredBy(item); |
|
10464 |
} |
|
10465 |
||
10466 |
/*! |
|
10467 |
\reimp |
|
10468 |
*/ |
|
10469 |
QPainterPath QGraphicsSimpleTextItem::opaqueArea() const |
|
10470 |
{ |
|
10471 |
return QAbstractGraphicsShapeItem::opaqueArea(); |
|
10472 |
} |
|
10473 |
||
10474 |
/*! |
|
10475 |
\reimp |
|
10476 |
*/ |
|
10477 |
int QGraphicsSimpleTextItem::type() const |
|
10478 |
{ |
|
10479 |
return Type; |
|
10480 |
} |
|
10481 |
||
10482 |
/*! |
|
10483 |
\internal |
|
10484 |
*/ |
|
10485 |
bool QGraphicsSimpleTextItem::supportsExtension(Extension extension) const |
|
10486 |
{ |
|
10487 |
Q_UNUSED(extension); |
|
10488 |
return false; |
|
10489 |
} |
|
10490 |
||
10491 |
/*! |
|
10492 |
\internal |
|
10493 |
*/ |
|
10494 |
void QGraphicsSimpleTextItem::setExtension(Extension extension, const QVariant &variant) |
|
10495 |
{ |
|
10496 |
Q_UNUSED(extension); |
|
10497 |
Q_UNUSED(variant); |
|
10498 |
} |
|
10499 |
||
10500 |
/*! |
|
10501 |
\internal |
|
10502 |
*/ |
|
10503 |
QVariant QGraphicsSimpleTextItem::extension(const QVariant &variant) const |
|
10504 |
{ |
|
10505 |
Q_UNUSED(variant); |
|
10506 |
return QVariant(); |
|
10507 |
} |
|
10508 |
||
10509 |
/*! |
|
10510 |
\class QGraphicsItemGroup |
|
10511 |
\brief The QGraphicsItemGroup class provides treating a group of items as |
|
10512 |
one. |
|
10513 |
\since 4.2 |
|
10514 |
\ingroup graphicsview-api |
|
10515 |
||
10516 |
A QGraphicsItemGroup is a special type of compound item that |
|
10517 |
treats itself and all its children as one item (i.e., all events |
|
10518 |
and geometries for all children are merged together). It's common |
|
10519 |
to use item groups in presentation tools, when the user wants to |
|
10520 |
group several smaller items into one big item in order to simplify |
|
10521 |
moving and copying of items. |
|
10522 |
||
10523 |
If all you want is to store items inside other items, you can use |
|
10524 |
any QGraphicsItem directly by passing a suitable parent to |
|
10525 |
setParentItem(). |
|
10526 |
||
10527 |
The boundingRect() function of QGraphicsItemGroup returns the |
|
10528 |
bounding rectangle of all items in the item group. |
|
10529 |
QGraphicsItemGroup ignores the ItemIgnoresTransformations flag on |
|
10530 |
its children (i.e., with respect to the geometry of the group |
|
10531 |
item, the children are treated as if they were transformable). |
|
10532 |
||
10533 |
There are two ways to construct an item group. The easiest and |
|
10534 |
most common approach is to pass a list of items (e.g., all |
|
10535 |
selected items) to QGraphicsScene::createItemGroup(), which |
|
10536 |
returns a new QGraphicsItemGroup item. The other approach is to |
|
10537 |
manually construct a QGraphicsItemGroup item, add it to the scene |
|
10538 |
calling QGraphicsScene::addItem(), and then add items to the group |
|
10539 |
manually, one at a time by calling addToGroup(). To dismantle |
|
10540 |
("ungroup") an item group, you can either call |
|
10541 |
QGraphicsScene::destroyItemGroup(), or you can manually remove all |
|
10542 |
items from the group by calling removeFromGroup(). |
|
10543 |
||
10544 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 17 |
|
10545 |
||
10546 |
The operation of adding and removing items preserves the items' |
|
10547 |
scene-relative position and transformation, as opposed to calling |
|
10548 |
setParentItem(), where only the child item's parent-relative |
|
10549 |
position and transformation are kept. |
|
10550 |
||
10551 |
The addtoGroup() function reparents the target item to this item |
|
10552 |
group, keeping the item's position and transformation intact |
|
10553 |
relative to the scene. Visually, this means that items added via |
|
10554 |
addToGroup() will remain completely unchanged as a result of this |
|
10555 |
operation, regardless of the item or the group's current position |
|
10556 |
or transformation; although the item's position and matrix are |
|
10557 |
likely to change. |
|
10558 |
||
10559 |
The removeFromGroup() function has similar semantics to |
|
10560 |
setParentItem(); it reparents the item to the parent item of the |
|
10561 |
item group. As with addToGroup(), the item's scene-relative |
|
10562 |
position and transformation remain intact. |
|
10563 |
||
10564 |
\sa QGraphicsItem, {The Graphics View Framework} |
|
10565 |
*/ |
|
10566 |
||
10567 |
class QGraphicsItemGroupPrivate : public QGraphicsItemPrivate |
|
10568 |
{ |
|
10569 |
public: |
|
10570 |
QRectF itemsBoundingRect; |
|
10571 |
}; |
|
10572 |
||
10573 |
/*! |
|
10574 |
Constructs a QGraphicsItemGroup. \a parent is passed to QGraphicsItem's |
|
10575 |
constructor. |
|
10576 |
||
10577 |
\sa QGraphicsScene::addItem() |
|
10578 |
*/ |
|
10579 |
QGraphicsItemGroup::QGraphicsItemGroup(QGraphicsItem *parent |
|
10580 |
#ifndef Q_QDOC |
|
10581 |
// obsolete argument |
|
10582 |
, QGraphicsScene *scene |
|
10583 |
#endif |
|
10584 |
) |
|
10585 |
: QGraphicsItem(*new QGraphicsItemGroupPrivate, parent, scene) |
|
10586 |
{ |
|
10587 |
setHandlesChildEvents(true); |
|
10588 |
} |
|
10589 |
||
10590 |
/*! |
|
10591 |
Destroys the QGraphicsItemGroup. |
|
10592 |
*/ |
|
10593 |
QGraphicsItemGroup::~QGraphicsItemGroup() |
|
10594 |
{ |
|
10595 |
} |
|
10596 |
||
10597 |
/*! |
|
10598 |
Adds the given \a item to this item group. The item will be |
|
10599 |
reparented to this group, but its position and transformation |
|
10600 |
relative to the scene will stay intact. |
|
10601 |
||
10602 |
\sa removeFromGroup(), QGraphicsScene::createItemGroup() |
|
10603 |
*/ |
|
10604 |
void QGraphicsItemGroup::addToGroup(QGraphicsItem *item) |
|
10605 |
{ |
|
10606 |
Q_D(QGraphicsItemGroup); |
|
10607 |
if (!item) { |
|
10608 |
qWarning("QGraphicsItemGroup::addToGroup: cannot add null item"); |
|
10609 |
return; |
|
10610 |
} |
|
10611 |
if (item == this) { |
|
10612 |
qWarning("QGraphicsItemGroup::addToGroup: cannot add a group to itself"); |
|
10613 |
return; |
|
10614 |
} |
|
10615 |
||
10616 |
// COMBINE |
|
10617 |
bool ok; |
|
10618 |
QTransform itemTransform = item->itemTransform(this, &ok); |
|
10619 |
||
10620 |
if (!ok) { |
|
10621 |
qWarning("QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates"); |
|
10622 |
return; |
|
10623 |
} |
|
10624 |
||
10625 |
QTransform newItemTransform(itemTransform); |
|
10626 |
item->setPos(mapFromItem(item, 0, 0)); |
|
10627 |
item->setParentItem(this); |
|
10628 |
||
10629 |
// removing position from translation component of the new transform |
|
10630 |
if (!item->pos().isNull()) |
|
10631 |
newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); |
|
10632 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10633 |
// removing additional transformations properties applied with itemTransform() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10634 |
QPointF origin = item->transformOriginPoint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10635 |
QMatrix4x4 m; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10636 |
QList<QGraphicsTransform*> transformList = item->transformations(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10637 |
for (int i = 0; i < transformList.size(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10638 |
transformList.at(i)->applyTo(&m); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10639 |
newItemTransform *= m.toTransform().inverted(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10640 |
newItemTransform.translate(origin.x(), origin.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10641 |
newItemTransform.rotate(-item->rotation()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10642 |
newItemTransform.scale(1/item->scale(), 1/item->scale()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10643 |
newItemTransform.translate(-origin.x(), -origin.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10644 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10645 |
// ### Expensive, we could maybe use dirtySceneTransform bit for optimization |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10646 |
|
0 | 10647 |
item->setTransform(newItemTransform); |
10648 |
item->d_func()->setIsMemberOfGroup(true); |
|
10649 |
prepareGeometryChange(); |
|
10650 |
d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect()); |
|
10651 |
update(); |
|
10652 |
} |
|
10653 |
||
10654 |
/*! |
|
10655 |
Removes the specified \a item from this group. The item will be |
|
10656 |
reparented to this group's parent item, or to 0 if this group has |
|
10657 |
no parent. Its position and transformation relative to the scene |
|
10658 |
will stay intact. |
|
10659 |
||
10660 |
\sa addToGroup(), QGraphicsScene::destroyItemGroup() |
|
10661 |
*/ |
|
10662 |
void QGraphicsItemGroup::removeFromGroup(QGraphicsItem *item) |
|
10663 |
{ |
|
10664 |
Q_D(QGraphicsItemGroup); |
|
10665 |
if (!item) { |
|
10666 |
qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item"); |
|
10667 |
return; |
|
10668 |
} |
|
10669 |
||
10670 |
QGraphicsItem *newParent = d_ptr->parent; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10671 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10672 |
// COMBINE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10673 |
bool ok; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10674 |
QTransform itemTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10675 |
if (newParent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10676 |
itemTransform = item->itemTransform(newParent, &ok); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10677 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10678 |
itemTransform = item->sceneTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10679 |
|
0 | 10680 |
QPointF oldPos = item->mapToItem(newParent, 0, 0); |
10681 |
item->setParentItem(newParent); |
|
10682 |
item->setPos(oldPos); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10683 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10684 |
// removing position from translation component of the new transform |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10685 |
if (!item->pos().isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10686 |
itemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10687 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10688 |
// removing additional transformations properties applied |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10689 |
// with itemTransform() or sceneTransform() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10690 |
QPointF origin = item->transformOriginPoint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10691 |
QMatrix4x4 m; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10692 |
QList<QGraphicsTransform*> transformList = item->transformations(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10693 |
for (int i = 0; i < transformList.size(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10694 |
transformList.at(i)->applyTo(&m); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10695 |
itemTransform *= m.toTransform().inverted(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10696 |
itemTransform.translate(origin.x(), origin.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10697 |
itemTransform.rotate(-item->rotation()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10698 |
itemTransform.scale(1 / item->scale(), 1 / item->scale()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10699 |
itemTransform.translate(-origin.x(), -origin.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10700 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10701 |
// ### Expensive, we could maybe use dirtySceneTransform bit for optimization |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10702 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10703 |
item->setTransform(itemTransform); |
0 | 10704 |
item->d_func()->setIsMemberOfGroup(item->group() != 0); |
10705 |
||
10706 |
// ### Quite expensive. But removeFromGroup() isn't called very often. |
|
10707 |
prepareGeometryChange(); |
|
10708 |
d->itemsBoundingRect = childrenBoundingRect(); |
|
10709 |
} |
|
10710 |
||
10711 |
/*! |
|
10712 |
\reimp |
|
10713 |
||
10714 |
Returns the bounding rect of this group item, and all its children. |
|
10715 |
*/ |
|
10716 |
QRectF QGraphicsItemGroup::boundingRect() const |
|
10717 |
{ |
|
10718 |
Q_D(const QGraphicsItemGroup); |
|
10719 |
return d->itemsBoundingRect; |
|
10720 |
} |
|
10721 |
||
10722 |
/*! |
|
10723 |
\reimp |
|
10724 |
*/ |
|
10725 |
void QGraphicsItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
|
10726 |
QWidget *widget) |
|
10727 |
{ |
|
10728 |
Q_UNUSED(widget); |
|
10729 |
if (option->state & QStyle::State_Selected) { |
|
10730 |
Q_D(QGraphicsItemGroup); |
|
10731 |
painter->setBrush(Qt::NoBrush); |
|
10732 |
painter->drawRect(d->itemsBoundingRect); |
|
10733 |
} |
|
10734 |
} |
|
10735 |
||
10736 |
/*! |
|
10737 |
\reimp |
|
10738 |
*/ |
|
10739 |
bool QGraphicsItemGroup::isObscuredBy(const QGraphicsItem *item) const |
|
10740 |
{ |
|
10741 |
return QGraphicsItem::isObscuredBy(item); |
|
10742 |
} |
|
10743 |
||
10744 |
/*! |
|
10745 |
\reimp |
|
10746 |
*/ |
|
10747 |
QPainterPath QGraphicsItemGroup::opaqueArea() const |
|
10748 |
{ |
|
10749 |
return QGraphicsItem::opaqueArea(); |
|
10750 |
} |
|
10751 |
||
10752 |
/*! |
|
10753 |
\reimp |
|
10754 |
*/ |
|
10755 |
int QGraphicsItemGroup::type() const |
|
10756 |
{ |
|
10757 |
return Type; |
|
10758 |
} |
|
10759 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10760 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 10761 |
QRectF QGraphicsItemEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const |
10762 |
{ |
|
10763 |
const bool deviceCoordinates = (system == Qt::DeviceCoordinates); |
|
10764 |
if (!info && deviceCoordinates) { |
|
10765 |
// Device coordinates without info not yet supported. |
|
10766 |
qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context"); |
|
10767 |
return QRectF(); |
|
10768 |
} |
|
10769 |
||
10770 |
QRectF rect = item->boundingRect(); |
|
10771 |
if (!item->d_ptr->children.isEmpty()) |
|
10772 |
rect |= item->childrenBoundingRect(); |
|
10773 |
||
10774 |
if (deviceCoordinates) { |
|
10775 |
Q_ASSERT(info->painter); |
|
10776 |
rect = info->painter->worldTransform().mapRect(rect); |
|
10777 |
} |
|
10778 |
||
10779 |
return rect; |
|
10780 |
} |
|
10781 |
||
10782 |
void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter) |
|
10783 |
{ |
|
10784 |
if (!info) { |
|
10785 |
qWarning("QGraphicsEffectSource::draw: Can only begin as a result of QGraphicsEffect::draw"); |
|
10786 |
return; |
|
10787 |
} |
|
10788 |
||
10789 |
Q_ASSERT(item->d_ptr->scene); |
|
10790 |
QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func(); |
|
10791 |
if (painter == info->painter) { |
|
10792 |
scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion, |
|
10793 |
info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform, |
|
10794 |
info->drawItem); |
|
10795 |
} else { |
|
10796 |
QTransform effectTransform = info->painter->worldTransform().inverted(); |
|
10797 |
effectTransform *= painter->worldTransform(); |
|
10798 |
scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion, |
|
10799 |
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform, |
|
10800 |
info->drawItem); |
|
10801 |
} |
|
10802 |
} |
|
10803 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10804 |
QRect QGraphicsItemEffectSourcePrivate::paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded) const |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10805 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10806 |
QRectF effectRectF; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10807 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10808 |
if (unpadded) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10809 |
*unpadded = false; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10810 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10811 |
if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10812 |
if (info) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10813 |
effectRectF = item->graphicsEffect()->boundingRectFor(boundingRect(Qt::DeviceCoordinates)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10814 |
if (unpadded) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10815 |
*unpadded = (effectRectF.size() == sourceRect.size()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10816 |
if (info && system == Qt::LogicalCoordinates) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10817 |
effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10818 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10819 |
// no choice but to send a logical coordinate bounding rect to boundingRectFor |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10820 |
effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10821 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10822 |
} else if (mode == QGraphicsEffect::PadToTransparentBorder) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10823 |
// adjust by 1.5 to account for cosmetic pens |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10824 |
effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10825 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10826 |
effectRectF = sourceRect; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10827 |
if (unpadded) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10828 |
*unpadded = true; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10829 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10830 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10831 |
return effectRectF.toAlignedRect(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10832 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10833 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10834 |
QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10835 |
QGraphicsEffect::PixmapPadMode mode) const |
0 | 10836 |
{ |
10837 |
const bool deviceCoordinates = (system == Qt::DeviceCoordinates); |
|
10838 |
if (!info && deviceCoordinates) { |
|
10839 |
// Device coordinates without info not yet supported. |
|
10840 |
qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); |
|
10841 |
return QPixmap(); |
|
10842 |
} |
|
10843 |
if (!item->d_ptr->scene) |
|
10844 |
return QPixmap(); |
|
10845 |
QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func(); |
|
10846 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10847 |
bool unpadded; |
0 | 10848 |
const QRectF sourceRect = boundingRect(system); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
10849 |
QRect effectRect = paddedEffectRect(system, mode, sourceRect, &unpadded); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10850 |
|
0 | 10851 |
if (offset) |
10852 |
*offset = effectRect.topLeft(); |
|
10853 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10854 |
bool untransformed = !deviceCoordinates |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10855 |
|| info->painter->worldTransform().type() <= QTransform::TxTranslate; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10856 |
if (untransformed && unpadded && isPixmap()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10857 |
if (offset) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10858 |
*offset = boundingRect(system).topLeft().toPoint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10859 |
return static_cast<QGraphicsPixmapItem *>(item)->pixmap(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10860 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10861 |
|
0 | 10862 |
if (deviceCoordinates) { |
10863 |
// Clip to viewport rect. |
|
10864 |
int left, top, right, bottom; |
|
10865 |
effectRect.getCoords(&left, &top, &right, &bottom); |
|
10866 |
if (left < 0) { |
|
10867 |
if (offset) |
|
10868 |
offset->rx() += -left; |
|
10869 |
effectRect.setX(0); |
|
10870 |
} |
|
10871 |
if (top < 0) { |
|
10872 |
if (offset) |
|
10873 |
offset->ry() += -top; |
|
10874 |
effectRect.setY(0); |
|
10875 |
} |
|
10876 |
// NB! We use +-1 for historical reasons (see QRect documentation). |
|
10877 |
QPaintDevice *device = info->painter->device(); |
|
10878 |
const int deviceWidth = device->width(); |
|
10879 |
const int deviceHeight = device->height(); |
|
10880 |
if (right + 1 > deviceWidth) |
|
10881 |
effectRect.setRight(deviceWidth - 1); |
|
10882 |
if (bottom + 1 > deviceHeight) |
|
10883 |
effectRect.setBottom(deviceHeight -1); |
|
10884 |
||
10885 |
} |
|
10886 |
if (effectRect.isEmpty()) |
|
10887 |
return QPixmap(); |
|
10888 |
||
10889 |
QPixmap pixmap(effectRect.size()); |
|
10890 |
pixmap.fill(Qt::transparent); |
|
10891 |
QPainter pixmapPainter(&pixmap); |
|
10892 |
pixmapPainter.setRenderHints(info ? info->painter->renderHints() : QPainter::TextAntialiasing); |
|
10893 |
||
10894 |
QTransform effectTransform = QTransform::fromTranslate(-effectRect.x(), -effectRect.y()); |
|
10895 |
if (deviceCoordinates && info->effectTransform) |
|
10896 |
effectTransform *= *info->effectTransform; |
|
10897 |
||
10898 |
if (!info) { |
|
10899 |
// Logical coordinates without info. |
|
10900 |
QTransform sceneTransform = item->sceneTransform(); |
|
10901 |
QTransform newEffectTransform = sceneTransform.inverted(); |
|
10902 |
newEffectTransform *= effectTransform; |
|
10903 |
scened->draw(item, &pixmapPainter, 0, &sceneTransform, 0, 0, qreal(1.0), |
|
10904 |
&newEffectTransform, false, true); |
|
10905 |
} else if (deviceCoordinates) { |
|
10906 |
// Device coordinates with info. |
|
10907 |
scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion, |
|
10908 |
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform, |
|
10909 |
info->drawItem); |
|
10910 |
} else { |
|
10911 |
// Item coordinates with info. |
|
10912 |
QTransform newEffectTransform = info->transformPtr->inverted(); |
|
10913 |
newEffectTransform *= effectTransform; |
|
10914 |
scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion, |
|
10915 |
info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform, |
|
10916 |
info->drawItem); |
|
10917 |
} |
|
10918 |
||
10919 |
pixmapPainter.end(); |
|
10920 |
||
10921 |
return pixmap; |
|
10922 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10923 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 10924 |
|
10925 |
#ifndef QT_NO_DEBUG_STREAM |
|
10926 |
QDebug operator<<(QDebug debug, QGraphicsItem *item) |
|
10927 |
{ |
|
10928 |
if (!item) { |
|
10929 |
debug << "QGraphicsItem(0)"; |
|
10930 |
return debug; |
|
10931 |
} |
|
10932 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10933 |
if (QGraphicsObject *o = item->toGraphicsObject()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10934 |
debug << o->metaObject()->className(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10935 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10936 |
debug << "QGraphicsItem"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10937 |
debug << "(this =" << (void*)item |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10938 |
<< ", parent =" << (void*)item->parentItem() |
0 | 10939 |
<< ", pos =" << item->pos() |
10940 |
<< ", z =" << item->zValue() << ", flags = " |
|
10941 |
<< item->flags() << ")"; |
|
10942 |
return debug; |
|
10943 |
} |
|
10944 |
||
10945 |
QDebug operator<<(QDebug debug, QGraphicsObject *item) |
|
10946 |
{ |
|
10947 |
if (!item) { |
|
10948 |
debug << "QGraphicsObject(0)"; |
|
10949 |
return debug; |
|
10950 |
} |
|
10951 |
||
10952 |
debug.nospace() << item->metaObject()->className() << '(' << (void*)item; |
|
10953 |
if (!item->objectName().isEmpty()) |
|
10954 |
debug << ", name = " << item->objectName(); |
|
10955 |
debug.nospace() << ", parent = " << ((void*)item->parentItem()) |
|
10956 |
<< ", pos = " << item->pos() |
|
10957 |
<< ", z = " << item->zValue() << ", flags = " |
|
10958 |
<< item->flags() << ')'; |
|
10959 |
return debug.space(); |
|
10960 |
} |
|
10961 |
||
10962 |
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change) |
|
10963 |
{ |
|
10964 |
const char *str = "UnknownChange"; |
|
10965 |
switch (change) { |
|
10966 |
case QGraphicsItem::ItemChildAddedChange: |
|
10967 |
str = "ItemChildAddedChange"; |
|
10968 |
break; |
|
10969 |
case QGraphicsItem::ItemChildRemovedChange: |
|
10970 |
str = "ItemChildRemovedChange"; |
|
10971 |
break; |
|
10972 |
case QGraphicsItem::ItemCursorChange: |
|
10973 |
str = "ItemCursorChange"; |
|
10974 |
break; |
|
10975 |
case QGraphicsItem::ItemCursorHasChanged: |
|
10976 |
str = "ItemCursorHasChanged"; |
|
10977 |
break; |
|
10978 |
case QGraphicsItem::ItemEnabledChange: |
|
10979 |
str = "ItemEnabledChange"; |
|
10980 |
break; |
|
10981 |
case QGraphicsItem::ItemEnabledHasChanged: |
|
10982 |
str = "ItemEnabledHasChanged"; |
|
10983 |
break; |
|
10984 |
case QGraphicsItem::ItemFlagsChange: |
|
10985 |
str = "ItemFlagsChange"; |
|
10986 |
break; |
|
10987 |
case QGraphicsItem::ItemFlagsHaveChanged: |
|
10988 |
str = "ItemFlagsHaveChanged"; |
|
10989 |
break; |
|
10990 |
case QGraphicsItem::ItemMatrixChange: |
|
10991 |
str = "ItemMatrixChange"; |
|
10992 |
break; |
|
10993 |
case QGraphicsItem::ItemParentChange: |
|
10994 |
str = "ItemParentChange"; |
|
10995 |
break; |
|
10996 |
case QGraphicsItem::ItemParentHasChanged: |
|
10997 |
str = "ItemParentHasChanged"; |
|
10998 |
break; |
|
10999 |
case QGraphicsItem::ItemPositionChange: |
|
11000 |
str = "ItemPositionChange"; |
|
11001 |
break; |
|
11002 |
case QGraphicsItem::ItemPositionHasChanged: |
|
11003 |
str = "ItemPositionHasChanged"; |
|
11004 |
break; |
|
11005 |
case QGraphicsItem::ItemSceneChange: |
|
11006 |
str = "ItemSceneChange"; |
|
11007 |
break; |
|
11008 |
case QGraphicsItem::ItemSceneHasChanged: |
|
11009 |
str = "ItemSceneHasChanged"; |
|
11010 |
break; |
|
11011 |
case QGraphicsItem::ItemSelectedChange: |
|
11012 |
str = "ItemSelectedChange"; |
|
11013 |
break; |
|
11014 |
case QGraphicsItem::ItemSelectedHasChanged: |
|
11015 |
str = "ItemSelectedHasChanged"; |
|
11016 |
break; |
|
11017 |
case QGraphicsItem::ItemToolTipChange: |
|
11018 |
str = "ItemToolTipChange"; |
|
11019 |
break; |
|
11020 |
case QGraphicsItem::ItemToolTipHasChanged: |
|
11021 |
str = "ItemToolTipHasChanged"; |
|
11022 |
break; |
|
11023 |
case QGraphicsItem::ItemTransformChange: |
|
11024 |
str = "ItemTransformChange"; |
|
11025 |
break; |
|
11026 |
case QGraphicsItem::ItemTransformHasChanged: |
|
11027 |
str = "ItemTransformHasChanged"; |
|
11028 |
break; |
|
11029 |
case QGraphicsItem::ItemVisibleChange: |
|
11030 |
str = "ItemVisibleChange"; |
|
11031 |
break; |
|
11032 |
case QGraphicsItem::ItemVisibleHasChanged: |
|
11033 |
str = "ItemVisibleHasChanged"; |
|
11034 |
break; |
|
11035 |
case QGraphicsItem::ItemZValueChange: |
|
11036 |
str = "ItemZValueChange"; |
|
11037 |
break; |
|
11038 |
case QGraphicsItem::ItemZValueHasChanged: |
|
11039 |
str = "ItemZValueHasChanged"; |
|
11040 |
break; |
|
11041 |
case QGraphicsItem::ItemOpacityChange: |
|
11042 |
str = "ItemOpacityChange"; |
|
11043 |
break; |
|
11044 |
case QGraphicsItem::ItemOpacityHasChanged: |
|
11045 |
str = "ItemOpacityHasChanged"; |
|
11046 |
break; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11047 |
case QGraphicsItem::ItemScenePositionHasChanged: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11048 |
str = "ItemScenePositionHasChanged"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11049 |
break; |
0 | 11050 |
} |
11051 |
debug << str; |
|
11052 |
return debug; |
|
11053 |
} |
|
11054 |
||
11055 |
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag) |
|
11056 |
{ |
|
11057 |
const char *str = "UnknownFlag"; |
|
11058 |
switch (flag) { |
|
11059 |
case QGraphicsItem::ItemIsMovable: |
|
11060 |
str = "ItemIsMovable"; |
|
11061 |
break; |
|
11062 |
case QGraphicsItem::ItemIsSelectable: |
|
11063 |
str = "ItemIsSelectable"; |
|
11064 |
break; |
|
11065 |
case QGraphicsItem::ItemIsFocusable: |
|
11066 |
str = "ItemIsFocusable"; |
|
11067 |
break; |
|
11068 |
case QGraphicsItem::ItemClipsToShape: |
|
11069 |
str = "ItemClipsToShape"; |
|
11070 |
break; |
|
11071 |
case QGraphicsItem::ItemClipsChildrenToShape: |
|
11072 |
str = "ItemClipsChildrenToShape"; |
|
11073 |
break; |
|
11074 |
case QGraphicsItem::ItemIgnoresTransformations: |
|
11075 |
str = "ItemIgnoresTransformations"; |
|
11076 |
break; |
|
11077 |
case QGraphicsItem::ItemIgnoresParentOpacity: |
|
11078 |
str = "ItemIgnoresParentOpacity"; |
|
11079 |
break; |
|
11080 |
case QGraphicsItem::ItemDoesntPropagateOpacityToChildren: |
|
11081 |
str = "ItemDoesntPropagateOpacityToChildren"; |
|
11082 |
break; |
|
11083 |
case QGraphicsItem::ItemStacksBehindParent: |
|
11084 |
str = "ItemStacksBehindParent"; |
|
11085 |
break; |
|
11086 |
case QGraphicsItem::ItemUsesExtendedStyleOption: |
|
11087 |
str = "ItemUsesExtendedStyleOption"; |
|
11088 |
break; |
|
11089 |
case QGraphicsItem::ItemHasNoContents: |
|
11090 |
str = "ItemHasNoContents"; |
|
11091 |
break; |
|
11092 |
case QGraphicsItem::ItemSendsGeometryChanges: |
|
11093 |
str = "ItemSendsGeometryChanges"; |
|
11094 |
break; |
|
11095 |
case QGraphicsItem::ItemAcceptsInputMethod: |
|
11096 |
str = "ItemAcceptsInputMethod"; |
|
11097 |
break; |
|
11098 |
case QGraphicsItem::ItemNegativeZStacksBehindParent: |
|
11099 |
str = "ItemNegativeZStacksBehindParent"; |
|
11100 |
break; |
|
11101 |
case QGraphicsItem::ItemIsPanel: |
|
11102 |
str = "ItemIsPanel"; |
|
11103 |
break; |
|
11104 |
case QGraphicsItem::ItemIsFocusScope: |
|
11105 |
str = "ItemIsFocusScope"; |
|
11106 |
break; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11107 |
case QGraphicsItem::ItemSendsScenePositionChanges: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11108 |
str = "ItemSendsScenePositionChanges"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11109 |
break; |
0 | 11110 |
} |
11111 |
debug << str; |
|
11112 |
return debug; |
|
11113 |
} |
|
11114 |
||
11115 |
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags) |
|
11116 |
{ |
|
11117 |
debug << '('; |
|
11118 |
bool f = false; |
|
11119 |
for (int i = 0; i < 16; ++i) { |
|
11120 |
if (flags & (1 << i)) { |
|
11121 |
if (f) |
|
11122 |
debug << '|'; |
|
11123 |
f = true; |
|
11124 |
debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i))); |
|
11125 |
} |
|
11126 |
} |
|
11127 |
debug << ')'; |
|
11128 |
return debug; |
|
11129 |
} |
|
11130 |
||
11131 |
#endif |
|
11132 |
||
11133 |
QT_END_NAMESPACE |
|
11134 |
||
11135 |
#include "moc_qgraphicsitem.cpp" |
|
11136 |
||
11137 |
#endif // QT_NO_GRAPHICSVIEW |