author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@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 QGraphicsScene |
|
44 |
\brief The QGraphicsScene class provides a surface for managing a large |
|
45 |
number of 2D graphical items. |
|
46 |
\since 4.2 |
|
47 |
\ingroup graphicsview-api |
|
48 |
||
49 |
||
50 |
The class serves as a container for QGraphicsItems. It is used together |
|
51 |
with QGraphicsView for visualizing graphical items, such as lines, |
|
52 |
rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is |
|
53 |
part of \l{The Graphics View Framework}. |
|
54 |
||
55 |
QGraphicsScene also provides functionality that lets you efficiently |
|
56 |
determine both the location of items, and for determining what items are |
|
57 |
visible within an arbitrary area on the scene. With the QGraphicsView |
|
58 |
widget, you can either visualize the whole scene, or zoom in and view only |
|
59 |
parts of the scene. |
|
60 |
||
61 |
Example: |
|
62 |
||
63 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 0 |
|
64 |
||
65 |
Note that QGraphicsScene has no visual appearance of its own; it only |
|
66 |
manages the items. You need to create a QGraphicsView widget to visualize |
|
67 |
the scene. |
|
68 |
||
69 |
To add items to a scene, you start off by constructing a QGraphicsScene |
|
70 |
object. Then, you have two options: either add your existing QGraphicsItem |
|
71 |
objects by calling addItem(), or you can call one of the convenience |
|
72 |
functions addEllipse(), addLine(), addPath(), addPixmap(), addPolygon(), |
|
73 |
addRect(), or addText(), which all return a pointer to the newly added item. |
|
74 |
The dimensions of the items added with these functions are relative to the |
|
75 |
item's coordinate system, and the items position is initialized to (0, |
|
76 |
0) in the scene. |
|
77 |
||
78 |
You can then visualize the scene using QGraphicsView. When the scene |
|
79 |
changes, (e.g., when an item moves or is transformed) QGraphicsScene |
|
80 |
emits the changed() signal. To remove an item, call removeItem(). |
|
81 |
||
82 |
QGraphicsScene uses an indexing algorithm to manage the location of items |
|
83 |
efficiently. By default, a BSP (Binary Space Partitioning) tree is used; an |
|
84 |
algorithm suitable for large scenes where most items remain static (i.e., |
|
85 |
do not move around). You can choose to disable this index by calling |
|
86 |
setItemIndexMethod(). For more information about the available indexing |
|
87 |
algorithms, see the itemIndexMethod property. |
|
88 |
||
89 |
The scene's bounding rect is set by calling setSceneRect(). Items can be |
|
90 |
placed at any position on the scene, and the size of the scene is by |
|
91 |
default unlimited. The scene rect is used only for internal bookkeeping, |
|
92 |
maintaining the scene's item index. If the scene rect is unset, |
|
93 |
QGraphicsScene will use the bounding area of all items, as returned by |
|
94 |
itemsBoundingRect(), as the scene rect. However, itemsBoundingRect() is a |
|
95 |
relatively time consuming function, as it operates by collecting |
|
96 |
positional information for every item on the scene. Because of this, you |
|
97 |
should always set the scene rect when operating on large scenes. |
|
98 |
||
99 |
One of QGraphicsScene's greatest strengths is its ability to efficiently |
|
100 |
determine the location of items. Even with millions of items on the scene, |
|
101 |
the items() functions can determine the location of an item within few |
|
102 |
milliseconds. There are several overloads to items(): one that finds items |
|
103 |
at a certain position, one that finds items inside or intersecting with a |
|
104 |
polygon or a rectangle, and more. The list of returned items is sorted by |
|
105 |
stacking order, with the topmost item being the first item in the list. |
|
106 |
For convenience, there is also an itemAt() function that returns the |
|
107 |
topmost item at a given position. |
|
108 |
||
109 |
QGraphicsScene maintains selection information for the scene. To select |
|
110 |
items, call setSelectionArea(), and to clear the current selection, call |
|
111 |
clearSelection(). Call selectedItems() to get the list of all selected |
|
112 |
items. |
|
113 |
||
114 |
\section1 Event Handling and Propagation |
|
115 |
||
116 |
Another responsibility that QGraphicsScene has, is to propagate events |
|
117 |
from QGraphicsView. To send an event to a scene, you construct an event |
|
118 |
that inherits QEvent, and then send it using, for example, |
|
119 |
QApplication::sendEvent(). event() is responsible for dispatching |
|
120 |
the event to the individual items. Some common events are handled by |
|
121 |
convenience event handlers. For example, key press events are handled by |
|
122 |
keyPressEvent(), and mouse press events are handled by mousePressEvent(). |
|
123 |
||
124 |
Key events are delivered to the \e {focus item}. To set the focus item, |
|
125 |
you can either call setFocusItem(), passing an item that accepts focus, or |
|
126 |
the item itself can call QGraphicsItem::setFocus(). Call focusItem() to |
|
127 |
get the current focus item. For compatibility with widgets, the scene also |
|
128 |
maintains its own focus information. By default, the scene does not have |
|
129 |
focus, and all key events are discarded. If setFocus() is called, or if an |
|
130 |
item on the scene gains focus, the scene automatically gains focus. If the |
|
131 |
scene has focus, hasFocus() will return true, and key events will be |
|
132 |
forwarded to the focus item, if any. If the scene loses focus, (i.e., |
|
133 |
someone calls clearFocus(),) while an item has focus, the scene will |
|
134 |
maintain its item focus information, and once the scene regains focus, it |
|
135 |
will make sure the last focus item regains focus. |
|
136 |
||
137 |
For mouse-over effects, QGraphicsScene dispatches \e {hover |
|
138 |
events}. If an item accepts hover events (see |
|
139 |
QGraphicsItem::acceptHoverEvents()), it will receive a \l |
|
140 |
{QEvent::}{GraphicsSceneHoverEnter} event when the mouse enters |
|
141 |
its area. As the mouse continues moving inside the item's area, |
|
142 |
QGraphicsScene will send it \l {QEvent::}{GraphicsSceneHoverMove} |
|
143 |
events. When the mouse leaves the item's area, the item will |
|
144 |
receive a \l {QEvent::}{GraphicsSceneHoverLeave} event. |
|
145 |
||
146 |
All mouse events are delivered to the current \e {mouse grabber} |
|
147 |
item. An item becomes the scene's mouse grabber if it accepts |
|
148 |
mouse events (see QGraphicsItem::acceptedMouseButtons()) and it |
|
149 |
receives a mouse press. It stays the mouse grabber until it |
|
150 |
receives a mouse release when no other mouse buttons are |
|
151 |
pressed. You can call mouseGrabberItem() to determine what item is |
|
152 |
currently grabbing the mouse. |
|
153 |
||
154 |
\sa QGraphicsItem, QGraphicsView |
|
155 |
*/ |
|
156 |
||
157 |
/*! |
|
158 |
\enum QGraphicsScene::SceneLayer |
|
159 |
\since 4.3 |
|
160 |
||
161 |
This enum describes the rendering layers in a QGraphicsScene. When |
|
162 |
QGraphicsScene draws the scene contents, it renders each of these layers |
|
163 |
separately, in order. |
|
164 |
||
165 |
Each layer represents a flag that can be OR'ed together when calling |
|
166 |
functions such as invalidate() or QGraphicsView::invalidateScene(). |
|
167 |
||
168 |
\value ItemLayer The item layer. QGraphicsScene renders all items are in |
|
169 |
this layer by calling the virtual function drawItems(). The item layer is |
|
170 |
drawn after the background layer, but before the foreground layer. |
|
171 |
||
172 |
\value BackgroundLayer The background layer. QGraphicsScene renders the |
|
173 |
scene's background in this layer by calling the virtual function |
|
174 |
drawBackground(). The background layer is drawn first of all layers. |
|
175 |
||
176 |
\value ForegroundLayer The foreground layer. QGraphicsScene renders the |
|
177 |
scene's foreground in this layer by calling the virtual function |
|
178 |
drawForeground(). The foreground layer is drawn last of all layers. |
|
179 |
||
180 |
\value AllLayers All layers; this value represents a combination of all |
|
181 |
three layers. |
|
182 |
||
183 |
\sa invalidate(), QGraphicsView::invalidateScene() |
|
184 |
*/ |
|
185 |
||
186 |
/*! |
|
187 |
\enum QGraphicsScene::ItemIndexMethod |
|
188 |
||
189 |
This enum describes the indexing algorithms QGraphicsScene provides for |
|
190 |
managing positional information about items on the scene. |
|
191 |
||
192 |
\value BspTreeIndex A Binary Space Partitioning tree is applied. All |
|
193 |
QGraphicsScene's item location algorithms are of an order close to |
|
194 |
logarithmic complexity, by making use of binary search. Adding, moving and |
|
195 |
removing items is logarithmic. This approach is best for static scenes |
|
196 |
(i.e., scenes where most items do not move). |
|
197 |
||
198 |
\value NoIndex No index is applied. Item location is of linear complexity, |
|
199 |
as all items on the scene are searched. Adding, moving and removing items, |
|
200 |
however, is done in constant time. This approach is ideal for dynamic |
|
201 |
scenes, where many items are added, moved or removed continuously. |
|
202 |
||
203 |
\sa setItemIndexMethod(), bspTreeDepth |
|
204 |
*/ |
|
205 |
||
206 |
#include "qgraphicsscene.h" |
|
207 |
||
208 |
#ifndef QT_NO_GRAPHICSVIEW |
|
209 |
||
210 |
#include "qgraphicsitem.h" |
|
211 |
#include "qgraphicsitem_p.h" |
|
212 |
#include "qgraphicslayout.h" |
|
213 |
#include "qgraphicsscene_p.h" |
|
214 |
#include "qgraphicssceneevent.h" |
|
215 |
#include "qgraphicsview.h" |
|
216 |
#include "qgraphicsview_p.h" |
|
217 |
#include "qgraphicswidget.h" |
|
218 |
#include "qgraphicswidget_p.h" |
|
219 |
#include "qgraphicssceneindex_p.h" |
|
220 |
#include "qgraphicsscenebsptreeindex_p.h" |
|
221 |
#include "qgraphicsscenelinearindex_p.h" |
|
222 |
||
223 |
#include <QtCore/qdebug.h> |
|
224 |
#include <QtCore/qlist.h> |
|
225 |
#include <QtCore/qmath.h> |
|
226 |
#include <QtCore/qrect.h> |
|
227 |
#include <QtCore/qset.h> |
|
228 |
#include <QtCore/qstack.h> |
|
229 |
#include <QtCore/qtimer.h> |
|
230 |
#include <QtCore/qvarlengtharray.h> |
|
231 |
#include <QtGui/qapplication.h> |
|
232 |
#include <QtGui/qdesktopwidget.h> |
|
233 |
#include <QtGui/qevent.h> |
|
234 |
#include <QtGui/qgraphicslayout.h> |
|
235 |
#include <QtGui/qgraphicsproxywidget.h> |
|
236 |
#include <QtGui/qgraphicswidget.h> |
|
237 |
#include <QtGui/qmatrix.h> |
|
238 |
#include <QtGui/qpaintengine.h> |
|
239 |
#include <QtGui/qpainter.h> |
|
240 |
#include <QtGui/qpixmapcache.h> |
|
241 |
#include <QtGui/qpolygon.h> |
|
242 |
#include <QtGui/qstyleoption.h> |
|
243 |
#include <QtGui/qtooltip.h> |
|
244 |
#include <QtGui/qtransform.h> |
|
245 |
#include <QtGui/qinputcontext.h> |
|
246 |
#include <QtGui/qgraphicseffect.h> |
|
247 |
#include <private/qapplication_p.h> |
|
248 |
#include <private/qobject_p.h> |
|
249 |
#ifdef Q_WS_X11 |
|
250 |
#include <private/qt_x11_p.h> |
|
251 |
#endif |
|
252 |
#include <private/qgraphicseffect_p.h> |
|
253 |
#include <private/qgesturemanager_p.h> |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
254 |
#include <private/qpathclipper_p.h> |
0 | 255 |
|
256 |
// #define GESTURE_DEBUG |
|
257 |
#ifndef GESTURE_DEBUG |
|
258 |
# define DEBUG if (0) qDebug |
|
259 |
#else |
|
260 |
# define DEBUG qDebug |
|
261 |
#endif |
|
262 |
||
263 |
QT_BEGIN_NAMESPACE |
|
264 |
||
265 |
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); |
|
266 |
||
267 |
static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent) |
|
268 |
{ |
|
269 |
hover->setWidget(mouseEvent->widget()); |
|
270 |
hover->setPos(mouseEvent->pos()); |
|
271 |
hover->setScenePos(mouseEvent->scenePos()); |
|
272 |
hover->setScreenPos(mouseEvent->screenPos()); |
|
273 |
hover->setLastPos(mouseEvent->lastPos()); |
|
274 |
hover->setLastScenePos(mouseEvent->lastScenePos()); |
|
275 |
hover->setLastScreenPos(mouseEvent->lastScreenPos()); |
|
276 |
hover->setModifiers(mouseEvent->modifiers()); |
|
277 |
hover->setAccepted(mouseEvent->isAccepted()); |
|
278 |
} |
|
279 |
||
280 |
int QGraphicsScenePrivate::changedSignalIndex; |
|
281 |
||
282 |
/*! |
|
283 |
\internal |
|
284 |
*/ |
|
285 |
QGraphicsScenePrivate::QGraphicsScenePrivate() |
|
286 |
: indexMethod(QGraphicsScene::BspTreeIndex), |
|
287 |
index(0), |
|
288 |
lastItemCount(0), |
|
289 |
hasSceneRect(false), |
|
290 |
dirtyGrowingItemsBoundingRect(true), |
|
291 |
updateAll(false), |
|
292 |
calledEmitUpdated(false), |
|
293 |
processDirtyItemsEmitted(false), |
|
294 |
selectionChanging(0), |
|
295 |
needSortTopLevelItems(true), |
|
296 |
holesInTopLevelSiblingIndex(false), |
|
297 |
topLevelSequentialOrdering(true), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
scenePosDescendantsUpdatePending(false), |
0 | 299 |
stickyFocus(false), |
300 |
hasFocus(false), |
|
301 |
focusItem(0), |
|
302 |
lastFocusItem(0), |
|
303 |
tabFocusFirst(0), |
|
304 |
activePanel(0), |
|
305 |
lastActivePanel(0), |
|
306 |
activationRefCount(0), |
|
307 |
childExplicitActivation(0), |
|
308 |
lastMouseGrabberItem(0), |
|
309 |
lastMouseGrabberItemHasImplicitMouseGrab(false), |
|
310 |
dragDropItem(0), |
|
311 |
enterWidget(0), |
|
312 |
lastDropAction(Qt::IgnoreAction), |
|
313 |
allItemsIgnoreHoverEvents(true), |
|
314 |
allItemsUseDefaultCursor(true), |
|
315 |
painterStateProtection(true), |
|
316 |
sortCacheEnabled(false), |
|
317 |
style(0), |
|
318 |
allItemsIgnoreTouchEvents(true) |
|
319 |
{ |
|
320 |
} |
|
321 |
||
322 |
/*! |
|
323 |
\internal |
|
324 |
*/ |
|
325 |
void QGraphicsScenePrivate::init() |
|
326 |
{ |
|
327 |
Q_Q(QGraphicsScene); |
|
328 |
||
329 |
index = new QGraphicsSceneBspTreeIndex(q); |
|
330 |
||
331 |
// Keep this index so we can check for connected slots later on. |
|
332 |
if (!changedSignalIndex) { |
|
333 |
changedSignalIndex = signalIndex("changed(QList<QRectF>)"); |
|
334 |
} |
|
335 |
qApp->d_func()->scene_list.append(q); |
|
336 |
q->update(); |
|
337 |
} |
|
338 |
||
339 |
/*! |
|
340 |
\internal |
|
341 |
*/ |
|
342 |
QGraphicsScenePrivate *QGraphicsScenePrivate::get(QGraphicsScene *q) |
|
343 |
{ |
|
344 |
return q->d_func(); |
|
345 |
} |
|
346 |
||
347 |
void QGraphicsScenePrivate::_q_emitUpdated() |
|
348 |
{ |
|
349 |
Q_Q(QGraphicsScene); |
|
350 |
calledEmitUpdated = false; |
|
351 |
||
352 |
if (dirtyGrowingItemsBoundingRect) { |
|
353 |
if (!hasSceneRect) { |
|
354 |
const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; |
|
355 |
growingItemsBoundingRect |= q->itemsBoundingRect(); |
|
356 |
if (oldGrowingItemsBoundingRect != growingItemsBoundingRect) |
|
357 |
emit q->sceneRectChanged(growingItemsBoundingRect); |
|
358 |
} |
|
359 |
dirtyGrowingItemsBoundingRect = false; |
|
360 |
} |
|
361 |
||
362 |
// Ensure all views are connected if anything is connected. This disables |
|
363 |
// the optimization that items send updates directly to the views, but it |
|
364 |
// needs to happen in order to keep compatibility with the behavior from |
|
365 |
// Qt 4.4 and backward. |
|
366 |
if (isSignalConnected(changedSignalIndex)) { |
|
367 |
for (int i = 0; i < views.size(); ++i) { |
|
368 |
QGraphicsView *view = views.at(i); |
|
369 |
if (!view->d_func()->connectedToScene) { |
|
370 |
view->d_func()->connectedToScene = true; |
|
371 |
q->connect(q, SIGNAL(changed(QList<QRectF>)), |
|
372 |
views.at(i), SLOT(updateScene(QList<QRectF>))); |
|
373 |
} |
|
374 |
} |
|
375 |
} else { |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
376 |
if (views.isEmpty()) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
377 |
updateAll = false; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
378 |
return; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
379 |
} |
0 | 380 |
for (int i = 0; i < views.size(); ++i) |
381 |
views.at(i)->d_func()->processPendingUpdates(); |
|
382 |
// It's important that we update all views before we dispatch, hence two for-loops. |
|
383 |
for (int i = 0; i < views.size(); ++i) |
|
384 |
views.at(i)->d_func()->dispatchPendingUpdateRequests(); |
|
385 |
return; |
|
386 |
} |
|
387 |
||
388 |
// Notify the changes to anybody interested. |
|
389 |
QList<QRectF> oldUpdatedRects; |
|
390 |
oldUpdatedRects = updateAll ? (QList<QRectF>() << q->sceneRect()) : updatedRects; |
|
391 |
updateAll = false; |
|
392 |
updatedRects.clear(); |
|
393 |
emit q->changed(oldUpdatedRects); |
|
394 |
} |
|
395 |
||
396 |
/*! |
|
397 |
\internal |
|
398 |
||
399 |
### This function is almost identical to QGraphicsItemPrivate::addChild(). |
|
400 |
*/ |
|
401 |
void QGraphicsScenePrivate::registerTopLevelItem(QGraphicsItem *item) |
|
402 |
{ |
|
403 |
item->d_ptr->ensureSequentialSiblingIndex(); |
|
404 |
needSortTopLevelItems = true; // ### maybe false |
|
405 |
item->d_ptr->siblingIndex = topLevelItems.size(); |
|
406 |
topLevelItems.append(item); |
|
407 |
} |
|
408 |
||
409 |
/*! |
|
410 |
\internal |
|
411 |
||
412 |
### This function is almost identical to QGraphicsItemPrivate::removeChild(). |
|
413 |
*/ |
|
414 |
void QGraphicsScenePrivate::unregisterTopLevelItem(QGraphicsItem *item) |
|
415 |
{ |
|
416 |
if (!holesInTopLevelSiblingIndex) |
|
417 |
holesInTopLevelSiblingIndex = item->d_ptr->siblingIndex != topLevelItems.size() - 1; |
|
418 |
if (topLevelSequentialOrdering && !holesInTopLevelSiblingIndex) |
|
419 |
topLevelItems.removeAt(item->d_ptr->siblingIndex); |
|
420 |
else |
|
421 |
topLevelItems.removeOne(item); |
|
422 |
// NB! Do not use topLevelItems.removeAt(item->d_ptr->siblingIndex) because |
|
423 |
// the item is not guaranteed to be at the index after the list is sorted |
|
424 |
// (see ensureSortedTopLevelItems()). |
|
425 |
item->d_ptr->siblingIndex = -1; |
|
426 |
if (topLevelSequentialOrdering) |
|
427 |
topLevelSequentialOrdering = !holesInTopLevelSiblingIndex; |
|
428 |
} |
|
429 |
||
430 |
/*! |
|
431 |
\internal |
|
432 |
*/ |
|
433 |
void QGraphicsScenePrivate::_q_polishItems() |
|
434 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
435 |
if (unpolishedItems.isEmpty()) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
436 |
return; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
437 |
|
0 | 438 |
const QVariant booleanTrueVariant(true); |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
439 |
QGraphicsItem *item = 0; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
440 |
QGraphicsItemPrivate *itemd = 0; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
441 |
const int oldUnpolishedCount = unpolishedItems.count(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
442 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
443 |
for (int i = 0; i < oldUnpolishedCount; ++i) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
444 |
item = unpolishedItems.at(i); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
445 |
if (!item) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
446 |
continue; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
447 |
itemd = item->d_ptr.data(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
448 |
itemd->pendingPolish = false; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
449 |
if (!itemd->explicitlyHidden) { |
0 | 450 |
item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); |
451 |
item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); |
|
452 |
} |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
453 |
if (itemd->isWidget) { |
0 | 454 |
QEvent event(QEvent::Polish); |
455 |
QApplication::sendEvent((QGraphicsWidget *)item, &event); |
|
456 |
} |
|
457 |
} |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
458 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
459 |
if (unpolishedItems.count() == oldUnpolishedCount) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
460 |
// No new items were added to the vector. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
461 |
unpolishedItems.clear(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
462 |
} else { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
463 |
// New items were appended; keep them and remove the old ones. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
464 |
unpolishedItems.remove(0, oldUnpolishedCount); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
465 |
unpolishedItems.squeeze(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
466 |
QMetaObject::invokeMethod(q_ptr, "_q_polishItems", Qt::QueuedConnection); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
467 |
} |
0 | 468 |
} |
469 |
||
470 |
void QGraphicsScenePrivate::_q_processDirtyItems() |
|
471 |
{ |
|
472 |
processDirtyItemsEmitted = false; |
|
473 |
||
474 |
if (updateAll) { |
|
475 |
Q_ASSERT(calledEmitUpdated); |
|
476 |
// No need for further processing (except resetting the dirty states). |
|
477 |
// The growingItemsBoundingRect is updated in _q_emitUpdated. |
|
478 |
for (int i = 0; i < topLevelItems.size(); ++i) |
|
479 |
resetDirtyItem(topLevelItems.at(i), /*recursive=*/true); |
|
480 |
return; |
|
481 |
} |
|
482 |
||
483 |
const bool wasPendingSceneUpdate = calledEmitUpdated; |
|
484 |
const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; |
|
485 |
||
486 |
// Process items recursively. |
|
487 |
for (int i = 0; i < topLevelItems.size(); ++i) |
|
488 |
processDirtyItemsRecursive(topLevelItems.at(i)); |
|
489 |
||
490 |
dirtyGrowingItemsBoundingRect = false; |
|
491 |
if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect) |
|
492 |
emit q_func()->sceneRectChanged(growingItemsBoundingRect); |
|
493 |
||
494 |
if (wasPendingSceneUpdate) |
|
495 |
return; |
|
496 |
||
497 |
for (int i = 0; i < views.size(); ++i) |
|
498 |
views.at(i)->d_func()->processPendingUpdates(); |
|
499 |
||
500 |
if (calledEmitUpdated) { |
|
501 |
// We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive |
|
502 |
// and we cannot wait for the control to reach the eventloop before the |
|
503 |
// changed signal is emitted, so we emit it now. |
|
504 |
_q_emitUpdated(); |
|
505 |
} |
|
506 |
||
507 |
// Immediately dispatch all pending update requests on the views. |
|
508 |
for (int i = 0; i < views.size(); ++i) |
|
509 |
views.at(i)->d_func()->dispatchPendingUpdateRequests(); |
|
510 |
} |
|
511 |
||
512 |
/*! |
|
513 |
\internal |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
void QGraphicsScenePrivate::setScenePosItemEnabled(QGraphicsItem *item, bool enabled) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
QGraphicsItem *p = item->d_ptr->parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
while (p) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
p->d_ptr->scenePosDescendants = enabled; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
p = p->d_ptr->parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
if (!enabled && !scenePosDescendantsUpdatePending) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
scenePosDescendantsUpdatePending = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
524 |
QMetaObject::invokeMethod(q_func(), "_q_updateScenePosDescendants", Qt::QueuedConnection); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
525 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
526 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
527 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
528 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
530 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
void QGraphicsScenePrivate::registerScenePosItem(QGraphicsItem *item) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
533 |
scenePosItems.insert(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
setScenePosItemEnabled(item, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
void QGraphicsScenePrivate::unregisterScenePosItem(QGraphicsItem *item) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
542 |
scenePosItems.remove(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
setScenePosItemEnabled(item, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
void QGraphicsScenePrivate::_q_updateScenePosDescendants() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
foreach (QGraphicsItem *item, scenePosItems) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
QGraphicsItem *p = item->d_ptr->parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
while (p) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
p->d_ptr->scenePosDescendants = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
p = p->d_ptr->parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
scenePosDescendantsUpdatePending = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
\internal |
0 | 563 |
|
564 |
Schedules an item for removal. This function leaves some stale indexes |
|
565 |
around in the BSP tree if called from the item's destructor; these will |
|
566 |
be cleaned up the next time someone triggers purgeRemovedItems(). |
|
567 |
||
568 |
Note: This function might get called from QGraphicsItem's destructor. \a item is |
|
569 |
being destroyed, so we cannot call any pure virtual functions on it (such |
|
570 |
as boundingRect()). Also, it is unnecessary to update the item's own state |
|
571 |
in any way. |
|
572 |
*/ |
|
573 |
void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) |
|
574 |
{ |
|
575 |
Q_Q(QGraphicsScene); |
|
576 |
||
577 |
// Clear focus on the item to remove any reference in the focusWidget chain. |
|
578 |
item->clearFocus(); |
|
579 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
markDirty(item, QRectF(), /*invalidateChildren=*/false, /*force=*/false, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
/*ignoreOpacity=*/false, /*removingItemFromScene=*/true); |
0 | 582 |
|
583 |
if (item->d_ptr->inDestructor) { |
|
584 |
// The item is actually in its destructor, we call the special method in the index. |
|
585 |
index->deleteItem(item); |
|
586 |
} else { |
|
587 |
// Can potentially call item->boundingRect() (virtual function), that's why |
|
588 |
// we only can call this function if the item is not in its destructor. |
|
589 |
index->removeItem(item); |
|
590 |
} |
|
591 |
||
592 |
item->d_ptr->clearSubFocus(); |
|
593 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
if (item->flags() & QGraphicsItem::ItemSendsScenePositionChanges) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
595 |
unregisterScenePosItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
596 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
QGraphicsScene *oldScene = item->d_func()->scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
598 |
item->d_func()->scene = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
599 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
//We need to remove all children first because they might use their parent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
//attributes (e.g. sceneTransform). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
if (!item->d_ptr->inDestructor) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
// Remove all children recursively |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
for (int i = 0; i < item->d_ptr->children.size(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
q->removeItem(item->d_ptr->children.at(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
|
0 | 608 |
if (!item->d_ptr->inDestructor && item == tabFocusFirst) { |
609 |
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
610 |
widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
611 |
} |
0 | 612 |
|
613 |
// Unregister focus proxy. |
|
614 |
item->d_ptr->resetFocusProxy(); |
|
615 |
||
616 |
// Remove from parent, or unregister from toplevels. |
|
617 |
if (QGraphicsItem *parentItem = item->parentItem()) { |
|
618 |
if (parentItem->scene()) { |
|
619 |
Q_ASSERT_X(parentItem->scene() == q, "QGraphicsScene::removeItem", |
|
620 |
"Parent item's scene is different from this item's scene"); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
621 |
item->setParentItem(0); |
0 | 622 |
} |
623 |
} else { |
|
624 |
unregisterTopLevelItem(item); |
|
625 |
} |
|
626 |
||
627 |
// Reset the mouse grabber and focus item data. |
|
628 |
if (item == focusItem) |
|
629 |
focusItem = 0; |
|
630 |
if (item == lastFocusItem) |
|
631 |
lastFocusItem = 0; |
|
632 |
if (item == activePanel) { |
|
633 |
// ### deactivate... |
|
634 |
activePanel = 0; |
|
635 |
} |
|
636 |
if (item == lastActivePanel) |
|
637 |
lastActivePanel = 0; |
|
638 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
// Cancel active touches |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
QMap<int, QGraphicsItem *>::iterator it = itemForTouchPointId.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
while (it != itemForTouchPointId.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
if (it.value() == item) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
644 |
sceneCurrentTouchPoints.remove(it.key()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
it = itemForTouchPointId.erase(it); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
++it; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
|
0 | 652 |
// Disable selectionChanged() for individual items |
653 |
++selectionChanging; |
|
654 |
int oldSelectedItemsSize = selectedItems.size(); |
|
655 |
||
656 |
// Update selected & hovered item bookkeeping |
|
657 |
selectedItems.remove(item); |
|
658 |
hoverItems.removeAll(item); |
|
659 |
cachedItemsUnderMouse.removeAll(item); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
660 |
if (item->d_ptr->pendingPolish) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
661 |
const int unpolishedIndex = unpolishedItems.indexOf(item); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
662 |
if (unpolishedIndex != -1) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
663 |
unpolishedItems[unpolishedIndex] = 0; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
664 |
item->d_ptr->pendingPolish = false; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
665 |
} |
0 | 666 |
resetDirtyItem(item); |
667 |
||
668 |
//We remove all references of item from the sceneEventFilter arrays |
|
669 |
QMultiMap<QGraphicsItem*, QGraphicsItem*>::iterator iterator = sceneEventFilters.begin(); |
|
670 |
while (iterator != sceneEventFilters.end()) { |
|
671 |
if (iterator.value() == item || iterator.key() == item) |
|
672 |
iterator = sceneEventFilters.erase(iterator); |
|
673 |
else |
|
674 |
++iterator; |
|
675 |
} |
|
676 |
||
677 |
if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal) |
|
678 |
leaveModal(item); |
|
679 |
||
680 |
// Reset the mouse grabber and focus item data. |
|
681 |
if (mouseGrabberItems.contains(item)) |
|
682 |
ungrabMouse(item, /* item is dying */ item->d_ptr->inDestructor); |
|
683 |
||
684 |
// Reset the keyboard grabber |
|
685 |
if (keyboardGrabberItems.contains(item)) |
|
686 |
ungrabKeyboard(item, /* item is dying */ item->d_ptr->inDestructor); |
|
687 |
||
688 |
// Reset the last mouse grabber item |
|
689 |
if (item == lastMouseGrabberItem) |
|
690 |
lastMouseGrabberItem = 0; |
|
691 |
||
692 |
// Reenable selectionChanged() for individual items |
|
693 |
--selectionChanging; |
|
694 |
if (!selectionChanging && selectedItems.size() != oldSelectedItemsSize) |
|
695 |
emit q->selectionChanged(); |
|
696 |
} |
|
697 |
||
698 |
/*! |
|
699 |
\internal |
|
700 |
*/ |
|
701 |
void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent) |
|
702 |
{ |
|
703 |
Q_Q(QGraphicsScene); |
|
704 |
if (item && item->scene() != q) { |
|
705 |
qWarning("QGraphicsScene::setActivePanel: item %p must be part of this scene", |
|
706 |
item); |
|
707 |
return; |
|
708 |
} |
|
709 |
||
710 |
// Ensure the scene has focus when we change panel activation. |
|
711 |
q->setFocus(Qt::ActiveWindowFocusReason); |
|
712 |
||
713 |
// Find the item's panel. |
|
714 |
QGraphicsItem *panel = item ? item->panel() : 0; |
|
715 |
lastActivePanel = panel ? activePanel : 0; |
|
716 |
if (panel == activePanel || (!q->isActive() && !duringActivationEvent)) |
|
717 |
return; |
|
718 |
||
719 |
// Deactivate the last active panel. |
|
720 |
if (activePanel) { |
|
721 |
if (QGraphicsItem *fi = activePanel->focusItem()) { |
|
722 |
// Remove focus from the current focus item. |
|
723 |
if (fi == q->focusItem()) |
|
724 |
q->setFocusItem(0, Qt::ActiveWindowFocusReason); |
|
725 |
} |
|
726 |
||
727 |
QEvent event(QEvent::WindowDeactivate); |
|
728 |
q->sendEvent(activePanel, &event); |
|
729 |
} else if (panel && !duringActivationEvent) { |
|
730 |
// Deactivate the scene if changing activation to a panel. |
|
731 |
QEvent event(QEvent::WindowDeactivate); |
|
732 |
foreach (QGraphicsItem *item, q->items()) { |
|
733 |
if (item->isVisible() && !item->isPanel() && !item->parentItem()) |
|
734 |
q->sendEvent(item, &event); |
|
735 |
} |
|
736 |
} |
|
737 |
||
738 |
// Update activate state. |
|
739 |
activePanel = panel; |
|
740 |
QEvent event(QEvent::ActivationChange); |
|
741 |
QApplication::sendEvent(q, &event); |
|
742 |
||
743 |
// Activate |
|
744 |
if (panel) { |
|
745 |
QEvent event(QEvent::WindowActivate); |
|
746 |
q->sendEvent(panel, &event); |
|
747 |
||
748 |
// Set focus on the panel's focus item. |
|
749 |
if (QGraphicsItem *focusItem = panel->focusItem()) |
|
750 |
focusItem->setFocus(Qt::ActiveWindowFocusReason); |
|
751 |
} else if (q->isActive()) { |
|
752 |
// Activate the scene |
|
753 |
QEvent event(QEvent::WindowActivate); |
|
754 |
foreach (QGraphicsItem *item, q->items()) { |
|
755 |
if (item->isVisible() && !item->isPanel() && !item->parentItem()) |
|
756 |
q->sendEvent(item, &event); |
|
757 |
} |
|
758 |
} |
|
759 |
} |
|
760 |
||
761 |
/*! |
|
762 |
\internal |
|
763 |
*/ |
|
764 |
void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, |
|
765 |
Qt::FocusReason focusReason) |
|
766 |
{ |
|
767 |
Q_Q(QGraphicsScene); |
|
768 |
if (item == focusItem) |
|
769 |
return; |
|
770 |
||
771 |
// Clear focus if asked to set focus on something that can't |
|
772 |
// accept input focus. |
|
773 |
if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable) |
|
774 |
|| !item->isVisible() || !item->isEnabled())) { |
|
775 |
item = 0; |
|
776 |
} |
|
777 |
||
778 |
// Set focus on the scene if an item requests focus. |
|
779 |
if (item) { |
|
780 |
q->setFocus(focusReason); |
|
781 |
if (item == focusItem) |
|
782 |
return; |
|
783 |
} |
|
784 |
||
785 |
if (focusItem) { |
|
786 |
QFocusEvent event(QEvent::FocusOut, focusReason); |
|
787 |
lastFocusItem = focusItem; |
|
788 |
focusItem = 0; |
|
789 |
sendEvent(lastFocusItem, &event); |
|
790 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
#ifndef QT_NO_IM |
0 | 792 |
if (lastFocusItem |
793 |
&& (lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { |
|
794 |
// Reset any visible preedit text |
|
795 |
QInputMethodEvent imEvent; |
|
796 |
sendEvent(lastFocusItem, &imEvent); |
|
797 |
||
798 |
// Close any external input method panel. This happens |
|
799 |
// automatically by removing WA_InputMethodEnabled on |
|
800 |
// the views, but if we are changing focus, we have to |
|
801 |
// do it ourselves. |
|
802 |
if (item) { |
|
803 |
for (int i = 0; i < views.size(); ++i) |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
804 |
if (views.at(i)->inputContext()) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
805 |
views.at(i)->inputContext()->reset(); |
0 | 806 |
} |
807 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
808 |
#endif //QT_NO_IM |
0 | 809 |
} |
810 |
||
811 |
if (item) { |
|
812 |
focusItem = item; |
|
813 |
QFocusEvent event(QEvent::FocusIn, focusReason); |
|
814 |
sendEvent(item, &event); |
|
815 |
} |
|
816 |
||
817 |
updateInputMethodSensitivityInViews(); |
|
818 |
} |
|
819 |
||
820 |
/*! |
|
821 |
\internal |
|
822 |
*/ |
|
823 |
void QGraphicsScenePrivate::addPopup(QGraphicsWidget *widget) |
|
824 |
{ |
|
825 |
Q_ASSERT(widget); |
|
826 |
Q_ASSERT(!popupWidgets.contains(widget)); |
|
827 |
popupWidgets << widget; |
|
828 |
if (QGraphicsWidget *focusWidget = widget->focusWidget()) { |
|
829 |
focusWidget->setFocus(Qt::PopupFocusReason); |
|
830 |
} else { |
|
831 |
grabKeyboard((QGraphicsItem *)widget); |
|
832 |
if (focusItem && popupWidgets.size() == 1) { |
|
833 |
QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason); |
|
834 |
sendEvent(focusItem, &event); |
|
835 |
} |
|
836 |
} |
|
837 |
grabMouse((QGraphicsItem *)widget); |
|
838 |
} |
|
839 |
||
840 |
/*! |
|
841 |
\internal |
|
842 |
||
843 |
Remove \a widget from the popup list. Important notes: |
|
844 |
||
845 |
\a widget is guaranteed to be in the list of popups, but it might not be |
|
846 |
the last entry; you can hide any item in the pop list before the others, |
|
847 |
and this must cause all later mouse grabbers to lose the grab. |
|
848 |
*/ |
|
849 |
void QGraphicsScenePrivate::removePopup(QGraphicsWidget *widget, bool itemIsDying) |
|
850 |
{ |
|
851 |
Q_ASSERT(widget); |
|
852 |
int index = popupWidgets.indexOf(widget); |
|
853 |
Q_ASSERT(index != -1); |
|
854 |
||
855 |
for (int i = popupWidgets.size() - 1; i >= index; --i) { |
|
856 |
QGraphicsWidget *widget = popupWidgets.takeLast(); |
|
857 |
ungrabMouse(widget, itemIsDying); |
|
858 |
if (focusItem && popupWidgets.isEmpty()) { |
|
859 |
QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason); |
|
860 |
sendEvent(focusItem, &event); |
|
861 |
} else if (keyboardGrabberItems.contains(static_cast<QGraphicsItem *>(widget))) { |
|
862 |
ungrabKeyboard(static_cast<QGraphicsItem *>(widget), itemIsDying); |
|
863 |
} |
|
864 |
if (!itemIsDying && widget->isVisible()) { |
|
865 |
widget->hide(); |
|
866 |
widget->QGraphicsItem::d_ptr->explicitlyHidden = 0; |
|
867 |
} |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
/*! |
|
872 |
\internal |
|
873 |
*/ |
|
874 |
void QGraphicsScenePrivate::grabMouse(QGraphicsItem *item, bool implicit) |
|
875 |
{ |
|
876 |
// Append to list of mouse grabber items, and send a mouse grab event. |
|
877 |
if (mouseGrabberItems.contains(item)) { |
|
878 |
if (mouseGrabberItems.last() == item) { |
|
879 |
Q_ASSERT(!implicit); |
|
880 |
if (!lastMouseGrabberItemHasImplicitMouseGrab) { |
|
881 |
qWarning("QGraphicsItem::grabMouse: already a mouse grabber"); |
|
882 |
} else { |
|
883 |
// Upgrade to an explicit mouse grab |
|
884 |
lastMouseGrabberItemHasImplicitMouseGrab = false; |
|
885 |
} |
|
886 |
} else { |
|
887 |
qWarning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p", |
|
888 |
mouseGrabberItems.last()); |
|
889 |
} |
|
890 |
return; |
|
891 |
} |
|
892 |
||
893 |
// Send ungrab event to the last grabber. |
|
894 |
if (!mouseGrabberItems.isEmpty()) { |
|
895 |
QGraphicsItem *last = mouseGrabberItems.last(); |
|
896 |
if (lastMouseGrabberItemHasImplicitMouseGrab) { |
|
897 |
// Implicit mouse grab is immediately lost. |
|
898 |
last->ungrabMouse(); |
|
899 |
} else { |
|
900 |
// Just send ungrab event to current grabber. |
|
901 |
QEvent ungrabEvent(QEvent::UngrabMouse); |
|
902 |
sendEvent(last, &ungrabEvent); |
|
903 |
} |
|
904 |
} |
|
905 |
||
906 |
mouseGrabberItems << item; |
|
907 |
lastMouseGrabberItemHasImplicitMouseGrab = implicit; |
|
908 |
||
909 |
// Send grab event to current grabber. |
|
910 |
QEvent grabEvent(QEvent::GrabMouse); |
|
911 |
sendEvent(item, &grabEvent); |
|
912 |
} |
|
913 |
||
914 |
/*! |
|
915 |
\internal |
|
916 |
*/ |
|
917 |
void QGraphicsScenePrivate::ungrabMouse(QGraphicsItem *item, bool itemIsDying) |
|
918 |
{ |
|
919 |
int index = mouseGrabberItems.indexOf(item); |
|
920 |
if (index == -1) { |
|
921 |
qWarning("QGraphicsItem::ungrabMouse: not a mouse grabber"); |
|
922 |
return; |
|
923 |
} |
|
924 |
||
925 |
if (item != mouseGrabberItems.last()) { |
|
926 |
// Recursively ungrab the next mouse grabber until we reach this item |
|
927 |
// to ensure state consistency. |
|
928 |
ungrabMouse(mouseGrabberItems.at(index + 1), itemIsDying); |
|
929 |
} |
|
930 |
if (!popupWidgets.isEmpty() && item == popupWidgets.last()) { |
|
931 |
// If the item is a popup, go via removePopup to ensure state |
|
932 |
// consistency and that it gets hidden correctly - beware that |
|
933 |
// removePopup() reenters this function to continue removing the grab. |
|
934 |
removePopup((QGraphicsWidget *)item, itemIsDying); |
|
935 |
return; |
|
936 |
} |
|
937 |
||
938 |
// Send notification about mouse ungrab. |
|
939 |
if (!itemIsDying) { |
|
940 |
QEvent event(QEvent::UngrabMouse); |
|
941 |
sendEvent(item, &event); |
|
942 |
} |
|
943 |
||
944 |
// Remove the item from the list of grabbers. Whenever this happens, we |
|
945 |
// reset the implicitGrab (there can be only ever be one implicit grabber |
|
946 |
// in a scene, and it is always the latest grabber; if the implicit grab |
|
947 |
// is lost, it is not automatically regained. |
|
948 |
mouseGrabberItems.takeLast(); |
|
949 |
lastMouseGrabberItemHasImplicitMouseGrab = false; |
|
950 |
||
951 |
// Send notification about mouse regrab. ### It's unfortunate that all the |
|
952 |
// items get a GrabMouse event, but this is a rare case with a simple |
|
953 |
// implementation and it does ensure a consistent state. |
|
954 |
if (!itemIsDying && !mouseGrabberItems.isEmpty()) { |
|
955 |
QGraphicsItem *last = mouseGrabberItems.last(); |
|
956 |
QEvent event(QEvent::GrabMouse); |
|
957 |
sendEvent(last, &event); |
|
958 |
} |
|
959 |
} |
|
960 |
||
961 |
/*! |
|
962 |
\internal |
|
963 |
*/ |
|
964 |
void QGraphicsScenePrivate::clearMouseGrabber() |
|
965 |
{ |
|
966 |
if (!mouseGrabberItems.isEmpty()) |
|
967 |
mouseGrabberItems.first()->ungrabMouse(); |
|
968 |
lastMouseGrabberItem = 0; |
|
969 |
} |
|
970 |
||
971 |
/*! |
|
972 |
\internal |
|
973 |
*/ |
|
974 |
void QGraphicsScenePrivate::grabKeyboard(QGraphicsItem *item) |
|
975 |
{ |
|
976 |
if (keyboardGrabberItems.contains(item)) { |
|
977 |
if (keyboardGrabberItems.last() == item) |
|
978 |
qWarning("QGraphicsItem::grabKeyboard: already a keyboard grabber"); |
|
979 |
else |
|
980 |
qWarning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p", |
|
981 |
keyboardGrabberItems.last()); |
|
982 |
return; |
|
983 |
} |
|
984 |
||
985 |
// Send ungrab event to the last grabber. |
|
986 |
if (!keyboardGrabberItems.isEmpty()) { |
|
987 |
// Just send ungrab event to current grabber. |
|
988 |
QEvent ungrabEvent(QEvent::UngrabKeyboard); |
|
989 |
sendEvent(keyboardGrabberItems.last(), &ungrabEvent); |
|
990 |
} |
|
991 |
||
992 |
keyboardGrabberItems << item; |
|
993 |
||
994 |
// Send grab event to current grabber. |
|
995 |
QEvent grabEvent(QEvent::GrabKeyboard); |
|
996 |
sendEvent(item, &grabEvent); |
|
997 |
} |
|
998 |
||
999 |
/*! |
|
1000 |
\internal |
|
1001 |
*/ |
|
1002 |
void QGraphicsScenePrivate::ungrabKeyboard(QGraphicsItem *item, bool itemIsDying) |
|
1003 |
{ |
|
1004 |
int index = keyboardGrabberItems.lastIndexOf(item); |
|
1005 |
if (index == -1) { |
|
1006 |
qWarning("QGraphicsItem::ungrabKeyboard: not a keyboard grabber"); |
|
1007 |
return; |
|
1008 |
} |
|
1009 |
if (item != keyboardGrabberItems.last()) { |
|
1010 |
// Recursively ungrab the topmost keyboard grabber until we reach this |
|
1011 |
// item to ensure state consistency. |
|
1012 |
ungrabKeyboard(keyboardGrabberItems.at(index + 1), itemIsDying); |
|
1013 |
} |
|
1014 |
||
1015 |
// Send notification about keyboard ungrab. |
|
1016 |
if (!itemIsDying) { |
|
1017 |
QEvent event(QEvent::UngrabKeyboard); |
|
1018 |
sendEvent(item, &event); |
|
1019 |
} |
|
1020 |
||
1021 |
// Remove the item from the list of grabbers. |
|
1022 |
keyboardGrabberItems.takeLast(); |
|
1023 |
||
1024 |
// Send notification about mouse regrab. |
|
1025 |
if (!itemIsDying && !keyboardGrabberItems.isEmpty()) { |
|
1026 |
QGraphicsItem *last = keyboardGrabberItems.last(); |
|
1027 |
QEvent event(QEvent::GrabKeyboard); |
|
1028 |
sendEvent(last, &event); |
|
1029 |
} |
|
1030 |
} |
|
1031 |
||
1032 |
/*! |
|
1033 |
\internal |
|
1034 |
*/ |
|
1035 |
void QGraphicsScenePrivate::clearKeyboardGrabber() |
|
1036 |
{ |
|
1037 |
if (!keyboardGrabberItems.isEmpty()) |
|
1038 |
ungrabKeyboard(keyboardGrabberItems.first()); |
|
1039 |
} |
|
1040 |
||
1041 |
void QGraphicsScenePrivate::enableMouseTrackingOnViews() |
|
1042 |
{ |
|
1043 |
foreach (QGraphicsView *view, views) |
|
1044 |
view->viewport()->setMouseTracking(true); |
|
1045 |
} |
|
1046 |
||
1047 |
/*! |
|
1048 |
Returns all items for the screen position in \a event. |
|
1049 |
*/ |
|
1050 |
QList<QGraphicsItem *> QGraphicsScenePrivate::itemsAtPosition(const QPoint &screenPos, |
|
1051 |
const QPointF &scenePos, |
|
1052 |
QWidget *widget) const |
|
1053 |
{ |
|
1054 |
Q_Q(const QGraphicsScene); |
|
1055 |
QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0; |
|
1056 |
if (!view) |
|
1057 |
return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder, QTransform()); |
|
1058 |
||
1059 |
const QRectF pointRect(QPointF(widget->mapFromGlobal(screenPos)), QSizeF(1, 1)); |
|
1060 |
if (!view->isTransformed()) |
|
1061 |
return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder); |
|
1062 |
||
1063 |
const QTransform viewTransform = view->viewportTransform(); |
|
1064 |
if (viewTransform.type() <= QTransform::TxScale) { |
|
1065 |
return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape, |
|
1066 |
Qt::DescendingOrder, viewTransform); |
|
1067 |
} |
|
1068 |
return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape, |
|
1069 |
Qt::DescendingOrder, viewTransform); |
|
1070 |
} |
|
1071 |
||
1072 |
/*! |
|
1073 |
\internal |
|
1074 |
*/ |
|
1075 |
void QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event) |
|
1076 |
{ |
|
1077 |
for (int i = 0x1; i <= 0x10; i <<= 1) { |
|
1078 |
if (event->buttons() & i) { |
|
1079 |
mouseGrabberButtonDownPos.insert(Qt::MouseButton(i), |
|
1080 |
mouseGrabberItems.last()->d_ptr->genericMapFromScene(event->scenePos(), |
|
1081 |
event->widget())); |
|
1082 |
mouseGrabberButtonDownScenePos.insert(Qt::MouseButton(i), event->scenePos()); |
|
1083 |
mouseGrabberButtonDownScreenPos.insert(Qt::MouseButton(i), event->screenPos()); |
|
1084 |
} |
|
1085 |
} |
|
1086 |
} |
|
1087 |
||
1088 |
/*! |
|
1089 |
\internal |
|
1090 |
*/ |
|
1091 |
void QGraphicsScenePrivate::installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) |
|
1092 |
{ |
|
1093 |
sceneEventFilters.insert(watched, filter); |
|
1094 |
} |
|
1095 |
||
1096 |
/*! |
|
1097 |
\internal |
|
1098 |
*/ |
|
1099 |
void QGraphicsScenePrivate::removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) |
|
1100 |
{ |
|
1101 |
if (!sceneEventFilters.contains(watched)) |
|
1102 |
return; |
|
1103 |
||
1104 |
QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(watched); |
|
1105 |
QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(watched); |
|
1106 |
do { |
|
1107 |
if (it.value() == filter) |
|
1108 |
it = sceneEventFilters.erase(it); |
|
1109 |
else |
|
1110 |
++it; |
|
1111 |
} while (it != end); |
|
1112 |
} |
|
1113 |
||
1114 |
/*! |
|
1115 |
\internal |
|
1116 |
*/ |
|
1117 |
bool QGraphicsScenePrivate::filterDescendantEvent(QGraphicsItem *item, QEvent *event) |
|
1118 |
{ |
|
1119 |
if (item && (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents)) { |
|
1120 |
QGraphicsItem *parent = item->parentItem(); |
|
1121 |
while (parent) { |
|
1122 |
if (parent->d_ptr->filtersDescendantEvents && parent->sceneEventFilter(item, event)) |
|
1123 |
return true; |
|
1124 |
if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents)) |
|
1125 |
return false; |
|
1126 |
parent = parent->parentItem(); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
return false; |
|
1130 |
} |
|
1131 |
||
1132 |
/*! |
|
1133 |
\internal |
|
1134 |
*/ |
|
1135 |
bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) |
|
1136 |
{ |
|
1137 |
if (item && !sceneEventFilters.contains(item)) |
|
1138 |
return false; |
|
1139 |
||
1140 |
QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(item); |
|
1141 |
QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(item); |
|
1142 |
while (it != end) { |
|
1143 |
// ### The filterer and filteree might both be deleted. |
|
1144 |
if (it.value()->sceneEventFilter(it.key(), event)) |
|
1145 |
return true; |
|
1146 |
++it; |
|
1147 |
} |
|
1148 |
return false; |
|
1149 |
} |
|
1150 |
||
1151 |
/*! |
|
1152 |
\internal |
|
1153 |
||
1154 |
This is the final dispatch point for any events from the scene to the |
|
1155 |
item. It filters the event first - if the filter returns true, the event |
|
1156 |
is considered to have been eaten by the filter, and is therefore stopped |
|
1157 |
(the default filter returns false). Then/otherwise, if the item is |
|
1158 |
enabled, the event is sent; otherwise it is stopped. |
|
1159 |
*/ |
|
1160 |
bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) |
|
1161 |
{ |
|
1162 |
if (QGraphicsObject *object = item->toGraphicsObject()) { |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1163 |
QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1164 |
if (gestureManager) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1165 |
if (gestureManager->filterEvent(object, event)) |
0 | 1166 |
return true; |
1167 |
} |
|
1168 |
} |
|
1169 |
||
1170 |
if (filterEvent(item, event)) |
|
1171 |
return false; |
|
1172 |
if (filterDescendantEvent(item, event)) |
|
1173 |
return false; |
|
1174 |
if (!item || !item->isEnabled()) |
|
1175 |
return false; |
|
1176 |
if (QGraphicsObject *o = item->toGraphicsObject()) { |
|
1177 |
bool spont = event->spontaneous(); |
|
1178 |
if (spont ? qt_sendSpontaneousEvent(o, event) : QApplication::sendEvent(o, event)) |
|
1179 |
return true; |
|
1180 |
event->spont = spont; |
|
1181 |
} |
|
1182 |
return item->sceneEvent(event); |
|
1183 |
} |
|
1184 |
||
1185 |
/*! |
|
1186 |
\internal |
|
1187 |
*/ |
|
1188 |
void QGraphicsScenePrivate::cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest, |
|
1189 |
QGraphicsSceneDragDropEvent *source) |
|
1190 |
{ |
|
1191 |
dest->setWidget(source->widget()); |
|
1192 |
dest->setPos(source->pos()); |
|
1193 |
dest->setScenePos(source->scenePos()); |
|
1194 |
dest->setScreenPos(source->screenPos()); |
|
1195 |
dest->setButtons(source->buttons()); |
|
1196 |
dest->setModifiers(source->modifiers()); |
|
1197 |
dest->setPossibleActions(source->possibleActions()); |
|
1198 |
dest->setProposedAction(source->proposedAction()); |
|
1199 |
dest->setDropAction(source->dropAction()); |
|
1200 |
dest->setSource(source->source()); |
|
1201 |
dest->setMimeData(source->mimeData()); |
|
1202 |
} |
|
1203 |
||
1204 |
/*! |
|
1205 |
\internal |
|
1206 |
*/ |
|
1207 |
void QGraphicsScenePrivate::sendDragDropEvent(QGraphicsItem *item, |
|
1208 |
QGraphicsSceneDragDropEvent *dragDropEvent) |
|
1209 |
{ |
|
1210 |
dragDropEvent->setPos(item->d_ptr->genericMapFromScene(dragDropEvent->scenePos(), dragDropEvent->widget())); |
|
1211 |
sendEvent(item, dragDropEvent); |
|
1212 |
} |
|
1213 |
||
1214 |
/*! |
|
1215 |
\internal |
|
1216 |
*/ |
|
1217 |
void QGraphicsScenePrivate::sendHoverEvent(QEvent::Type type, QGraphicsItem *item, |
|
1218 |
QGraphicsSceneHoverEvent *hoverEvent) |
|
1219 |
{ |
|
1220 |
QGraphicsSceneHoverEvent event(type); |
|
1221 |
event.setWidget(hoverEvent->widget()); |
|
1222 |
event.setPos(item->d_ptr->genericMapFromScene(hoverEvent->scenePos(), hoverEvent->widget())); |
|
1223 |
event.setScenePos(hoverEvent->scenePos()); |
|
1224 |
event.setScreenPos(hoverEvent->screenPos()); |
|
1225 |
event.setLastPos(item->d_ptr->genericMapFromScene(hoverEvent->lastScenePos(), hoverEvent->widget())); |
|
1226 |
event.setLastScenePos(hoverEvent->lastScenePos()); |
|
1227 |
event.setLastScreenPos(hoverEvent->lastScreenPos()); |
|
1228 |
event.setModifiers(hoverEvent->modifiers()); |
|
1229 |
sendEvent(item, &event); |
|
1230 |
} |
|
1231 |
||
1232 |
/*! |
|
1233 |
\internal |
|
1234 |
*/ |
|
1235 |
void QGraphicsScenePrivate::sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent) |
|
1236 |
{ |
|
1237 |
if (mouseEvent->button() == 0 && mouseEvent->buttons() == 0 && lastMouseGrabberItemHasImplicitMouseGrab) { |
|
1238 |
// ### This is a temporary fix for until we get proper mouse |
|
1239 |
// grab events. |
|
1240 |
clearMouseGrabber(); |
|
1241 |
return; |
|
1242 |
} |
|
1243 |
||
1244 |
QGraphicsItem *item = mouseGrabberItems.last(); |
|
1245 |
if (item->isBlockedByModalPanel()) |
|
1246 |
return; |
|
1247 |
||
1248 |
for (int i = 0x1; i <= 0x10; i <<= 1) { |
|
1249 |
Qt::MouseButton button = Qt::MouseButton(i); |
|
1250 |
mouseEvent->setButtonDownPos(button, mouseGrabberButtonDownPos.value(button, item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget()))); |
|
1251 |
mouseEvent->setButtonDownScenePos(button, mouseGrabberButtonDownScenePos.value(button, mouseEvent->scenePos())); |
|
1252 |
mouseEvent->setButtonDownScreenPos(button, mouseGrabberButtonDownScreenPos.value(button, mouseEvent->screenPos())); |
|
1253 |
} |
|
1254 |
mouseEvent->setPos(item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget())); |
|
1255 |
mouseEvent->setLastPos(item->d_ptr->genericMapFromScene(mouseEvent->lastScenePos(), mouseEvent->widget())); |
|
1256 |
sendEvent(item, mouseEvent); |
|
1257 |
} |
|
1258 |
||
1259 |
/*! |
|
1260 |
\internal |
|
1261 |
*/ |
|
1262 |
void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent) |
|
1263 |
{ |
|
1264 |
Q_Q(QGraphicsScene); |
|
1265 |
||
1266 |
// Ignore by default, unless we find a mouse grabber that accepts it. |
|
1267 |
mouseEvent->ignore(); |
|
1268 |
||
1269 |
// Deliver to any existing mouse grabber. |
|
1270 |
if (!mouseGrabberItems.isEmpty()) { |
|
1271 |
if (mouseGrabberItems.last()->isBlockedByModalPanel()) |
|
1272 |
return; |
|
1273 |
// The event is ignored by default, but we disregard the event's |
|
1274 |
// accepted state after delivery; the mouse is grabbed, after all. |
|
1275 |
sendMouseEvent(mouseEvent); |
|
1276 |
return; |
|
1277 |
} |
|
1278 |
||
1279 |
// Start by determining the number of items at the current position. |
|
1280 |
// Reuse value from earlier calculations if possible. |
|
1281 |
if (cachedItemsUnderMouse.isEmpty()) { |
|
1282 |
cachedItemsUnderMouse = itemsAtPosition(mouseEvent->screenPos(), |
|
1283 |
mouseEvent->scenePos(), |
|
1284 |
mouseEvent->widget()); |
|
1285 |
} |
|
1286 |
||
1287 |
// Update window activation. |
|
1288 |
QGraphicsItem *topItem = cachedItemsUnderMouse.value(0); |
|
1289 |
QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0; |
|
1290 |
if (newActiveWindow && newActiveWindow->isBlockedByModalPanel(&topItem)) { |
|
1291 |
// pass activation to the blocking modal window |
|
1292 |
newActiveWindow = topItem ? topItem->window() : 0; |
|
1293 |
} |
|
1294 |
||
1295 |
if (newActiveWindow != q->activeWindow()) |
|
1296 |
q->setActiveWindow(newActiveWindow); |
|
1297 |
||
1298 |
// Set focus on the topmost enabled item that can take focus. |
|
1299 |
bool setFocus = false; |
|
1300 |
foreach (QGraphicsItem *item, cachedItemsUnderMouse) { |
|
1301 |
if (item->isBlockedByModalPanel()) { |
|
1302 |
// Make sure we don't clear focus. |
|
1303 |
setFocus = true; |
|
1304 |
break; |
|
1305 |
} |
|
1306 |
if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) { |
|
1307 |
if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) { |
|
1308 |
setFocus = true; |
|
1309 |
if (item != q->focusItem()) |
|
1310 |
q->setFocusItem(item, Qt::MouseFocusReason); |
|
1311 |
break; |
|
1312 |
} |
|
1313 |
} |
|
1314 |
if (item->isPanel()) |
|
1315 |
break; |
|
1316 |
} |
|
1317 |
||
1318 |
// Check for scene modality. |
|
1319 |
bool sceneModality = false; |
|
1320 |
for (int i = 0; i < modalPanels.size(); ++i) { |
|
1321 |
if (modalPanels.at(i)->panelModality() == QGraphicsItem::SceneModal) { |
|
1322 |
sceneModality = true; |
|
1323 |
break; |
|
1324 |
} |
|
1325 |
} |
|
1326 |
||
1327 |
// If nobody could take focus, clear it. |
|
1328 |
if (!stickyFocus && !setFocus && !sceneModality) |
|
1329 |
q->setFocusItem(0, Qt::MouseFocusReason); |
|
1330 |
||
1331 |
// Any item will do. |
|
1332 |
if (sceneModality && cachedItemsUnderMouse.isEmpty()) |
|
1333 |
cachedItemsUnderMouse << modalPanels.first(); |
|
1334 |
||
1335 |
// Find a mouse grabber by sending mouse press events to all mouse grabber |
|
1336 |
// candidates one at a time, until the event is accepted. It's accepted by |
|
1337 |
// default, so the receiver has to explicitly ignore it for it to pass |
|
1338 |
// through. |
|
1339 |
foreach (QGraphicsItem *item, cachedItemsUnderMouse) { |
|
1340 |
if (!(item->acceptedMouseButtons() & mouseEvent->button())) { |
|
1341 |
// Skip items that don't accept the event's mouse button. |
|
1342 |
continue; |
|
1343 |
} |
|
1344 |
||
1345 |
// Check if this item is blocked by a modal panel and deliver the mouse event to the |
|
1346 |
// blocking panel instead of this item if blocked. |
|
1347 |
(void) item->isBlockedByModalPanel(&item); |
|
1348 |
||
1349 |
grabMouse(item, /* implicit = */ true); |
|
1350 |
mouseEvent->accept(); |
|
1351 |
||
1352 |
// check if the item we are sending to are disabled (before we send the event) |
|
1353 |
bool disabled = !item->isEnabled(); |
|
1354 |
bool isPanel = item->isPanel(); |
|
1355 |
if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick |
|
1356 |
&& item != lastMouseGrabberItem && lastMouseGrabberItem) { |
|
1357 |
// If this item is different from the item that received the last |
|
1358 |
// mouse event, and mouseEvent is a doubleclick event, then the |
|
1359 |
// event is converted to a press. Known limitation: |
|
1360 |
// Triple-clicking will not generate a doubleclick, though. |
|
1361 |
QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress); |
|
1362 |
mousePress.spont = mouseEvent->spont; |
|
1363 |
mousePress.accept(); |
|
1364 |
mousePress.setButton(mouseEvent->button()); |
|
1365 |
mousePress.setButtons(mouseEvent->buttons()); |
|
1366 |
mousePress.setScreenPos(mouseEvent->screenPos()); |
|
1367 |
mousePress.setScenePos(mouseEvent->scenePos()); |
|
1368 |
mousePress.setModifiers(mouseEvent->modifiers()); |
|
1369 |
mousePress.setWidget(mouseEvent->widget()); |
|
1370 |
mousePress.setButtonDownPos(mouseEvent->button(), |
|
1371 |
mouseEvent->buttonDownPos(mouseEvent->button())); |
|
1372 |
mousePress.setButtonDownScenePos(mouseEvent->button(), |
|
1373 |
mouseEvent->buttonDownScenePos(mouseEvent->button())); |
|
1374 |
mousePress.setButtonDownScreenPos(mouseEvent->button(), |
|
1375 |
mouseEvent->buttonDownScreenPos(mouseEvent->button())); |
|
1376 |
sendMouseEvent(&mousePress); |
|
1377 |
mouseEvent->setAccepted(mousePress.isAccepted()); |
|
1378 |
} else { |
|
1379 |
sendMouseEvent(mouseEvent); |
|
1380 |
} |
|
1381 |
||
1382 |
bool dontSendUngrabEvents = mouseGrabberItems.isEmpty() || mouseGrabberItems.last() != item; |
|
1383 |
if (disabled) { |
|
1384 |
ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); |
|
1385 |
break; |
|
1386 |
} |
|
1387 |
if (mouseEvent->isAccepted()) { |
|
1388 |
if (!mouseGrabberItems.isEmpty()) |
|
1389 |
storeMouseButtonsForMouseGrabber(mouseEvent); |
|
1390 |
lastMouseGrabberItem = item; |
|
1391 |
return; |
|
1392 |
} |
|
1393 |
ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); |
|
1394 |
||
1395 |
// Don't propagate through panels. |
|
1396 |
if (isPanel) |
|
1397 |
break; |
|
1398 |
} |
|
1399 |
||
1400 |
// Is the event still ignored? Then the mouse press goes to the scene. |
|
1401 |
// Reset the mouse grabber, clear the selection, clear focus, and leave |
|
1402 |
// the event ignored so that it can propagate through the originating |
|
1403 |
// view. |
|
1404 |
if (!mouseEvent->isAccepted()) { |
|
1405 |
clearMouseGrabber(); |
|
1406 |
||
1407 |
QGraphicsView *view = mouseEvent->widget() ? qobject_cast<QGraphicsView *>(mouseEvent->widget()->parentWidget()) : 0; |
|
1408 |
bool dontClearSelection = view && view->dragMode() == QGraphicsView::ScrollHandDrag; |
|
1409 |
if (!dontClearSelection) { |
|
1410 |
// Clear the selection if the originating view isn't in scroll |
|
1411 |
// hand drag mode. The view will clear the selection if no drag |
|
1412 |
// happened. |
|
1413 |
q->clearSelection(); |
|
1414 |
} |
|
1415 |
} |
|
1416 |
} |
|
1417 |
||
1418 |
/*! |
|
1419 |
\internal |
|
1420 |
||
1421 |
Ensures that the list of toplevels is sorted by insertion order, and that |
|
1422 |
the siblingIndexes are packed (no gaps), and start at 0. |
|
1423 |
||
1424 |
### This function is almost identical to |
|
1425 |
QGraphicsItemPrivate::ensureSequentialSiblingIndex(). |
|
1426 |
*/ |
|
1427 |
void QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes() |
|
1428 |
{ |
|
1429 |
if (!topLevelSequentialOrdering) { |
|
1430 |
qSort(topLevelItems.begin(), topLevelItems.end(), QGraphicsItemPrivate::insertionOrder); |
|
1431 |
topLevelSequentialOrdering = true; |
|
1432 |
needSortTopLevelItems = 1; |
|
1433 |
} |
|
1434 |
if (holesInTopLevelSiblingIndex) { |
|
1435 |
holesInTopLevelSiblingIndex = 0; |
|
1436 |
for (int i = 0; i < topLevelItems.size(); ++i) |
|
1437 |
topLevelItems[i]->d_ptr->siblingIndex = i; |
|
1438 |
} |
|
1439 |
} |
|
1440 |
||
1441 |
/*! |
|
1442 |
\internal |
|
1443 |
||
1444 |
Set the font and propagate the changes if the font is different from the |
|
1445 |
current font. |
|
1446 |
*/ |
|
1447 |
void QGraphicsScenePrivate::setFont_helper(const QFont &font) |
|
1448 |
{ |
|
1449 |
if (this->font == font && this->font.resolve() == font.resolve()) |
|
1450 |
return; |
|
1451 |
updateFont(font); |
|
1452 |
} |
|
1453 |
||
1454 |
/*! |
|
1455 |
\internal |
|
1456 |
||
1457 |
Resolve the scene's font against the application font, and propagate the |
|
1458 |
changes too all items in the scene. |
|
1459 |
*/ |
|
1460 |
void QGraphicsScenePrivate::resolveFont() |
|
1461 |
{ |
|
1462 |
QFont naturalFont = QApplication::font(); |
|
1463 |
naturalFont.resolve(0); |
|
1464 |
QFont resolvedFont = font.resolve(naturalFont); |
|
1465 |
updateFont(resolvedFont); |
|
1466 |
} |
|
1467 |
||
1468 |
/*! |
|
1469 |
\internal |
|
1470 |
||
1471 |
Update the font, and whether or not it has changed, reresolve all fonts in |
|
1472 |
the scene. |
|
1473 |
*/ |
|
1474 |
void QGraphicsScenePrivate::updateFont(const QFont &font) |
|
1475 |
{ |
|
1476 |
Q_Q(QGraphicsScene); |
|
1477 |
||
1478 |
// Update local font setting. |
|
1479 |
this->font = font; |
|
1480 |
||
1481 |
// Resolve the fonts of all top-level widget items, or widget items |
|
1482 |
// whose parent is not a widget. |
|
1483 |
foreach (QGraphicsItem *item, q->items()) { |
|
1484 |
if (!item->parentItem()) { |
|
1485 |
// Resolvefont for an item is a noop operation, but |
|
1486 |
// every item can be a widget, or can have a widget |
|
1487 |
// childre. |
|
1488 |
item->d_ptr->resolveFont(font.resolve()); |
|
1489 |
} |
|
1490 |
} |
|
1491 |
||
1492 |
// Send the scene a FontChange event. |
|
1493 |
QEvent event(QEvent::FontChange); |
|
1494 |
QApplication::sendEvent(q, &event); |
|
1495 |
} |
|
1496 |
||
1497 |
/*! |
|
1498 |
\internal |
|
1499 |
||
1500 |
Set the palette and propagate the changes if the palette is different from |
|
1501 |
the current palette. |
|
1502 |
*/ |
|
1503 |
void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette) |
|
1504 |
{ |
|
1505 |
if (this->palette == palette && this->palette.resolve() == palette.resolve()) |
|
1506 |
return; |
|
1507 |
updatePalette(palette); |
|
1508 |
} |
|
1509 |
||
1510 |
/*! |
|
1511 |
\internal |
|
1512 |
||
1513 |
Resolve the scene's palette against the application palette, and propagate |
|
1514 |
the changes too all items in the scene. |
|
1515 |
*/ |
|
1516 |
void QGraphicsScenePrivate::resolvePalette() |
|
1517 |
{ |
|
1518 |
QPalette naturalPalette = QApplication::palette(); |
|
1519 |
naturalPalette.resolve(0); |
|
1520 |
QPalette resolvedPalette = palette.resolve(naturalPalette); |
|
1521 |
updatePalette(resolvedPalette); |
|
1522 |
} |
|
1523 |
||
1524 |
/*! |
|
1525 |
\internal |
|
1526 |
||
1527 |
Update the palette, and whether or not it has changed, reresolve all |
|
1528 |
palettes in the scene. |
|
1529 |
*/ |
|
1530 |
void QGraphicsScenePrivate::updatePalette(const QPalette &palette) |
|
1531 |
{ |
|
1532 |
Q_Q(QGraphicsScene); |
|
1533 |
||
1534 |
// Update local palette setting. |
|
1535 |
this->palette = palette; |
|
1536 |
||
1537 |
// Resolve the palettes of all top-level widget items, or widget items |
|
1538 |
// whose parent is not a widget. |
|
1539 |
foreach (QGraphicsItem *item, q->items()) { |
|
1540 |
if (!item->parentItem()) { |
|
1541 |
// Resolvefont for an item is a noop operation, but |
|
1542 |
// every item can be a widget, or can have a widget |
|
1543 |
// childre. |
|
1544 |
item->d_ptr->resolvePalette(palette.resolve()); |
|
1545 |
} |
|
1546 |
} |
|
1547 |
||
1548 |
// Send the scene a PaletteChange event. |
|
1549 |
QEvent event(QEvent::PaletteChange); |
|
1550 |
QApplication::sendEvent(q, &event); |
|
1551 |
} |
|
1552 |
||
1553 |
/*! |
|
1554 |
Constructs a QGraphicsScene object. The \a parent parameter is |
|
1555 |
passed to QObject's constructor. |
|
1556 |
*/ |
|
1557 |
QGraphicsScene::QGraphicsScene(QObject *parent) |
|
1558 |
: QObject(*new QGraphicsScenePrivate, parent) |
|
1559 |
{ |
|
1560 |
d_func()->init(); |
|
1561 |
} |
|
1562 |
||
1563 |
/*! |
|
1564 |
Constructs a QGraphicsScene object, using \a sceneRect for its |
|
1565 |
scene rectangle. The \a parent parameter is passed to QObject's |
|
1566 |
constructor. |
|
1567 |
||
1568 |
\sa sceneRect |
|
1569 |
*/ |
|
1570 |
QGraphicsScene::QGraphicsScene(const QRectF &sceneRect, QObject *parent) |
|
1571 |
: QObject(*new QGraphicsScenePrivate, parent) |
|
1572 |
{ |
|
1573 |
d_func()->init(); |
|
1574 |
setSceneRect(sceneRect); |
|
1575 |
} |
|
1576 |
||
1577 |
/*! |
|
1578 |
Constructs a QGraphicsScene object, using the rectangle specified |
|
1579 |
by (\a x, \a y), and the given \a width and \a height for its |
|
1580 |
scene rectangle. The \a parent parameter is passed to QObject's |
|
1581 |
constructor. |
|
1582 |
||
1583 |
\sa sceneRect |
|
1584 |
*/ |
|
1585 |
QGraphicsScene::QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent) |
|
1586 |
: QObject(*new QGraphicsScenePrivate, parent) |
|
1587 |
{ |
|
1588 |
d_func()->init(); |
|
1589 |
setSceneRect(x, y, width, height); |
|
1590 |
} |
|
1591 |
||
1592 |
/*! |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1593 |
Removes and deletes all items from the scene object |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1594 |
before destroying the scene object. The scene object |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1595 |
is removed from the application's global scene list, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1596 |
and it is removed from all associated views. |
0 | 1597 |
*/ |
1598 |
QGraphicsScene::~QGraphicsScene() |
|
1599 |
{ |
|
1600 |
Q_D(QGraphicsScene); |
|
1601 |
||
1602 |
// Remove this scene from qApp's global scene list. |
|
1603 |
qApp->d_func()->scene_list.removeAll(this); |
|
1604 |
||
1605 |
clear(); |
|
1606 |
||
1607 |
// Remove this scene from all associated views. |
|
1608 |
for (int j = 0; j < d->views.size(); ++j) |
|
1609 |
d->views.at(j)->setScene(0); |
|
1610 |
} |
|
1611 |
||
1612 |
/*! |
|
1613 |
\property QGraphicsScene::sceneRect |
|
1614 |
\brief the scene rectangle; the bounding rectangle of the scene |
|
1615 |
||
1616 |
The scene rectangle defines the extent of the scene. It is |
|
1617 |
primarily used by QGraphicsView to determine the view's default |
|
1618 |
scrollable area, and by QGraphicsScene to manage item indexing. |
|
1619 |
||
1620 |
If unset, or if set to a null QRectF, sceneRect() will return the largest |
|
1621 |
bounding rect of all items on the scene since the scene was created (i.e., |
|
1622 |
a rectangle that grows when items are added to or moved in the scene, but |
|
1623 |
never shrinks). |
|
1624 |
||
1625 |
\sa width(), height(), QGraphicsView::sceneRect |
|
1626 |
*/ |
|
1627 |
QRectF QGraphicsScene::sceneRect() const |
|
1628 |
{ |
|
1629 |
Q_D(const QGraphicsScene); |
|
1630 |
if (d->hasSceneRect) |
|
1631 |
return d->sceneRect; |
|
1632 |
||
1633 |
if (d->dirtyGrowingItemsBoundingRect) { |
|
1634 |
// Lazily update the growing items bounding rect |
|
1635 |
QGraphicsScenePrivate *thatd = const_cast<QGraphicsScenePrivate *>(d); |
|
1636 |
QRectF oldGrowingBoundingRect = thatd->growingItemsBoundingRect; |
|
1637 |
thatd->growingItemsBoundingRect |= itemsBoundingRect(); |
|
1638 |
thatd->dirtyGrowingItemsBoundingRect = false; |
|
1639 |
if (oldGrowingBoundingRect != thatd->growingItemsBoundingRect) |
|
1640 |
emit const_cast<QGraphicsScene *>(this)->sceneRectChanged(thatd->growingItemsBoundingRect); |
|
1641 |
} |
|
1642 |
return d->growingItemsBoundingRect; |
|
1643 |
} |
|
1644 |
void QGraphicsScene::setSceneRect(const QRectF &rect) |
|
1645 |
{ |
|
1646 |
Q_D(QGraphicsScene); |
|
1647 |
if (rect != d->sceneRect) { |
|
1648 |
d->hasSceneRect = !rect.isNull(); |
|
1649 |
d->sceneRect = rect; |
|
1650 |
emit sceneRectChanged(d->hasSceneRect ? rect : d->growingItemsBoundingRect); |
|
1651 |
} |
|
1652 |
} |
|
1653 |
||
1654 |
/*! |
|
1655 |
\fn qreal QGraphicsScene::width() const |
|
1656 |
||
1657 |
This convenience function is equivalent to calling sceneRect().width(). |
|
1658 |
||
1659 |
\sa height() |
|
1660 |
*/ |
|
1661 |
||
1662 |
/*! |
|
1663 |
\fn qreal QGraphicsScene::height() const |
|
1664 |
||
1665 |
This convenience function is equivalent to calling \c sceneRect().height(). |
|
1666 |
||
1667 |
\sa width() |
|
1668 |
*/ |
|
1669 |
||
1670 |
/*! |
|
1671 |
Renders the \a source rect from scene into \a target, using \a painter. This |
|
1672 |
function is useful for capturing the contents of the scene onto a paint |
|
1673 |
device, such as a QImage (e.g., to take a screenshot), or for printing |
|
1674 |
with QPrinter. For example: |
|
1675 |
||
1676 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 1 |
|
1677 |
||
1678 |
If \a source is a null rect, this function will use sceneRect() to |
|
1679 |
determine what to render. If \a target is a null rect, the dimensions of \a |
|
1680 |
painter's paint device will be used. |
|
1681 |
||
1682 |
The source rect contents will be transformed according to \a |
|
1683 |
aspectRatioMode to fit into the target rect. By default, the aspect ratio |
|
1684 |
is kept, and \a source is scaled to fit in \a target. |
|
1685 |
||
1686 |
\sa QGraphicsView::render() |
|
1687 |
*/ |
|
1688 |
void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRectF &source, |
|
1689 |
Qt::AspectRatioMode aspectRatioMode) |
|
1690 |
{ |
|
1691 |
// ### Switch to using the recursive rendering algorithm instead. |
|
1692 |
||
1693 |
// Default source rect = scene rect |
|
1694 |
QRectF sourceRect = source; |
|
1695 |
if (sourceRect.isNull()) |
|
1696 |
sourceRect = sceneRect(); |
|
1697 |
||
1698 |
// Default target rect = device rect |
|
1699 |
QRectF targetRect = target; |
|
1700 |
if (targetRect.isNull()) { |
|
1701 |
if (painter->device()->devType() == QInternal::Picture) |
|
1702 |
targetRect = sourceRect; |
|
1703 |
else |
|
1704 |
targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); |
|
1705 |
} |
|
1706 |
||
1707 |
// Find the ideal x / y scaling ratio to fit \a source into \a target. |
|
1708 |
qreal xratio = targetRect.width() / sourceRect.width(); |
|
1709 |
qreal yratio = targetRect.height() / sourceRect.height(); |
|
1710 |
||
1711 |
// Scale according to the aspect ratio mode. |
|
1712 |
switch (aspectRatioMode) { |
|
1713 |
case Qt::KeepAspectRatio: |
|
1714 |
xratio = yratio = qMin(xratio, yratio); |
|
1715 |
break; |
|
1716 |
case Qt::KeepAspectRatioByExpanding: |
|
1717 |
xratio = yratio = qMax(xratio, yratio); |
|
1718 |
break; |
|
1719 |
case Qt::IgnoreAspectRatio: |
|
1720 |
break; |
|
1721 |
} |
|
1722 |
||
1723 |
// Find all items to draw, and reverse the list (we want to draw |
|
1724 |
// in reverse order). |
|
1725 |
QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect); |
|
1726 |
QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()]; |
|
1727 |
int numItems = itemList.size(); |
|
1728 |
for (int i = 0; i < numItems; ++i) |
|
1729 |
itemArray[numItems - i - 1] = itemList.at(i); |
|
1730 |
itemList.clear(); |
|
1731 |
||
1732 |
painter->save(); |
|
1733 |
||
1734 |
// Transform the painter. |
|
1735 |
painter->setClipRect(targetRect); |
|
1736 |
QTransform painterTransform; |
|
1737 |
painterTransform *= QTransform() |
|
1738 |
.translate(targetRect.left(), targetRect.top()) |
|
1739 |
.scale(xratio, yratio) |
|
1740 |
.translate(-sourceRect.left(), -sourceRect.top()); |
|
1741 |
painter->setWorldTransform(painterTransform, true); |
|
1742 |
||
1743 |
// Two unit vectors. |
|
1744 |
QLineF v1(0, 0, 1, 0); |
|
1745 |
QLineF v2(0, 0, 0, 1); |
|
1746 |
||
1747 |
// Generate the style options |
|
1748 |
QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems]; |
|
1749 |
for (int i = 0; i < numItems; ++i) |
|
1750 |
itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect()); |
|
1751 |
||
1752 |
// Render the scene. |
|
1753 |
drawBackground(painter, sourceRect); |
|
1754 |
drawItems(painter, numItems, itemArray, styleOptionArray); |
|
1755 |
drawForeground(painter, sourceRect); |
|
1756 |
||
1757 |
delete [] itemArray; |
|
1758 |
delete [] styleOptionArray; |
|
1759 |
||
1760 |
painter->restore(); |
|
1761 |
} |
|
1762 |
||
1763 |
/*! |
|
1764 |
\property QGraphicsScene::itemIndexMethod |
|
1765 |
\brief the item indexing method. |
|
1766 |
||
1767 |
QGraphicsScene applies an indexing algorithm to the scene, to speed up |
|
1768 |
item discovery functions like items() and itemAt(). Indexing is most |
|
1769 |
efficient for static scenes (i.e., where items don't move around). For |
|
1770 |
dynamic scenes, or scenes with many animated items, the index bookkeeping |
|
1771 |
can outweight the fast lookup speeds. |
|
1772 |
||
1773 |
For the common case, the default index method BspTreeIndex works fine. If |
|
1774 |
your scene uses many animations and you are experiencing slowness, you can |
|
1775 |
disable indexing by calling \c setItemIndexMethod(NoIndex). |
|
1776 |
||
1777 |
\sa bspTreeDepth |
|
1778 |
*/ |
|
1779 |
QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod() const |
|
1780 |
{ |
|
1781 |
Q_D(const QGraphicsScene); |
|
1782 |
return d->indexMethod; |
|
1783 |
} |
|
1784 |
void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method) |
|
1785 |
{ |
|
1786 |
Q_D(QGraphicsScene); |
|
1787 |
if (d->indexMethod == method) |
|
1788 |
return; |
|
1789 |
||
1790 |
d->indexMethod = method; |
|
1791 |
||
1792 |
QList<QGraphicsItem *> oldItems = d->index->items(Qt::DescendingOrder); |
|
1793 |
delete d->index; |
|
1794 |
if (method == BspTreeIndex) |
|
1795 |
d->index = new QGraphicsSceneBspTreeIndex(this); |
|
1796 |
else |
|
1797 |
d->index = new QGraphicsSceneLinearIndex(this); |
|
1798 |
for (int i = oldItems.size() - 1; i >= 0; --i) |
|
1799 |
d->index->addItem(oldItems.at(i)); |
|
1800 |
} |
|
1801 |
||
1802 |
/*! |
|
1803 |
\property QGraphicsScene::bspTreeDepth |
|
1804 |
\brief the depth of QGraphicsScene's BSP index tree |
|
1805 |
\since 4.3 |
|
1806 |
||
1807 |
This property has no effect when NoIndex is used. |
|
1808 |
||
1809 |
This value determines the depth of QGraphicsScene's BSP tree. The depth |
|
1810 |
directly affects QGraphicsScene's performance and memory usage; the latter |
|
1811 |
growing exponentially with the depth of the tree. With an optimal tree |
|
1812 |
depth, QGraphicsScene can instantly determine the locality of items, even |
|
1813 |
for scenes with thousands or millions of items. This also greatly improves |
|
1814 |
rendering performance. |
|
1815 |
||
1816 |
By default, the value is 0, in which case Qt will guess a reasonable |
|
1817 |
default depth based on the size, location and number of items in the |
|
1818 |
scene. If these parameters change frequently, however, you may experience |
|
1819 |
slowdowns as QGraphicsScene retunes the depth internally. You can avoid |
|
1820 |
potential slowdowns by fixating the tree depth through setting this |
|
1821 |
property. |
|
1822 |
||
1823 |
The depth of the tree and the size of the scene rectangle decide the |
|
1824 |
granularity of the scene's partitioning. The size of each scene segment is |
|
1825 |
determined by the following algorithm: |
|
1826 |
||
1827 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 2 |
|
1828 |
||
1829 |
The BSP tree has an optimal size when each segment contains between 0 and |
|
1830 |
10 items. |
|
1831 |
||
1832 |
\sa itemIndexMethod |
|
1833 |
*/ |
|
1834 |
int QGraphicsScene::bspTreeDepth() const |
|
1835 |
{ |
|
1836 |
Q_D(const QGraphicsScene); |
|
1837 |
QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); |
|
1838 |
return bspTree ? bspTree->bspTreeDepth() : 0; |
|
1839 |
} |
|
1840 |
void QGraphicsScene::setBspTreeDepth(int depth) |
|
1841 |
{ |
|
1842 |
Q_D(QGraphicsScene); |
|
1843 |
if (depth < 0) { |
|
1844 |
qWarning("QGraphicsScene::setBspTreeDepth: invalid depth %d ignored; must be >= 0", depth); |
|
1845 |
return; |
|
1846 |
} |
|
1847 |
||
1848 |
QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); |
|
1849 |
if (!bspTree) { |
|
1850 |
qWarning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP"); |
|
1851 |
return; |
|
1852 |
} |
|
1853 |
bspTree->setBspTreeDepth(depth); |
|
1854 |
} |
|
1855 |
||
1856 |
/*! |
|
1857 |
\property QGraphicsScene::sortCacheEnabled |
|
1858 |
\brief whether sort caching is enabled |
|
1859 |
\since 4.5 |
|
1860 |
\obsolete |
|
1861 |
||
1862 |
Since Qt 4.6, this property has no effect. |
|
1863 |
*/ |
|
1864 |
bool QGraphicsScene::isSortCacheEnabled() const |
|
1865 |
{ |
|
1866 |
Q_D(const QGraphicsScene); |
|
1867 |
return d->sortCacheEnabled; |
|
1868 |
} |
|
1869 |
void QGraphicsScene::setSortCacheEnabled(bool enabled) |
|
1870 |
{ |
|
1871 |
Q_D(QGraphicsScene); |
|
1872 |
if (d->sortCacheEnabled == enabled) |
|
1873 |
return; |
|
1874 |
d->sortCacheEnabled = enabled; |
|
1875 |
} |
|
1876 |
||
1877 |
/*! |
|
1878 |
Calculates and returns the bounding rect of all items on the scene. This |
|
1879 |
function works by iterating over all items, and because if this, it can |
|
1880 |
be slow for large scenes. |
|
1881 |
||
1882 |
\sa sceneRect() |
|
1883 |
*/ |
|
1884 |
QRectF QGraphicsScene::itemsBoundingRect() const |
|
1885 |
{ |
|
1886 |
// Does not take untransformable items into account. |
|
1887 |
QRectF boundingRect; |
|
1888 |
foreach (QGraphicsItem *item, items()) |
|
1889 |
boundingRect |= item->sceneBoundingRect(); |
|
1890 |
return boundingRect; |
|
1891 |
} |
|
1892 |
||
1893 |
/*! |
|
1894 |
Returns a list of all items in the scene in descending stacking order. |
|
1895 |
||
1896 |
\sa addItem(), removeItem(), {QGraphicsItem#Sorting}{Sorting} |
|
1897 |
*/ |
|
1898 |
QList<QGraphicsItem *> QGraphicsScene::items() const |
|
1899 |
{ |
|
1900 |
Q_D(const QGraphicsScene); |
|
1901 |
return d->index->items(Qt::DescendingOrder); |
|
1902 |
} |
|
1903 |
||
1904 |
/*! |
|
1905 |
Returns an ordered list of all items on the scene. \a order decides the |
|
1906 |
stacking order. |
|
1907 |
||
1908 |
\sa addItem(), removeItem(), {QGraphicsItem#Sorting}{Sorting} |
|
1909 |
*/ |
|
1910 |
QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const |
|
1911 |
{ |
|
1912 |
Q_D(const QGraphicsScene); |
|
1913 |
return d->index->items(order); |
|
1914 |
} |
|
1915 |
||
1916 |
/*! |
|
1917 |
\obsolete |
|
1918 |
||
1919 |
Returns all visible items at position \a pos in the scene. The items are |
|
1920 |
listed in descending stacking order (i.e., the first item in the list is the |
|
1921 |
top-most item, and the last item is the bottom-most item). |
|
1922 |
||
1923 |
This function is deprecated and returns incorrect results if the scene |
|
1924 |
contains items that ignore transformations. Use the overload that takes |
|
1925 |
a QTransform instead. |
|
1926 |
||
1927 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
1928 |
*/ |
|
1929 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const |
|
1930 |
{ |
|
1931 |
Q_D(const QGraphicsScene); |
|
1932 |
return d->index->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder); |
|
1933 |
} |
|
1934 |
||
1935 |
/*! |
|
1936 |
\overload |
|
1937 |
\obsolete |
|
1938 |
||
1939 |
Returns all visible items that, depending on \a mode, are either inside or |
|
1940 |
intersect with the specified \a rectangle. |
|
1941 |
||
1942 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
1943 |
exact shape intersects with or is contained by \a rectangle are returned. |
|
1944 |
||
1945 |
This function is deprecated and returns incorrect results if the scene |
|
1946 |
contains items that ignore transformations. Use the overload that takes |
|
1947 |
a QTransform instead. |
|
1948 |
||
1949 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
1950 |
*/ |
|
1951 |
QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rectangle, Qt::ItemSelectionMode mode) const |
|
1952 |
{ |
|
1953 |
Q_D(const QGraphicsScene); |
|
1954 |
return d->index->items(rectangle, mode, Qt::DescendingOrder); |
|
1955 |
} |
|
1956 |
||
1957 |
/*! |
|
1958 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode) const |
|
1959 |
\obsolete |
|
1960 |
\since 4.3 |
|
1961 |
||
1962 |
This convenience function is equivalent to calling items(QRectF(\a x, \a y, \a w, \a h), \a mode). |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1963 |
|
0 | 1964 |
This function is deprecated and returns incorrect results if the scene |
1965 |
contains items that ignore transformations. Use the overload that takes |
|
1966 |
a QTransform instead. |
|
1967 |
*/ |
|
1968 |
||
1969 |
/*! |
|
1970 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const |
|
1971 |
\overload |
|
1972 |
\since 4.6 |
|
1973 |
||
1974 |
\brief Returns all visible items that, depending on \a mode, are |
|
1975 |
either inside or intersect with the rectangle defined by \a x, \a y, |
|
1976 |
\a w and \a h, in a list sorted using \a order. |
|
1977 |
||
1978 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
1979 |
be provided if the scene contains items that ignore transformations. |
|
1980 |
*/ |
|
1981 |
||
1982 |
/*! |
|
1983 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode) const |
|
1984 |
\overload |
|
1985 |
\obsolete |
|
1986 |
||
1987 |
Returns all visible items that, depending on \a mode, are either inside or |
|
1988 |
intersect with the polygon \a polygon. |
|
1989 |
||
1990 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
1991 |
exact shape intersects with or is contained by \a polygon are returned. |
|
1992 |
||
1993 |
This function is deprecated and returns incorrect results if the scene |
|
1994 |
contains items that ignore transformations. Use the overload that takes |
|
1995 |
a QTransform instead. |
|
1996 |
||
1997 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
1998 |
*/ |
|
1999 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode) const |
|
2000 |
{ |
|
2001 |
Q_D(const QGraphicsScene); |
|
2002 |
return d->index->items(polygon, mode, Qt::DescendingOrder); |
|
2003 |
} |
|
2004 |
||
2005 |
/*! |
|
2006 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const |
|
2007 |
\overload |
|
2008 |
\obsolete |
|
2009 |
||
2010 |
Returns all visible items that, depending on \a path, are either inside or |
|
2011 |
intersect with the path \a path. |
|
2012 |
||
2013 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
2014 |
exact shape intersects with or is contained by \a path are returned. |
|
2015 |
||
2016 |
This function is deprecated and returns incorrect results if the scene |
|
2017 |
contains items that ignore transformations. Use the overload that takes |
|
2018 |
a QTransform instead. |
|
2019 |
||
2020 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
2021 |
*/ |
|
2022 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const |
|
2023 |
{ |
|
2024 |
Q_D(const QGraphicsScene); |
|
2025 |
return d->index->items(path, mode, Qt::DescendingOrder); |
|
2026 |
} |
|
2027 |
||
2028 |
/*! |
|
2029 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2030 |
\since 4.6 |
|
2031 |
||
2032 |
\brief Returns all visible items that, depending on \a mode, are at |
|
2033 |
the specified \a pos in a list sorted using \a order. |
|
2034 |
||
2035 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
2036 |
exact shape intersects with \a pos are returned. |
|
2037 |
||
2038 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2039 |
be provided if the scene contains items that ignore transformations. |
|
2040 |
||
2041 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
2042 |
*/ |
|
2043 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos, Qt::ItemSelectionMode mode, |
|
2044 |
Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2045 |
{ |
|
2046 |
Q_D(const QGraphicsScene); |
|
2047 |
return d->index->items(pos, mode, order, deviceTransform); |
|
2048 |
} |
|
2049 |
||
2050 |
/*! |
|
2051 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2052 |
\overload |
|
2053 |
\since 4.6 |
|
2054 |
||
2055 |
\brief Returns all visible items that, depending on \a mode, are |
|
2056 |
either inside or intersect with the specified \a rect and return a |
|
2057 |
list sorted using \a order. |
|
2058 |
||
2059 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
2060 |
exact shape intersects with or is contained by \a rect are returned. |
|
2061 |
||
2062 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2063 |
be provided if the scene contains items that ignore transformations. |
|
2064 |
||
2065 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
2066 |
*/ |
|
2067 |
QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode, |
|
2068 |
Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2069 |
{ |
|
2070 |
Q_D(const QGraphicsScene); |
|
2071 |
return d->index->items(rect, mode, order, deviceTransform); |
|
2072 |
} |
|
2073 |
||
2074 |
/*! |
|
2075 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2076 |
\overload |
|
2077 |
\since 4.6 |
|
2078 |
||
2079 |
\brief Returns all visible items that, depending on \a mode, are |
|
2080 |
either inside or intersect with the specified \a polygon and return |
|
2081 |
a list sorted using \a order. |
|
2082 |
||
2083 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
2084 |
exact shape intersects with or is contained by \a polygon are returned. |
|
2085 |
||
2086 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2087 |
be provided if the scene contains items that ignore transformations. |
|
2088 |
||
2089 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
2090 |
*/ |
|
2091 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, |
|
2092 |
Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2093 |
{ |
|
2094 |
Q_D(const QGraphicsScene); |
|
2095 |
return d->index->items(polygon, mode, order, deviceTransform); |
|
2096 |
} |
|
2097 |
||
2098 |
/*! |
|
2099 |
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2100 |
\overload |
|
2101 |
\since 4.6 |
|
2102 |
||
2103 |
\brief Returns all visible items that, depending on \a mode, are |
|
2104 |
either inside or intersect with the specified \a path and return a |
|
2105 |
list sorted using \a order. |
|
2106 |
||
2107 |
The default value for \a mode is Qt::IntersectsItemShape; all items whose |
|
2108 |
exact shape intersects with or is contained by \a path are returned. |
|
2109 |
||
2110 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2111 |
be provided if the scene contains items that ignore transformations. |
|
2112 |
||
2113 |
\sa itemAt(), {QGraphicsItem#Sorting}{Sorting} |
|
2114 |
*/ |
|
2115 |
QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode, |
|
2116 |
Qt::SortOrder order, const QTransform &deviceTransform) const |
|
2117 |
{ |
|
2118 |
Q_D(const QGraphicsScene); |
|
2119 |
return d->index->items(path, mode, order, deviceTransform); |
|
2120 |
} |
|
2121 |
||
2122 |
/*! |
|
2123 |
Returns a list of all items that collide with \a item. Collisions are |
|
2124 |
determined by calling QGraphicsItem::collidesWithItem(); the collision |
|
2125 |
detection is determined by \a mode. By default, all items whose shape |
|
2126 |
intersects \a item or is contained inside \a item's shape are returned. |
|
2127 |
||
2128 |
The items are returned in descending stacking order (i.e., the first item |
|
2129 |
in the list is the uppermost item, and the last item is the lowermost |
|
2130 |
item). |
|
2131 |
||
2132 |
\sa items(), itemAt(), QGraphicsItem::collidesWithItem(), {QGraphicsItem#Sorting}{Sorting} |
|
2133 |
*/ |
|
2134 |
QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item, |
|
2135 |
Qt::ItemSelectionMode mode) const |
|
2136 |
{ |
|
2137 |
Q_D(const QGraphicsScene); |
|
2138 |
if (!item) { |
|
2139 |
qWarning("QGraphicsScene::collidingItems: cannot find collisions for null item"); |
|
2140 |
return QList<QGraphicsItem *>(); |
|
2141 |
} |
|
2142 |
||
2143 |
// Does not support ItemIgnoresTransformations. |
|
2144 |
QList<QGraphicsItem *> tmp; |
|
2145 |
foreach (QGraphicsItem *itemInVicinity, d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder)) { |
|
2146 |
if (item != itemInVicinity && item->collidesWithItem(itemInVicinity, mode)) |
|
2147 |
tmp << itemInVicinity; |
|
2148 |
} |
|
2149 |
return tmp; |
|
2150 |
} |
|
2151 |
||
2152 |
/*! |
|
2153 |
\overload |
|
2154 |
\obsolete |
|
2155 |
||
2156 |
Returns the topmost visible item at the specified \a position, or 0 if |
|
2157 |
there are no items at this position. |
|
2158 |
||
2159 |
This function is deprecated and returns incorrect results if the scene |
|
2160 |
contains items that ignore transformations. Use the overload that takes |
|
2161 |
a QTransform instead. |
|
2162 |
||
2163 |
\sa items(), collidingItems(), {QGraphicsItem#Sorting}{Sorting} |
|
2164 |
*/ |
|
2165 |
QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position) const |
|
2166 |
{ |
|
2167 |
QList<QGraphicsItem *> itemsAtPoint = items(position); |
|
2168 |
return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first(); |
|
2169 |
} |
|
2170 |
||
2171 |
/*! |
|
2172 |
\since 4.6 |
|
2173 |
||
2174 |
Returns the topmost visible item at the specified \a position, or 0 |
|
2175 |
if there are no items at this position. |
|
2176 |
||
2177 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2178 |
be provided if the scene contains items that ignore transformations. |
|
2179 |
||
2180 |
\sa items(), collidingItems(), {QGraphicsItem#Sorting}{Sorting} |
|
2181 |
*/ |
|
2182 |
QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform &deviceTransform) const |
|
2183 |
{ |
|
2184 |
QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape, |
|
2185 |
Qt::DescendingOrder, deviceTransform); |
|
2186 |
return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first(); |
|
2187 |
} |
|
2188 |
||
2189 |
/*! |
|
2190 |
\fn QGraphicsScene::itemAt(qreal x, qreal y, const QTransform &deviceTransform) const |
|
2191 |
\overload |
|
2192 |
\since 4.6 |
|
2193 |
||
2194 |
Returns the topmost item at the position specified by (\a x, \a |
|
2195 |
y), or 0 if there are no items at this position. |
|
2196 |
||
2197 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2198 |
be provided if the scene contains items that ignore transformations. |
|
2199 |
||
2200 |
This convenience function is equivalent to calling \c |
|
2201 |
{itemAt(QPointF(x, y), deviceTransform)}. |
|
2202 |
*/ |
|
2203 |
||
2204 |
/*! |
|
2205 |
\fn QGraphicsScene::itemAt(qreal x, qreal y) const |
|
2206 |
\overload |
|
2207 |
\obsolete |
|
2208 |
||
2209 |
Returns the topmost item at the position specified by (\a x, \a |
|
2210 |
y), or 0 if there are no items at this position. |
|
2211 |
||
2212 |
This convenience function is equivalent to calling \c |
|
2213 |
{itemAt(QPointF(x, y))}. |
|
2214 |
||
2215 |
This function is deprecated and returns incorrect results if the scene |
|
2216 |
contains items that ignore transformations. Use the overload that takes |
|
2217 |
a QTransform instead. |
|
2218 |
*/ |
|
2219 |
||
2220 |
/*! |
|
2221 |
Returns a list of all currently selected items. The items are |
|
2222 |
returned in no particular order. |
|
2223 |
||
2224 |
\sa setSelectionArea() |
|
2225 |
*/ |
|
2226 |
QList<QGraphicsItem *> QGraphicsScene::selectedItems() const |
|
2227 |
{ |
|
2228 |
Q_D(const QGraphicsScene); |
|
2229 |
||
2230 |
// Optimization: Lazily removes items that are not selected. |
|
2231 |
QGraphicsScene *that = const_cast<QGraphicsScene *>(this); |
|
2232 |
QSet<QGraphicsItem *> actuallySelectedSet; |
|
2233 |
foreach (QGraphicsItem *item, that->d_func()->selectedItems) { |
|
2234 |
if (item->isSelected()) |
|
2235 |
actuallySelectedSet << item; |
|
2236 |
} |
|
2237 |
||
2238 |
that->d_func()->selectedItems = actuallySelectedSet; |
|
2239 |
||
2240 |
return d->selectedItems.values(); |
|
2241 |
} |
|
2242 |
||
2243 |
/*! |
|
2244 |
Returns the selection area that was previously set with |
|
2245 |
setSelectionArea(), or an empty QPainterPath if no selection area has been |
|
2246 |
set. |
|
2247 |
||
2248 |
\sa setSelectionArea() |
|
2249 |
*/ |
|
2250 |
QPainterPath QGraphicsScene::selectionArea() const |
|
2251 |
{ |
|
2252 |
Q_D(const QGraphicsScene); |
|
2253 |
return d->selectionArea; |
|
2254 |
} |
|
2255 |
||
2256 |
/*! |
|
2257 |
\since 4.6 |
|
2258 |
||
2259 |
Sets the selection area to \a path. All items within this area are |
|
2260 |
immediately selected, and all items outside are unselected. You can get |
|
2261 |
the list of all selected items by calling selectedItems(). |
|
2262 |
||
2263 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2264 |
be provided if the scene contains items that ignore transformations. |
|
2265 |
||
2266 |
For an item to be selected, it must be marked as \e selectable |
|
2267 |
(QGraphicsItem::ItemIsSelectable). |
|
2268 |
||
2269 |
\sa clearSelection(), selectionArea() |
|
2270 |
*/ |
|
2271 |
void QGraphicsScene::setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform) |
|
2272 |
{ |
|
2273 |
setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform); |
|
2274 |
} |
|
2275 |
||
2276 |
/*! |
|
2277 |
\obsolete |
|
2278 |
\overload |
|
2279 |
||
2280 |
Sets the selection area to \a path. |
|
2281 |
||
2282 |
This function is deprecated and leads to incorrect results if the scene |
|
2283 |
contains items that ignore transformations. Use the overload that takes |
|
2284 |
a QTransform instead. |
|
2285 |
*/ |
|
2286 |
void QGraphicsScene::setSelectionArea(const QPainterPath &path) |
|
2287 |
{ |
|
2288 |
setSelectionArea(path, Qt::IntersectsItemShape, QTransform()); |
|
2289 |
} |
|
2290 |
||
2291 |
/*! |
|
2292 |
\obsolete |
|
2293 |
\overload |
|
2294 |
\since 4.3 |
|
2295 |
||
2296 |
Sets the selection area to \a path using \a mode to determine if items are |
|
2297 |
included in the selection area. |
|
2298 |
||
2299 |
\sa clearSelection(), selectionArea() |
|
2300 |
*/ |
|
2301 |
void QGraphicsScene::setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode) |
|
2302 |
{ |
|
2303 |
setSelectionArea(path, mode, QTransform()); |
|
2304 |
} |
|
2305 |
||
2306 |
/*! |
|
2307 |
\overload |
|
2308 |
\since 4.6 |
|
2309 |
||
2310 |
Sets the selection area to \a path using \a mode to determine if items are |
|
2311 |
included in the selection area. |
|
2312 |
||
2313 |
\a deviceTransform is the transformation that applies to the view, and needs to |
|
2314 |
be provided if the scene contains items that ignore transformations. |
|
2315 |
||
2316 |
\sa clearSelection(), selectionArea() |
|
2317 |
*/ |
|
2318 |
void QGraphicsScene::setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, |
|
2319 |
const QTransform &deviceTransform) |
|
2320 |
{ |
|
2321 |
Q_D(QGraphicsScene); |
|
2322 |
||
2323 |
// Note: with boolean path operations, we can improve performance here |
|
2324 |
// quite a lot by "growing" the old path instead of replacing it. That |
|
2325 |
// allows us to only check the intersect area for changes, instead of |
|
2326 |
// reevaluating the whole path over again. |
|
2327 |
d->selectionArea = path; |
|
2328 |
||
2329 |
QSet<QGraphicsItem *> unselectItems = d->selectedItems; |
|
2330 |
||
2331 |
// Disable emitting selectionChanged() for individual items. |
|
2332 |
++d->selectionChanging; |
|
2333 |
bool changed = false; |
|
2334 |
||
2335 |
// Set all items in path to selected. |
|
2336 |
foreach (QGraphicsItem *item, items(path, mode, Qt::DescendingOrder, deviceTransform)) { |
|
2337 |
if (item->flags() & QGraphicsItem::ItemIsSelectable) { |
|
2338 |
if (!item->isSelected()) |
|
2339 |
changed = true; |
|
2340 |
unselectItems.remove(item); |
|
2341 |
item->setSelected(true); |
|
2342 |
} |
|
2343 |
} |
|
2344 |
||
2345 |
// Unselect all items outside path. |
|
2346 |
foreach (QGraphicsItem *item, unselectItems) { |
|
2347 |
item->setSelected(false); |
|
2348 |
changed = true; |
|
2349 |
} |
|
2350 |
||
2351 |
// Reenable emitting selectionChanged() for individual items. |
|
2352 |
--d->selectionChanging; |
|
2353 |
||
2354 |
if (!d->selectionChanging && changed) |
|
2355 |
emit selectionChanged(); |
|
2356 |
} |
|
2357 |
||
2358 |
/*! |
|
2359 |
Clears the current selection. |
|
2360 |
||
2361 |
\sa setSelectionArea(), selectedItems() |
|
2362 |
*/ |
|
2363 |
void QGraphicsScene::clearSelection() |
|
2364 |
{ |
|
2365 |
Q_D(QGraphicsScene); |
|
2366 |
||
2367 |
// Disable emitting selectionChanged |
|
2368 |
++d->selectionChanging; |
|
2369 |
bool changed = !d->selectedItems.isEmpty(); |
|
2370 |
||
2371 |
foreach (QGraphicsItem *item, d->selectedItems) |
|
2372 |
item->setSelected(false); |
|
2373 |
d->selectedItems.clear(); |
|
2374 |
||
2375 |
// Reenable emitting selectionChanged() for individual items. |
|
2376 |
--d->selectionChanging; |
|
2377 |
||
2378 |
if (!d->selectionChanging && changed) |
|
2379 |
emit selectionChanged(); |
|
2380 |
} |
|
2381 |
||
2382 |
/*! |
|
2383 |
\since 4.4 |
|
2384 |
||
2385 |
Removes and deletes all items from the scene, but otherwise leaves the |
|
2386 |
state of the scene unchanged. |
|
2387 |
||
2388 |
\sa addItem() |
|
2389 |
*/ |
|
2390 |
void QGraphicsScene::clear() |
|
2391 |
{ |
|
2392 |
Q_D(QGraphicsScene); |
|
2393 |
// NB! We have to clear the index before deleting items; otherwise the |
|
2394 |
// index might try to access dangling item pointers. |
|
2395 |
d->index->clear(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2396 |
// NB! QGraphicsScenePrivate::unregisterTopLevelItem() removes items |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2397 |
while (!d->topLevelItems.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2398 |
delete d->topLevelItems.first(); |
0 | 2399 |
Q_ASSERT(d->topLevelItems.isEmpty()); |
2400 |
d->lastItemCount = 0; |
|
2401 |
d->allItemsIgnoreHoverEvents = true; |
|
2402 |
d->allItemsUseDefaultCursor = true; |
|
2403 |
d->allItemsIgnoreTouchEvents = true; |
|
2404 |
} |
|
2405 |
||
2406 |
/*! |
|
2407 |
Groups all items in \a items into a new QGraphicsItemGroup, and returns a |
|
2408 |
pointer to the group. The group is created with the common ancestor of \a |
|
2409 |
items as its parent, and with position (0, 0). The items are all |
|
2410 |
reparented to the group, and their positions and transformations are |
|
2411 |
mapped to the group. If \a items is empty, this function will return an |
|
2412 |
empty top-level QGraphicsItemGroup. |
|
2413 |
||
2414 |
QGraphicsScene has ownership of the group item; you do not need to delete |
|
2415 |
it. To dismantle (ungroup) a group, call destroyItemGroup(). |
|
2416 |
||
2417 |
\sa destroyItemGroup(), QGraphicsItemGroup::addToGroup() |
|
2418 |
*/ |
|
2419 |
QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *> &items) |
|
2420 |
{ |
|
2421 |
// Build a list of the first item's ancestors |
|
2422 |
QList<QGraphicsItem *> ancestors; |
|
2423 |
int n = 0; |
|
2424 |
if (!items.isEmpty()) { |
|
2425 |
QGraphicsItem *parent = items.at(n++); |
|
2426 |
while ((parent = parent->parentItem())) |
|
2427 |
ancestors.append(parent); |
|
2428 |
} |
|
2429 |
||
2430 |
// Find the common ancestor for all items |
|
2431 |
QGraphicsItem *commonAncestor = 0; |
|
2432 |
if (!ancestors.isEmpty()) { |
|
2433 |
while (n < items.size()) { |
|
2434 |
int commonIndex = -1; |
|
2435 |
QGraphicsItem *parent = items.at(n++); |
|
2436 |
do { |
|
2437 |
int index = ancestors.indexOf(parent, qMax(0, commonIndex)); |
|
2438 |
if (index != -1) { |
|
2439 |
commonIndex = index; |
|
2440 |
break; |
|
2441 |
} |
|
2442 |
} while ((parent = parent->parentItem())); |
|
2443 |
||
2444 |
if (commonIndex == -1) { |
|
2445 |
commonAncestor = 0; |
|
2446 |
break; |
|
2447 |
} |
|
2448 |
||
2449 |
commonAncestor = ancestors.at(commonIndex); |
|
2450 |
} |
|
2451 |
} |
|
2452 |
||
2453 |
// Create a new group at that level |
|
2454 |
QGraphicsItemGroup *group = new QGraphicsItemGroup(commonAncestor); |
|
2455 |
if (!commonAncestor) |
|
2456 |
addItem(group); |
|
2457 |
foreach (QGraphicsItem *item, items) |
|
2458 |
group->addToGroup(item); |
|
2459 |
return group; |
|
2460 |
} |
|
2461 |
||
2462 |
/*! |
|
2463 |
Reparents all items in \a group to \a group's parent item, then removes \a |
|
2464 |
group from the scene, and finally deletes it. The items' positions and |
|
2465 |
transformations are mapped from the group to the group's parent. |
|
2466 |
||
2467 |
\sa createItemGroup(), QGraphicsItemGroup::removeFromGroup() |
|
2468 |
*/ |
|
2469 |
void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup *group) |
|
2470 |
{ |
|
2471 |
foreach (QGraphicsItem *item, group->children()) |
|
2472 |
group->removeFromGroup(item); |
|
2473 |
removeItem(group); |
|
2474 |
delete group; |
|
2475 |
} |
|
2476 |
||
2477 |
/*! |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2478 |
Adds or moves the \a item and all its childen to this scene. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2479 |
This scene takes ownership of the \a item. |
0 | 2480 |
|
2481 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns |
|
2482 |
true), QGraphicsScene will emit changed() once control goes back |
|
2483 |
to the event loop. |
|
2484 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2485 |
If the item is already in a different scene, it will first be |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2486 |
removed from its old scene, and then added to this scene as a |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2487 |
top-level. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2488 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2489 |
QGraphicsScene will send ItemSceneChange notifications to \a item |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2490 |
while it is added to the scene. If item does not currently belong |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2491 |
to a scene, only one notification is sent. If it does belong to |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2492 |
scene already (i.e., it is moved to this scene), QGraphicsScene |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2493 |
will send an addition notification as the item is removed from its |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2494 |
previous scene. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2495 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2496 |
If the item is a panel, the scene is active, and there is no |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2497 |
active panel in the scene, then the item will be activated. |
0 | 2498 |
|
2499 |
\sa removeItem(), addEllipse(), addLine(), addPath(), addPixmap(), |
|
2500 |
addRect(), addText(), addWidget(), {QGraphicsItem#Sorting}{Sorting} |
|
2501 |
*/ |
|
2502 |
void QGraphicsScene::addItem(QGraphicsItem *item) |
|
2503 |
{ |
|
2504 |
Q_D(QGraphicsScene); |
|
2505 |
if (!item) { |
|
2506 |
qWarning("QGraphicsScene::addItem: cannot add null item"); |
|
2507 |
return; |
|
2508 |
} |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2509 |
if (item->d_ptr->scene == this) { |
0 | 2510 |
qWarning("QGraphicsScene::addItem: item has already been added to this scene"); |
2511 |
return; |
|
2512 |
} |
|
2513 |
// Remove this item from its existing scene |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2514 |
if (QGraphicsScene *oldScene = item->d_ptr->scene) |
0 | 2515 |
oldScene->removeItem(item); |
2516 |
||
2517 |
// Notify the item that its scene is changing, and allow the item to |
|
2518 |
// react. |
|
2519 |
const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, |
|
2520 |
qVariantFromValue<QGraphicsScene *>(this))); |
|
2521 |
QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); |
|
2522 |
if (targetScene != this) { |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2523 |
if (targetScene && item->d_ptr->scene != targetScene) |
0 | 2524 |
targetScene->addItem(item); |
2525 |
return; |
|
2526 |
} |
|
2527 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2528 |
if (d->unpolishedItems.isEmpty()) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2529 |
QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2530 |
d->unpolishedItems.append(item); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2531 |
item->d_ptr->pendingPolish = true; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2532 |
|
0 | 2533 |
// Detach this item from its parent if the parent's scene is different |
2534 |
// from this scene. |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2535 |
if (QGraphicsItem *itemParent = item->d_ptr->parent) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2536 |
if (itemParent->d_ptr->scene != this) |
0 | 2537 |
item->setParentItem(0); |
2538 |
} |
|
2539 |
||
2540 |
// Add the item to this scene |
|
2541 |
item->d_func()->scene = targetScene; |
|
2542 |
||
2543 |
// Add the item in the index |
|
2544 |
d->index->addItem(item); |
|
2545 |
||
2546 |
// Add to list of toplevels if this item is a toplevel. |
|
2547 |
if (!item->d_ptr->parent) |
|
2548 |
d->registerTopLevelItem(item); |
|
2549 |
||
2550 |
// Add to list of items that require an update. We cannot assume that the |
|
2551 |
// item is fully constructed, so calling item->update() can lead to a pure |
|
2552 |
// virtual function call to boundingRect(). |
|
2553 |
d->markDirty(item); |
|
2554 |
d->dirtyGrowingItemsBoundingRect = true; |
|
2555 |
||
2556 |
// Disable selectionChanged() for individual items |
|
2557 |
++d->selectionChanging; |
|
2558 |
int oldSelectedItemSize = d->selectedItems.size(); |
|
2559 |
||
2560 |
// Enable mouse tracking if the item accepts hover events or has a cursor set. |
|
2561 |
if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) { |
|
2562 |
d->allItemsIgnoreHoverEvents = false; |
|
2563 |
d->enableMouseTrackingOnViews(); |
|
2564 |
} |
|
2565 |
#ifndef QT_NO_CURSOR |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2566 |
if (d->allItemsUseDefaultCursor && item->d_ptr->hasCursor) { |
0 | 2567 |
d->allItemsUseDefaultCursor = false; |
2568 |
if (d->allItemsIgnoreHoverEvents) // already enabled otherwise |
|
2569 |
d->enableMouseTrackingOnViews(); |
|
2570 |
} |
|
2571 |
#endif //QT_NO_CURSOR |
|
2572 |
||
2573 |
// Enable touch events if the item accepts touch events. |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2574 |
if (d->allItemsIgnoreTouchEvents && item->d_ptr->acceptTouchEvents) { |
0 | 2575 |
d->allItemsIgnoreTouchEvents = false; |
2576 |
d->enableTouchEventsOnViews(); |
|
2577 |
} |
|
2578 |
||
2579 |
// Update selection lists |
|
2580 |
if (item->isSelected()) |
|
2581 |
d->selectedItems << item; |
|
2582 |
if (item->isWidget() && item->isVisible() && static_cast<QGraphicsWidget *>(item)->windowType() == Qt::Popup) |
|
2583 |
d->addPopup(static_cast<QGraphicsWidget *>(item)); |
|
2584 |
if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal) |
|
2585 |
d->enterModal(item); |
|
2586 |
||
2587 |
// Update creation order focus chain. Make sure to leave the widget's |
|
2588 |
// internal tab order intact. |
|
2589 |
if (item->isWidget()) { |
|
2590 |
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); |
|
2591 |
if (!d->tabFocusFirst) { |
|
2592 |
// No first tab focus widget - make this the first tab focus |
|
2593 |
// widget. |
|
2594 |
d->tabFocusFirst = widget; |
|
2595 |
} else if (!widget->parentWidget()) { |
|
2596 |
// Adding a widget that is not part of a tab focus chain. |
|
2597 |
QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev; |
|
2598 |
QGraphicsWidget *lastNew = widget->d_func()->focusPrev; |
|
2599 |
last->d_func()->focusNext = widget; |
|
2600 |
widget->d_func()->focusPrev = last; |
|
2601 |
d->tabFocusFirst->d_func()->focusPrev = lastNew; |
|
2602 |
lastNew->d_func()->focusNext = d->tabFocusFirst; |
|
2603 |
} |
|
2604 |
} |
|
2605 |
||
2606 |
// Add all children recursively |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2607 |
item->d_ptr->ensureSortedChildren(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2608 |
for (int i = 0; i < item->d_ptr->children.size(); ++i) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2609 |
addItem(item->d_ptr->children.at(i)); |
0 | 2610 |
|
2611 |
// Resolve font and palette. |
|
2612 |
item->d_ptr->resolveFont(d->font.resolve()); |
|
2613 |
item->d_ptr->resolvePalette(d->palette.resolve()); |
|
2614 |
||
2615 |
||
2616 |
// Reenable selectionChanged() for individual items |
|
2617 |
--d->selectionChanging; |
|
2618 |
if (!d->selectionChanging && d->selectedItems.size() != oldSelectedItemSize) |
|
2619 |
emit selectionChanged(); |
|
2620 |
||
2621 |
// Deliver post-change notification |
|
2622 |
item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); |
|
2623 |
||
2624 |
// Update explicit activation |
|
2625 |
bool autoActivate = true; |
|
2626 |
if (!d->childExplicitActivation && item->d_ptr->explicitActivate) |
|
2627 |
d->childExplicitActivation = item->d_ptr->wantsActive ? 1 : 2; |
|
2628 |
if (d->childExplicitActivation && item->isPanel()) { |
|
2629 |
if (d->childExplicitActivation == 1) |
|
2630 |
setActivePanel(item); |
|
2631 |
else |
|
2632 |
autoActivate = false; |
|
2633 |
d->childExplicitActivation = 0; |
|
2634 |
} else if (!item->d_ptr->parent) { |
|
2635 |
d->childExplicitActivation = 0; |
|
2636 |
} |
|
2637 |
||
2638 |
// Auto-activate this item's panel if nothing else has been activated |
|
2639 |
if (autoActivate) { |
|
2640 |
if (!d->lastActivePanel && !d->activePanel && item->isPanel()) { |
|
2641 |
if (isActive()) |
|
2642 |
setActivePanel(item); |
|
2643 |
else |
|
2644 |
d->lastActivePanel = item; |
|
2645 |
} |
|
2646 |
} |
|
2647 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2648 |
if (item->d_ptr->flags & QGraphicsItem::ItemSendsScenePositionChanges) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2649 |
d->registerScenePosItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2650 |
|
0 | 2651 |
// Ensure that newly added items that have subfocus set, gain |
2652 |
// focus automatically if there isn't a focus item already. |
|
2653 |
if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item) |
|
2654 |
item->focusItem()->setFocus(); |
|
2655 |
||
2656 |
d->updateInputMethodSensitivityInViews(); |
|
2657 |
} |
|
2658 |
||
2659 |
/*! |
|
2660 |
Creates and adds an ellipse item to the scene, and returns the item |
|
2661 |
pointer. The geometry of the ellipse is defined by \a rect, and its pen |
|
2662 |
and brush are initialized to \a pen and \a brush. |
|
2663 |
||
2664 |
Note that the item's geometry is provided in item coordinates, and its |
|
2665 |
position is initialized to (0, 0). |
|
2666 |
||
2667 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2668 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2669 |
loop. |
|
2670 |
||
2671 |
\sa addLine(), addPath(), addPixmap(), addRect(), addText(), addItem(), |
|
2672 |
addWidget() |
|
2673 |
*/ |
|
2674 |
QGraphicsEllipseItem *QGraphicsScene::addEllipse(const QRectF &rect, const QPen &pen, const QBrush &brush) |
|
2675 |
{ |
|
2676 |
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rect); |
|
2677 |
item->setPen(pen); |
|
2678 |
item->setBrush(brush); |
|
2679 |
addItem(item); |
|
2680 |
return item; |
|
2681 |
} |
|
2682 |
||
2683 |
/*! |
|
2684 |
\fn QGraphicsEllipseItem *QGraphicsScene::addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush) |
|
2685 |
\since 4.3 |
|
2686 |
||
2687 |
This convenience function is equivalent to calling addEllipse(QRectF(\a x, |
|
2688 |
\a y, \a w, \a h), \a pen, \a brush). |
|
2689 |
*/ |
|
2690 |
||
2691 |
/*! |
|
2692 |
Creates and adds a line item to the scene, and returns the item |
|
2693 |
pointer. The geometry of the line is defined by \a line, and its pen |
|
2694 |
is initialized to \a pen. |
|
2695 |
||
2696 |
Note that the item's geometry is provided in item coordinates, and its |
|
2697 |
position is initialized to (0, 0). |
|
2698 |
||
2699 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2700 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2701 |
loop. |
|
2702 |
||
2703 |
\sa addEllipse(), addPath(), addPixmap(), addRect(), addText(), addItem(), |
|
2704 |
addWidget() |
|
2705 |
*/ |
|
2706 |
QGraphicsLineItem *QGraphicsScene::addLine(const QLineF &line, const QPen &pen) |
|
2707 |
{ |
|
2708 |
QGraphicsLineItem *item = new QGraphicsLineItem(line); |
|
2709 |
item->setPen(pen); |
|
2710 |
addItem(item); |
|
2711 |
return item; |
|
2712 |
} |
|
2713 |
||
2714 |
/*! |
|
2715 |
\fn QGraphicsLineItem *QGraphicsScene::addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen) |
|
2716 |
\since 4.3 |
|
2717 |
||
2718 |
This convenience function is equivalent to calling addLine(QLineF(\a x1, |
|
2719 |
\a y1, \a x2, \a y2), \a pen). |
|
2720 |
*/ |
|
2721 |
||
2722 |
/*! |
|
2723 |
Creates and adds a path item to the scene, and returns the item |
|
2724 |
pointer. The geometry of the path is defined by \a path, and its pen and |
|
2725 |
brush are initialized to \a pen and \a brush. |
|
2726 |
||
2727 |
Note that the item's geometry is provided in item coordinates, and its |
|
2728 |
position is initialized to (0, 0). |
|
2729 |
||
2730 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2731 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2732 |
loop. |
|
2733 |
||
2734 |
\sa addEllipse(), addLine(), addPixmap(), addRect(), addText(), addItem(), |
|
2735 |
addWidget() |
|
2736 |
*/ |
|
2737 |
QGraphicsPathItem *QGraphicsScene::addPath(const QPainterPath &path, const QPen &pen, const QBrush &brush) |
|
2738 |
{ |
|
2739 |
QGraphicsPathItem *item = new QGraphicsPathItem(path); |
|
2740 |
item->setPen(pen); |
|
2741 |
item->setBrush(brush); |
|
2742 |
addItem(item); |
|
2743 |
return item; |
|
2744 |
} |
|
2745 |
||
2746 |
/*! |
|
2747 |
Creates and adds a pixmap item to the scene, and returns the item |
|
2748 |
pointer. The pixmap is defined by \a pixmap. |
|
2749 |
||
2750 |
Note that the item's geometry is provided in item coordinates, and its |
|
2751 |
position is initialized to (0, 0). |
|
2752 |
||
2753 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2754 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2755 |
loop. |
|
2756 |
||
2757 |
\sa addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), |
|
2758 |
addWidget() |
|
2759 |
*/ |
|
2760 |
QGraphicsPixmapItem *QGraphicsScene::addPixmap(const QPixmap &pixmap) |
|
2761 |
{ |
|
2762 |
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap); |
|
2763 |
addItem(item); |
|
2764 |
return item; |
|
2765 |
} |
|
2766 |
||
2767 |
/*! |
|
2768 |
Creates and adds a polygon item to the scene, and returns the item |
|
2769 |
pointer. The polygon is defined by \a polygon, and its pen and |
|
2770 |
brush are initialized to \a pen and \a brush. |
|
2771 |
||
2772 |
Note that the item's geometry is provided in item coordinates, and its |
|
2773 |
position is initialized to (0, 0). |
|
2774 |
||
2775 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2776 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2777 |
loop. |
|
2778 |
||
2779 |
\sa addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), |
|
2780 |
addWidget() |
|
2781 |
*/ |
|
2782 |
QGraphicsPolygonItem *QGraphicsScene::addPolygon(const QPolygonF &polygon, |
|
2783 |
const QPen &pen, const QBrush &brush) |
|
2784 |
{ |
|
2785 |
QGraphicsPolygonItem *item = new QGraphicsPolygonItem(polygon); |
|
2786 |
item->setPen(pen); |
|
2787 |
item->setBrush(brush); |
|
2788 |
addItem(item); |
|
2789 |
return item; |
|
2790 |
} |
|
2791 |
||
2792 |
/*! |
|
2793 |
Creates and adds a rectangle item to the scene, and returns the item |
|
2794 |
pointer. The geometry of the rectangle is defined by \a rect, and its pen |
|
2795 |
and brush are initialized to \a pen and \a brush. |
|
2796 |
||
2797 |
Note that the item's geometry is provided in item coordinates, and its |
|
2798 |
position is initialized to (0, 0). For example, if a QRect(50, 50, 100, |
|
2799 |
100) is added, its top-left corner will be at (50, 50) relative to the |
|
2800 |
origin in the items coordinate system. |
|
2801 |
||
2802 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2803 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2804 |
loop. |
|
2805 |
||
2806 |
\sa addEllipse(), addLine(), addPixmap(), addPixmap(), addText(), |
|
2807 |
addItem(), addWidget() |
|
2808 |
*/ |
|
2809 |
QGraphicsRectItem *QGraphicsScene::addRect(const QRectF &rect, const QPen &pen, const QBrush &brush) |
|
2810 |
{ |
|
2811 |
QGraphicsRectItem *item = new QGraphicsRectItem(rect); |
|
2812 |
item->setPen(pen); |
|
2813 |
item->setBrush(brush); |
|
2814 |
addItem(item); |
|
2815 |
return item; |
|
2816 |
} |
|
2817 |
||
2818 |
/*! |
|
2819 |
\fn QGraphicsRectItem *QGraphicsScene::addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush) |
|
2820 |
\since 4.3 |
|
2821 |
||
2822 |
This convenience function is equivalent to calling addRect(QRectF(\a x, |
|
2823 |
\a y, \a w, \a h), \a pen, \a brush). |
|
2824 |
*/ |
|
2825 |
||
2826 |
/*! |
|
2827 |
Creates and adds a text item to the scene, and returns the item |
|
2828 |
pointer. The text string is initialized to \a text, and its font |
|
2829 |
is initialized to \a font. |
|
2830 |
||
2831 |
The item's position is initialized to (0, 0). |
|
2832 |
||
2833 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2834 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2835 |
loop. |
|
2836 |
||
2837 |
\sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), |
|
2838 |
addItem(), addWidget() |
|
2839 |
*/ |
|
2840 |
QGraphicsTextItem *QGraphicsScene::addText(const QString &text, const QFont &font) |
|
2841 |
{ |
|
2842 |
QGraphicsTextItem *item = new QGraphicsTextItem(text); |
|
2843 |
item->setFont(font); |
|
2844 |
addItem(item); |
|
2845 |
return item; |
|
2846 |
} |
|
2847 |
||
2848 |
/*! |
|
2849 |
Creates and adds a QGraphicsSimpleTextItem to the scene, and returns the |
|
2850 |
item pointer. The text string is initialized to \a text, and its font is |
|
2851 |
initialized to \a font. |
|
2852 |
||
2853 |
The item's position is initialized to (0, 0). |
|
2854 |
||
2855 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2856 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2857 |
loop. |
|
2858 |
||
2859 |
\sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), |
|
2860 |
addItem(), addWidget() |
|
2861 |
*/ |
|
2862 |
QGraphicsSimpleTextItem *QGraphicsScene::addSimpleText(const QString &text, const QFont &font) |
|
2863 |
{ |
|
2864 |
QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text); |
|
2865 |
item->setFont(font); |
|
2866 |
addItem(item); |
|
2867 |
return item; |
|
2868 |
} |
|
2869 |
||
2870 |
/*! |
|
2871 |
Creates a new QGraphicsProxyWidget for \a widget, adds it to the scene, |
|
2872 |
and returns a pointer to the proxy. \a wFlags set the default window flags |
|
2873 |
for the embedding proxy widget. |
|
2874 |
||
2875 |
The item's position is initialized to (0, 0). |
|
2876 |
||
2877 |
If the item is visible (i.e., QGraphicsItem::isVisible() returns true), |
|
2878 |
QGraphicsScene will emit changed() once control goes back to the event |
|
2879 |
loop. |
|
2880 |
||
2881 |
Note that widgets with the Qt::WA_PaintOnScreen widget attribute |
|
2882 |
set and widgets that wrap an external application or controller |
|
2883 |
are not supported. Examples are QGLWidget and QAxWidget. |
|
2884 |
||
2885 |
\sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), |
|
2886 |
addText(), addSimpleText(), addItem() |
|
2887 |
*/ |
|
2888 |
QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags) |
|
2889 |
{ |
|
2890 |
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, wFlags); |
|
2891 |
proxy->setWidget(widget); |
|
2892 |
addItem(proxy); |
|
2893 |
return proxy; |
|
2894 |
} |
|
2895 |
||
2896 |
/*! |
|
2897 |
Removes the item \a item and all its children from the scene. The |
|
2898 |
ownership of \a item is passed on to the caller (i.e., |
|
2899 |
QGraphicsScene will no longer delete \a item when destroyed). |
|
2900 |
||
2901 |
\sa addItem() |
|
2902 |
*/ |
|
2903 |
void QGraphicsScene::removeItem(QGraphicsItem *item) |
|
2904 |
{ |
|
2905 |
// ### Refactoring: This function shares much functionality with _q_removeItemLater() |
|
2906 |
Q_D(QGraphicsScene); |
|
2907 |
if (!item) { |
|
2908 |
qWarning("QGraphicsScene::removeItem: cannot remove 0-item"); |
|
2909 |
return; |
|
2910 |
} |
|
2911 |
if (item->scene() != this) { |
|
2912 |
qWarning("QGraphicsScene::removeItem: item %p's scene (%p)" |
|
2913 |
" is different from this scene (%p)", |
|
2914 |
item, item->scene(), this); |
|
2915 |
return; |
|
2916 |
} |
|
2917 |
||
2918 |
// Notify the item that it's scene is changing to 0, allowing the item to |
|
2919 |
// react. |
|
2920 |
const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, |
|
2921 |
qVariantFromValue<QGraphicsScene *>(0))); |
|
2922 |
QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); |
|
2923 |
if (targetScene != 0 && targetScene != this) { |
|
2924 |
targetScene->addItem(item); |
|
2925 |
return; |
|
2926 |
} |
|
2927 |
||
2928 |
d->removeItemHelper(item); |
|
2929 |
||
2930 |
// Deliver post-change notification |
|
2931 |
item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); |
|
2932 |
||
2933 |
d->updateInputMethodSensitivityInViews(); |
|
2934 |
} |
|
2935 |
||
2936 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2937 |
When the scene is active, this functions returns the scene's current focus |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2938 |
item, or 0 if no item currently has focus. When the scene is inactive, this |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2939 |
functions returns the item that will gain input focus when the scene becomes |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2940 |
active. |
0 | 2941 |
|
2942 |
The focus item receives keyboard input when the scene receives a |
|
2943 |
key event. |
|
2944 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2945 |
\sa setFocusItem(), QGraphicsItem::hasFocus(), isActive() |
0 | 2946 |
*/ |
2947 |
QGraphicsItem *QGraphicsScene::focusItem() const |
|
2948 |
{ |
|
2949 |
Q_D(const QGraphicsScene); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2950 |
return isActive() ? d->focusItem : d->lastFocusItem; |
0 | 2951 |
} |
2952 |
||
2953 |
/*! |
|
2954 |
Sets the scene's focus item to \a item, with the focus reason \a |
|
2955 |
focusReason, after removing focus from any previous item that may have had |
|
2956 |
focus. |
|
2957 |
||
2958 |
If \a item is 0, or if it either does not accept focus (i.e., it does not |
|
2959 |
have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible |
|
2960 |
or not enabled, this function only removes focus from any previous |
|
2961 |
focusitem. |
|
2962 |
||
2963 |
If item is not 0, and the scene does not currently have focus (i.e., |
|
2964 |
hasFocus() returns false), this function will call setFocus() |
|
2965 |
automatically. |
|
2966 |
||
2967 |
\sa focusItem(), hasFocus(), setFocus() |
|
2968 |
*/ |
|
2969 |
void QGraphicsScene::setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason) |
|
2970 |
{ |
|
2971 |
Q_D(QGraphicsScene); |
|
2972 |
if (item) |
|
2973 |
item->setFocus(focusReason); |
|
2974 |
else |
|
2975 |
d->setFocusItemHelper(item, focusReason); |
|
2976 |
} |
|
2977 |
||
2978 |
/*! |
|
2979 |
Returns true if the scene has focus; otherwise returns false. If the scene |
|
2980 |
has focus, it will will forward key events from QKeyEvent to any item that |
|
2981 |
has focus. |
|
2982 |
||
2983 |
\sa setFocus(), setFocusItem() |
|
2984 |
*/ |
|
2985 |
bool QGraphicsScene::hasFocus() const |
|
2986 |
{ |
|
2987 |
Q_D(const QGraphicsScene); |
|
2988 |
return d->hasFocus; |
|
2989 |
} |
|
2990 |
||
2991 |
/*! |
|
2992 |
Sets focus on the scene by sending a QFocusEvent to the scene, passing \a |
|
2993 |
focusReason as the reason. If the scene regains focus after having |
|
2994 |
previously lost it while an item had focus, the last focus item will |
|
2995 |
receive focus with \a focusReason as the reason. |
|
2996 |
||
2997 |
If the scene already has focus, this function does nothing. |
|
2998 |
||
2999 |
\sa hasFocus(), clearFocus(), setFocusItem() |
|
3000 |
*/ |
|
3001 |
void QGraphicsScene::setFocus(Qt::FocusReason focusReason) |
|
3002 |
{ |
|
3003 |
Q_D(QGraphicsScene); |
|
3004 |
if (d->hasFocus || !isActive()) |
|
3005 |
return; |
|
3006 |
QFocusEvent event(QEvent::FocusIn, focusReason); |
|
3007 |
QCoreApplication::sendEvent(this, &event); |
|
3008 |
} |
|
3009 |
||
3010 |
/*! |
|
3011 |
Clears focus from the scene. If any item has focus when this function is |
|
3012 |
called, it will lose focus, and regain focus again once the scene regains |
|
3013 |
focus. |
|
3014 |
||
3015 |
A scene that does not have focus ignores key events. |
|
3016 |
||
3017 |
\sa hasFocus(), setFocus(), setFocusItem() |
|
3018 |
*/ |
|
3019 |
void QGraphicsScene::clearFocus() |
|
3020 |
{ |
|
3021 |
Q_D(QGraphicsScene); |
|
3022 |
if (d->hasFocus) { |
|
3023 |
d->hasFocus = false; |
|
3024 |
setFocusItem(0, Qt::OtherFocusReason); |
|
3025 |
} |
|
3026 |
} |
|
3027 |
||
3028 |
/*! |
|
3029 |
\property QGraphicsScene::stickyFocus |
|
3030 |
\brief whether clicking into the scene background will clear focus |
|
3031 |
||
3032 |
\since 4.6 |
|
3033 |
||
3034 |
In a QGraphicsScene with stickyFocus set to true, focus will remain |
|
3035 |
unchanged when the user clicks into the scene background or on an item |
|
3036 |
that does not accept focus. Otherwise, focus will be cleared. |
|
3037 |
||
3038 |
By default, this property is false. |
|
3039 |
||
3040 |
Focus changes in response to a mouse press. You can reimplement |
|
3041 |
mousePressEvent() in a subclass of QGraphicsScene to toggle this property |
|
3042 |
based on where the user has clicked. |
|
3043 |
||
3044 |
\sa clearFocus(), setFocusItem() |
|
3045 |
*/ |
|
3046 |
void QGraphicsScene::setStickyFocus(bool enabled) |
|
3047 |
{ |
|
3048 |
Q_D(QGraphicsScene); |
|
3049 |
d->stickyFocus = enabled; |
|
3050 |
} |
|
3051 |
bool QGraphicsScene::stickyFocus() const |
|
3052 |
{ |
|
3053 |
Q_D(const QGraphicsScene); |
|
3054 |
return d->stickyFocus; |
|
3055 |
} |
|
3056 |
||
3057 |
/*! |
|
3058 |
Returns the current mouse grabber item, or 0 if no item is currently |
|
3059 |
grabbing the mouse. The mouse grabber item is the item that receives all |
|
3060 |
mouse events sent to the scene. |
|
3061 |
||
3062 |
An item becomes a mouse grabber when it receives and accepts a |
|
3063 |
mouse press event, and it stays the mouse grabber until either of |
|
3064 |
the following events occur: |
|
3065 |
||
3066 |
\list |
|
3067 |
\o If the item receives a mouse release event when there are no other |
|
3068 |
buttons pressed, it loses the mouse grab. |
|
3069 |
\o If the item becomes invisible (i.e., someone calls \c {item->setVisible(false))}, |
|
3070 |
or if it becomes disabled (i.e., someone calls \c {item->setEnabled(false))}, |
|
3071 |
it loses the mouse grab. |
|
3072 |
\o If the item is removed from the scene, it loses the mouse grab. |
|
3073 |
\endlist |
|
3074 |
||
3075 |
If the item loses its mouse grab, the scene will ignore all mouse events |
|
3076 |
until a new item grabs the mouse (i.e., until a new item receives a mouse |
|
3077 |
press event). |
|
3078 |
*/ |
|
3079 |
QGraphicsItem *QGraphicsScene::mouseGrabberItem() const |
|
3080 |
{ |
|
3081 |
Q_D(const QGraphicsScene); |
|
3082 |
return !d->mouseGrabberItems.isEmpty() ? d->mouseGrabberItems.last() : 0; |
|
3083 |
} |
|
3084 |
||
3085 |
/*! |
|
3086 |
\property QGraphicsScene::backgroundBrush |
|
3087 |
\brief the background brush of the scene. |
|
3088 |
||
3089 |
Set this property to changes the scene's background to a different color, |
|
3090 |
gradient or texture. The default background brush is Qt::NoBrush. The |
|
3091 |
background is drawn before (behind) the items. |
|
3092 |
||
3093 |
Example: |
|
3094 |
||
3095 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 3 |
|
3096 |
||
3097 |
QGraphicsScene::render() calls drawBackground() to draw the scene |
|
3098 |
background. For more detailed control over how the background is drawn, |
|
3099 |
you can reimplement drawBackground() in a subclass of QGraphicsScene. |
|
3100 |
*/ |
|
3101 |
QBrush QGraphicsScene::backgroundBrush() const |
|
3102 |
{ |
|
3103 |
Q_D(const QGraphicsScene); |
|
3104 |
return d->backgroundBrush; |
|
3105 |
} |
|
3106 |
void QGraphicsScene::setBackgroundBrush(const QBrush &brush) |
|
3107 |
{ |
|
3108 |
Q_D(QGraphicsScene); |
|
3109 |
d->backgroundBrush = brush; |
|
3110 |
foreach (QGraphicsView *view, d->views) { |
|
3111 |
view->resetCachedContent(); |
|
3112 |
view->viewport()->update(); |
|
3113 |
} |
|
3114 |
update(); |
|
3115 |
} |
|
3116 |
||
3117 |
/*! |
|
3118 |
\property QGraphicsScene::foregroundBrush |
|
3119 |
\brief the foreground brush of the scene. |
|
3120 |
||
3121 |
Change this property to set the scene's foreground to a different |
|
3122 |
color, gradient or texture. |
|
3123 |
||
3124 |
The foreground is drawn after (on top of) the items. The default |
|
3125 |
foreground brush is Qt::NoBrush ( i.e. the foreground is not |
|
3126 |
drawn). |
|
3127 |
||
3128 |
Example: |
|
3129 |
||
3130 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 4 |
|
3131 |
||
3132 |
QGraphicsScene::render() calls drawForeground() to draw the scene |
|
3133 |
foreground. For more detailed control over how the foreground is |
|
3134 |
drawn, you can reimplement the drawForeground() function in a |
|
3135 |
QGraphicsScene subclass. |
|
3136 |
*/ |
|
3137 |
QBrush QGraphicsScene::foregroundBrush() const |
|
3138 |
{ |
|
3139 |
Q_D(const QGraphicsScene); |
|
3140 |
return d->foregroundBrush; |
|
3141 |
} |
|
3142 |
void QGraphicsScene::setForegroundBrush(const QBrush &brush) |
|
3143 |
{ |
|
3144 |
Q_D(QGraphicsScene); |
|
3145 |
d->foregroundBrush = brush; |
|
3146 |
foreach (QGraphicsView *view, views()) |
|
3147 |
view->viewport()->update(); |
|
3148 |
update(); |
|
3149 |
} |
|
3150 |
||
3151 |
/*! |
|
3152 |
This method is used by input methods to query a set of properties of |
|
3153 |
the scene to be able to support complex input method operations as support |
|
3154 |
for surrounding text and reconversions. |
|
3155 |
||
3156 |
The \a query parameter specifies which property is queried. |
|
3157 |
||
3158 |
\sa QWidget::inputMethodQuery() |
|
3159 |
*/ |
|
3160 |
QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const |
|
3161 |
{ |
|
3162 |
Q_D(const QGraphicsScene); |
|
3163 |
if (!d->focusItem || !(d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) |
|
3164 |
return QVariant(); |
|
3165 |
const QTransform matrix = d->focusItem->sceneTransform(); |
|
3166 |
QVariant value = d->focusItem->inputMethodQuery(query); |
|
3167 |
if (value.type() == QVariant::RectF) |
|
3168 |
value = matrix.mapRect(value.toRectF()); |
|
3169 |
else if (value.type() == QVariant::PointF) |
|
3170 |
value = matrix.map(value.toPointF()); |
|
3171 |
else if (value.type() == QVariant::Rect) |
|
3172 |
value = matrix.mapRect(value.toRect()); |
|
3173 |
else if (value.type() == QVariant::Point) |
|
3174 |
value = matrix.map(value.toPoint()); |
|
3175 |
return value; |
|
3176 |
} |
|
3177 |
||
3178 |
/*! |
|
3179 |
\fn void QGraphicsScene::update(const QRectF &rect) |
|
3180 |
Schedules a redraw of the area \a rect on the scene. |
|
3181 |
||
3182 |
\sa sceneRect(), changed() |
|
3183 |
*/ |
|
3184 |
void QGraphicsScene::update(const QRectF &rect) |
|
3185 |
{ |
|
3186 |
Q_D(QGraphicsScene); |
|
3187 |
if (d->updateAll || (rect.isEmpty() && !rect.isNull())) |
|
3188 |
return; |
|
3189 |
||
3190 |
// Check if anyone's connected; if not, we can send updates directly to |
|
3191 |
// the views. Otherwise or if there are no views, use old behavior. |
|
3192 |
bool directUpdates = !(d->isSignalConnected(d->changedSignalIndex)) && !d->views.isEmpty(); |
|
3193 |
if (rect.isNull()) { |
|
3194 |
d->updateAll = true; |
|
3195 |
d->updatedRects.clear(); |
|
3196 |
if (directUpdates) { |
|
3197 |
// Update all views. |
|
3198 |
for (int i = 0; i < d->views.size(); ++i) |
|
3199 |
d->views.at(i)->d_func()->fullUpdatePending = true; |
|
3200 |
} |
|
3201 |
} else { |
|
3202 |
if (directUpdates) { |
|
3203 |
// Update all views. |
|
3204 |
for (int i = 0; i < d->views.size(); ++i) { |
|
3205 |
QGraphicsView *view = d->views.at(i); |
|
3206 |
view->d_func()->updateRegion(QRegion(view->mapFromScene(rect).boundingRect())); |
|
3207 |
} |
|
3208 |
} else { |
|
3209 |
d->updatedRects << rect; |
|
3210 |
} |
|
3211 |
} |
|
3212 |
||
3213 |
if (!d->calledEmitUpdated) { |
|
3214 |
d->calledEmitUpdated = true; |
|
3215 |
QMetaObject::invokeMethod(this, "_q_emitUpdated", Qt::QueuedConnection); |
|
3216 |
} |
|
3217 |
} |
|
3218 |
||
3219 |
/*! |
|
3220 |
\fn void QGraphicsScene::update(qreal x, qreal y, qreal w, qreal h) |
|
3221 |
\overload |
|
3222 |
\since 4.3 |
|
3223 |
||
3224 |
This function is equivalent to calling update(QRectF(\a x, \a y, \a w, |
|
3225 |
\a h)); |
|
3226 |
*/ |
|
3227 |
||
3228 |
/*! |
|
3229 |
Invalidates and schedules a redraw of the \a layers in \a rect on the |
|
3230 |
scene. Any cached content in \a layers is unconditionally invalidated and |
|
3231 |
redrawn. |
|
3232 |
||
3233 |
You can use this function overload to notify QGraphicsScene of changes to |
|
3234 |
the background or the foreground of the scene. This function is commonly |
|
3235 |
used for scenes with tile-based backgrounds to notify changes when |
|
3236 |
QGraphicsView has enabled |
|
3237 |
\l{QGraphicsView::CacheBackground}{CacheBackground}. |
|
3238 |
||
3239 |
Example: |
|
3240 |
||
3241 |
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 5 |
|
3242 |
||
3243 |
Note that QGraphicsView currently supports background caching only (see |
|
3244 |
QGraphicsView::CacheBackground). This function is equivalent to calling |
|
3245 |
update() if any layer but BackgroundLayer is passed. |
|
3246 |
||
3247 |
\sa QGraphicsView::resetCachedContent() |
|
3248 |
*/ |
|
3249 |
void QGraphicsScene::invalidate(const QRectF &rect, SceneLayers layers) |
|
3250 |
{ |
|
3251 |
foreach (QGraphicsView *view, views()) |
|
3252 |
view->invalidateScene(rect, layers); |
|
3253 |
update(rect); |
|
3254 |
} |
|
3255 |
||
3256 |
/*! |
|
3257 |
\fn void QGraphicsScene::invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers) |
|
3258 |
\overload |
|
3259 |
\since 4.3 |
|
3260 |
||
3261 |
This convenience function is equivalent to calling invalidate(QRectF(\a x, \a |
|
3262 |
y, \a w, \a h), \a layers); |
|
3263 |
*/ |
|
3264 |
||
3265 |
/*! |
|
3266 |
Returns a list of all the views that display this scene. |
|
3267 |
||
3268 |
\sa QGraphicsView::scene() |
|
3269 |
*/ |
|
3270 |
QList <QGraphicsView *> QGraphicsScene::views() const |
|
3271 |
{ |
|
3272 |
Q_D(const QGraphicsScene); |
|
3273 |
return d->views; |
|
3274 |
} |
|
3275 |
||
3276 |
/*! |
|
3277 |
This slot \e advances the scene by one step, by calling |
|
3278 |
QGraphicsItem::advance() for all items on the scene. This is done in two |
|
3279 |
phases: in the first phase, all items are notified that the scene is about |
|
3280 |
to change, and in the second phase all items are notified that they can |
|
3281 |
move. In the first phase, QGraphicsItem::advance() is called passing a |
|
3282 |
value of 0 as an argument, and 1 is passed in the second phase. |
|
3283 |
||
3284 |
\sa QGraphicsItem::advance(), QGraphicsItemAnimation, QTimeLine |
|
3285 |
*/ |
|
3286 |
void QGraphicsScene::advance() |
|
3287 |
{ |
|
3288 |
for (int i = 0; i < 2; ++i) { |
|
3289 |
foreach (QGraphicsItem *item, items()) |
|
3290 |
item->advance(i); |
|
3291 |
} |
|
3292 |
} |
|
3293 |
||
3294 |
/*! |
|
3295 |
Processes the event \a event, and dispatches it to the respective |
|
3296 |
event handlers. |
|
3297 |
||
3298 |
In addition to calling the convenience event handlers, this |
|
3299 |
function is responsible for converting mouse move events to hover |
|
3300 |
events for when there is no mouse grabber item. Hover events are |
|
3301 |
delivered directly to items; there is no convenience function for |
|
3302 |
them. |
|
3303 |
||
3304 |
Unlike QWidget, QGraphicsScene does not have the convenience functions |
|
3305 |
\l{QWidget::}{enterEvent()} and \l{QWidget::}{leaveEvent()}. Use this |
|
3306 |
function to obtain those events instead. |
|
3307 |
||
3308 |
\sa contextMenuEvent(), keyPressEvent(), keyReleaseEvent(), |
|
3309 |
mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), |
|
3310 |
mouseDoubleClickEvent(), focusInEvent(), focusOutEvent() |
|
3311 |
*/ |
|
3312 |
bool QGraphicsScene::event(QEvent *event) |
|
3313 |
{ |
|
3314 |
Q_D(QGraphicsScene); |
|
3315 |
||
3316 |
switch (event->type()) { |
|
3317 |
case QEvent::GraphicsSceneMousePress: |
|
3318 |
case QEvent::GraphicsSceneMouseMove: |
|
3319 |
case QEvent::GraphicsSceneMouseRelease: |
|
3320 |
case QEvent::GraphicsSceneMouseDoubleClick: |
|
3321 |
case QEvent::GraphicsSceneHoverEnter: |
|
3322 |
case QEvent::GraphicsSceneHoverLeave: |
|
3323 |
case QEvent::GraphicsSceneHoverMove: |
|
3324 |
case QEvent::TouchBegin: |
|
3325 |
case QEvent::TouchUpdate: |
|
3326 |
case QEvent::TouchEnd: |
|
3327 |
// Reset the under-mouse list to ensure that this event gets fresh |
|
3328 |
// item-under-mouse data. Be careful about this list; if people delete |
|
3329 |
// items from inside event handlers, this list can quickly end up |
|
3330 |
// having stale pointers in it. We need to clear it before dispatching |
|
3331 |
// events that use it. |
|
3332 |
// ### this should only be cleared if we received a new mouse move event, |
|
3333 |
// which relies on us fixing the replay mechanism in QGraphicsView. |
|
3334 |
d->cachedItemsUnderMouse.clear(); |
|
3335 |
default: |
|
3336 |
break; |
|
3337 |
} |
|
3338 |
||
3339 |
switch (event->type()) { |
|
3340 |
case QEvent::GraphicsSceneDragEnter: |
|
3341 |
dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
3342 |
break; |
|
3343 |
case QEvent::GraphicsSceneDragMove: |
|
3344 |
dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
3345 |
break; |
|
3346 |
case QEvent::GraphicsSceneDragLeave: |
|
3347 |
dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
3348 |
break; |
|
3349 |
case QEvent::GraphicsSceneDrop: |
|
3350 |
dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); |
|
3351 |
break; |
|
3352 |
case QEvent::GraphicsSceneContextMenu: |
|
3353 |
contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event)); |
|
3354 |
break; |
|
3355 |
case QEvent::KeyPress: |
|
3356 |
if (!d->focusItem) { |
|
3357 |
QKeyEvent *k = static_cast<QKeyEvent *>(event); |
|
3358 |
if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { |
|
3359 |
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? |
|
3360 |
bool res = false; |
|
3361 |
if (k->key() == Qt::Key_Backtab |
|
3362 |
|| (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) { |
|
3363 |
res = focusNextPrevChild(false); |
|
3364 |
} else if (k->key() == Qt::Key_Tab) { |
|
3365 |
res = focusNextPrevChild(true); |
|
3366 |
} |
|
3367 |
if (!res) |
|
3368 |
event->ignore(); |
|
3369 |
return true; |
|
3370 |
} |
|
3371 |
} |
|
3372 |
} |
|
3373 |
keyPressEvent(static_cast<QKeyEvent *>(event)); |
|
3374 |
break; |
|
3375 |
case QEvent::KeyRelease: |
|
3376 |
keyReleaseEvent(static_cast<QKeyEvent *>(event)); |
|
3377 |
break; |
|
3378 |
case QEvent::ShortcutOverride: { |
|
3379 |
QGraphicsItem *parent = focusItem(); |
|
3380 |
while (parent) { |
|
3381 |
d->sendEvent(parent, event); |
|
3382 |
if (event->isAccepted()) |
|
3383 |
return true; |
|
3384 |
parent = parent->parentItem(); |
|
3385 |
} |
|
3386 |
} |
|
3387 |
return false; |
|
3388 |
case QEvent::GraphicsSceneMouseMove: |
|
3389 |
{ |
|
3390 |
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event); |
|
3391 |
d->lastSceneMousePos = mouseEvent->scenePos(); |
|
3392 |
mouseMoveEvent(mouseEvent); |
|
3393 |
break; |
|
3394 |
} |
|
3395 |
case QEvent::GraphicsSceneMousePress: |
|
3396 |
mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
3397 |
break; |
|
3398 |
case QEvent::GraphicsSceneMouseRelease: |
|
3399 |
mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
3400 |
break; |
|
3401 |
case QEvent::GraphicsSceneMouseDoubleClick: |
|
3402 |
mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
3403 |
break; |
|
3404 |
case QEvent::GraphicsSceneWheel: |
|
3405 |
wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event)); |
|
3406 |
break; |
|
3407 |
case QEvent::FocusIn: |
|
3408 |
focusInEvent(static_cast<QFocusEvent *>(event)); |
|
3409 |
break; |
|
3410 |
case QEvent::FocusOut: |
|
3411 |
focusOutEvent(static_cast<QFocusEvent *>(event)); |
|
3412 |
break; |
|
3413 |
case QEvent::GraphicsSceneHoverEnter: |
|
3414 |
case QEvent::GraphicsSceneHoverLeave: |
|
3415 |
case QEvent::GraphicsSceneHoverMove: |
|
3416 |
{ |
|
3417 |
QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event); |
|
3418 |
d->lastSceneMousePos = hoverEvent->scenePos(); |
|
3419 |
d->dispatchHoverEvent(hoverEvent); |
|
3420 |
break; |
|
3421 |
} |
|
3422 |
case QEvent::Leave: |
|
3423 |
d->leaveScene(); |
|
3424 |
break; |
|
3425 |
case QEvent::GraphicsSceneHelp: |
|
3426 |
helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event)); |
|
3427 |
break; |
|
3428 |
case QEvent::InputMethod: |
|
3429 |
inputMethodEvent(static_cast<QInputMethodEvent *>(event)); |
|
3430 |
break; |
|
3431 |
case QEvent::WindowActivate: |
|
3432 |
if (!d->activationRefCount++) { |
|
3433 |
if (d->lastActivePanel) { |
|
3434 |
// Activate the last panel. |
|
3435 |
d->setActivePanelHelper(d->lastActivePanel, true); |
|
3436 |
} else if (d->tabFocusFirst && d->tabFocusFirst->isPanel()) { |
|
3437 |
// Activate the panel of the first item in the tab focus |
|
3438 |
// chain. |
|
3439 |
d->setActivePanelHelper(d->tabFocusFirst, true); |
|
3440 |
} else { |
|
3441 |
// Activate all toplevel items. |
|
3442 |
QEvent event(QEvent::WindowActivate); |
|
3443 |
foreach (QGraphicsItem *item, items()) { |
|
3444 |
if (item->isVisible() && !item->isPanel() && !item->parentItem()) |
|
3445 |
sendEvent(item, &event); |
|
3446 |
} |
|
3447 |
} |
|
3448 |
} |
|
3449 |
break; |
|
3450 |
case QEvent::WindowDeactivate: |
|
3451 |
if (!--d->activationRefCount) { |
|
3452 |
if (d->activePanel) { |
|
3453 |
// Deactivate the active panel (but keep it so we can |
|
3454 |
// reactivate it later). |
|
3455 |
QGraphicsItem *lastActivePanel = d->activePanel; |
|
3456 |
d->setActivePanelHelper(0, true); |
|
3457 |
d->lastActivePanel = lastActivePanel; |
|
3458 |
} else { |
|
3459 |
// Activate all toplevel items. |
|
3460 |
QEvent event(QEvent::WindowDeactivate); |
|
3461 |
foreach (QGraphicsItem *item, items()) { |
|
3462 |
if (item->isVisible() && !item->isPanel() && !item->parentItem()) |
|
3463 |
sendEvent(item, &event); |
|
3464 |
} |
|
3465 |
} |
|
3466 |
} |
|
3467 |
break; |
|
3468 |
case QEvent::ApplicationFontChange: { |
|
3469 |
// Resolve the existing scene font. |
|
3470 |
d->resolveFont(); |
|
3471 |
break; |
|
3472 |
} |
|
3473 |
case QEvent::FontChange: |
|
3474 |
// Update the entire scene when the font changes. |
|
3475 |
update(); |
|
3476 |
break; |
|
3477 |
case QEvent::ApplicationPaletteChange: { |
|
3478 |
// Resolve the existing scene palette. |
|
3479 |
d->resolvePalette(); |
|
3480 |
break; |
|
3481 |
} |
|
3482 |
case QEvent::PaletteChange: |
|
3483 |
// Update the entire scene when the palette changes. |
|
3484 |
update(); |
|
3485 |
break; |
|
3486 |
case QEvent::StyleChange: |
|
3487 |
// Reresolve all widgets' styles. Update all top-level widgets' |
|
3488 |
// geometries that do not have an explicit style set. |
|
3489 |
update(); |
|
3490 |
break; |
|
3491 |
case QEvent::TouchBegin: |
|
3492 |
case QEvent::TouchUpdate: |
|
3493 |
case QEvent::TouchEnd: |
|
3494 |
d->touchEventHandler(static_cast<QTouchEvent *>(event)); |
|
3495 |
break; |
|
3496 |
case QEvent::Gesture: |
|
3497 |
case QEvent::GestureOverride: |
|
3498 |
d->gestureEventHandler(static_cast<QGestureEvent *>(event)); |
|
3499 |
break; |
|
3500 |
default: |
|
3501 |
return QObject::event(event); |
|
3502 |
} |
|
3503 |
return true; |
|
3504 |
} |
|
3505 |
||
3506 |
/*! |
|
3507 |
\reimp |
|
3508 |
||
3509 |
QGraphicsScene filters QApplication's events to detect palette and font |
|
3510 |
changes. |
|
3511 |
*/ |
|
3512 |
bool QGraphicsScene::eventFilter(QObject *watched, QEvent *event) |
|
3513 |
{ |
|
3514 |
if (watched != qApp) |
|
3515 |
return false; |
|
3516 |
||
3517 |
switch (event->type()) { |
|
3518 |
case QEvent::ApplicationPaletteChange: |
|
3519 |
QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange)); |
|
3520 |
break; |
|
3521 |
case QEvent::ApplicationFontChange: |
|
3522 |
QApplication::postEvent(this, new QEvent(QEvent::ApplicationFontChange)); |
|
3523 |
break; |
|
3524 |
default: |
|
3525 |
break; |
|
3526 |
} |
|
3527 |
return false; |
|
3528 |
} |
|
3529 |
||
3530 |
/*! |
|
3531 |
This event handler, for event \a contextMenuEvent, can be reimplemented in |
|
3532 |
a subclass to receive context menu events. The default implementation |
|
3533 |
forwards the event to the topmost item that accepts context menu events at |
|
3534 |
the position of the event. If no items accept context menu events at this |
|
3535 |
position, the event is ignored. |
|
3536 |
||
3537 |
\sa QGraphicsItem::contextMenuEvent() |
|
3538 |
*/ |
|
3539 |
void QGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) |
|
3540 |
{ |
|
3541 |
Q_D(QGraphicsScene); |
|
3542 |
// Ignore by default. |
|
3543 |
contextMenuEvent->ignore(); |
|
3544 |
||
3545 |
// Send the event to all items at this position until one item accepts the |
|
3546 |
// event. |
|
3547 |
foreach (QGraphicsItem *item, d->itemsAtPosition(contextMenuEvent->screenPos(), |
|
3548 |
contextMenuEvent->scenePos(), |
|
3549 |
contextMenuEvent->widget())) { |
|
3550 |
contextMenuEvent->setPos(item->d_ptr->genericMapFromScene(contextMenuEvent->scenePos(), |
|
3551 |
contextMenuEvent->widget())); |
|
3552 |
contextMenuEvent->accept(); |
|
3553 |
if (!d->sendEvent(item, contextMenuEvent)) |
|
3554 |
break; |
|
3555 |
||
3556 |
if (contextMenuEvent->isAccepted()) |
|
3557 |
break; |
|
3558 |
} |
|
3559 |
} |
|
3560 |
||
3561 |
/*! |
|
3562 |
This event handler, for event \a event, can be reimplemented in a subclass |
|
3563 |
to receive drag enter events for the scene. |
|
3564 |
||
3565 |
The default implementation accepts the event and prepares the scene to |
|
3566 |
accept drag move events. |
|
3567 |
||
3568 |
\sa QGraphicsItem::dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), |
|
3569 |
dropEvent() |
|
3570 |
*/ |
|
3571 |
void QGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) |
|
3572 |
{ |
|
3573 |
Q_D(QGraphicsScene); |
|
3574 |
d->dragDropItem = 0; |
|
3575 |
d->lastDropAction = Qt::IgnoreAction; |
|
3576 |
event->accept(); |
|
3577 |
} |
|
3578 |
||
3579 |
/*! |
|
3580 |
This event handler, for event \a event, can be reimplemented in a subclass |
|
3581 |
to receive drag move events for the scene. |
|
3582 |
||
3583 |
\sa QGraphicsItem::dragMoveEvent(), dragEnterEvent(), dragLeaveEvent(), |
|
3584 |
dropEvent() |
|
3585 |
*/ |
|
3586 |
void QGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event) |
|
3587 |
{ |
|
3588 |
Q_D(QGraphicsScene); |
|
3589 |
event->ignore(); |
|
3590 |
||
3591 |
if (!d->mouseGrabberItems.isEmpty()) { |
|
3592 |
// Mouse grabbers that start drag events lose the mouse grab. |
|
3593 |
d->clearMouseGrabber(); |
|
3594 |
d->mouseGrabberButtonDownPos.clear(); |
|
3595 |
d->mouseGrabberButtonDownScenePos.clear(); |
|
3596 |
d->mouseGrabberButtonDownScreenPos.clear(); |
|
3597 |
} |
|
3598 |
||
3599 |
bool eventDelivered = false; |
|
3600 |
||
3601 |
// Find the topmost enabled items under the cursor. They are all |
|
3602 |
// candidates for accepting drag & drop events. |
|
3603 |
foreach (QGraphicsItem *item, d->itemsAtPosition(event->screenPos(), |
|
3604 |
event->scenePos(), |
|
3605 |
event->widget())) { |
|
3606 |
if (!item->isEnabled() || !item->acceptDrops()) |
|
3607 |
continue; |
|
3608 |
||
3609 |
if (item != d->dragDropItem) { |
|
3610 |
// Enter the new drag drop item. If it accepts the event, we send |
|
3611 |
// the leave to the parent item. |
|
3612 |
QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); |
|
3613 |
d->cloneDragDropEvent(&dragEnter, event); |
|
3614 |
dragEnter.setDropAction(event->proposedAction()); |
|
3615 |
d->sendDragDropEvent(item, &dragEnter); |
|
3616 |
event->setAccepted(dragEnter.isAccepted()); |
|
3617 |
event->setDropAction(dragEnter.dropAction()); |
|
3618 |
if (!event->isAccepted()) { |
|
3619 |
// Propagate to the item under |
|
3620 |
continue; |
|
3621 |
} |
|
3622 |
||
3623 |
d->lastDropAction = event->dropAction(); |
|
3624 |
||
3625 |
if (d->dragDropItem) { |
|
3626 |
// Leave the last drag drop item. A perfect implementation |
|
3627 |
// would set the position of this event to the point where |
|
3628 |
// this event and the last event intersect with the item's |
|
3629 |
// shape, but that's not easy to do. :-) |
|
3630 |
QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); |
|
3631 |
d->cloneDragDropEvent(&dragLeave, event); |
|
3632 |
d->sendDragDropEvent(d->dragDropItem, &dragLeave); |
|
3633 |
} |
|
3634 |
||
3635 |
// We've got a new drag & drop item |
|
3636 |
d->dragDropItem = item; |
|
3637 |
} |
|
3638 |
||
3639 |
// Send the move event. |
|
3640 |
event->setDropAction(d->lastDropAction); |
|
3641 |
event->accept(); |
|
3642 |
d->sendDragDropEvent(item, event); |
|
3643 |
if (event->isAccepted()) |
|
3644 |
d->lastDropAction = event->dropAction(); |
|
3645 |
eventDelivered = true; |
|
3646 |
break; |
|
3647 |
} |
|
3648 |
||
3649 |
if (!eventDelivered) { |
|
3650 |
if (d->dragDropItem) { |
|
3651 |
// Leave the last drag drop item |
|
3652 |
QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); |
|
3653 |
d->cloneDragDropEvent(&dragLeave, event); |
|
3654 |
d->sendDragDropEvent(d->dragDropItem, &dragLeave); |
|
3655 |
d->dragDropItem = 0; |
|
3656 |
} |
|
3657 |
// Propagate |
|
3658 |
event->setDropAction(Qt::IgnoreAction); |
|
3659 |
} |
|
3660 |
} |
|
3661 |
||
3662 |
/*! |
|
3663 |
This event handler, for event \a event, can be reimplemented in a subclass |
|
3664 |
to receive drag leave events for the scene. |
|
3665 |
||
3666 |
\sa QGraphicsItem::dragLeaveEvent(), dragEnterEvent(), dragMoveEvent(), |
|
3667 |
dropEvent() |
|
3668 |
*/ |
|
3669 |
void QGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) |
|
3670 |
{ |
|
3671 |
Q_D(QGraphicsScene); |
|
3672 |
if (d->dragDropItem) { |
|
3673 |
// Leave the last drag drop item |
|
3674 |
d->sendDragDropEvent(d->dragDropItem, event); |
|
3675 |
d->dragDropItem = 0; |
|
3676 |
} |
|
3677 |
} |
|
3678 |
||
3679 |
/*! |
|
3680 |
This event handler, for event \a event, can be reimplemented in a subclass |
|
3681 |
to receive drop events for the scene. |
|
3682 |
||
3683 |
\sa QGraphicsItem::dropEvent(), dragEnterEvent(), dragMoveEvent(), |
|
3684 |
dragLeaveEvent() |
|
3685 |
*/ |
|
3686 |
void QGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event) |
|
3687 |
{ |
|
3688 |
Q_UNUSED(event); |
|
3689 |
Q_D(QGraphicsScene); |
|
3690 |
if (d->dragDropItem) { |
|
3691 |
// Drop on the last drag drop item |
|
3692 |
d->sendDragDropEvent(d->dragDropItem, event); |
|
3693 |
d->dragDropItem = 0; |
|
3694 |
} |
|
3695 |
} |
|
3696 |
||
3697 |
/*! |
|
3698 |
This event handler, for event \a focusEvent, can be reimplemented in a |
|
3699 |
subclass to receive focus in events. |
|
3700 |
||
3701 |
The default implementation sets focus on the scene, and then on the last |
|
3702 |
focus item. |
|
3703 |
||
3704 |
\sa QGraphicsItem::focusOutEvent() |
|
3705 |
*/ |
|
3706 |
void QGraphicsScene::focusInEvent(QFocusEvent *focusEvent) |
|
3707 |
{ |
|
3708 |
Q_D(QGraphicsScene); |
|
3709 |
||
3710 |
d->hasFocus = true; |
|
3711 |
switch (focusEvent->reason()) { |
|
3712 |
case Qt::TabFocusReason: |
|
3713 |
if (!focusNextPrevChild(true)) |
|
3714 |
focusEvent->ignore(); |
|
3715 |
break; |
|
3716 |
case Qt::BacktabFocusReason: |
|
3717 |
if (!focusNextPrevChild(false)) |
|
3718 |
focusEvent->ignore(); |
|
3719 |
break; |
|
3720 |
default: |
|
3721 |
if (d->lastFocusItem) { |
|
3722 |
// Set focus on the last focus item |
|
3723 |
setFocusItem(d->lastFocusItem, focusEvent->reason()); |
|
3724 |
} |
|
3725 |
break; |
|
3726 |
} |
|
3727 |
} |
|
3728 |
||
3729 |
/*! |
|
3730 |
This event handler, for event \a focusEvent, can be reimplemented in a |
|
3731 |
subclass to receive focus out events. |
|
3732 |
||
3733 |
The default implementation removes focus from any focus item, then removes |
|
3734 |
focus from the scene. |
|
3735 |
||
3736 |
\sa QGraphicsItem::focusInEvent() |
|
3737 |
*/ |
|
3738 |
void QGraphicsScene::focusOutEvent(QFocusEvent *focusEvent) |
|
3739 |
{ |
|
3740 |
Q_D(QGraphicsScene); |
|
3741 |
d->hasFocus = false; |
|
3742 |
setFocusItem(0, focusEvent->reason()); |
|
3743 |
||
3744 |
// Remove all popups when the scene loses focus. |
|
3745 |
if (!d->popupWidgets.isEmpty()) |
|
3746 |
d->removePopup(d->popupWidgets.first()); |
|
3747 |
} |
|
3748 |
||
3749 |
/*! |
|
3750 |
This event handler, for event \a helpEvent, can be |
|
3751 |
reimplemented in a subclass to receive help events. The events |
|
3752 |
are of type QEvent::ToolTip, which are created when a tooltip is |
|
3753 |
requested. |
|
3754 |
||
3755 |
The default implementation shows the tooltip of the topmost |
|
3756 |
item, i.e., the item with the highest z-value, at the mouse |
|
3757 |
cursor position. If no item has a tooltip set, this function |
|
3758 |
does nothing. |
|
3759 |
||
3760 |
\sa QGraphicsItem::toolTip(), QGraphicsSceneHelpEvent |
|
3761 |
*/ |
|
3762 |
void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent) |
|
3763 |
{ |
|
3764 |
#ifdef QT_NO_TOOLTIP |
|
3765 |
Q_UNUSED(helpEvent); |
|
3766 |
#else |
|
3767 |
// Find the first item that does tooltips |
|
3768 |
Q_D(QGraphicsScene); |
|
3769 |
QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(), |
|
3770 |
helpEvent->scenePos(), |
|
3771 |
helpEvent->widget()); |
|
3772 |
QGraphicsItem *toolTipItem = 0; |
|
3773 |
for (int i = 0; i < itemsAtPos.size(); ++i) { |
|
3774 |
QGraphicsItem *tmp = itemsAtPos.at(i); |
|
3775 |
if (!tmp->toolTip().isEmpty()) { |
|
3776 |
toolTipItem = tmp; |
|
3777 |
break; |
|
3778 |
} |
|
3779 |
} |
|
3780 |
||
3781 |
// Show or hide the tooltip |
|
3782 |
QString text; |
|
3783 |
QPoint point; |
|
3784 |
if (toolTipItem && !toolTipItem->toolTip().isEmpty()) { |
|
3785 |
text = toolTipItem->toolTip(); |
|
3786 |
point = helpEvent->screenPos(); |
|
3787 |
} |
|
3788 |
QToolTip::showText(point, text, helpEvent->widget()); |
|
3789 |
helpEvent->setAccepted(!text.isEmpty()); |
|
3790 |
#endif |
|
3791 |
} |
|
3792 |
||
3793 |
bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const |
|
3794 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3795 |
return (item->d_ptr->acceptsHover |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3796 |
|| (item->d_ptr->isWidget |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3797 |
&& static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
3798 |
&& !item->isBlockedByModalPanel(); |
0 | 3799 |
} |
3800 |
||
3801 |
/*! |
|
3802 |
This event handler, for event \a hoverEvent, can be reimplemented in a |
|
3803 |
subclass to receive hover enter events. The default implementation |
|
3804 |
forwards the event to the topmost item that accepts hover events at the |
|
3805 |
scene position from the event. |
|
3806 |
||
3807 |
\sa QGraphicsItem::hoverEvent(), QGraphicsItem::setAcceptHoverEvents() |
|
3808 |
*/ |
|
3809 |
bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent) |
|
3810 |
{ |
|
3811 |
if (allItemsIgnoreHoverEvents) |
|
3812 |
return false; |
|
3813 |
||
3814 |
// Find the first item that accepts hover events, reusing earlier |
|
3815 |
// calculated data is possible. |
|
3816 |
if (cachedItemsUnderMouse.isEmpty()) { |
|
3817 |
cachedItemsUnderMouse = itemsAtPosition(hoverEvent->screenPos(), |
|
3818 |
hoverEvent->scenePos(), |
|
3819 |
hoverEvent->widget()); |
|
3820 |
} |
|
3821 |
||
3822 |
QGraphicsItem *item = 0; |
|
3823 |
for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) { |
|
3824 |
QGraphicsItem *tmp = cachedItemsUnderMouse.at(i); |
|
3825 |
if (itemAcceptsHoverEvents_helper(tmp)) { |
|
3826 |
item = tmp; |
|
3827 |
break; |
|
3828 |
} |
|
3829 |
} |
|
3830 |
||
3831 |
// Find the common ancestor item for the new topmost hoverItem and the |
|
3832 |
// last item in the hoverItem list. |
|
3833 |
QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.last()) : 0; |
|
3834 |
while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem)) |
|
3835 |
commonAncestorItem = commonAncestorItem->parentItem(); |
|
3836 |
if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) { |
|
3837 |
// The common ancestor isn't in the same panel as the two hovered |
|
3838 |
// items. |
|
3839 |
commonAncestorItem = 0; |
|
3840 |
} |
|
3841 |
||
3842 |
// Check if the common ancestor item is known. |
|
3843 |
int index = commonAncestorItem ? hoverItems.indexOf(commonAncestorItem) : -1; |
|
3844 |
// Send hover leaves to any existing hovered children of the common |
|
3845 |
// ancestor item. |
|
3846 |
for (int i = hoverItems.size() - 1; i > index; --i) { |
|
3847 |
QGraphicsItem *lastItem = hoverItems.takeLast(); |
|
3848 |
if (itemAcceptsHoverEvents_helper(lastItem)) |
|
3849 |
sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, hoverEvent); |
|
3850 |
} |
|
3851 |
||
3852 |
// Item is a child of a known item. Generate enter events for the |
|
3853 |
// missing links. |
|
3854 |
QList<QGraphicsItem *> parents; |
|
3855 |
QGraphicsItem *parent = item; |
|
3856 |
while (parent && parent != commonAncestorItem) { |
|
3857 |
parents.prepend(parent); |
|
3858 |
if (parent->isPanel()) { |
|
3859 |
// Stop at the panel - we don't deliver beyond this point. |
|
3860 |
break; |
|
3861 |
} |
|
3862 |
parent = parent->parentItem(); |
|
3863 |
} |
|
3864 |
for (int i = 0; i < parents.size(); ++i) { |
|
3865 |
parent = parents.at(i); |
|
3866 |
hoverItems << parent; |
|
3867 |
if (itemAcceptsHoverEvents_helper(parent)) |
|
3868 |
sendHoverEvent(QEvent::GraphicsSceneHoverEnter, parent, hoverEvent); |
|
3869 |
} |
|
3870 |
||
3871 |
// Generate a move event for the item itself |
|
3872 |
if (item |
|
3873 |
&& !hoverItems.isEmpty() |
|
3874 |
&& item == hoverItems.last()) { |
|
3875 |
sendHoverEvent(QEvent::GraphicsSceneHoverMove, item, hoverEvent); |
|
3876 |
return true; |
|
3877 |
} |
|
3878 |
return false; |
|
3879 |
} |
|
3880 |
||
3881 |
/*! |
|
3882 |
\internal |
|
3883 |
||
3884 |
Handles all actions necessary to clean up the scene when the mouse leaves |
|
3885 |
the view. |
|
3886 |
*/ |
|
3887 |
void QGraphicsScenePrivate::leaveScene() |
|
3888 |
{ |
|
3889 |
Q_Q(QGraphicsScene); |
|
3890 |
#ifndef QT_NO_TOOLTIP |
|
3891 |
QToolTip::hideText(); |
|
3892 |
#endif |
|
3893 |
// Send HoverLeave events to all existing hover items, topmost first. |
|
3894 |
QGraphicsView *senderWidget = qobject_cast<QGraphicsView *>(q->sender()); |
|
3895 |
QGraphicsSceneHoverEvent hoverEvent; |
|
3896 |
hoverEvent.setWidget(senderWidget); |
|
3897 |
||
3898 |
if (senderWidget) { |
|
3899 |
QPoint cursorPos = QCursor::pos(); |
|
3900 |
hoverEvent.setScenePos(senderWidget->mapToScene(senderWidget->mapFromGlobal(cursorPos))); |
|
3901 |
hoverEvent.setLastScenePos(hoverEvent.scenePos()); |
|
3902 |
hoverEvent.setScreenPos(cursorPos); |
|
3903 |
hoverEvent.setLastScreenPos(hoverEvent.screenPos()); |
|
3904 |
} |
|
3905 |
||
3906 |
while (!hoverItems.isEmpty()) { |
|
3907 |
QGraphicsItem *lastItem = hoverItems.takeLast(); |
|
3908 |
if (itemAcceptsHoverEvents_helper(lastItem)) |
|
3909 |
sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, &hoverEvent); |
|
3910 |
} |
|
3911 |
} |
|
3912 |
||
3913 |
/*! |
|
3914 |
This event handler, for event \a keyEvent, can be reimplemented in a |
|
3915 |
subclass to receive keypress events. The default implementation forwards |
|
3916 |
the event to current focus item. |
|
3917 |
||
3918 |
\sa QGraphicsItem::keyPressEvent(), focusItem() |
|
3919 |
*/ |
|
3920 |
void QGraphicsScene::keyPressEvent(QKeyEvent *keyEvent) |
|
3921 |
{ |
|
3922 |
// ### Merge this function with keyReleaseEvent; they are identical |
|
3923 |
// ### (except this comment). |
|
3924 |
Q_D(QGraphicsScene); |
|
3925 |
QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0; |
|
3926 |
if (!item) |
|
3927 |
item = focusItem(); |
|
3928 |
if (item) { |
|
3929 |
QGraphicsItem *p = item; |
|
3930 |
do { |
|
3931 |
// Accept the event by default |
|
3932 |
keyEvent->accept(); |
|
3933 |
// Send it; QGraphicsItem::keyPressEvent ignores it. If the event |
|
3934 |
// is filtered out, stop propagating it. |
|
3935 |
if (p->isBlockedByModalPanel()) |
|
3936 |
break; |
|
3937 |
if (!d->sendEvent(p, keyEvent)) |
|
3938 |
break; |
|
3939 |
} while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem())); |
|
3940 |
} else { |
|
3941 |
keyEvent->ignore(); |
|
3942 |
} |
|
3943 |
} |
|
3944 |
||
3945 |
/*! |
|
3946 |
This event handler, for event \a keyEvent, can be reimplemented in a |
|
3947 |
subclass to receive key release events. The default implementation |
|
3948 |
forwards the event to current focus item. |
|
3949 |
||
3950 |
\sa QGraphicsItem::keyReleaseEvent(), focusItem() |
|
3951 |
*/ |
|
3952 |
void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent) |
|
3953 |
{ |
|
3954 |
// ### Merge this function with keyPressEvent; they are identical (except |
|
3955 |
// ### this comment). |
|
3956 |
Q_D(QGraphicsScene); |
|
3957 |
QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0; |
|
3958 |
if (!item) |
|
3959 |
item = focusItem(); |
|
3960 |
if (item) { |
|
3961 |
QGraphicsItem *p = item; |
|
3962 |
do { |
|
3963 |
// Accept the event by default |
|
3964 |
keyEvent->accept(); |
|
3965 |
// Send it; QGraphicsItem::keyPressEvent ignores it. If the event |
|
3966 |
// is filtered out, stop propagating it. |
|
3967 |
if (p->isBlockedByModalPanel()) |
|
3968 |
break; |
|
3969 |
if (!d->sendEvent(p, keyEvent)) |
|
3970 |
break; |
|
3971 |
} while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem())); |
|
3972 |
} else { |
|
3973 |
keyEvent->ignore(); |
|
3974 |
} |
|
3975 |
} |
|
3976 |
||
3977 |
/*! |
|
3978 |
This event handler, for event \a mouseEvent, can be reimplemented |
|
3979 |
in a subclass to receive mouse press events for the scene. |
|
3980 |
||
3981 |
The default implementation depends on the state of the scene. If |
|
3982 |
there is a mouse grabber item, then the event is sent to the mouse |
|
3983 |
grabber. Otherwise, it is forwarded to the topmost item that |
|
3984 |
accepts mouse events at the scene position from the event, and |
|
3985 |
that item promptly becomes the mouse grabber item. |
|
3986 |
||
3987 |
If there is no item at the given position on the scene, the |
|
3988 |
selection area is reset, any focus item loses its input focus, and |
|
3989 |
the event is then ignored. |
|
3990 |
||
3991 |
\sa QGraphicsItem::mousePressEvent(), |
|
3992 |
QGraphicsItem::setAcceptedMouseButtons() |
|
3993 |
*/ |
|
3994 |
void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) |
|
3995 |
{ |
|
3996 |
Q_D(QGraphicsScene); |
|
3997 |
if (d->mouseGrabberItems.isEmpty()) { |
|
3998 |
// Dispatch hover events |
|
3999 |
QGraphicsSceneHoverEvent hover; |
|
4000 |
_q_hoverFromMouseEvent(&hover, mouseEvent); |
|
4001 |
d->dispatchHoverEvent(&hover); |
|
4002 |
} |
|
4003 |
||
4004 |
d->mousePressEventHandler(mouseEvent); |
|
4005 |
} |
|
4006 |
||
4007 |
/*! |
|
4008 |
This event handler, for event \a mouseEvent, can be reimplemented |
|
4009 |
in a subclass to receive mouse move events for the scene. |
|
4010 |
||
4011 |
The default implementation depends on the mouse grabber state. If there is |
|
4012 |
a mouse grabber item, the event is sent to the mouse grabber. If there |
|
4013 |
are any items that accept hover events at the current position, the event |
|
4014 |
is translated into a hover event and accepted; otherwise it's ignored. |
|
4015 |
||
4016 |
\sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseReleaseEvent(), |
|
4017 |
QGraphicsItem::mouseDoubleClickEvent(), QGraphicsItem::setAcceptedMouseButtons() |
|
4018 |
*/ |
|
4019 |
void QGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) |
|
4020 |
{ |
|
4021 |
Q_D(QGraphicsScene); |
|
4022 |
if (d->mouseGrabberItems.isEmpty()) { |
|
4023 |
if (mouseEvent->buttons()) |
|
4024 |
return; |
|
4025 |
QGraphicsSceneHoverEvent hover; |
|
4026 |
_q_hoverFromMouseEvent(&hover, mouseEvent); |
|
4027 |
mouseEvent->setAccepted(d->dispatchHoverEvent(&hover)); |
|
4028 |
return; |
|
4029 |
} |
|
4030 |
||
4031 |
// Forward the event to the mouse grabber |
|
4032 |
d->sendMouseEvent(mouseEvent); |
|
4033 |
mouseEvent->accept(); |
|
4034 |
} |
|
4035 |
||
4036 |
/*! |
|
4037 |
This event handler, for event \a mouseEvent, can be reimplemented |
|
4038 |
in a subclass to receive mouse release events for the scene. |
|
4039 |
||
4040 |
The default implementation depends on the mouse grabber state. If |
|
4041 |
there is no mouse grabber, the event is ignored. Otherwise, if |
|
4042 |
there is a mouse grabber item, the event is sent to the mouse |
|
4043 |
grabber. If this mouse release represents the last pressed button |
|
4044 |
on the mouse, the mouse grabber item then loses the mouse grab. |
|
4045 |
||
4046 |
\sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), |
|
4047 |
QGraphicsItem::mouseDoubleClickEvent(), QGraphicsItem::setAcceptedMouseButtons() |
|
4048 |
*/ |
|
4049 |
void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) |
|
4050 |
{ |
|
4051 |
Q_D(QGraphicsScene); |
|
4052 |
if (d->mouseGrabberItems.isEmpty()) { |
|
4053 |
mouseEvent->ignore(); |
|
4054 |
return; |
|
4055 |
} |
|
4056 |
||
4057 |
// Forward the event to the mouse grabber |
|
4058 |
d->sendMouseEvent(mouseEvent); |
|
4059 |
mouseEvent->accept(); |
|
4060 |
||
4061 |
// Reset the mouse grabber when the last mouse button has been released. |
|
4062 |
if (!mouseEvent->buttons()) { |
|
4063 |
if (!d->mouseGrabberItems.isEmpty()) { |
|
4064 |
d->lastMouseGrabberItem = d->mouseGrabberItems.last(); |
|
4065 |
if (d->lastMouseGrabberItemHasImplicitMouseGrab) |
|
4066 |
d->mouseGrabberItems.last()->ungrabMouse(); |
|
4067 |
} else { |
|
4068 |
d->lastMouseGrabberItem = 0; |
|
4069 |
} |
|
4070 |
||
4071 |
// Generate a hoverevent |
|
4072 |
QGraphicsSceneHoverEvent hoverEvent; |
|
4073 |
_q_hoverFromMouseEvent(&hoverEvent, mouseEvent); |
|
4074 |
d->dispatchHoverEvent(&hoverEvent); |
|
4075 |
} |
|
4076 |
} |
|
4077 |
||
4078 |
/*! |
|
4079 |
This event handler, for event \a mouseEvent, can be reimplemented |
|
4080 |
in a subclass to receive mouse doubleclick events for the scene. |
|
4081 |
||
4082 |
If someone doubleclicks on the scene, the scene will first receive |
|
4083 |
a mouse press event, followed by a release event (i.e., a click), |
|
4084 |
then a doubleclick event, and finally a release event. If the |
|
4085 |
doubleclick event is delivered to a different item than the one |
|
4086 |
that received the first press and release, it will be delivered as |
|
4087 |
a press event. However, tripleclick events are not delivered as |
|
4088 |
doubleclick events in this case. |
|
4089 |
||
4090 |
The default implementation is similar to mousePressEvent(). |
|
4091 |
||
4092 |
\sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), |
|
4093 |
QGraphicsItem::mouseReleaseEvent(), QGraphicsItem::setAcceptedMouseButtons() |
|
4094 |
*/ |
|
4095 |
void QGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) |
|
4096 |
{ |
|
4097 |
Q_D(QGraphicsScene); |
|
4098 |
d->mousePressEventHandler(mouseEvent); |
|
4099 |
} |
|
4100 |
||
4101 |
/*! |
|
4102 |
This event handler, for event \a wheelEvent, can be reimplemented in a |
|
4103 |
subclass to receive mouse wheel events for the scene. |
|
4104 |
||
4105 |
By default, the event is delivered to the topmost visible item under the |
|
4106 |
cursor. If ignored, the event propagates to the item beneath, and again |
|
4107 |
until the event is accepted, or it reaches the scene. If no items accept |
|
4108 |
the event, it is ignored. |
|
4109 |
||
4110 |
\sa QGraphicsItem::wheelEvent() |
|
4111 |
*/ |
|
4112 |
void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) |
|
4113 |
{ |
|
4114 |
Q_D(QGraphicsScene); |
|
4115 |
QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(), |
|
4116 |
wheelEvent->scenePos(), |
|
4117 |
wheelEvent->widget()); |
|
4118 |
||
4119 |
bool hasSetFocus = false; |
|
4120 |
foreach (QGraphicsItem *item, wheelCandidates) { |
|
4121 |
if (!hasSetFocus && item->isEnabled() |
|
4122 |
&& ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) { |
|
4123 |
if (item->isWidget() && static_cast<QGraphicsWidget *>(item)->focusPolicy() == Qt::WheelFocus) { |
|
4124 |
hasSetFocus = true; |
|
4125 |
if (item != focusItem()) |
|
4126 |
setFocusItem(item, Qt::MouseFocusReason); |
|
4127 |
} |
|
4128 |
} |
|
4129 |
||
4130 |
wheelEvent->setPos(item->d_ptr->genericMapFromScene(wheelEvent->scenePos(), |
|
4131 |
wheelEvent->widget())); |
|
4132 |
wheelEvent->accept(); |
|
4133 |
bool isPanel = item->isPanel(); |
|
4134 |
d->sendEvent(item, wheelEvent); |
|
4135 |
if (isPanel || wheelEvent->isAccepted()) |
|
4136 |
break; |
|
4137 |
} |
|
4138 |
} |
|
4139 |
||
4140 |
/*! |
|
4141 |
This event handler, for event \a event, can be reimplemented in a |
|
4142 |
subclass to receive input method events for the scene. |
|
4143 |
||
4144 |
The default implementation forwards the event to the focusItem(). |
|
4145 |
If no item currently has focus or the current focus item does not |
|
4146 |
accept input methods, this function does nothing. |
|
4147 |
||
4148 |
\sa QGraphicsItem::inputMethodEvent() |
|
4149 |
*/ |
|
4150 |
void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event) |
|
4151 |
{ |
|
4152 |
Q_D(QGraphicsScene); |
|
4153 |
if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) |
|
4154 |
d->sendEvent(d->focusItem, event); |
|
4155 |
} |
|
4156 |
||
4157 |
/*! |
|
4158 |
Draws the background of the scene using \a painter, before any items and |
|
4159 |
the foreground are drawn. Reimplement this function to provide a custom |
|
4160 |
background for the scene. |
|
4161 |
||
4162 |
All painting is done in \e scene coordinates. The \a rect |
|
4163 |
parameter is the exposed rectangle. |
|
4164 |
||
4165 |
If all you want is to define a color, texture, or gradient for the |
|
4166 |
background, you can call setBackgroundBrush() instead. |
|
4167 |
||
4168 |
\sa drawForeground(), drawItems() |
|
4169 |
*/ |
|
4170 |
void QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) |
|
4171 |
{ |
|
4172 |
Q_D(QGraphicsScene); |
|
4173 |
||
4174 |
if (d->backgroundBrush.style() != Qt::NoBrush) { |
|
4175 |
if (d->painterStateProtection) |
|
4176 |
painter->save(); |
|
4177 |
painter->setBrushOrigin(0, 0); |
|
4178 |
painter->fillRect(rect, backgroundBrush()); |
|
4179 |
if (d->painterStateProtection) |
|
4180 |
painter->restore(); |
|
4181 |
} |
|
4182 |
} |
|
4183 |
||
4184 |
/*! |
|
4185 |
Draws the foreground of the scene using \a painter, after the background |
|
4186 |
and all items have been drawn. Reimplement this function to provide a |
|
4187 |
custom foreground for the scene. |
|
4188 |
||
4189 |
All painting is done in \e scene coordinates. The \a rect |
|
4190 |
parameter is the exposed rectangle. |
|
4191 |
||
4192 |
If all you want is to define a color, texture or gradient for the |
|
4193 |
foreground, you can call setForegroundBrush() instead. |
|
4194 |
||
4195 |
\sa drawBackground(), drawItems() |
|
4196 |
*/ |
|
4197 |
void QGraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) |
|
4198 |
{ |
|
4199 |
Q_D(QGraphicsScene); |
|
4200 |
||
4201 |
if (d->foregroundBrush.style() != Qt::NoBrush) { |
|
4202 |
if (d->painterStateProtection) |
|
4203 |
painter->save(); |
|
4204 |
painter->setBrushOrigin(0, 0); |
|
4205 |
painter->fillRect(rect, foregroundBrush()); |
|
4206 |
if (d->painterStateProtection) |
|
4207 |
painter->restore(); |
|
4208 |
} |
|
4209 |
} |
|
4210 |
||
4211 |
static void _q_paintItem(QGraphicsItem *item, QPainter *painter, |
|
4212 |
const QStyleOptionGraphicsItem *option, QWidget *widget, |
|
4213 |
bool useWindowOpacity, bool painterStateProtection) |
|
4214 |
{ |
|
4215 |
if (!item->isWidget()) { |
|
4216 |
item->paint(painter, option, widget); |
|
4217 |
return; |
|
4218 |
} |
|
4219 |
QGraphicsWidget *widgetItem = static_cast<QGraphicsWidget *>(item); |
|
4220 |
QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(widgetItem); |
|
4221 |
const qreal windowOpacity = (proxy && proxy->widget() && useWindowOpacity) |
|
4222 |
? proxy->widget()->windowOpacity() : 1.0; |
|
4223 |
const qreal oldPainterOpacity = painter->opacity(); |
|
4224 |
||
4225 |
if (qFuzzyIsNull(windowOpacity)) |
|
4226 |
return; |
|
4227 |
// Set new painter opacity. |
|
4228 |
if (windowOpacity < 1.0) |
|
4229 |
painter->setOpacity(oldPainterOpacity * windowOpacity); |
|
4230 |
||
4231 |
// set layoutdirection on the painter |
|
4232 |
Qt::LayoutDirection oldLayoutDirection = painter->layoutDirection(); |
|
4233 |
painter->setLayoutDirection(widgetItem->layoutDirection()); |
|
4234 |
||
4235 |
if (widgetItem->isWindow() && widgetItem->windowType() != Qt::Popup && widgetItem->windowType() != Qt::ToolTip |
|
4236 |
&& !(widgetItem->windowFlags() & Qt::FramelessWindowHint)) { |
|
4237 |
if (painterStateProtection) |
|
4238 |
painter->save(); |
|
4239 |
widgetItem->paintWindowFrame(painter, option, widget); |
|
4240 |
if (painterStateProtection) |
|
4241 |
painter->restore(); |
|
4242 |
} |
|
4243 |
||
4244 |
widgetItem->paint(painter, option, widget); |
|
4245 |
||
4246 |
// Restore layoutdirection on the painter. |
|
4247 |
painter->setLayoutDirection(oldLayoutDirection); |
|
4248 |
// Restore painter opacity. |
|
4249 |
if (windowOpacity < 1.0) |
|
4250 |
painter->setOpacity(oldPainterOpacity); |
|
4251 |
} |
|
4252 |
||
4253 |
static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &pixmapExposed, |
|
4254 |
const QTransform &itemToPixmap, QPainter::RenderHints renderHints, |
|
4255 |
const QStyleOptionGraphicsItem *option, bool painterStateProtection) |
|
4256 |
{ |
|
4257 |
QPixmap subPix; |
|
4258 |
QPainter pixmapPainter; |
|
4259 |
QRect br = pixmapExposed.boundingRect(); |
|
4260 |
||
4261 |
// Don't use subpixmap if we get a full update. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4262 |
if (pixmapExposed.isEmpty() || (pixmapExposed.rectCount() == 1 && br.contains(pix->rect()))) { |
0 | 4263 |
pix->fill(Qt::transparent); |
4264 |
pixmapPainter.begin(pix); |
|
4265 |
} else { |
|
4266 |
subPix = QPixmap(br.size()); |
|
4267 |
subPix.fill(Qt::transparent); |
|
4268 |
pixmapPainter.begin(&subPix); |
|
4269 |
pixmapPainter.translate(-br.topLeft()); |
|
4270 |
if (!pixmapExposed.isEmpty()) { |
|
4271 |
// Applied to subPix; paint is adjusted to the coordinate space is |
|
4272 |
// correct. |
|
4273 |
pixmapPainter.setClipRegion(pixmapExposed); |
|
4274 |
} |
|
4275 |
} |
|
4276 |
||
4277 |
pixmapPainter.setRenderHints(pixmapPainter.renderHints(), false); |
|
4278 |
pixmapPainter.setRenderHints(renderHints, true); |
|
4279 |
pixmapPainter.setWorldTransform(itemToPixmap, true); |
|
4280 |
||
4281 |
// Render. |
|
4282 |
_q_paintItem(item, &pixmapPainter, option, 0, false, painterStateProtection); |
|
4283 |
pixmapPainter.end(); |
|
4284 |
||
4285 |
if (!subPix.isNull()) { |
|
4286 |
// Blit the subpixmap into the main pixmap. |
|
4287 |
pixmapPainter.begin(pix); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4288 |
pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source); |
0 | 4289 |
pixmapPainter.setClipRegion(pixmapExposed); |
4290 |
pixmapPainter.drawPixmap(br.topLeft(), subPix); |
|
4291 |
pixmapPainter.end(); |
|
4292 |
} |
|
4293 |
} |
|
4294 |
||
4295 |
/*! |
|
4296 |
\internal |
|
4297 |
||
4298 |
Draws items directly, or using cache. |
|
4299 |
*/ |
|
4300 |
void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painter, |
|
4301 |
const QStyleOptionGraphicsItem *option, QWidget *widget, |
|
4302 |
bool painterStateProtection) |
|
4303 |
{ |
|
4304 |
QGraphicsItemPrivate *itemd = item->d_ptr.data(); |
|
4305 |
QGraphicsItem::CacheMode cacheMode = QGraphicsItem::CacheMode(itemd->cacheMode); |
|
4306 |
||
4307 |
// Render directly, using no cache. |
|
4308 |
if (cacheMode == QGraphicsItem::NoCache |
|
4309 |
#ifdef Q_WS_X11 |
|
4310 |
|| !X11->use_xrender |
|
4311 |
#endif |
|
4312 |
) { |
|
4313 |
_q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, true, painterStateProtection); |
|
4314 |
return; |
|
4315 |
} |
|
4316 |
||
4317 |
const qreal oldPainterOpacity = painter->opacity(); |
|
4318 |
qreal newPainterOpacity = oldPainterOpacity; |
|
4319 |
QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(item)) : 0; |
|
4320 |
if (proxy && proxy->widget()) { |
|
4321 |
const qreal windowOpacity = proxy->widget()->windowOpacity(); |
|
4322 |
if (windowOpacity < 1.0) |
|
4323 |
newPainterOpacity *= windowOpacity; |
|
4324 |
} |
|
4325 |
||
4326 |
// Item's (local) bounding rect |
|
4327 |
QRectF brect = item->boundingRect(); |
|
4328 |
QRectF adjustedBrect(brect); |
|
4329 |
_q_adjustRect(&adjustedBrect); |
|
4330 |
if (adjustedBrect.isEmpty()) |
|
4331 |
return; |
|
4332 |
||
4333 |
// Fetch the off-screen transparent buffer and exposed area info. |
|
4334 |
QPixmapCache::Key pixmapKey; |
|
4335 |
QPixmap pix; |
|
4336 |
bool pixmapFound; |
|
4337 |
QGraphicsItemCache *itemCache = itemd->extraItemCache(); |
|
4338 |
if (cacheMode == QGraphicsItem::ItemCoordinateCache) { |
|
4339 |
if (itemCache->boundingRect != brect.toRect()) { |
|
4340 |
itemCache->boundingRect = brect.toRect(); |
|
4341 |
itemCache->allExposed = true; |
|
4342 |
itemCache->exposed.clear(); |
|
4343 |
} |
|
4344 |
pixmapKey = itemCache->key; |
|
4345 |
} else { |
|
4346 |
pixmapKey = itemCache->deviceData.value(widget).key; |
|
4347 |
} |
|
4348 |
||
4349 |
// Find pixmap in cache. |
|
4350 |
pixmapFound = QPixmapCache::find(pixmapKey, &pix); |
|
4351 |
||
4352 |
// Render using item coordinate cache mode. |
|
4353 |
if (cacheMode == QGraphicsItem::ItemCoordinateCache) { |
|
4354 |
QSize pixmapSize; |
|
4355 |
bool fixedCacheSize = false; |
|
4356 |
QRectF brectAligned = brect.toAlignedRect(); |
|
4357 |
if ((fixedCacheSize = itemCache->fixedSize.isValid())) { |
|
4358 |
pixmapSize = itemCache->fixedSize; |
|
4359 |
} else { |
|
4360 |
pixmapSize = brectAligned.size().toSize(); |
|
4361 |
} |
|
4362 |
||
4363 |
// Create or recreate the pixmap. |
|
4364 |
int adjust = itemCache->fixedSize.isValid() ? 0 : 2; |
|
4365 |
QSize adjustSize(adjust*2, adjust*2); |
|
4366 |
QRectF br = brectAligned.adjusted(-adjust, -adjust, adjust, adjust); |
|
4367 |
if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) { |
|
4368 |
pix = QPixmap(pixmapSize + adjustSize); |
|
4369 |
itemCache->exposed.clear(); |
|
4370 |
itemCache->allExposed = true; |
|
4371 |
} |
|
4372 |
||
4373 |
// Redraw any newly exposed areas. |
|
4374 |
if (itemCache->allExposed || !itemCache->exposed.isEmpty()) { |
|
4375 |
||
4376 |
//We know that we will modify the pixmap, removing it from the cache |
|
4377 |
//will detach the one we have and avoid a deep copy |
|
4378 |
if (pixmapFound) |
|
4379 |
QPixmapCache::remove(pixmapKey); |
|
4380 |
||
4381 |
// Fit the item's bounding rect into the pixmap's coordinates. |
|
4382 |
QTransform itemToPixmap; |
|
4383 |
if (fixedCacheSize) { |
|
4384 |
const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); |
|
4385 |
itemToPixmap.scale(scale.x(), scale.y()); |
|
4386 |
} |
|
4387 |
itemToPixmap.translate(-br.x(), -br.y()); |
|
4388 |
||
4389 |
// Generate the item's exposedRect and map its list of expose |
|
4390 |
// rects to device coordinates. |
|
4391 |
styleOptionTmp = *option; |
|
4392 |
QRegion pixmapExposed; |
|
4393 |
QRectF exposedRect; |
|
4394 |
if (!itemCache->allExposed) { |
|
4395 |
for (int i = 0; i < itemCache->exposed.size(); ++i) { |
|
4396 |
QRectF r = itemCache->exposed.at(i); |
|
4397 |
exposedRect |= r; |
|
4398 |
pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect(); |
|
4399 |
} |
|
4400 |
} else { |
|
4401 |
exposedRect = brect; |
|
4402 |
} |
|
4403 |
styleOptionTmp.exposedRect = exposedRect; |
|
4404 |
||
4405 |
// Render. |
|
4406 |
_q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), |
|
4407 |
&styleOptionTmp, painterStateProtection); |
|
4408 |
||
4409 |
// insert this pixmap into the cache. |
|
4410 |
itemCache->key = QPixmapCache::insert(pix); |
|
4411 |
||
4412 |
// Reset expose data. |
|
4413 |
itemCache->allExposed = false; |
|
4414 |
itemCache->exposed.clear(); |
|
4415 |
} |
|
4416 |
||
4417 |
// Redraw the exposed area using the transformed painter. Depending on |
|
4418 |
// the hardware, this may be a server-side operation, or an expensive |
|
4419 |
// qpixmap-image-transform-pixmap roundtrip. |
|
4420 |
if (newPainterOpacity != oldPainterOpacity) { |
|
4421 |
painter->setOpacity(newPainterOpacity); |
|
4422 |
painter->drawPixmap(br, pix, QRectF(QPointF(), pix.size())); |
|
4423 |
painter->setOpacity(oldPainterOpacity); |
|
4424 |
} else { |
|
4425 |
painter->drawPixmap(br, pix, QRectF(QPointF(), pix.size())); |
|
4426 |
} |
|
4427 |
return; |
|
4428 |
} |
|
4429 |
||
4430 |
// Render using device coordinate cache mode. |
|
4431 |
if (cacheMode == QGraphicsItem::DeviceCoordinateCache) { |
|
4432 |
// Find the item's bounds in device coordinates. |
|
4433 |
QRectF deviceBounds = painter->worldTransform().mapRect(brect); |
|
4434 |
QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1); |
|
4435 |
if (deviceRect.isEmpty()) |
|
4436 |
return; |
|
4437 |
QRect viewRect = widget ? widget->rect() : QRect(); |
|
4438 |
if (widget && !viewRect.intersects(deviceRect)) |
|
4439 |
return; |
|
4440 |
||
4441 |
// Resort to direct rendering if the device rect exceeds the |
|
4442 |
// (optional) maximum bounds. (QGraphicsSvgItem uses this). |
|
4443 |
QSize maximumCacheSize = |
|
4444 |
itemd->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize(); |
|
4445 |
if (!maximumCacheSize.isEmpty() |
|
4446 |
&& (deviceRect.width() > maximumCacheSize.width() |
|
4447 |
|| deviceRect.height() > maximumCacheSize.height())) { |
|
4448 |
_q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, |
|
4449 |
oldPainterOpacity != newPainterOpacity, painterStateProtection); |
|
4450 |
return; |
|
4451 |
} |
|
4452 |
||
4453 |
// Create or reuse offscreen pixmap, possibly scroll/blit from the old one. |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4454 |
// If the world transform is rotated we always recreate the cache to avoid |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4455 |
// wrong blending. |
0 | 4456 |
bool pixModified = false; |
4457 |
QGraphicsItemCache::DeviceData *deviceData = &itemCache->deviceData[widget]; |
|
4458 |
bool invertable = true; |
|
4459 |
QTransform diff = deviceData->lastTransform.inverted(&invertable); |
|
4460 |
if (invertable) |
|
4461 |
diff *= painter->worldTransform(); |
|
4462 |
deviceData->lastTransform = painter->worldTransform(); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4463 |
if (!invertable |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4464 |
|| diff.type() > QTransform::TxTranslate |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4465 |
|| painter->worldTransform().type() > QTransform::TxScale) { |
0 | 4466 |
pixModified = true; |
4467 |
itemCache->allExposed = true; |
|
4468 |
itemCache->exposed.clear(); |
|
4469 |
pix = QPixmap(); |
|
4470 |
} |
|
4471 |
||
4472 |
// ### This is a pretty bad way to determine when to start partial |
|
4473 |
// exposure for DeviceCoordinateCache but it's the least intrusive |
|
4474 |
// approach for now. |
|
4475 |
#if 0 |
|
4476 |
// Only if the device rect isn't fully contained. |
|
4477 |
bool allowPartialCacheExposure = !viewRect.contains(deviceRect); |
|
4478 |
#else |
|
4479 |
// Only if deviceRect is 20% taller or wider than the desktop. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4480 |
bool allowPartialCacheExposure = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4481 |
if (widget) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4482 |
QRect desktopRect = QApplication::desktop()->availableGeometry(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4483 |
allowPartialCacheExposure = (desktopRect.width() * 1.2 < deviceRect.width() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4484 |
|| desktopRect.height() * 1.2 < deviceRect.height()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4485 |
} |
0 | 4486 |
#endif |
4487 |
QRegion scrollExposure; |
|
4488 |
if (deviceData->cacheIndent != QPoint() || allowPartialCacheExposure) { |
|
4489 |
// Part of pixmap is drawn. Either device contains viewrect (big |
|
4490 |
// item covers whole screen) or parts of device are outside the |
|
4491 |
// viewport. In either case the device rect must be the intersect |
|
4492 |
// between the two. |
|
4493 |
int dx = deviceRect.left() < viewRect.left() ? viewRect.left() - deviceRect.left() : 0; |
|
4494 |
int dy = deviceRect.top() < viewRect.top() ? viewRect.top() - deviceRect.top() : 0; |
|
4495 |
QPoint newCacheIndent(dx, dy); |
|
4496 |
deviceRect &= viewRect; |
|
4497 |
||
4498 |
if (pix.isNull()) { |
|
4499 |
deviceData->cacheIndent = QPoint(); |
|
4500 |
itemCache->allExposed = true; |
|
4501 |
itemCache->exposed.clear(); |
|
4502 |
pixModified = true; |
|
4503 |
} |
|
4504 |
||
4505 |
// Copy / "scroll" the old pixmap onto the new ole and calculate |
|
4506 |
// scrolled exposure. |
|
4507 |
if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size()) { |
|
4508 |
QPoint diff = newCacheIndent - deviceData->cacheIndent; |
|
4509 |
QPixmap newPix(deviceRect.size()); |
|
4510 |
// ### Investigate removing this fill (test with Plasma and |
|
4511 |
// graphicssystem raster). |
|
4512 |
newPix.fill(Qt::transparent); |
|
4513 |
if (!pix.isNull()) { |
|
4514 |
QPainter newPixPainter(&newPix); |
|
4515 |
newPixPainter.drawPixmap(-diff, pix); |
|
4516 |
newPixPainter.end(); |
|
4517 |
} |
|
4518 |
QRegion exposed; |
|
4519 |
exposed += newPix.rect(); |
|
4520 |
if (!pix.isNull()) |
|
4521 |
exposed -= QRect(-diff, pix.size()); |
|
4522 |
scrollExposure = exposed; |
|
4523 |
||
4524 |
pix = newPix; |
|
4525 |
pixModified = true; |
|
4526 |
} |
|
4527 |
deviceData->cacheIndent = newCacheIndent; |
|
4528 |
} else { |
|
4529 |
// Full pixmap is drawn. |
|
4530 |
deviceData->cacheIndent = QPoint(); |
|
4531 |
||
4532 |
// Auto-adjust the pixmap size. |
|
4533 |
if (deviceRect.size() != pix.size()) { |
|
4534 |
// exposed needs to cover the whole pixmap |
|
4535 |
pix = QPixmap(deviceRect.size()); |
|
4536 |
pixModified = true; |
|
4537 |
itemCache->allExposed = true; |
|
4538 |
itemCache->exposed.clear(); |
|
4539 |
} |
|
4540 |
} |
|
4541 |
||
4542 |
// Check for newly invalidated areas. |
|
4543 |
if (itemCache->allExposed || !itemCache->exposed.isEmpty() || !scrollExposure.isEmpty()) { |
|
4544 |
//We know that we will modify the pixmap, removing it from the cache |
|
4545 |
//will detach the one we have and avoid a deep copy |
|
4546 |
if (pixmapFound) |
|
4547 |
QPixmapCache::remove(pixmapKey); |
|
4548 |
||
4549 |
// Construct an item-to-pixmap transform. |
|
4550 |
QPointF p = deviceRect.topLeft(); |
|
4551 |
QTransform itemToPixmap = painter->worldTransform(); |
|
4552 |
if (!p.isNull()) |
|
4553 |
itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y()); |
|
4554 |
||
4555 |
// Map the item's logical expose to pixmap coordinates. |
|
4556 |
QRegion pixmapExposed = scrollExposure; |
|
4557 |
if (!itemCache->allExposed) { |
|
4558 |
const QVector<QRectF> &exposed = itemCache->exposed; |
|
4559 |
for (int i = 0; i < exposed.size(); ++i) |
|
4560 |
pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1); |
|
4561 |
} |
|
4562 |
||
4563 |
// Calculate the style option's exposedRect. |
|
4564 |
QRectF br; |
|
4565 |
if (itemCache->allExposed) { |
|
4566 |
br = item->boundingRect(); |
|
4567 |
} else { |
|
4568 |
const QVector<QRectF> &exposed = itemCache->exposed; |
|
4569 |
for (int i = 0; i < exposed.size(); ++i) |
|
4570 |
br |= exposed.at(i); |
|
4571 |
QTransform pixmapToItem = itemToPixmap.inverted(); |
|
4572 |
foreach (QRect r, scrollExposure.rects()) |
|
4573 |
br |= pixmapToItem.mapRect(r); |
|
4574 |
} |
|
4575 |
styleOptionTmp = *option; |
|
4576 |
styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1); |
|
4577 |
||
4578 |
// Render the exposed areas. |
|
4579 |
_q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), |
|
4580 |
&styleOptionTmp, painterStateProtection); |
|
4581 |
||
4582 |
// Reset expose data. |
|
4583 |
pixModified = true; |
|
4584 |
itemCache->allExposed = false; |
|
4585 |
itemCache->exposed.clear(); |
|
4586 |
} |
|
4587 |
||
4588 |
if (pixModified) { |
|
4589 |
// Insert this pixmap into the cache. |
|
4590 |
deviceData->key = QPixmapCache::insert(pix); |
|
4591 |
} |
|
4592 |
||
4593 |
// Redraw the exposed area using an untransformed painter. This |
|
4594 |
// effectively becomes a bitblit that does not transform the cache. |
|
4595 |
QTransform restoreTransform = painter->worldTransform(); |
|
4596 |
painter->setWorldTransform(QTransform()); |
|
4597 |
if (newPainterOpacity != oldPainterOpacity) { |
|
4598 |
painter->setOpacity(newPainterOpacity); |
|
4599 |
painter->drawPixmap(deviceRect.topLeft(), pix); |
|
4600 |
painter->setOpacity(oldPainterOpacity); |
|
4601 |
} else { |
|
4602 |
painter->drawPixmap(deviceRect.topLeft(), pix); |
|
4603 |
} |
|
4604 |
painter->setWorldTransform(restoreTransform); |
|
4605 |
return; |
|
4606 |
} |
|
4607 |
} |
|
4608 |
||
4609 |
void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const viewTransform, |
|
4610 |
QRegion *exposedRegion, QWidget *widget) |
|
4611 |
{ |
|
4612 |
// Make sure we don't have unpolished items before we draw. |
|
4613 |
if (!unpolishedItems.isEmpty()) |
|
4614 |
_q_polishItems(); |
|
4615 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4616 |
updateAll = false; |
0 | 4617 |
QRectF exposedSceneRect; |
4618 |
if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) { |
|
4619 |
exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1); |
|
4620 |
if (viewTransform) |
|
4621 |
exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect); |
|
4622 |
} |
|
4623 |
const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder); |
|
4624 |
for (int i = 0; i < tli.size(); ++i) |
|
4625 |
drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget); |
|
4626 |
} |
|
4627 |
||
4628 |
void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, |
|
4629 |
const QTransform *const viewTransform, |
|
4630 |
QRegion *exposedRegion, QWidget *widget, |
|
4631 |
qreal parentOpacity, const QTransform *const effectTransform) |
|
4632 |
{ |
|
4633 |
Q_ASSERT(item); |
|
4634 |
||
4635 |
if (!item->d_ptr->visible) |
|
4636 |
return; |
|
4637 |
||
4638 |
const bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); |
|
4639 |
const bool itemHasChildren = !item->d_ptr->children.isEmpty(); |
|
4640 |
if (!itemHasContents && !itemHasChildren) |
|
4641 |
return; // Item has neither contents nor children!(?) |
|
4642 |
||
4643 |
const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4644 |
const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); |
0 | 4645 |
if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) |
4646 |
return; |
|
4647 |
||
4648 |
QTransform transform(Qt::Uninitialized); |
|
4649 |
QTransform *transformPtr = 0; |
|
4650 |
bool translateOnlyTransform = false; |
|
4651 |
#define ENSURE_TRANSFORM_PTR \ |
|
4652 |
if (!transformPtr) { \ |
|
4653 |
Q_ASSERT(!itemIsUntransformable); \ |
|
4654 |
if (viewTransform) { \ |
|
4655 |
transform = item->d_ptr->sceneTransform; \ |
|
4656 |
transform *= *viewTransform; \ |
|
4657 |
transformPtr = &transform; \ |
|
4658 |
} else { \ |
|
4659 |
transformPtr = &item->d_ptr->sceneTransform; \ |
|
4660 |
translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; \ |
|
4661 |
} \ |
|
4662 |
} |
|
4663 |
||
4664 |
// Update the item's scene transform if the item is transformable; |
|
4665 |
// otherwise calculate the full transform, |
|
4666 |
bool wasDirtyParentSceneTransform = false; |
|
4667 |
const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); |
|
4668 |
if (itemIsUntransformable) { |
|
4669 |
transform = item->deviceTransform(viewTransform ? *viewTransform : QTransform()); |
|
4670 |
transformPtr = &transform; |
|
4671 |
} else if (item->d_ptr->dirtySceneTransform) { |
|
4672 |
item->d_ptr->updateSceneTransformFromParent(); |
|
4673 |
Q_ASSERT(!item->d_ptr->dirtySceneTransform); |
|
4674 |
wasDirtyParentSceneTransform = true; |
|
4675 |
} |
|
4676 |
||
4677 |
const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); |
|
4678 |
bool drawItem = itemHasContents && !itemIsFullyTransparent; |
|
4679 |
if (drawItem) { |
|
4680 |
const QRectF brect = adjustedItemEffectiveBoundingRect(item); |
|
4681 |
ENSURE_TRANSFORM_PTR |
|
4682 |
QRect viewBoundingRect = translateOnlyTransform ? brect.translated(transformPtr->dx(), transformPtr->dy()).toRect() |
|
4683 |
: transformPtr->mapRect(brect).toRect(); |
|
4684 |
if (widget) |
|
4685 |
item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect); |
|
4686 |
viewBoundingRect.adjust(-1, -1, 1, 1); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4687 |
drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4688 |
: !viewBoundingRect.normalized().isEmpty(); |
0 | 4689 |
if (!drawItem) { |
4690 |
if (!itemHasChildren) |
|
4691 |
return; |
|
4692 |
if (itemClipsChildrenToShape) { |
|
4693 |
if (wasDirtyParentSceneTransform) |
|
4694 |
item->d_ptr->invalidateChildrenSceneTransform(); |
|
4695 |
return; |
|
4696 |
} |
|
4697 |
} |
|
4698 |
} // else we know for sure this item has children we must process. |
|
4699 |
||
4700 |
if (itemHasChildren && itemClipsChildrenToShape) |
|
4701 |
ENSURE_TRANSFORM_PTR; |
|
4702 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4703 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 4704 |
if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) { |
4705 |
ENSURE_TRANSFORM_PTR; |
|
4706 |
QGraphicsItemPaintInfo info(viewTransform, transformPtr, effectTransform, exposedRegion, widget, &styleOptionTmp, |
|
4707 |
painter, opacity, wasDirtyParentSceneTransform, drawItem); |
|
4708 |
QGraphicsEffectSource *source = item->d_ptr->graphicsEffect->d_func()->source; |
|
4709 |
QGraphicsItemEffectSourcePrivate *sourced = static_cast<QGraphicsItemEffectSourcePrivate *> |
|
4710 |
(source->d_func()); |
|
4711 |
sourced->info = &info; |
|
4712 |
const QTransform restoreTransform = painter->worldTransform(); |
|
4713 |
if (effectTransform) |
|
4714 |
painter->setWorldTransform(*transformPtr * *effectTransform); |
|
4715 |
else |
|
4716 |
painter->setWorldTransform(*transformPtr); |
|
4717 |
painter->setOpacity(opacity); |
|
4718 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4719 |
if (sourced->currentCachedSystem() != Qt::LogicalCoordinates |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4720 |
&& sourced->lastEffectTransform != painter->worldTransform()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4721 |
{ |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4722 |
if (sourced->lastEffectTransform.type() <= QTransform::TxTranslate |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4723 |
&& painter->worldTransform().type() <= QTransform::TxTranslate) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4724 |
{ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4725 |
QRectF sourceRect = sourced->boundingRect(Qt::DeviceCoordinates); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4726 |
QRect effectRect = sourced->paddedEffectRect(Qt::DeviceCoordinates, sourced->currentCachedMode(), sourceRect); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4727 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4728 |
sourced->setCachedOffset(effectRect.topLeft()); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4729 |
} else { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4730 |
sourced->invalidateCache(QGraphicsEffectSourcePrivate::TransformChanged); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4731 |
} |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4732 |
|
0 | 4733 |
sourced->lastEffectTransform = painter->worldTransform(); |
4734 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4735 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4736 |
item->d_ptr->graphicsEffect->draw(painter); |
0 | 4737 |
painter->setWorldTransform(restoreTransform); |
4738 |
sourced->info = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4739 |
} else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4740 |
#endif //QT_NO_GRAPHICSEFFECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4741 |
{ |
0 | 4742 |
draw(item, painter, viewTransform, transformPtr, exposedRegion, widget, opacity, |
4743 |
effectTransform, wasDirtyParentSceneTransform, drawItem); |
|
4744 |
} |
|
4745 |
} |
|
4746 |
||
4747 |
void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const QTransform *const viewTransform, |
|
4748 |
const QTransform *const transformPtr, QRegion *exposedRegion, QWidget *widget, |
|
4749 |
qreal opacity, const QTransform *effectTransform, |
|
4750 |
bool wasDirtyParentSceneTransform, bool drawItem) |
|
4751 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4752 |
const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); |
0 | 4753 |
const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); |
4754 |
const bool itemHasChildren = !item->d_ptr->children.isEmpty(); |
|
4755 |
||
4756 |
int i = 0; |
|
4757 |
if (itemHasChildren) { |
|
4758 |
item->d_ptr->ensureSortedChildren(); |
|
4759 |
||
4760 |
if (itemClipsChildrenToShape) { |
|
4761 |
painter->save(); |
|
4762 |
Q_ASSERT(transformPtr); |
|
4763 |
if (effectTransform) |
|
4764 |
painter->setWorldTransform(*transformPtr * *effectTransform); |
|
4765 |
else |
|
4766 |
painter->setWorldTransform(*transformPtr); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4767 |
QRectF clipRect; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4768 |
const QPainterPath clipPath(item->shape()); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4769 |
if (QPathClipper::pathToRect(clipPath, &clipRect)) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4770 |
painter->setClipRect(clipRect, Qt::IntersectClip); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4771 |
else |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4772 |
painter->setClipPath(clipPath, Qt::IntersectClip); |
0 | 4773 |
} |
4774 |
||
4775 |
// Draw children behind |
|
4776 |
for (i = 0; i < item->d_ptr->children.size(); ++i) { |
|
4777 |
QGraphicsItem *child = item->d_ptr->children.at(i); |
|
4778 |
if (wasDirtyParentSceneTransform) |
|
4779 |
child->d_ptr->dirtySceneTransform = 1; |
|
4780 |
if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent)) |
|
4781 |
break; |
|
4782 |
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity)) |
|
4783 |
continue; |
|
4784 |
drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); |
|
4785 |
} |
|
4786 |
} |
|
4787 |
||
4788 |
// Draw item |
|
4789 |
if (drawItem) { |
|
4790 |
Q_ASSERT(!itemIsFullyTransparent); |
|
4791 |
Q_ASSERT(!(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents)); |
|
4792 |
Q_ASSERT(transformPtr); |
|
4793 |
item->d_ptr->initStyleOption(&styleOptionTmp, *transformPtr, exposedRegion |
|
4794 |
? *exposedRegion : QRegion(), exposedRegion == 0); |
|
4795 |
||
4796 |
const bool itemClipsToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsToShape; |
|
4797 |
const bool savePainter = itemClipsToShape || painterStateProtection; |
|
4798 |
if (savePainter) |
|
4799 |
painter->save(); |
|
4800 |
||
4801 |
if (!itemHasChildren || !itemClipsChildrenToShape) { |
|
4802 |
if (effectTransform) |
|
4803 |
painter->setWorldTransform(*transformPtr * *effectTransform); |
|
4804 |
else |
|
4805 |
painter->setWorldTransform(*transformPtr); |
|
4806 |
} |
|
4807 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4808 |
if (itemClipsToShape) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4809 |
QRectF clipRect; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4810 |
const QPainterPath clipPath(item->shape()); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4811 |
if (QPathClipper::pathToRect(clipPath, &clipRect)) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4812 |
painter->setClipRect(clipRect, Qt::IntersectClip); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4813 |
else |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4814 |
painter->setClipPath(clipPath, Qt::IntersectClip); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4815 |
} |
0 | 4816 |
painter->setOpacity(opacity); |
4817 |
||
4818 |
if (!item->d_ptr->cacheMode && !item->d_ptr->isWidget) |
|
4819 |
item->paint(painter, &styleOptionTmp, widget); |
|
4820 |
else |
|
4821 |
drawItemHelper(item, painter, &styleOptionTmp, widget, painterStateProtection); |
|
4822 |
||
4823 |
if (savePainter) |
|
4824 |
painter->restore(); |
|
4825 |
} |
|
4826 |
||
4827 |
// Draw children in front |
|
4828 |
if (itemHasChildren) { |
|
4829 |
for (; i < item->d_ptr->children.size(); ++i) { |
|
4830 |
QGraphicsItem *child = item->d_ptr->children.at(i); |
|
4831 |
if (wasDirtyParentSceneTransform) |
|
4832 |
child->d_ptr->dirtySceneTransform = 1; |
|
4833 |
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity)) |
|
4834 |
continue; |
|
4835 |
drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); |
|
4836 |
} |
|
4837 |
} |
|
4838 |
||
4839 |
// Restore child clip |
|
4840 |
if (itemHasChildren && itemClipsChildrenToShape) |
|
4841 |
painter->restore(); |
|
4842 |
} |
|
4843 |
||
4844 |
void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, bool invalidateChildren, |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4845 |
bool force, bool ignoreOpacity, bool removingItemFromScene, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4846 |
bool updateBoundingRect) |
0 | 4847 |
{ |
4848 |
Q_ASSERT(item); |
|
4849 |
if (updateAll) |
|
4850 |
return; |
|
4851 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4852 |
if (item->d_ptr->discardUpdateRequest(/*ignoreVisibleBit=*/force, |
0 | 4853 |
/*ignoreDirtyBit=*/removingItemFromScene || invalidateChildren, |
4854 |
/*ignoreOpacity=*/ignoreOpacity)) { |
|
4855 |
if (item->d_ptr->dirty) { |
|
4856 |
// The item is already marked as dirty and will be processed later. However, |
|
4857 |
// we have to make sure ignoreVisible and ignoreOpacity are set properly; |
|
4858 |
// otherwise things like: item->update(); item->hide() (force is now true) |
|
4859 |
// won't work as expected. |
|
4860 |
if (force) |
|
4861 |
item->d_ptr->ignoreVisible = 1; |
|
4862 |
if (ignoreOpacity) |
|
4863 |
item->d_ptr->ignoreOpacity = 1; |
|
4864 |
} |
|
4865 |
return; |
|
4866 |
} |
|
4867 |
||
4868 |
const bool fullItemUpdate = rect.isNull(); |
|
4869 |
if (!fullItemUpdate && rect.isEmpty()) |
|
4870 |
return; |
|
4871 |
||
4872 |
if (!processDirtyItemsEmitted) { |
|
4873 |
QMetaObject::invokeMethod(q_ptr, "_q_processDirtyItems", Qt::QueuedConnection); |
|
4874 |
processDirtyItemsEmitted = true; |
|
4875 |
} |
|
4876 |
||
4877 |
if (removingItemFromScene) { |
|
4878 |
// Note that this function can be called from the item's destructor, so |
|
4879 |
// do NOT call any virtual functions on it within this block. |
|
4880 |
if (isSignalConnected(changedSignalIndex) || views.isEmpty()) { |
|
4881 |
// This block of code is kept for compatibility. Since 4.5, by default |
|
4882 |
// QGraphicsView does not connect the signal and we use the below |
|
4883 |
// method of delivering updates. |
|
4884 |
q_func()->update(); |
|
4885 |
return; |
|
4886 |
} |
|
4887 |
||
4888 |
for (int i = 0; i < views.size(); ++i) { |
|
4889 |
QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func(); |
|
4890 |
QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport); |
|
4891 |
rect.translate(viewPrivate->dirtyScrollOffset); |
|
4892 |
viewPrivate->updateRect(rect); |
|
4893 |
} |
|
4894 |
return; |
|
4895 |
} |
|
4896 |
||
4897 |
bool hasNoContents = item->d_ptr->flags & QGraphicsItem::ItemHasNoContents |
|
4898 |
&& !item->d_ptr->graphicsEffect; |
|
4899 |
if (!hasNoContents) { |
|
4900 |
item->d_ptr->dirty = 1; |
|
4901 |
if (fullItemUpdate) |
|
4902 |
item->d_ptr->fullUpdatePending = 1; |
|
4903 |
else if (!item->d_ptr->fullUpdatePending) |
|
4904 |
item->d_ptr->needsRepaint |= rect; |
|
4905 |
} |
|
4906 |
||
4907 |
if (invalidateChildren) { |
|
4908 |
item->d_ptr->allChildrenDirty = 1; |
|
4909 |
item->d_ptr->dirtyChildren = 1; |
|
4910 |
} |
|
4911 |
||
4912 |
if (force) |
|
4913 |
item->d_ptr->ignoreVisible = 1; |
|
4914 |
if (ignoreOpacity) |
|
4915 |
item->d_ptr->ignoreOpacity = 1; |
|
4916 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4917 |
if (!updateBoundingRect) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4918 |
item->d_ptr->markParentDirty(); |
0 | 4919 |
} |
4920 |
||
4921 |
static inline bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item, |
|
4922 |
const QRectF &rect, bool itemIsUntransformable) |
|
4923 |
{ |
|
4924 |
Q_ASSERT(view); |
|
4925 |
Q_ASSERT(item); |
|
4926 |
||
4927 |
QGraphicsItem *itemq = static_cast<QGraphicsItem *>(item->q_ptr); |
|
4928 |
QGraphicsView *viewq = static_cast<QGraphicsView *>(view->q_ptr); |
|
4929 |
||
4930 |
if (itemIsUntransformable) { |
|
4931 |
const QTransform xform = itemq->deviceTransform(viewq->viewportTransform()); |
|
4932 |
if (!item->hasBoundingRegionGranularity) |
|
4933 |
return view->updateRect(xform.mapRect(rect).toRect()); |
|
4934 |
return view->updateRegion(xform.map(QRegion(rect.toRect()))); |
|
4935 |
} |
|
4936 |
||
4937 |
if (item->sceneTransformTranslateOnly && view->identityMatrix) { |
|
4938 |
const qreal dx = item->sceneTransform.dx(); |
|
4939 |
const qreal dy = item->sceneTransform.dy(); |
|
4940 |
if (!item->hasBoundingRegionGranularity) { |
|
4941 |
QRectF r(rect); |
|
4942 |
r.translate(dx - view->horizontalScroll(), dy - view->verticalScroll()); |
|
4943 |
return view->updateRect(r.toRect()); |
|
4944 |
} |
|
4945 |
QRegion r(rect.toRect()); |
|
4946 |
r.translate(qRound(dx) - view->horizontalScroll(), qRound(dy) - view->verticalScroll()); |
|
4947 |
return view->updateRegion(r); |
|
4948 |
} |
|
4949 |
||
4950 |
if (!viewq->isTransformed()) { |
|
4951 |
if (!item->hasBoundingRegionGranularity) |
|
4952 |
return view->updateRect(item->sceneTransform.mapRect(rect).toRect()); |
|
4953 |
return view->updateRegion(item->sceneTransform.map(QRegion(rect.toRect()))); |
|
4954 |
} |
|
4955 |
||
4956 |
QTransform xform = item->sceneTransform; |
|
4957 |
xform *= viewq->viewportTransform(); |
|
4958 |
if (!item->hasBoundingRegionGranularity) |
|
4959 |
return view->updateRect(xform.mapRect(rect).toRect()); |
|
4960 |
return view->updateRegion(xform.map(QRegion(rect.toRect()))); |
|
4961 |
} |
|
4962 |
||
4963 |
void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren, |
|
4964 |
qreal parentOpacity) |
|
4965 |
{ |
|
4966 |
Q_Q(QGraphicsScene); |
|
4967 |
Q_ASSERT(item); |
|
4968 |
Q_ASSERT(!updateAll); |
|
4969 |
||
4970 |
if (!item->d_ptr->dirty && !item->d_ptr->dirtyChildren) { |
|
4971 |
resetDirtyItem(item); |
|
4972 |
return; |
|
4973 |
} |
|
4974 |
||
4975 |
const bool itemIsHidden = !item->d_ptr->ignoreVisible && !item->d_ptr->visible; |
|
4976 |
if (itemIsHidden) { |
|
4977 |
resetDirtyItem(item, /*recursive=*/true); |
|
4978 |
return; |
|
4979 |
} |
|
4980 |
||
4981 |
bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); |
|
4982 |
const bool itemHasChildren = !item->d_ptr->children.isEmpty(); |
|
4983 |
if (!itemHasContents) { |
|
4984 |
if (!itemHasChildren) { |
|
4985 |
resetDirtyItem(item); |
|
4986 |
return; // Item has neither contents nor children!(?) |
|
4987 |
} |
|
4988 |
if (item->d_ptr->graphicsEffect) |
|
4989 |
itemHasContents = true; |
|
4990 |
} |
|
4991 |
||
4992 |
const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4993 |
const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
4994 |
&& QGraphicsItemPrivate::isOpacityNull(opacity); |
0 | 4995 |
if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) { |
4996 |
resetDirtyItem(item, /*recursive=*/itemHasChildren); |
|
4997 |
return; |
|
4998 |
} |
|
4999 |
||
5000 |
bool wasDirtyParentSceneTransform = item->d_ptr->dirtySceneTransform; |
|
5001 |
const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); |
|
5002 |
if (wasDirtyParentSceneTransform && !itemIsUntransformable) { |
|
5003 |
item->d_ptr->updateSceneTransformFromParent(); |
|
5004 |
Q_ASSERT(!item->d_ptr->dirtySceneTransform); |
|
5005 |
} |
|
5006 |
||
5007 |
const bool wasDirtyParentViewBoundingRects = item->d_ptr->paintedViewBoundingRectsNeedRepaint; |
|
5008 |
if (itemIsFullyTransparent || !itemHasContents || dirtyAncestorContainsChildren) { |
|
5009 |
// Make sure we don't process invisible items or items with no content. |
|
5010 |
item->d_ptr->dirty = 0; |
|
5011 |
item->d_ptr->fullUpdatePending = 0; |
|
5012 |
// Might have a dirty view bounding rect otherwise. |
|
5013 |
if (itemIsFullyTransparent || !itemHasContents) |
|
5014 |
item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0; |
|
5015 |
} |
|
5016 |
||
5017 |
if (!hasSceneRect && item->d_ptr->geometryChanged && item->d_ptr->visible) { |
|
5018 |
// Update growingItemsBoundingRect. |
|
5019 |
if (item->d_ptr->sceneTransformTranslateOnly) { |
|
5020 |
growingItemsBoundingRect |= item->boundingRect().translated(item->d_ptr->sceneTransform.dx(), |
|
5021 |
item->d_ptr->sceneTransform.dy()); |
|
5022 |
} else { |
|
5023 |
growingItemsBoundingRect |= item->d_ptr->sceneTransform.mapRect(item->boundingRect()); |
|
5024 |
} |
|
5025 |
} |
|
5026 |
||
5027 |
// Process item. |
|
5028 |
if (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint) { |
|
5029 |
const bool useCompatUpdate = views.isEmpty() || isSignalConnected(changedSignalIndex); |
|
5030 |
const QRectF itemBoundingRect = adjustedItemEffectiveBoundingRect(item); |
|
5031 |
||
5032 |
if (useCompatUpdate && !itemIsUntransformable && qFuzzyIsNull(item->boundingRegionGranularity())) { |
|
5033 |
// This block of code is kept for compatibility. Since 4.5, by default |
|
5034 |
// QGraphicsView does not connect the signal and we use the below |
|
5035 |
// method of delivering updates. |
|
5036 |
if (item->d_ptr->sceneTransformTranslateOnly) { |
|
5037 |
q->update(itemBoundingRect.translated(item->d_ptr->sceneTransform.dx(), |
|
5038 |
item->d_ptr->sceneTransform.dy())); |
|
5039 |
} else { |
|
5040 |
q->update(item->d_ptr->sceneTransform.mapRect(itemBoundingRect)); |
|
5041 |
} |
|
5042 |
} else { |
|
5043 |
QRectF dirtyRect; |
|
5044 |
bool uninitializedDirtyRect = true; |
|
5045 |
||
5046 |
for (int j = 0; j < views.size(); ++j) { |
|
5047 |
QGraphicsView *view = views.at(j); |
|
5048 |
QGraphicsViewPrivate *viewPrivate = view->d_func(); |
|
5049 |
QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport]; |
|
5050 |
if (viewPrivate->fullUpdatePending |
|
5051 |
|| viewPrivate->viewportUpdateMode == QGraphicsView::NoViewportUpdate) { |
|
5052 |
// Okay, if we have a full update pending or no viewport update, this item's |
|
5053 |
// paintedViewBoundingRect will be updated correctly in the next paintEvent if |
|
5054 |
// it is inside the viewport, but for now we can pretend that it is outside. |
|
5055 |
paintedViewBoundingRect = QRect(-1, -1, -1, -1); |
|
5056 |
continue; |
|
5057 |
} |
|
5058 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5059 |
if (item->d_ptr->paintedViewBoundingRectsNeedRepaint) { |
0 | 5060 |
paintedViewBoundingRect.translate(viewPrivate->dirtyScrollOffset); |
5061 |
if (!viewPrivate->updateRect(paintedViewBoundingRect)) |
|
5062 |
paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport. |
|
5063 |
} |
|
5064 |
||
5065 |
if (!item->d_ptr->dirty) |
|
5066 |
continue; |
|
5067 |
||
5068 |
if (!item->d_ptr->paintedViewBoundingRectsNeedRepaint |
|
5069 |
&& paintedViewBoundingRect.x() == -1 && paintedViewBoundingRect.y() == -1 |
|
5070 |
&& paintedViewBoundingRect.width() == -1 && paintedViewBoundingRect.height() == -1) { |
|
5071 |
continue; // Outside viewport. |
|
5072 |
} |
|
5073 |
||
5074 |
if (uninitializedDirtyRect) { |
|
5075 |
dirtyRect = itemBoundingRect; |
|
5076 |
if (!item->d_ptr->fullUpdatePending) { |
|
5077 |
_q_adjustRect(&item->d_ptr->needsRepaint); |
|
5078 |
dirtyRect &= item->d_ptr->needsRepaint; |
|
5079 |
} |
|
5080 |
uninitializedDirtyRect = false; |
|
5081 |
} |
|
5082 |
||
5083 |
if (dirtyRect.isEmpty()) |
|
5084 |
continue; // Discard updates outside the bounding rect. |
|
5085 |
||
5086 |
if (!updateHelper(viewPrivate, item->d_ptr.data(), dirtyRect, itemIsUntransformable) |
|
5087 |
&& item->d_ptr->paintedViewBoundingRectsNeedRepaint) { |
|
5088 |
paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport. |
|
5089 |
} |
|
5090 |
} |
|
5091 |
} |
|
5092 |
} |
|
5093 |
||
5094 |
// Process children. |
|
5095 |
if (itemHasChildren && item->d_ptr->dirtyChildren) { |
|
5096 |
if (!dirtyAncestorContainsChildren) { |
|
5097 |
dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending |
|
5098 |
&& (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); |
|
5099 |
} |
|
5100 |
const bool allChildrenDirty = item->d_ptr->allChildrenDirty; |
|
5101 |
const bool parentIgnoresVisible = item->d_ptr->ignoreVisible; |
|
5102 |
const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity; |
|
5103 |
for (int i = 0; i < item->d_ptr->children.size(); ++i) { |
|
5104 |
QGraphicsItem *child = item->d_ptr->children.at(i); |
|
5105 |
if (wasDirtyParentSceneTransform) |
|
5106 |
child->d_ptr->dirtySceneTransform = 1; |
|
5107 |
if (wasDirtyParentViewBoundingRects) |
|
5108 |
child->d_ptr->paintedViewBoundingRectsNeedRepaint = 1; |
|
5109 |
if (parentIgnoresVisible) |
|
5110 |
child->d_ptr->ignoreVisible = 1; |
|
5111 |
if (parentIgnoresOpacity) |
|
5112 |
child->d_ptr->ignoreOpacity = 1; |
|
5113 |
if (allChildrenDirty) { |
|
5114 |
child->d_ptr->dirty = 1; |
|
5115 |
child->d_ptr->fullUpdatePending = 1; |
|
5116 |
child->d_ptr->dirtyChildren = 1; |
|
5117 |
child->d_ptr->allChildrenDirty = 1; |
|
5118 |
} |
|
5119 |
processDirtyItemsRecursive(child, dirtyAncestorContainsChildren, opacity); |
|
5120 |
} |
|
5121 |
} else if (wasDirtyParentSceneTransform) { |
|
5122 |
item->d_ptr->invalidateChildrenSceneTransform(); |
|
5123 |
} |
|
5124 |
||
5125 |
resetDirtyItem(item); |
|
5126 |
} |
|
5127 |
||
5128 |
/*! |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5129 |
\obsolete |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5130 |
|
0 | 5131 |
Paints the given \a items using the provided \a painter, after the |
5132 |
background has been drawn, and before the foreground has been |
|
5133 |
drawn. All painting is done in \e scene coordinates. Before |
|
5134 |
drawing each item, the painter must be transformed using |
|
5135 |
QGraphicsItem::sceneTransform(). |
|
5136 |
||
5137 |
The \a options parameter is the list of style option objects for |
|
5138 |
each item in \a items. The \a numItems parameter is the number of |
|
5139 |
items in \a items and options in \a options. The \a widget |
|
5140 |
parameter is optional; if specified, it should point to the widget |
|
5141 |
that is being painted on. |
|
5142 |
||
5143 |
The default implementation prepares the painter matrix, and calls |
|
5144 |
QGraphicsItem::paint() on all items. Reimplement this function to |
|
5145 |
provide custom painting of all items for the scene; gaining |
|
5146 |
complete control over how each item is drawn. In some cases this |
|
5147 |
can increase drawing performance significantly. |
|
5148 |
||
5149 |
Example: |
|
5150 |
||
5151 |
\snippet doc/src/snippets/graphicssceneadditemsnippet.cpp 0 |
|
5152 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5153 |
Since Qt 4.6, this function is not called anymore unless |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5154 |
the QGraphicsView::IndirectPainting flag is given as an Optimization |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5155 |
flag. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5156 |
|
0 | 5157 |
\sa drawBackground(), drawForeground() |
5158 |
*/ |
|
5159 |
void QGraphicsScene::drawItems(QPainter *painter, |
|
5160 |
int numItems, |
|
5161 |
QGraphicsItem *items[], |
|
5162 |
const QStyleOptionGraphicsItem options[], QWidget *widget) |
|
5163 |
{ |
|
5164 |
Q_D(QGraphicsScene); |
|
5165 |
// Make sure we don't have unpolished items before we draw. |
|
5166 |
if (!d->unpolishedItems.isEmpty()) |
|
5167 |
d->_q_polishItems(); |
|
5168 |
||
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5169 |
d->updateAll = false; |
0 | 5170 |
QTransform viewTransform = painter->worldTransform(); |
5171 |
Q_UNUSED(options); |
|
5172 |
||
5173 |
// Determine view, expose and flags. |
|
5174 |
QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0; |
|
5175 |
QRegion *expose = 0; |
|
5176 |
if (view) |
|
5177 |
expose = &view->d_func()->exposedRegion; |
|
5178 |
||
5179 |
// Find all toplevels, they are already sorted. |
|
5180 |
QList<QGraphicsItem *> topLevelItems; |
|
5181 |
for (int i = 0; i < numItems; ++i) { |
|
5182 |
QGraphicsItem *item = items[i]->topLevelItem(); |
|
5183 |
if (!item->d_ptr->itemDiscovered) { |
|
5184 |
topLevelItems << item; |
|
5185 |
item->d_ptr->itemDiscovered = 1; |
|
5186 |
d->drawSubtreeRecursive(item, painter, &viewTransform, expose, widget); |
|
5187 |
} |
|
5188 |
} |
|
5189 |
||
5190 |
// Reset discovery bits. |
|
5191 |
for (int i = 0; i < topLevelItems.size(); ++i) |
|
5192 |
topLevelItems.at(i)->d_ptr->itemDiscovered = 0; |
|
5193 |
||
5194 |
painter->setWorldTransform(viewTransform); |
|
5195 |
} |
|
5196 |
||
5197 |
/*! |
|
5198 |
\since 4.4 |
|
5199 |
||
5200 |
Finds a new widget to give the keyboard focus to, as appropriate for Tab |
|
5201 |
and Shift+Tab, and returns true if it can find a new widget, or false if |
|
5202 |
it cannot. If \a next is true, this function searches forward; if \a next |
|
5203 |
is false, it searches backward. |
|
5204 |
||
5205 |
You can reimplement this function in a subclass of QGraphicsScene to |
|
5206 |
provide fine-grained control over how tab focus passes inside your |
|
5207 |
scene. The default implementation is based on the tab focus chain defined |
|
5208 |
by QGraphicsWidget::setTabOrder(). |
|
5209 |
*/ |
|
5210 |
bool QGraphicsScene::focusNextPrevChild(bool next) |
|
5211 |
{ |
|
5212 |
Q_D(QGraphicsScene); |
|
5213 |
||
5214 |
QGraphicsItem *item = focusItem(); |
|
5215 |
if (item && !item->isWidget()) { |
|
5216 |
// Tab out of the scene. |
|
5217 |
return false; |
|
5218 |
} |
|
5219 |
if (!item) { |
|
5220 |
if (d->lastFocusItem && !d->lastFocusItem->isWidget()) { |
|
5221 |
// Restore focus to the last focusable non-widget item that had |
|
5222 |
// focus. |
|
5223 |
setFocusItem(d->lastFocusItem, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); |
|
5224 |
return true; |
|
5225 |
} |
|
5226 |
} |
|
5227 |
if (!d->tabFocusFirst) { |
|
5228 |
// No widgets... |
|
5229 |
return false; |
|
5230 |
} |
|
5231 |
||
5232 |
// The item must be a widget. |
|
5233 |
QGraphicsWidget *widget = 0; |
|
5234 |
if (!item) { |
|
5235 |
widget = next ? d->tabFocusFirst : d->tabFocusFirst->d_func()->focusPrev; |
|
5236 |
} else { |
|
5237 |
QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item); |
|
5238 |
widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev; |
|
5239 |
if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev)) |
|
5240 |
return false; |
|
5241 |
} |
|
5242 |
QGraphicsWidget *widgetThatHadFocus = widget; |
|
5243 |
||
5244 |
// Run around the focus chain until we find a widget that can take tab focus. |
|
5245 |
do { |
|
5246 |
if (widget->flags() & QGraphicsItem::ItemIsFocusable |
|
5247 |
&& widget->isEnabled() && widget->isVisibleTo(0) |
|
5248 |
&& (widget->focusPolicy() & Qt::TabFocus) |
|
5249 |
&& (!item || !item->isPanel() || item->isAncestorOf(widget)) |
|
5250 |
) { |
|
5251 |
setFocusItem(widget, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); |
|
5252 |
return true; |
|
5253 |
} |
|
5254 |
widget = next ? widget->d_func()->focusNext : widget->d_func()->focusPrev; |
|
5255 |
if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev)) |
|
5256 |
return false; |
|
5257 |
} while (widget != widgetThatHadFocus); |
|
5258 |
||
5259 |
return false; |
|
5260 |
} |
|
5261 |
||
5262 |
/*! |
|
5263 |
\fn QGraphicsScene::changed(const QList<QRectF> ®ion) |
|
5264 |
||
5265 |
This signal is emitted by QGraphicsScene when control reaches the |
|
5266 |
event loop, if the scene content changes. The \a region parameter |
|
5267 |
contains a list of scene rectangles that indicate the area that |
|
5268 |
has been changed. |
|
5269 |
||
5270 |
\sa QGraphicsView::updateScene() |
|
5271 |
*/ |
|
5272 |
||
5273 |
/*! |
|
5274 |
\fn QGraphicsScene::sceneRectChanged(const QRectF &rect) |
|
5275 |
||
5276 |
This signal is emitted by QGraphicsScene whenever the scene rect changes. |
|
5277 |
The \a rect parameter is the new scene rectangle. |
|
5278 |
||
5279 |
\sa QGraphicsView::updateSceneRect() |
|
5280 |
*/ |
|
5281 |
||
5282 |
/*! |
|
5283 |
\fn QGraphicsScene::selectionChanged() |
|
5284 |
\since 4.3 |
|
5285 |
||
5286 |
This signal is emitted by QGraphicsScene whenever the selection |
|
5287 |
changes. You can call selectedItems() to get the new list of selected |
|
5288 |
items. |
|
5289 |
||
5290 |
The selection changes whenever an item is selected or unselected, a |
|
5291 |
selection area is set, cleared or otherwise changed, if a preselected item |
|
5292 |
is added to the scene, or if a selected item is removed from the scene. |
|
5293 |
||
5294 |
QGraphicsScene emits this signal only once for group selection operations. |
|
5295 |
For example, if you set a selection area, select or unselect a |
|
5296 |
QGraphicsItemGroup, or if you add or remove from the scene a parent item |
|
5297 |
that contains several selected items, selectionChanged() is emitted only |
|
5298 |
once after the operation has completed (instead of once for each item). |
|
5299 |
||
5300 |
\sa setSelectionArea(), selectedItems(), QGraphicsItem::setSelected() |
|
5301 |
*/ |
|
5302 |
||
5303 |
/*! |
|
5304 |
\since 4.4 |
|
5305 |
||
5306 |
Returns the scene's style, or the same as QApplication::style() if the |
|
5307 |
scene has not been explicitly assigned a style. |
|
5308 |
||
5309 |
\sa setStyle() |
|
5310 |
*/ |
|
5311 |
QStyle *QGraphicsScene::style() const |
|
5312 |
{ |
|
5313 |
Q_D(const QGraphicsScene); |
|
5314 |
// ### This function, and the use of styles in general, is non-reentrant. |
|
5315 |
return d->style ? d->style : QApplication::style(); |
|
5316 |
} |
|
5317 |
||
5318 |
/*! |
|
5319 |
\since 4.4 |
|
5320 |
||
5321 |
Sets or replaces the style of the scene to \a style, and reparents the |
|
5322 |
style to this scene. Any previously assigned style is deleted. The scene's |
|
5323 |
style defaults to QApplication::style(), and serves as the default for all |
|
5324 |
QGraphicsWidget items in the scene. |
|
5325 |
||
5326 |
Changing the style, either directly by calling this function, or |
|
5327 |
indirectly by calling QApplication::setStyle(), will automatically update |
|
5328 |
the style for all widgets in the scene that do not have a style explicitly |
|
5329 |
assigned to them. |
|
5330 |
||
5331 |
If \a style is 0, QGraphicsScene will revert to QApplication::style(). |
|
5332 |
||
5333 |
\sa style() |
|
5334 |
*/ |
|
5335 |
void QGraphicsScene::setStyle(QStyle *style) |
|
5336 |
{ |
|
5337 |
Q_D(QGraphicsScene); |
|
5338 |
// ### This function, and the use of styles in general, is non-reentrant. |
|
5339 |
if (style == d->style) |
|
5340 |
return; |
|
5341 |
||
5342 |
// Delete the old style, |
|
5343 |
delete d->style; |
|
5344 |
if ((d->style = style)) |
|
5345 |
d->style->setParent(this); |
|
5346 |
||
5347 |
// Notify the scene. |
|
5348 |
QEvent event(QEvent::StyleChange); |
|
5349 |
QApplication::sendEvent(this, &event); |
|
5350 |
||
5351 |
// Notify all widgets that don't have a style explicitly set. |
|
5352 |
foreach (QGraphicsItem *item, items()) { |
|
5353 |
if (item->isWidget()) { |
|
5354 |
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); |
|
5355 |
if (!widget->testAttribute(Qt::WA_SetStyle)) |
|
5356 |
QApplication::sendEvent(widget, &event); |
|
5357 |
} |
|
5358 |
} |
|
5359 |
} |
|
5360 |
||
5361 |
/*! |
|
5362 |
\property QGraphicsScene::font |
|
5363 |
\since 4.4 |
|
5364 |
\brief the scene's default font |
|
5365 |
||
5366 |
This property provides the scene's font. The scene font defaults to, |
|
5367 |
and resolves all its entries from, QApplication::font. |
|
5368 |
||
5369 |
If the scene's font changes, either directly through setFont() or |
|
5370 |
indirectly when the application font changes, QGraphicsScene first |
|
5371 |
sends itself a \l{QEvent::FontChange}{FontChange} event, and it then |
|
5372 |
sends \l{QEvent::FontChange}{FontChange} events to all top-level |
|
5373 |
widget items in the scene. These items respond by resolving their own |
|
5374 |
fonts to the scene, and they then notify their children, who again |
|
5375 |
notify their children, and so on, until all widget items have updated |
|
5376 |
their fonts. |
|
5377 |
||
5378 |
Changing the scene font, (directly or indirectly through |
|
5379 |
QApplication::setFont(),) automatically schedules a redraw the entire |
|
5380 |
scene. |
|
5381 |
||
5382 |
\sa QWidget::font, QApplication::setFont(), palette, style() |
|
5383 |
*/ |
|
5384 |
QFont QGraphicsScene::font() const |
|
5385 |
{ |
|
5386 |
Q_D(const QGraphicsScene); |
|
5387 |
return d->font; |
|
5388 |
} |
|
5389 |
void QGraphicsScene::setFont(const QFont &font) |
|
5390 |
{ |
|
5391 |
Q_D(QGraphicsScene); |
|
5392 |
QFont naturalFont = QApplication::font(); |
|
5393 |
naturalFont.resolve(0); |
|
5394 |
QFont resolvedFont = font.resolve(naturalFont); |
|
5395 |
d->setFont_helper(resolvedFont); |
|
5396 |
} |
|
5397 |
||
5398 |
/*! |
|
5399 |
\property QGraphicsScene::palette |
|
5400 |
\since 4.4 |
|
5401 |
\brief the scene's default palette |
|
5402 |
||
5403 |
This property provides the scene's palette. The scene palette defaults to, |
|
5404 |
and resolves all its entries from, QApplication::palette. |
|
5405 |
||
5406 |
If the scene's palette changes, either directly through setPalette() or |
|
5407 |
indirectly when the application palette changes, QGraphicsScene first |
|
5408 |
sends itself a \l{QEvent::PaletteChange}{PaletteChange} event, and it then |
|
5409 |
sends \l{QEvent::PaletteChange}{PaletteChange} events to all top-level |
|
5410 |
widget items in the scene. These items respond by resolving their own |
|
5411 |
palettes to the scene, and they then notify their children, who again |
|
5412 |
notify their children, and so on, until all widget items have updated |
|
5413 |
their palettes. |
|
5414 |
||
5415 |
Changing the scene palette, (directly or indirectly through |
|
5416 |
QApplication::setPalette(),) automatically schedules a redraw the entire |
|
5417 |
scene. |
|
5418 |
||
5419 |
\sa QWidget::palette, QApplication::setPalette(), font, style() |
|
5420 |
*/ |
|
5421 |
QPalette QGraphicsScene::palette() const |
|
5422 |
{ |
|
5423 |
Q_D(const QGraphicsScene); |
|
5424 |
return d->palette; |
|
5425 |
} |
|
5426 |
void QGraphicsScene::setPalette(const QPalette &palette) |
|
5427 |
{ |
|
5428 |
Q_D(QGraphicsScene); |
|
5429 |
QPalette naturalPalette = QApplication::palette(); |
|
5430 |
naturalPalette.resolve(0); |
|
5431 |
QPalette resolvedPalette = palette.resolve(naturalPalette); |
|
5432 |
d->setPalette_helper(resolvedPalette); |
|
5433 |
} |
|
5434 |
||
5435 |
/*! |
|
5436 |
\since 4.6 |
|
5437 |
||
5438 |
Returns true if the scene is active (e.g., it's viewed by |
|
5439 |
at least one QGraphicsView that is active); otherwise returns false. |
|
5440 |
||
5441 |
\sa QGraphicsItem::isActive(), QWidget::isActiveWindow() |
|
5442 |
*/ |
|
5443 |
bool QGraphicsScene::isActive() const |
|
5444 |
{ |
|
5445 |
Q_D(const QGraphicsScene); |
|
5446 |
return d->activationRefCount > 0; |
|
5447 |
} |
|
5448 |
||
5449 |
/*! |
|
5450 |
\since 4.6 |
|
5451 |
Returns the current active panel, or 0 if no panel is currently active. |
|
5452 |
||
5453 |
\sa QGraphicsScene::setActivePanel() |
|
5454 |
*/ |
|
5455 |
QGraphicsItem *QGraphicsScene::activePanel() const |
|
5456 |
{ |
|
5457 |
Q_D(const QGraphicsScene); |
|
5458 |
return d->activePanel; |
|
5459 |
} |
|
5460 |
||
5461 |
/*! |
|
5462 |
\since 4.6 |
|
5463 |
Activates \a item, which must be an item in this scene. You |
|
5464 |
can also pass 0 for \a item, in which case QGraphicsScene will |
|
5465 |
deactivate any currently active panel. |
|
5466 |
||
5467 |
If the scene is currently inactive, \a item remains inactive until the |
|
5468 |
scene becomes active (or, ir \a item is 0, no item will be activated). |
|
5469 |
||
5470 |
\sa activePanel(), isActive(), QGraphicsItem::isActive() |
|
5471 |
*/ |
|
5472 |
void QGraphicsScene::setActivePanel(QGraphicsItem *item) |
|
5473 |
{ |
|
5474 |
Q_D(QGraphicsScene); |
|
5475 |
d->setActivePanelHelper(item, false); |
|
5476 |
} |
|
5477 |
||
5478 |
/*! |
|
5479 |
\since 4.4 |
|
5480 |
||
5481 |
Returns the current active window, or 0 if no window is currently |
|
5482 |
active. |
|
5483 |
||
5484 |
\sa QGraphicsScene::setActiveWindow() |
|
5485 |
*/ |
|
5486 |
QGraphicsWidget *QGraphicsScene::activeWindow() const |
|
5487 |
{ |
|
5488 |
Q_D(const QGraphicsScene); |
|
5489 |
if (d->activePanel && d->activePanel->isWindow()) |
|
5490 |
return static_cast<QGraphicsWidget *>(d->activePanel); |
|
5491 |
return 0; |
|
5492 |
} |
|
5493 |
||
5494 |
/*! |
|
5495 |
\since 4.4 |
|
5496 |
Activates \a widget, which must be a widget in this scene. You can also |
|
5497 |
pass 0 for \a widget, in which case QGraphicsScene will deactivate any |
|
5498 |
currently active window. |
|
5499 |
||
5500 |
\sa activeWindow(), QGraphicsWidget::isActiveWindow() |
|
5501 |
*/ |
|
5502 |
void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget) |
|
5503 |
{ |
|
5504 |
if (widget && widget->scene() != this) { |
|
5505 |
qWarning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene", |
|
5506 |
widget); |
|
5507 |
return; |
|
5508 |
} |
|
5509 |
||
5510 |
// Activate the widget's panel (all windows are panels). |
|
5511 |
QGraphicsItem *panel = widget ? widget->panel() : 0; |
|
5512 |
setActivePanel(panel); |
|
5513 |
||
5514 |
// Raise |
|
5515 |
if (panel) { |
|
5516 |
QList<QGraphicsItem *> siblingWindows; |
|
5517 |
QGraphicsItem *parent = panel->parentItem(); |
|
5518 |
// Raise ### inefficient for toplevels |
|
5519 |
foreach (QGraphicsItem *sibling, parent ? parent->children() : items()) { |
|
5520 |
if (sibling != panel && sibling->isWindow()) |
|
5521 |
siblingWindows << sibling; |
|
5522 |
} |
|
5523 |
||
5524 |
// Find the highest z value. |
|
5525 |
qreal z = panel->zValue(); |
|
5526 |
for (int i = 0; i < siblingWindows.size(); ++i) |
|
5527 |
z = qMax(z, siblingWindows.at(i)->zValue()); |
|
5528 |
||
5529 |
// This will probably never overflow. |
|
5530 |
const qreal litt = qreal(0.001); |
|
5531 |
panel->setZValue(z + litt); |
|
5532 |
} |
|
5533 |
} |
|
5534 |
||
5535 |
/*! |
|
5536 |
\since 4.6 |
|
5537 |
||
5538 |
Sends event \a event to item \a item through possible event filters. |
|
5539 |
||
5540 |
The event is sent only if the item is enabled. |
|
5541 |
||
5542 |
Returns \c false if the event was filtered or if the item is disabled. |
|
5543 |
Otherwise returns the value that was returned from the event handler. |
|
5544 |
||
5545 |
\sa QGraphicsItem::sceneEvent(), QGraphicsItem::sceneEventFilter() |
|
5546 |
*/ |
|
5547 |
bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event) |
|
5548 |
{ |
|
5549 |
Q_D(QGraphicsScene); |
|
5550 |
if (!item) { |
|
5551 |
qWarning("QGraphicsScene::sendEvent: cannot send event to a null item"); |
|
5552 |
return false; |
|
5553 |
} |
|
5554 |
if (item->scene() != this) { |
|
5555 |
qWarning("QGraphicsScene::sendEvent: item %p's scene (%p)" |
|
5556 |
" is different from this scene (%p)", |
|
5557 |
item, item->scene(), this); |
|
5558 |
return false; |
|
5559 |
} |
|
5560 |
return d->sendEvent(item, event); |
|
5561 |
} |
|
5562 |
||
5563 |
void QGraphicsScenePrivate::addView(QGraphicsView *view) |
|
5564 |
{ |
|
5565 |
views << view; |
|
5566 |
} |
|
5567 |
||
5568 |
void QGraphicsScenePrivate::removeView(QGraphicsView *view) |
|
5569 |
{ |
|
5570 |
views.removeAll(view); |
|
5571 |
} |
|
5572 |
||
5573 |
void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent) |
|
5574 |
{ |
|
5575 |
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); |
|
5576 |
for (int i = 0; i < touchPoints.count(); ++i) { |
|
5577 |
QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; |
|
5578 |
touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); |
|
5579 |
touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget())); |
|
5580 |
touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget())); |
|
5581 |
} |
|
5582 |
touchEvent->setTouchPoints(touchPoints); |
|
5583 |
} |
|
5584 |
||
5585 |
int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) |
|
5586 |
{ |
|
5587 |
int closestTouchPointId = -1; |
|
5588 |
qreal closestDistance = qreal(0.); |
|
5589 |
foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) { |
|
5590 |
qreal distance = QLineF(scenePos, touchPoint.scenePos()).length(); |
|
5591 |
if (closestTouchPointId == -1|| distance < closestDistance) { |
|
5592 |
closestTouchPointId = touchPoint.id(); |
|
5593 |
closestDistance = distance; |
|
5594 |
} |
|
5595 |
} |
|
5596 |
return closestTouchPointId; |
|
5597 |
} |
|
5598 |
||
5599 |
void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) |
|
5600 |
{ |
|
5601 |
typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints; |
|
5602 |
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents; |
|
5603 |
||
5604 |
for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) { |
|
5605 |
const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i); |
|
5606 |
||
5607 |
// update state |
|
5608 |
QGraphicsItem *item = 0; |
|
5609 |
if (touchPoint.state() == Qt::TouchPointPressed) { |
|
5610 |
if (sceneTouchEvent->deviceType() == QTouchEvent::TouchPad) { |
|
5611 |
// on touch-pad devices, send all touch points to the same item |
|
5612 |
item = itemForTouchPointId.isEmpty() |
|
5613 |
? 0 |
|
5614 |
: itemForTouchPointId.constBegin().value(); |
|
5615 |
} |
|
5616 |
||
5617 |
if (!item) { |
|
5618 |
// determine which item this touch point will go to |
|
5619 |
cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(), |
|
5620 |
touchPoint.scenePos(), |
|
5621 |
sceneTouchEvent->widget()); |
|
5622 |
item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first(); |
|
5623 |
} |
|
5624 |
||
5625 |
if (sceneTouchEvent->deviceType() == QTouchEvent::TouchScreen) { |
|
5626 |
// on touch-screens, combine this touch point with the closest one we find if it |
|
5627 |
// is a a direct descendent or ancestor ( |
|
5628 |
int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos()); |
|
5629 |
QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId); |
|
5630 |
if (!item |
|
5631 |
|| (closestItem |
|
5632 |
&& (item->isAncestorOf(closestItem) |
|
5633 |
|| closestItem->isAncestorOf(item)))) { |
|
5634 |
item = closestItem; |
|
5635 |
} |
|
5636 |
} |
|
5637 |
if (!item) |
|
5638 |
continue; |
|
5639 |
||
5640 |
itemForTouchPointId.insert(touchPoint.id(), item); |
|
5641 |
sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint); |
|
5642 |
} else if (touchPoint.state() == Qt::TouchPointReleased) { |
|
5643 |
item = itemForTouchPointId.take(touchPoint.id()); |
|
5644 |
if (!item) |
|
5645 |
continue; |
|
5646 |
||
5647 |
sceneCurrentTouchPoints.remove(touchPoint.id()); |
|
5648 |
} else { |
|
5649 |
item = itemForTouchPointId.value(touchPoint.id()); |
|
5650 |
if (!item) |
|
5651 |
continue; |
|
5652 |
Q_ASSERT(sceneCurrentTouchPoints.contains(touchPoint.id())); |
|
5653 |
sceneCurrentTouchPoints[touchPoint.id()] = touchPoint; |
|
5654 |
} |
|
5655 |
||
5656 |
StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item]; |
|
5657 |
statesAndTouchPoints.first |= touchPoint.state(); |
|
5658 |
statesAndTouchPoints.second.append(touchPoint); |
|
5659 |
} |
|
5660 |
||
5661 |
if (itemsNeedingEvents.isEmpty()) { |
|
5662 |
sceneTouchEvent->accept(); |
|
5663 |
return; |
|
5664 |
} |
|
5665 |
||
5666 |
bool ignoreSceneTouchEvent = true; |
|
5667 |
QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator it = itemsNeedingEvents.constBegin(); |
|
5668 |
const QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator end = itemsNeedingEvents.constEnd(); |
|
5669 |
for (; it != end; ++it) { |
|
5670 |
QGraphicsItem *item = it.key(); |
|
5671 |
||
5672 |
(void) item->isBlockedByModalPanel(&item); |
|
5673 |
||
5674 |
// determine event type from the state mask |
|
5675 |
QEvent::Type eventType; |
|
5676 |
switch (it.value().first) { |
|
5677 |
case Qt::TouchPointPressed: |
|
5678 |
// all touch points have pressed state |
|
5679 |
eventType = QEvent::TouchBegin; |
|
5680 |
break; |
|
5681 |
case Qt::TouchPointReleased: |
|
5682 |
// all touch points have released state |
|
5683 |
eventType = QEvent::TouchEnd; |
|
5684 |
break; |
|
5685 |
case Qt::TouchPointStationary: |
|
5686 |
// don't send the event if nothing changed |
|
5687 |
continue; |
|
5688 |
default: |
|
5689 |
// all other combinations |
|
5690 |
eventType = QEvent::TouchUpdate; |
|
5691 |
break; |
|
5692 |
} |
|
5693 |
||
5694 |
QTouchEvent touchEvent(eventType); |
|
5695 |
touchEvent.setWidget(sceneTouchEvent->widget()); |
|
5696 |
touchEvent.setDeviceType(sceneTouchEvent->deviceType()); |
|
5697 |
touchEvent.setModifiers(sceneTouchEvent->modifiers()); |
|
5698 |
touchEvent.setTouchPointStates(it.value().first); |
|
5699 |
touchEvent.setTouchPoints(it.value().second); |
|
5700 |
||
5701 |
switch (touchEvent.type()) { |
|
5702 |
case QEvent::TouchBegin: |
|
5703 |
{ |
|
5704 |
// if the TouchBegin handler recurses, we assume that means the event |
|
5705 |
// has been implicitly accepted and continue to send touch events |
|
5706 |
item->d_ptr->acceptedTouchBeginEvent = true; |
|
5707 |
bool res = sendTouchBeginEvent(item, &touchEvent) |
|
5708 |
&& touchEvent.isAccepted(); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5709 |
if (!res) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5710 |
// forget about these touch points, we didn't handle them |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5711 |
for (int i = 0; i < touchEvent.touchPoints().count(); ++i) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5712 |
const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5713 |
itemForTouchPointId.remove(touchPoint.id()); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5714 |
sceneCurrentTouchPoints.remove(touchPoint.id()); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5715 |
} |
0 | 5716 |
ignoreSceneTouchEvent = false; |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5717 |
} |
0 | 5718 |
break; |
5719 |
} |
|
5720 |
default: |
|
5721 |
if (item->d_ptr->acceptedTouchBeginEvent) { |
|
5722 |
updateTouchPointsForItem(item, &touchEvent); |
|
5723 |
(void) sendEvent(item, &touchEvent); |
|
5724 |
ignoreSceneTouchEvent = false; |
|
5725 |
} |
|
5726 |
break; |
|
5727 |
} |
|
5728 |
} |
|
5729 |
sceneTouchEvent->setAccepted(ignoreSceneTouchEvent); |
|
5730 |
} |
|
5731 |
||
5732 |
bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent) |
|
5733 |
{ |
|
5734 |
Q_Q(QGraphicsScene); |
|
5735 |
||
5736 |
if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) { |
|
5737 |
const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); |
|
5738 |
cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), |
|
5739 |
firstTouchPoint.scenePos(), |
|
5740 |
touchEvent->widget()); |
|
5741 |
} |
|
5742 |
Q_ASSERT(cachedItemsUnderMouse.first() == origin); |
|
5743 |
||
5744 |
// Set focus on the topmost enabled item that can take focus. |
|
5745 |
bool setFocus = false; |
|
5746 |
foreach (QGraphicsItem *item, cachedItemsUnderMouse) { |
|
5747 |
if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) { |
|
5748 |
if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) { |
|
5749 |
setFocus = true; |
|
5750 |
if (item != q->focusItem()) |
|
5751 |
q->setFocusItem(item, Qt::MouseFocusReason); |
|
5752 |
break; |
|
5753 |
} |
|
5754 |
} |
|
5755 |
if (item->isPanel()) |
|
5756 |
break; |
|
5757 |
} |
|
5758 |
||
5759 |
// If nobody could take focus, clear it. |
|
5760 |
if (!stickyFocus && !setFocus) |
|
5761 |
q->setFocusItem(0, Qt::MouseFocusReason); |
|
5762 |
||
5763 |
bool res = false; |
|
5764 |
bool eventAccepted = touchEvent->isAccepted(); |
|
5765 |
foreach (QGraphicsItem *item, cachedItemsUnderMouse) { |
|
5766 |
// first, try to deliver the touch event |
|
5767 |
updateTouchPointsForItem(item, touchEvent); |
|
5768 |
bool acceptTouchEvents = item->acceptTouchEvents(); |
|
5769 |
touchEvent->setAccepted(acceptTouchEvents); |
|
5770 |
res = acceptTouchEvents && sendEvent(item, touchEvent); |
|
5771 |
eventAccepted = touchEvent->isAccepted(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5772 |
if (itemForTouchPointId.value(touchEvent->touchPoints().first().id()) == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5773 |
// item was deleted |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5774 |
item = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5775 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5776 |
item->d_ptr->acceptedTouchBeginEvent = (res && eventAccepted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5777 |
} |
0 | 5778 |
touchEvent->spont = false; |
5779 |
if (res && eventAccepted) { |
|
5780 |
// the first item to accept the TouchBegin gets an implicit grab. |
|
5781 |
for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { |
|
5782 |
const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5783 |
itemForTouchPointId[touchPoint.id()] = item; // can be zero |
0 | 5784 |
} |
5785 |
break; |
|
5786 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5787 |
if (item && item->isPanel()) |
0 | 5788 |
break; |
5789 |
} |
|
5790 |
||
5791 |
touchEvent->setAccepted(eventAccepted); |
|
5792 |
return res; |
|
5793 |
} |
|
5794 |
||
5795 |
void QGraphicsScenePrivate::enableTouchEventsOnViews() |
|
5796 |
{ |
|
5797 |
foreach (QGraphicsView *view, views) |
|
5798 |
view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true); |
|
5799 |
} |
|
5800 |
||
5801 |
void QGraphicsScenePrivate::updateInputMethodSensitivityInViews() |
|
5802 |
{ |
|
5803 |
for (int i = 0; i < views.size(); ++i) |
|
5804 |
views.at(i)->d_func()->updateInputMethodSensitivity(); |
|
5805 |
} |
|
5806 |
||
5807 |
void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality) |
|
5808 |
{ |
|
5809 |
Q_Q(QGraphicsScene); |
|
5810 |
Q_ASSERT(panel && panel->isPanel()); |
|
5811 |
||
5812 |
QGraphicsItem::PanelModality panelModality = panel->d_ptr->panelModality; |
|
5813 |
if (previousModality != QGraphicsItem::NonModal) { |
|
5814 |
// the panel is changing from one modality type to another... temporarily set it back so |
|
5815 |
// that blockedPanels is populated correctly |
|
5816 |
panel->d_ptr->panelModality = previousModality; |
|
5817 |
} |
|
5818 |
||
5819 |
QSet<QGraphicsItem *> blockedPanels; |
|
5820 |
QList<QGraphicsItem *> items = q->items(); // ### store panels separately |
|
5821 |
for (int i = 0; i < items.count(); ++i) { |
|
5822 |
QGraphicsItem *item = items.at(i); |
|
5823 |
if (item->isPanel() && item->isBlockedByModalPanel()) |
|
5824 |
blockedPanels.insert(item); |
|
5825 |
} |
|
5826 |
// blockedPanels contains all currently blocked panels |
|
5827 |
||
5828 |
if (previousModality != QGraphicsItem::NonModal) { |
|
5829 |
// reset the modality to the proper value, since we changed it above |
|
5830 |
panel->d_ptr->panelModality = panelModality; |
|
5831 |
// remove this panel so that it will be reinserted at the front of the stack |
|
5832 |
modalPanels.removeAll(panel); |
|
5833 |
} |
|
5834 |
||
5835 |
modalPanels.prepend(panel); |
|
5836 |
||
5837 |
if (!hoverItems.isEmpty()) { |
|
5838 |
// send GraphicsSceneHoverLeave events to newly blocked hoverItems |
|
5839 |
QGraphicsSceneHoverEvent hoverEvent; |
|
5840 |
hoverEvent.setScenePos(lastSceneMousePos); |
|
5841 |
dispatchHoverEvent(&hoverEvent); |
|
5842 |
} |
|
5843 |
||
5844 |
if (!mouseGrabberItems.isEmpty() && lastMouseGrabberItemHasImplicitMouseGrab) { |
|
5845 |
QGraphicsItem *item = mouseGrabberItems.last(); |
|
5846 |
if (item->isBlockedByModalPanel()) |
|
5847 |
ungrabMouse(item, /*itemIsDying =*/ false); |
|
5848 |
} |
|
5849 |
||
5850 |
QEvent windowBlockedEvent(QEvent::WindowBlocked); |
|
5851 |
QEvent windowUnblockedEvent(QEvent::WindowUnblocked); |
|
5852 |
for (int i = 0; i < items.count(); ++i) { |
|
5853 |
QGraphicsItem *item = items.at(i); |
|
5854 |
if (item->isPanel()) { |
|
5855 |
if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) { |
|
5856 |
// send QEvent::WindowBlocked to newly blocked panels |
|
5857 |
sendEvent(item, &windowBlockedEvent); |
|
5858 |
} else if (blockedPanels.contains(item) && !item->isBlockedByModalPanel()) { |
|
5859 |
// send QEvent::WindowUnblocked to unblocked panels when downgrading |
|
5860 |
// a panel from SceneModal to PanelModal |
|
5861 |
sendEvent(item, &windowUnblockedEvent); |
|
5862 |
} |
|
5863 |
} |
|
5864 |
} |
|
5865 |
} |
|
5866 |
||
5867 |
void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel) |
|
5868 |
{ |
|
5869 |
Q_Q(QGraphicsScene); |
|
5870 |
Q_ASSERT(panel && panel->isPanel()); |
|
5871 |
||
5872 |
QSet<QGraphicsItem *> blockedPanels; |
|
5873 |
QList<QGraphicsItem *> items = q->items(); // ### same as above |
|
5874 |
for (int i = 0; i < items.count(); ++i) { |
|
5875 |
QGraphicsItem *item = items.at(i); |
|
5876 |
if (item->isPanel() && item->isBlockedByModalPanel()) |
|
5877 |
blockedPanels.insert(item); |
|
5878 |
} |
|
5879 |
||
5880 |
modalPanels.removeAll(panel); |
|
5881 |
||
5882 |
QEvent e(QEvent::WindowUnblocked); |
|
5883 |
for (int i = 0; i < items.count(); ++i) { |
|
5884 |
QGraphicsItem *item = items.at(i); |
|
5885 |
if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel()) |
|
5886 |
sendEvent(item, &e); |
|
5887 |
} |
|
5888 |
||
5889 |
// send GraphicsSceneHoverEnter events to newly unblocked items |
|
5890 |
QGraphicsSceneHoverEvent hoverEvent; |
|
5891 |
hoverEvent.setScenePos(lastSceneMousePos); |
|
5892 |
dispatchHoverEvent(&hoverEvent); |
|
5893 |
} |
|
5894 |
||
5895 |
void QGraphicsScenePrivate::getGestureTargets(const QSet<QGesture *> &gestures, |
|
5896 |
QWidget *viewport, |
|
5897 |
QMap<Qt::GestureType, QGesture *> *conflictedGestures, |
|
5898 |
QList<QList<QGraphicsObject *> > *conflictedItems, |
|
5899 |
QHash<QGesture *, QGraphicsObject *> *normalGestures) |
|
5900 |
{ |
|
5901 |
foreach (QGesture *gesture, gestures) { |
|
5902 |
Qt::GestureType gestureType = gesture->gestureType(); |
|
5903 |
if (gesture->hasHotSpot()) { |
|
5904 |
QPoint screenPos = gesture->hotSpot().toPoint(); |
|
5905 |
QList<QGraphicsItem *> items = itemsAtPosition(screenPos, QPointF(), viewport); |
|
5906 |
QList<QGraphicsObject *> result; |
|
5907 |
for (int j = 0; j < items.size(); ++j) { |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5908 |
QGraphicsItem *item = items.at(j); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5909 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5910 |
// Check if the item is blocked by a modal panel and use it as |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5911 |
// a target instead of this item. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5912 |
(void) item->isBlockedByModalPanel(&item); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5913 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5914 |
if (QGraphicsObject *itemobj = item->toGraphicsObject()) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5915 |
QGraphicsItemPrivate *d = item->d_func(); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5916 |
if (d->gestureContext.contains(gestureType)) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5917 |
result.append(itemobj); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5918 |
} |
0 | 5919 |
} |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5920 |
// Don't propagate through panels. |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5921 |
if (item->isPanel()) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
5922 |
break; |
0 | 5923 |
} |
5924 |
DEBUG() << "QGraphicsScenePrivate::getGestureTargets:" |
|
5925 |
<< gesture << result; |
|
5926 |
if (result.size() == 1) { |
|
5927 |
normalGestures->insert(gesture, result.first()); |
|
5928 |
} else if (!result.isEmpty()) { |
|
5929 |
conflictedGestures->insert(gestureType, gesture); |
|
5930 |
conflictedItems->append(result); |
|
5931 |
} |
|
5932 |
} |
|
5933 |
} |
|
5934 |
} |
|
5935 |
||
5936 |
void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) |
|
5937 |
{ |
|
5938 |
QWidget *viewport = event->widget(); |
|
5939 |
if (!viewport) |
|
5940 |
return; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5941 |
QList<QGesture *> allGestures = event->gestures(); |
0 | 5942 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
5943 |
<< "Delivering gestures:" << allGestures; |
|
5944 |
||
5945 |
typedef QHash<QGraphicsObject *, QList<QGesture *> > GesturesPerItem; |
|
5946 |
GesturesPerItem gesturesPerItem; |
|
5947 |
||
5948 |
QSet<QGesture *> startedGestures; |
|
5949 |
foreach (QGesture *gesture, allGestures) { |
|
5950 |
QGraphicsObject *target = gestureTargets.value(gesture, 0); |
|
5951 |
if (!target) { |
|
5952 |
// when we are not in started mode but don't have a target |
|
5953 |
// then the only one interested in gesture is the view/scene |
|
5954 |
if (gesture->state() == Qt::GestureStarted) |
|
5955 |
startedGestures.insert(gesture); |
|
5956 |
} else { |
|
5957 |
gesturesPerItem[target].append(gesture); |
|
5958 |
} |
|
5959 |
} |
|
5960 |
||
5961 |
QMap<Qt::GestureType, QGesture *> conflictedGestures; |
|
5962 |
QList<QList<QGraphicsObject *> > conflictedItems; |
|
5963 |
QHash<QGesture *, QGraphicsObject *> normalGestures; |
|
5964 |
getGestureTargets(startedGestures, viewport, &conflictedGestures, &conflictedItems, |
|
5965 |
&normalGestures); |
|
5966 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
5967 |
<< "Conflicting gestures:" << conflictedGestures.values() << conflictedItems; |
|
5968 |
Q_ASSERT((conflictedGestures.isEmpty() && conflictedItems.isEmpty()) || |
|
5969 |
(!conflictedGestures.isEmpty() && !conflictedItems.isEmpty())); |
|
5970 |
||
5971 |
// gestures that were sent as override events, but no one accepted them |
|
5972 |
QHash<QGesture *, QGraphicsObject *> ignoredConflictedGestures; |
|
5973 |
||
5974 |
// deliver conflicted gestures as override events first |
|
5975 |
while (!conflictedGestures.isEmpty() && !conflictedItems.isEmpty()) { |
|
5976 |
// get the topmost item to deliver the override event |
|
5977 |
Q_ASSERT(!conflictedItems.isEmpty()); |
|
5978 |
Q_ASSERT(!conflictedItems.first().isEmpty()); |
|
5979 |
QGraphicsObject *topmost = conflictedItems.first().first(); |
|
5980 |
for (int i = 1; i < conflictedItems.size(); ++i) { |
|
5981 |
QGraphicsObject *item = conflictedItems.at(i).first(); |
|
5982 |
if (qt_closestItemFirst(item, topmost)) { |
|
5983 |
topmost = item; |
|
5984 |
} |
|
5985 |
} |
|
5986 |
// get a list of gestures to send to the item |
|
5987 |
QList<Qt::GestureType> grabbedGestures = |
|
5988 |
topmost->QGraphicsItem::d_func()->gestureContext.keys(); |
|
5989 |
QList<QGesture *> gestures; |
|
5990 |
for (int i = 0; i < grabbedGestures.size(); ++i) { |
|
5991 |
if (QGesture *g = conflictedGestures.value(grabbedGestures.at(i), 0)) { |
|
5992 |
gestures.append(g); |
|
5993 |
if (!ignoredConflictedGestures.contains(g)) |
|
5994 |
ignoredConflictedGestures.insert(g, topmost); |
|
5995 |
} |
|
5996 |
} |
|
5997 |
||
5998 |
// send gesture override to the topmost item |
|
5999 |
QGestureEvent ev(gestures); |
|
6000 |
ev.t = QEvent::GestureOverride; |
|
6001 |
ev.setWidget(event->widget()); |
|
6002 |
// mark event and individual gestures as ignored |
|
6003 |
ev.ignore(); |
|
6004 |
foreach(QGesture *g, gestures) |
|
6005 |
ev.setAccepted(g, false); |
|
6006 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6007 |
<< "delivering override to" |
|
6008 |
<< topmost << gestures; |
|
6009 |
sendEvent(topmost, &ev); |
|
6010 |
// mark all accepted gestures to deliver them as normal gesture events |
|
6011 |
foreach (QGesture *g, gestures) { |
|
6012 |
if (ev.isAccepted() || ev.isAccepted(g)) { |
|
6013 |
conflictedGestures.remove(g->gestureType()); |
|
6014 |
gestureTargets.remove(g); |
|
6015 |
// add the gesture to the list of normal delivered gestures |
|
6016 |
normalGestures.insert(g, topmost); |
|
6017 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6018 |
<< "override was accepted:" |
|
6019 |
<< g << topmost; |
|
6020 |
ignoredConflictedGestures.remove(g); |
|
6021 |
} |
|
6022 |
} |
|
6023 |
// remove the item that we've already delivered from the list |
|
6024 |
for (int i = 0; i < conflictedItems.size(); ) { |
|
6025 |
QList<QGraphicsObject *> &items = conflictedItems[i]; |
|
6026 |
if (items.first() == topmost) { |
|
6027 |
items.removeFirst(); |
|
6028 |
if (items.isEmpty()) { |
|
6029 |
conflictedItems.removeAt(i); |
|
6030 |
continue; |
|
6031 |
} |
|
6032 |
} |
|
6033 |
++i; |
|
6034 |
} |
|
6035 |
} |
|
6036 |
||
6037 |
// put back those started gestures that are not in the conflicted state |
|
6038 |
// and remember their targets |
|
6039 |
QHash<QGesture *, QGraphicsObject *>::const_iterator it = normalGestures.begin(), |
|
6040 |
e = normalGestures.end(); |
|
6041 |
for (; it != e; ++it) { |
|
6042 |
QGesture *g = it.key(); |
|
6043 |
QGraphicsObject *receiver = it.value(); |
|
6044 |
Q_ASSERT(!gestureTargets.contains(g)); |
|
6045 |
gestureTargets.insert(g, receiver); |
|
6046 |
gesturesPerItem[receiver].append(g); |
|
6047 |
} |
|
6048 |
it = ignoredConflictedGestures.begin(); |
|
6049 |
e = ignoredConflictedGestures.end(); |
|
6050 |
for (; it != e; ++it) { |
|
6051 |
QGesture *g = it.key(); |
|
6052 |
QGraphicsObject *receiver = it.value(); |
|
6053 |
Q_ASSERT(!gestureTargets.contains(g)); |
|
6054 |
gestureTargets.insert(g, receiver); |
|
6055 |
gesturesPerItem[receiver].append(g); |
|
6056 |
} |
|
6057 |
||
6058 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6059 |
<< "Started gestures:" << normalGestures.keys() |
|
6060 |
<< "All gestures:" << gesturesPerItem.values(); |
|
6061 |
||
6062 |
// deliver all events |
|
6063 |
QList<QGesture *> alreadyIgnoredGestures; |
|
6064 |
QHash<QGraphicsObject *, QSet<QGesture *> > itemIgnoredGestures; |
|
6065 |
QList<QGraphicsObject *> targetItems = gesturesPerItem.keys(); |
|
6066 |
qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst); |
|
6067 |
for (int i = 0; i < targetItems.size(); ++i) { |
|
6068 |
QGraphicsObject *item = targetItems.at(i); |
|
6069 |
QList<QGesture *> gestures = gesturesPerItem.value(item); |
|
6070 |
// remove gestures that were already delivered once and were ignored |
|
6071 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6072 |
<< "already ignored gestures for item" |
|
6073 |
<< item << ":" << itemIgnoredGestures.value(item); |
|
6074 |
||
6075 |
if (itemIgnoredGestures.contains(item)) // don't deliver twice to the same item |
|
6076 |
continue; |
|
6077 |
||
6078 |
QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func(); |
|
6079 |
foreach(QGesture *g, alreadyIgnoredGestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6080 |
QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6081 |
gid->gestureContext.find(g->gestureType()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6082 |
bool deliver = contextit != gid->gestureContext.end() && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6083 |
(g->state() == Qt::GestureStarted || |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6084 |
(contextit.value() & Qt::ReceivePartialGestures)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6085 |
if (deliver) |
0 | 6086 |
gestures += g; |
6087 |
} |
|
6088 |
if (gestures.isEmpty()) |
|
6089 |
continue; |
|
6090 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6091 |
<< "delivering to" |
|
6092 |
<< item << gestures; |
|
6093 |
QGestureEvent ev(gestures); |
|
6094 |
ev.setWidget(event->widget()); |
|
6095 |
sendEvent(item, &ev); |
|
6096 |
QSet<QGesture *> ignoredGestures; |
|
6097 |
foreach (QGesture *g, gestures) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6098 |
if (!ev.isAccepted() && !ev.isAccepted(g)) { |
0 | 6099 |
ignoredGestures.insert(g); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6100 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6101 |
if (g->state() == Qt::GestureStarted) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6102 |
gestureTargets[g] = item; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6103 |
} |
0 | 6104 |
} |
6105 |
if (!ignoredGestures.isEmpty()) { |
|
6106 |
// get a list of items under the (current) hotspot of each ignored |
|
6107 |
// gesture and start delivery again from the beginning |
|
6108 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6109 |
<< "item has ignored the event, will propagate." |
|
6110 |
<< item << ignoredGestures; |
|
6111 |
itemIgnoredGestures[item] += ignoredGestures; |
|
6112 |
QMap<Qt::GestureType, QGesture *> conflictedGestures; |
|
6113 |
QList<QList<QGraphicsObject *> > itemsForConflictedGestures; |
|
6114 |
QHash<QGesture *, QGraphicsObject *> normalGestures; |
|
6115 |
getGestureTargets(ignoredGestures, viewport, |
|
6116 |
&conflictedGestures, &itemsForConflictedGestures, |
|
6117 |
&normalGestures); |
|
6118 |
QSet<QGraphicsObject *> itemsSet = targetItems.toSet(); |
|
6119 |
for (int k = 0; k < itemsForConflictedGestures.size(); ++k) |
|
6120 |
itemsSet += itemsForConflictedGestures.at(k).toSet(); |
|
6121 |
targetItems = itemsSet.toList(); |
|
6122 |
qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst); |
|
6123 |
alreadyIgnoredGestures = conflictedGestures.values(); |
|
6124 |
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" |
|
6125 |
<< "new targets:" << targetItems; |
|
6126 |
i = -1; // start delivery again |
|
6127 |
continue; |
|
6128 |
} |
|
6129 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6130 |
foreach (QGesture *g, startedGestures) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6131 |
if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6132 |
DEBUG() << "lets try to cancel some"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6133 |
// find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6134 |
cancelGesturesForChildren(g, event->widget()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6135 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6136 |
} |
0 | 6137 |
|
6138 |
// forget about targets for gestures that have ended |
|
6139 |
foreach (QGesture *g, allGestures) { |
|
6140 |
switch (g->state()) { |
|
6141 |
case Qt::GestureFinished: |
|
6142 |
case Qt::GestureCanceled: |
|
6143 |
gestureTargets.remove(g); |
|
6144 |
break; |
|
6145 |
default: |
|
6146 |
break; |
|
6147 |
} |
|
6148 |
} |
|
6149 |
} |
|
6150 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6151 |
void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidget *viewport) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6152 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6153 |
Q_ASSERT(original); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6154 |
QGraphicsItem *originalItem = gestureTargets.value(original); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6155 |
Q_ASSERT(originalItem); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6156 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6157 |
// iterate over all active gestures and for each find the owner |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6158 |
// if the owner is part of our sub-hierarchy, cancel it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6159 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6160 |
QSet<QGesture *> canceledGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6161 |
QHash<QGesture *, QGraphicsObject *>::Iterator iter = gestureTargets.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6162 |
while (iter != gestureTargets.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6163 |
QGraphicsObject *item = iter.value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6164 |
// note that we don't touch the gestures for our originalItem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6165 |
if (item != originalItem && originalItem->isAncestorOf(item)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6166 |
DEBUG() << " found a gesture to cancel" << iter.key(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6167 |
iter.key()->d_func()->state = Qt::GestureCanceled; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6168 |
canceledGestures << iter.key(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6169 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6170 |
++iter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6171 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6172 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6173 |
// sort them per target item by cherry picking from almostCanceledGestures and delivering |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6174 |
QSet<QGesture *> almostCanceledGestures = canceledGestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6175 |
QSet<QGesture *>::Iterator setIter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6176 |
while (!almostCanceledGestures.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6177 |
QGraphicsObject *target = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6178 |
QSet<QGesture*> gestures; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6179 |
setIter = almostCanceledGestures.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6180 |
// sort per target item |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6181 |
while (setIter != almostCanceledGestures.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6182 |
QGraphicsObject *item = gestureTargets.value(*setIter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6183 |
if (target == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6184 |
target = item; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6185 |
if (target == item) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6186 |
gestures << *setIter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6187 |
setIter = almostCanceledGestures.erase(setIter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6188 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6189 |
++setIter; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6190 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6191 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6192 |
Q_ASSERT(target); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6193 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6194 |
QList<QGesture *> list = gestures.toList(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6195 |
QGestureEvent ev(list); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6196 |
sendEvent(target, &ev); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6197 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6198 |
foreach (QGesture *g, list) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6199 |
if (ev.isAccepted() || ev.isAccepted(g)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6200 |
gestures.remove(g); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6201 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6202 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6203 |
foreach (QGesture *g, gestures) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6204 |
if (!g->hasHotSpot()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6205 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6206 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6207 |
QPoint screenPos = g->hotSpot().toPoint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6208 |
QList<QGraphicsItem *> items = itemsAtPosition(screenPos, QPointF(), viewport); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6209 |
for (int j = 0; j < items.size(); ++j) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6210 |
QGraphicsObject *item = items.at(j)->toGraphicsObject(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6211 |
if (!item) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6212 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6213 |
QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6214 |
if (d->gestureContext.contains(g->gestureType())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6215 |
QList<QGesture *> list; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6216 |
list << g; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6217 |
QGestureEvent ev(list); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6218 |
sendEvent(item, &ev); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6219 |
if (ev.isAccepted() || ev.isAccepted(g)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6220 |
break; // successfully delivered |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6221 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6222 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6223 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6224 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6225 |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
6226 |
QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
6227 |
Q_ASSERT(gestureManager); // it would be very odd if we got called without a manager. |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6228 |
for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) { |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
6229 |
gestureManager->recycle(*setIter); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6230 |
gestureTargets.remove(*setIter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6231 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6232 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6233 |
|
0 | 6234 |
QT_END_NAMESPACE |
6235 |
||
6236 |
#include "moc_qgraphicsscene.cpp" |
|
6237 |
||
6238 |
#endif // QT_NO_GRAPHICSVIEW |