Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsscene.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||
34 | /*! | - | ||||||||||||||||||||||||||||||
35 | \class QGraphicsScene | - | ||||||||||||||||||||||||||||||
36 | \brief The QGraphicsScene class provides a surface for managing a large | - | ||||||||||||||||||||||||||||||
37 | number of 2D graphical items. | - | ||||||||||||||||||||||||||||||
38 | \since 4.2 | - | ||||||||||||||||||||||||||||||
39 | \ingroup graphicsview-api | - | ||||||||||||||||||||||||||||||
40 | \inmodule QtWidgets | - | ||||||||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||||||||
42 | The class serves as a container for QGraphicsItems. It is used together | - | ||||||||||||||||||||||||||||||
43 | with QGraphicsView for visualizing graphical items, such as lines, | - | ||||||||||||||||||||||||||||||
44 | rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is | - | ||||||||||||||||||||||||||||||
45 | part of the \l{Graphics View Framework}. | - | ||||||||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||||||||
47 | QGraphicsScene also provides functionality that lets you efficiently | - | ||||||||||||||||||||||||||||||
48 | determine both the location of items, and for determining what items are | - | ||||||||||||||||||||||||||||||
49 | visible within an arbitrary area on the scene. With the QGraphicsView | - | ||||||||||||||||||||||||||||||
50 | widget, you can either visualize the whole scene, or zoom in and view only | - | ||||||||||||||||||||||||||||||
51 | parts of the scene. | - | ||||||||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||||||||
53 | Example: | - | ||||||||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||||||||
55 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 0 | - | ||||||||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||||||||
57 | Note that QGraphicsScene has no visual appearance of its own; it only | - | ||||||||||||||||||||||||||||||
58 | manages the items. You need to create a QGraphicsView widget to visualize | - | ||||||||||||||||||||||||||||||
59 | the scene. | - | ||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||
61 | To add items to a scene, you start off by constructing a QGraphicsScene | - | ||||||||||||||||||||||||||||||
62 | object. Then, you have two options: either add your existing QGraphicsItem | - | ||||||||||||||||||||||||||||||
63 | objects by calling addItem(), or you can call one of the convenience | - | ||||||||||||||||||||||||||||||
64 | functions addEllipse(), addLine(), addPath(), addPixmap(), addPolygon(), | - | ||||||||||||||||||||||||||||||
65 | addRect(), or addText(), which all return a pointer to the newly added item. | - | ||||||||||||||||||||||||||||||
66 | The dimensions of the items added with these functions are relative to the | - | ||||||||||||||||||||||||||||||
67 | item's coordinate system, and the items position is initialized to (0, | - | ||||||||||||||||||||||||||||||
68 | 0) in the scene. | - | ||||||||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||||||||
70 | You can then visualize the scene using QGraphicsView. When the scene | - | ||||||||||||||||||||||||||||||
71 | changes, (e.g., when an item moves or is transformed) QGraphicsScene | - | ||||||||||||||||||||||||||||||
72 | emits the changed() signal. To remove an item, call removeItem(). | - | ||||||||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||||||||
74 | QGraphicsScene uses an indexing algorithm to manage the location of items | - | ||||||||||||||||||||||||||||||
75 | efficiently. By default, a BSP (Binary Space Partitioning) tree is used; an | - | ||||||||||||||||||||||||||||||
76 | algorithm suitable for large scenes where most items remain static (i.e., | - | ||||||||||||||||||||||||||||||
77 | do not move around). You can choose to disable this index by calling | - | ||||||||||||||||||||||||||||||
78 | setItemIndexMethod(). For more information about the available indexing | - | ||||||||||||||||||||||||||||||
79 | algorithms, see the itemIndexMethod property. | - | ||||||||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||||||||
81 | The scene's bounding rect is set by calling setSceneRect(). Items can be | - | ||||||||||||||||||||||||||||||
82 | placed at any position on the scene, and the size of the scene is by | - | ||||||||||||||||||||||||||||||
83 | default unlimited. The scene rect is used only for internal bookkeeping, | - | ||||||||||||||||||||||||||||||
84 | maintaining the scene's item index. If the scene rect is unset, | - | ||||||||||||||||||||||||||||||
85 | QGraphicsScene will use the bounding area of all items, as returned by | - | ||||||||||||||||||||||||||||||
86 | itemsBoundingRect(), as the scene rect. However, itemsBoundingRect() is a | - | ||||||||||||||||||||||||||||||
87 | relatively time consuming function, as it operates by collecting | - | ||||||||||||||||||||||||||||||
88 | positional information for every item on the scene. Because of this, you | - | ||||||||||||||||||||||||||||||
89 | should always set the scene rect when operating on large scenes. | - | ||||||||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||||||||
91 | One of QGraphicsScene's greatest strengths is its ability to efficiently | - | ||||||||||||||||||||||||||||||
92 | determine the location of items. Even with millions of items on the scene, | - | ||||||||||||||||||||||||||||||
93 | the items() functions can determine the location of an item within a few | - | ||||||||||||||||||||||||||||||
94 | milliseconds. There are several overloads to items(): one that finds items | - | ||||||||||||||||||||||||||||||
95 | at a certain position, one that finds items inside or intersecting with a | - | ||||||||||||||||||||||||||||||
96 | polygon or a rectangle, and more. The list of returned items is sorted by | - | ||||||||||||||||||||||||||||||
97 | stacking order, with the topmost item being the first item in the list. | - | ||||||||||||||||||||||||||||||
98 | For convenience, there is also an itemAt() function that returns the | - | ||||||||||||||||||||||||||||||
99 | topmost item at a given position. | - | ||||||||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||||||||
101 | QGraphicsScene maintains selection information for the scene. To select | - | ||||||||||||||||||||||||||||||
102 | items, call setSelectionArea(), and to clear the current selection, call | - | ||||||||||||||||||||||||||||||
103 | clearSelection(). Call selectedItems() to get the list of all selected | - | ||||||||||||||||||||||||||||||
104 | items. | - | ||||||||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||||||||
106 | \section1 Event Handling and Propagation | - | ||||||||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||||||||
108 | Another responsibility that QGraphicsScene has, is to propagate events | - | ||||||||||||||||||||||||||||||
109 | from QGraphicsView. To send an event to a scene, you construct an event | - | ||||||||||||||||||||||||||||||
110 | that inherits QEvent, and then send it using, for example, | - | ||||||||||||||||||||||||||||||
111 | QApplication::sendEvent(). event() is responsible for dispatching | - | ||||||||||||||||||||||||||||||
112 | the event to the individual items. Some common events are handled by | - | ||||||||||||||||||||||||||||||
113 | convenience event handlers. For example, key press events are handled by | - | ||||||||||||||||||||||||||||||
114 | keyPressEvent(), and mouse press events are handled by mousePressEvent(). | - | ||||||||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||||||||
116 | Key events are delivered to the \e {focus item}. To set the focus item, | - | ||||||||||||||||||||||||||||||
117 | you can either call setFocusItem(), passing an item that accepts focus, or | - | ||||||||||||||||||||||||||||||
118 | the item itself can call QGraphicsItem::setFocus(). Call focusItem() to | - | ||||||||||||||||||||||||||||||
119 | get the current focus item. For compatibility with widgets, the scene also | - | ||||||||||||||||||||||||||||||
120 | maintains its own focus information. By default, the scene does not have | - | ||||||||||||||||||||||||||||||
121 | focus, and all key events are discarded. If setFocus() is called, or if an | - | ||||||||||||||||||||||||||||||
122 | item on the scene gains focus, the scene automatically gains focus. If the | - | ||||||||||||||||||||||||||||||
123 | scene has focus, hasFocus() will return true, and key events will be | - | ||||||||||||||||||||||||||||||
124 | forwarded to the focus item, if any. If the scene loses focus, (i.e., | - | ||||||||||||||||||||||||||||||
125 | someone calls clearFocus()) while an item has focus, the scene will | - | ||||||||||||||||||||||||||||||
126 | maintain its item focus information, and once the scene regains focus, it | - | ||||||||||||||||||||||||||||||
127 | will make sure the last focus item regains focus. | - | ||||||||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||||||||
129 | For mouse-over effects, QGraphicsScene dispatches \e {hover | - | ||||||||||||||||||||||||||||||
130 | events}. If an item accepts hover events (see | - | ||||||||||||||||||||||||||||||
131 | QGraphicsItem::acceptHoverEvents()), it will receive a \l | - | ||||||||||||||||||||||||||||||
132 | {QEvent::}{GraphicsSceneHoverEnter} event when the mouse enters | - | ||||||||||||||||||||||||||||||
133 | its area. As the mouse continues moving inside the item's area, | - | ||||||||||||||||||||||||||||||
134 | QGraphicsScene will send it \l {QEvent::}{GraphicsSceneHoverMove} | - | ||||||||||||||||||||||||||||||
135 | events. When the mouse leaves the item's area, the item will | - | ||||||||||||||||||||||||||||||
136 | receive a \l {QEvent::}{GraphicsSceneHoverLeave} event. | - | ||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||
138 | All mouse events are delivered to the current \e {mouse grabber} | - | ||||||||||||||||||||||||||||||
139 | item. An item becomes the scene's mouse grabber if it accepts | - | ||||||||||||||||||||||||||||||
140 | mouse events (see QGraphicsItem::acceptedMouseButtons()) and it | - | ||||||||||||||||||||||||||||||
141 | receives a mouse press. It stays the mouse grabber until it | - | ||||||||||||||||||||||||||||||
142 | receives a mouse release when no other mouse buttons are | - | ||||||||||||||||||||||||||||||
143 | pressed. You can call mouseGrabberItem() to determine what item is | - | ||||||||||||||||||||||||||||||
144 | currently grabbing the mouse. | - | ||||||||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||||||||
146 | \sa QGraphicsItem, QGraphicsView | - | ||||||||||||||||||||||||||||||
147 | */ | - | ||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||
149 | /*! | - | ||||||||||||||||||||||||||||||
150 | \enum QGraphicsScene::SceneLayer | - | ||||||||||||||||||||||||||||||
151 | \since 4.3 | - | ||||||||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||||||||
153 | This enum describes the rendering layers in a QGraphicsScene. When | - | ||||||||||||||||||||||||||||||
154 | QGraphicsScene draws the scene contents, it renders each of these layers | - | ||||||||||||||||||||||||||||||
155 | separately, in order. | - | ||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||
157 | Each layer represents a flag that can be OR'ed together when calling | - | ||||||||||||||||||||||||||||||
158 | functions such as invalidate() or QGraphicsView::invalidateScene(). | - | ||||||||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||||||||
160 | \value ItemLayer The item layer. QGraphicsScene renders all items are in | - | ||||||||||||||||||||||||||||||
161 | this layer by calling the virtual function drawItems(). The item layer is | - | ||||||||||||||||||||||||||||||
162 | drawn after the background layer, but before the foreground layer. | - | ||||||||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||||||||
164 | \value BackgroundLayer The background layer. QGraphicsScene renders the | - | ||||||||||||||||||||||||||||||
165 | scene's background in this layer by calling the virtual function | - | ||||||||||||||||||||||||||||||
166 | drawBackground(). The background layer is drawn first of all layers. | - | ||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||
168 | \value ForegroundLayer The foreground layer. QGraphicsScene renders the | - | ||||||||||||||||||||||||||||||
169 | scene's foreground in this layer by calling the virtual function | - | ||||||||||||||||||||||||||||||
170 | drawForeground(). The foreground layer is drawn last of all layers. | - | ||||||||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||||||||
172 | \value AllLayers All layers; this value represents a combination of all | - | ||||||||||||||||||||||||||||||
173 | three layers. | - | ||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||
175 | \sa invalidate(), QGraphicsView::invalidateScene() | - | ||||||||||||||||||||||||||||||
176 | */ | - | ||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||
178 | /*! | - | ||||||||||||||||||||||||||||||
179 | \enum QGraphicsScene::ItemIndexMethod | - | ||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||
181 | This enum describes the indexing algorithms QGraphicsScene provides for | - | ||||||||||||||||||||||||||||||
182 | managing positional information about items on the scene. | - | ||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||
184 | \value BspTreeIndex A Binary Space Partitioning tree is applied. All | - | ||||||||||||||||||||||||||||||
185 | QGraphicsScene's item location algorithms are of an order close to | - | ||||||||||||||||||||||||||||||
186 | logarithmic complexity, by making use of binary search. Adding, moving and | - | ||||||||||||||||||||||||||||||
187 | removing items is logarithmic. This approach is best for static scenes | - | ||||||||||||||||||||||||||||||
188 | (i.e., scenes where most items do not move). | - | ||||||||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||||||||
190 | \value NoIndex No index is applied. Item location is of linear complexity, | - | ||||||||||||||||||||||||||||||
191 | as all items on the scene are searched. Adding, moving and removing items, | - | ||||||||||||||||||||||||||||||
192 | however, is done in constant time. This approach is ideal for dynamic | - | ||||||||||||||||||||||||||||||
193 | scenes, where many items are added, moved or removed continuously. | - | ||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||
195 | \sa setItemIndexMethod(), bspTreeDepth | - | ||||||||||||||||||||||||||||||
196 | */ | - | ||||||||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||||||||
198 | #include "qgraphicsscene.h" | - | ||||||||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||||||||
200 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||
202 | #include "qgraphicsitem.h" | - | ||||||||||||||||||||||||||||||
203 | #include "qgraphicsitem_p.h" | - | ||||||||||||||||||||||||||||||
204 | #include "qgraphicslayout.h" | - | ||||||||||||||||||||||||||||||
205 | #include "qgraphicsscene_p.h" | - | ||||||||||||||||||||||||||||||
206 | #include "qgraphicssceneevent.h" | - | ||||||||||||||||||||||||||||||
207 | #include "qgraphicsview.h" | - | ||||||||||||||||||||||||||||||
208 | #include "qgraphicsview_p.h" | - | ||||||||||||||||||||||||||||||
209 | #include "qgraphicswidget.h" | - | ||||||||||||||||||||||||||||||
210 | #include "qgraphicswidget_p.h" | - | ||||||||||||||||||||||||||||||
211 | #include "qgraphicssceneindex_p.h" | - | ||||||||||||||||||||||||||||||
212 | #include "qgraphicsscenebsptreeindex_p.h" | - | ||||||||||||||||||||||||||||||
213 | #include "qgraphicsscenelinearindex_p.h" | - | ||||||||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||||||||
215 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||||||||||||||
216 | #include <QtCore/qlist.h> | - | ||||||||||||||||||||||||||||||
217 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||||||||
218 | #include <QtCore/qrect.h> | - | ||||||||||||||||||||||||||||||
219 | #include <QtCore/qset.h> | - | ||||||||||||||||||||||||||||||
220 | #include <QtCore/qstack.h> | - | ||||||||||||||||||||||||||||||
221 | #include <QtCore/qtimer.h> | - | ||||||||||||||||||||||||||||||
222 | #include <QtCore/qvarlengtharray.h> | - | ||||||||||||||||||||||||||||||
223 | #include <QtCore/QMetaMethod> | - | ||||||||||||||||||||||||||||||
224 | #include <QtWidgets/qapplication.h> | - | ||||||||||||||||||||||||||||||
225 | #include <QtWidgets/qdesktopwidget.h> | - | ||||||||||||||||||||||||||||||
226 | #include <QtGui/qevent.h> | - | ||||||||||||||||||||||||||||||
227 | #include <QtWidgets/qgraphicslayout.h> | - | ||||||||||||||||||||||||||||||
228 | #include <QtWidgets/qgraphicsproxywidget.h> | - | ||||||||||||||||||||||||||||||
229 | #include <QtWidgets/qgraphicswidget.h> | - | ||||||||||||||||||||||||||||||
230 | #include <QtGui/qmatrix.h> | - | ||||||||||||||||||||||||||||||
231 | #include <QtGui/qpaintengine.h> | - | ||||||||||||||||||||||||||||||
232 | #include <QtGui/qpainter.h> | - | ||||||||||||||||||||||||||||||
233 | #include <QtGui/qpixmapcache.h> | - | ||||||||||||||||||||||||||||||
234 | #include <QtGui/qpolygon.h> | - | ||||||||||||||||||||||||||||||
235 | #include <QtWidgets/qstyleoption.h> | - | ||||||||||||||||||||||||||||||
236 | #include <QtWidgets/qtooltip.h> | - | ||||||||||||||||||||||||||||||
237 | #include <QtGui/qtransform.h> | - | ||||||||||||||||||||||||||||||
238 | #include <QtGui/qinputmethod.h> | - | ||||||||||||||||||||||||||||||
239 | #include <QtWidgets/qgraphicseffect.h> | - | ||||||||||||||||||||||||||||||
240 | #include <private/qapplication_p.h> | - | ||||||||||||||||||||||||||||||
241 | #include <private/qobject_p.h> | - | ||||||||||||||||||||||||||||||
242 | #include <private/qgraphicseffect_p.h> | - | ||||||||||||||||||||||||||||||
243 | #include <private/qgesturemanager_p.h> | - | ||||||||||||||||||||||||||||||
244 | #include <private/qpathclipper_p.h> | - | ||||||||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||||||||
246 | // #define GESTURE_DEBUG | - | ||||||||||||||||||||||||||||||
247 | #ifndef GESTURE_DEBUG | - | ||||||||||||||||||||||||||||||
248 | # define DEBUG if (0) qDebug | - | ||||||||||||||||||||||||||||||
249 | #else | - | ||||||||||||||||||||||||||||||
250 | # define DEBUG qDebug | - | ||||||||||||||||||||||||||||||
251 | #endif | - | ||||||||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||||||||
253 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||
255 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||||||||||||||
256 | - | |||||||||||||||||||||||||||||||
257 | static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
258 | { | - | ||||||||||||||||||||||||||||||
259 | hover->setWidget(mouseEvent->widget()); | - | ||||||||||||||||||||||||||||||
260 | hover->setPos(mouseEvent->pos()); | - | ||||||||||||||||||||||||||||||
261 | hover->setScenePos(mouseEvent->scenePos()); | - | ||||||||||||||||||||||||||||||
262 | hover->setScreenPos(mouseEvent->screenPos()); | - | ||||||||||||||||||||||||||||||
263 | hover->setLastPos(mouseEvent->lastPos()); | - | ||||||||||||||||||||||||||||||
264 | hover->setLastScenePos(mouseEvent->lastScenePos()); | - | ||||||||||||||||||||||||||||||
265 | hover->setLastScreenPos(mouseEvent->lastScreenPos()); | - | ||||||||||||||||||||||||||||||
266 | hover->setModifiers(mouseEvent->modifiers()); | - | ||||||||||||||||||||||||||||||
267 | hover->setAccepted(mouseEvent->isAccepted()); | - | ||||||||||||||||||||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||||||||
270 | /*! | - | ||||||||||||||||||||||||||||||
271 | \internal | - | ||||||||||||||||||||||||||||||
272 | */ | - | ||||||||||||||||||||||||||||||
273 | QGraphicsScenePrivate::QGraphicsScenePrivate() | - | ||||||||||||||||||||||||||||||
274 | : indexMethod(QGraphicsScene::BspTreeIndex), | - | ||||||||||||||||||||||||||||||
275 | index(0), | - | ||||||||||||||||||||||||||||||
276 | lastItemCount(0), | - | ||||||||||||||||||||||||||||||
277 | hasSceneRect(false), | - | ||||||||||||||||||||||||||||||
278 | dirtyGrowingItemsBoundingRect(true), | - | ||||||||||||||||||||||||||||||
279 | updateAll(false), | - | ||||||||||||||||||||||||||||||
280 | calledEmitUpdated(false), | - | ||||||||||||||||||||||||||||||
281 | processDirtyItemsEmitted(false), | - | ||||||||||||||||||||||||||||||
282 | needSortTopLevelItems(true), | - | ||||||||||||||||||||||||||||||
283 | holesInTopLevelSiblingIndex(false), | - | ||||||||||||||||||||||||||||||
284 | topLevelSequentialOrdering(true), | - | ||||||||||||||||||||||||||||||
285 | scenePosDescendantsUpdatePending(false), | - | ||||||||||||||||||||||||||||||
286 | stickyFocus(false), | - | ||||||||||||||||||||||||||||||
287 | hasFocus(false), | - | ||||||||||||||||||||||||||||||
288 | lastMouseGrabberItemHasImplicitMouseGrab(false), | - | ||||||||||||||||||||||||||||||
289 | allItemsIgnoreHoverEvents(true), | - | ||||||||||||||||||||||||||||||
290 | allItemsUseDefaultCursor(true), | - | ||||||||||||||||||||||||||||||
291 | painterStateProtection(true), | - | ||||||||||||||||||||||||||||||
292 | sortCacheEnabled(false), | - | ||||||||||||||||||||||||||||||
293 | allItemsIgnoreTouchEvents(true), | - | ||||||||||||||||||||||||||||||
294 | minimumRenderSize(0.0), | - | ||||||||||||||||||||||||||||||
295 | selectionChanging(0), | - | ||||||||||||||||||||||||||||||
296 | rectAdjust(2), | - | ||||||||||||||||||||||||||||||
297 | focusItem(0), | - | ||||||||||||||||||||||||||||||
298 | lastFocusItem(0), | - | ||||||||||||||||||||||||||||||
299 | passiveFocusItem(0), | - | ||||||||||||||||||||||||||||||
300 | tabFocusFirst(0), | - | ||||||||||||||||||||||||||||||
301 | activePanel(0), | - | ||||||||||||||||||||||||||||||
302 | lastActivePanel(0), | - | ||||||||||||||||||||||||||||||
303 | activationRefCount(0), | - | ||||||||||||||||||||||||||||||
304 | childExplicitActivation(0), | - | ||||||||||||||||||||||||||||||
305 | lastMouseGrabberItem(0), | - | ||||||||||||||||||||||||||||||
306 | dragDropItem(0), | - | ||||||||||||||||||||||||||||||
307 | enterWidget(0), | - | ||||||||||||||||||||||||||||||
308 | lastDropAction(Qt::IgnoreAction), | - | ||||||||||||||||||||||||||||||
309 | style(0) | - | ||||||||||||||||||||||||||||||
310 | { | - | ||||||||||||||||||||||||||||||
311 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||||||||
313 | /*! | - | ||||||||||||||||||||||||||||||
314 | \internal | - | ||||||||||||||||||||||||||||||
315 | */ | - | ||||||||||||||||||||||||||||||
316 | void QGraphicsScenePrivate::init() | - | ||||||||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||||||||
318 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||||||||
320 | index = new QGraphicsSceneBspTreeIndex(q); | - | ||||||||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||||||||
322 | // Keep this index so we can check for connected slots later on. | - | ||||||||||||||||||||||||||||||
323 | changedSignalIndex = signalIndex("changed(QList<QRectF>)"); | - | ||||||||||||||||||||||||||||||
324 | processDirtyItemsIndex = q->metaObject()->indexOfSlot("_q_processDirtyItems()"); | - | ||||||||||||||||||||||||||||||
325 | polishItemsIndex = q->metaObject()->indexOfSlot("_q_polishItems()"); | - | ||||||||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||||||||
327 | qApp->d_func()->scene_list.append(q); | - | ||||||||||||||||||||||||||||||
328 | q->update(); | - | ||||||||||||||||||||||||||||||
329 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||||||||
331 | /*! | - | ||||||||||||||||||||||||||||||
332 | \internal | - | ||||||||||||||||||||||||||||||
333 | */ | - | ||||||||||||||||||||||||||||||
334 | QGraphicsScenePrivate *QGraphicsScenePrivate::get(QGraphicsScene *q) | - | ||||||||||||||||||||||||||||||
335 | { | - | ||||||||||||||||||||||||||||||
336 | return q->d_func(); never executed: return q->d_func(); | 0 | ||||||||||||||||||||||||||||||
337 | } | - | ||||||||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||||||||
339 | void QGraphicsScenePrivate::_q_emitUpdated() | - | ||||||||||||||||||||||||||||||
340 | { | - | ||||||||||||||||||||||||||||||
341 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
342 | calledEmitUpdated = false; | - | ||||||||||||||||||||||||||||||
343 | - | |||||||||||||||||||||||||||||||
344 | if (dirtyGrowingItemsBoundingRect) {
| 0 | ||||||||||||||||||||||||||||||
345 | if (!hasSceneRect) {
| 0 | ||||||||||||||||||||||||||||||
346 | const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; | - | ||||||||||||||||||||||||||||||
347 | growingItemsBoundingRect |= q->itemsBoundingRect(); | - | ||||||||||||||||||||||||||||||
348 | if (oldGrowingItemsBoundingRect != growingItemsBoundingRect)
| 0 | ||||||||||||||||||||||||||||||
349 | emit q->sceneRectChanged(growingItemsBoundingRect); never executed: q->sceneRectChanged(growingItemsBoundingRect); | 0 | ||||||||||||||||||||||||||||||
350 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
351 | dirtyGrowingItemsBoundingRect = false; | - | ||||||||||||||||||||||||||||||
352 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||||||||
354 | // Ensure all views are connected if anything is connected. This disables | - | ||||||||||||||||||||||||||||||
355 | // the optimization that items send updates directly to the views, but it | - | ||||||||||||||||||||||||||||||
356 | // needs to happen in order to keep compatibility with the behavior from | - | ||||||||||||||||||||||||||||||
357 | // Qt 4.4 and backward. | - | ||||||||||||||||||||||||||||||
358 | if (isSignalConnected(changedSignalIndex)) {
| 0 | ||||||||||||||||||||||||||||||
359 | for (int i = 0; i < views.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
360 | QGraphicsView *view = views.at(i); | - | ||||||||||||||||||||||||||||||
361 | if (!view->d_func()->connectedToScene) {
| 0 | ||||||||||||||||||||||||||||||
362 | view->d_func()->connectedToScene = true; | - | ||||||||||||||||||||||||||||||
363 | q->connect(q, SIGNAL(changed(QList<QRectF>)), | - | ||||||||||||||||||||||||||||||
364 | views.at(i), SLOT(updateScene(QList<QRectF>))); | - | ||||||||||||||||||||||||||||||
365 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
366 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
367 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
368 | if (views.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
369 | updateAll = false; | - | ||||||||||||||||||||||||||||||
370 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
371 | } | - | ||||||||||||||||||||||||||||||
372 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
373 | views.at(i)->d_func()->processPendingUpdates(); never executed: views.at(i)->d_func()->processPendingUpdates(); | 0 | ||||||||||||||||||||||||||||||
374 | // It's important that we update all views before we dispatch, hence two for-loops. | - | ||||||||||||||||||||||||||||||
375 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
376 | views.at(i)->d_func()->dispatchPendingUpdateRequests(); never executed: views.at(i)->d_func()->dispatchPendingUpdateRequests(); | 0 | ||||||||||||||||||||||||||||||
377 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
378 | } | - | ||||||||||||||||||||||||||||||
379 | - | |||||||||||||||||||||||||||||||
380 | // Notify the changes to anybody interested. | - | ||||||||||||||||||||||||||||||
381 | QList<QRectF> oldUpdatedRects; | - | ||||||||||||||||||||||||||||||
382 | oldUpdatedRects = updateAll ? (QList<QRectF>() << q->sceneRect()) : updatedRects;
| 0 | ||||||||||||||||||||||||||||||
383 | updateAll = false; | - | ||||||||||||||||||||||||||||||
384 | updatedRects.clear(); | - | ||||||||||||||||||||||||||||||
385 | emit q->changed(oldUpdatedRects); | - | ||||||||||||||||||||||||||||||
386 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||||||||
388 | /*! | - | ||||||||||||||||||||||||||||||
389 | \internal | - | ||||||||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||||||||
391 | ### This function is almost identical to QGraphicsItemPrivate::addChild(). | - | ||||||||||||||||||||||||||||||
392 | */ | - | ||||||||||||||||||||||||||||||
393 | void QGraphicsScenePrivate::registerTopLevelItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
394 | { | - | ||||||||||||||||||||||||||||||
395 | ensureSequentialTopLevelSiblingIndexes(); | - | ||||||||||||||||||||||||||||||
396 | needSortTopLevelItems = true; // ### maybe false | - | ||||||||||||||||||||||||||||||
397 | item->d_ptr->siblingIndex = topLevelItems.size(); | - | ||||||||||||||||||||||||||||||
398 | topLevelItems.append(item); | - | ||||||||||||||||||||||||||||||
399 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||||||||
401 | /*! | - | ||||||||||||||||||||||||||||||
402 | \internal | - | ||||||||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||||||||
404 | ### This function is almost identical to QGraphicsItemPrivate::removeChild(). | - | ||||||||||||||||||||||||||||||
405 | */ | - | ||||||||||||||||||||||||||||||
406 | void QGraphicsScenePrivate::unregisterTopLevelItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
407 | { | - | ||||||||||||||||||||||||||||||
408 | if (!holesInTopLevelSiblingIndex)
| 0 | ||||||||||||||||||||||||||||||
409 | holesInTopLevelSiblingIndex = item->d_ptr->siblingIndex != topLevelItems.size() - 1; never executed: holesInTopLevelSiblingIndex = item->d_ptr->siblingIndex != topLevelItems.size() - 1; | 0 | ||||||||||||||||||||||||||||||
410 | if (topLevelSequentialOrdering && !holesInTopLevelSiblingIndex)
| 0 | ||||||||||||||||||||||||||||||
411 | topLevelItems.removeAt(item->d_ptr->siblingIndex); never executed: topLevelItems.removeAt(item->d_ptr->siblingIndex); | 0 | ||||||||||||||||||||||||||||||
412 | else | - | ||||||||||||||||||||||||||||||
413 | topLevelItems.removeOne(item); never executed: topLevelItems.removeOne(item); | 0 | ||||||||||||||||||||||||||||||
414 | // NB! Do not use topLevelItems.removeAt(item->d_ptr->siblingIndex) because | - | ||||||||||||||||||||||||||||||
415 | // the item is not guaranteed to be at the index after the list is sorted | - | ||||||||||||||||||||||||||||||
416 | // (see ensureSortedTopLevelItems()). | - | ||||||||||||||||||||||||||||||
417 | item->d_ptr->siblingIndex = -1; | - | ||||||||||||||||||||||||||||||
418 | if (topLevelSequentialOrdering)
| 0 | ||||||||||||||||||||||||||||||
419 | topLevelSequentialOrdering = !holesInTopLevelSiblingIndex; never executed: topLevelSequentialOrdering = !holesInTopLevelSiblingIndex; | 0 | ||||||||||||||||||||||||||||||
420 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||||||||
422 | /*! | - | ||||||||||||||||||||||||||||||
423 | \internal | - | ||||||||||||||||||||||||||||||
424 | */ | - | ||||||||||||||||||||||||||||||
425 | void QGraphicsScenePrivate::_q_polishItems() | - | ||||||||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||||||||
427 | if (unpolishedItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
428 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
429 | - | |||||||||||||||||||||||||||||||
430 | const QVariant booleanTrueVariant(true); | - | ||||||||||||||||||||||||||||||
431 | QGraphicsItem *item = 0; | - | ||||||||||||||||||||||||||||||
432 | QGraphicsItemPrivate *itemd = 0; | - | ||||||||||||||||||||||||||||||
433 | const int oldUnpolishedCount = unpolishedItems.count(); | - | ||||||||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||||||||
435 | for (int i = 0; i < oldUnpolishedCount; ++i) {
| 0 | ||||||||||||||||||||||||||||||
436 | item = unpolishedItems.at(i); | - | ||||||||||||||||||||||||||||||
437 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
438 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
439 | itemd = item->d_ptr.data(); | - | ||||||||||||||||||||||||||||||
440 | itemd->pendingPolish = false; | - | ||||||||||||||||||||||||||||||
441 | if (!itemd->explicitlyHidden) {
| 0 | ||||||||||||||||||||||||||||||
442 | item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); | - | ||||||||||||||||||||||||||||||
443 | item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); | - | ||||||||||||||||||||||||||||||
444 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
445 | if (itemd->isWidget) {
| 0 | ||||||||||||||||||||||||||||||
446 | QEvent event(QEvent::Polish); | - | ||||||||||||||||||||||||||||||
447 | QApplication::sendEvent((QGraphicsWidget *)item, &event); | - | ||||||||||||||||||||||||||||||
448 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
450 | - | |||||||||||||||||||||||||||||||
451 | if (unpolishedItems.count() == oldUnpolishedCount) {
| 0 | ||||||||||||||||||||||||||||||
452 | // No new items were added to the vector. | - | ||||||||||||||||||||||||||||||
453 | unpolishedItems.clear(); | - | ||||||||||||||||||||||||||||||
454 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
455 | // New items were appended; keep them and remove the old ones. | - | ||||||||||||||||||||||||||||||
456 | unpolishedItems.remove(0, oldUnpolishedCount); | - | ||||||||||||||||||||||||||||||
457 | unpolishedItems.squeeze(); | - | ||||||||||||||||||||||||||||||
458 | QMetaObject::invokeMethod(q_ptr, "_q_polishItems", Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
459 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
460 | } | - | ||||||||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||||||||
462 | void QGraphicsScenePrivate::_q_processDirtyItems() | - | ||||||||||||||||||||||||||||||
463 | { | - | ||||||||||||||||||||||||||||||
464 | processDirtyItemsEmitted = false; | - | ||||||||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||||||||
466 | if (updateAll) {
| 0 | ||||||||||||||||||||||||||||||
467 | Q_ASSERT(calledEmitUpdated); | - | ||||||||||||||||||||||||||||||
468 | // No need for further processing (except resetting the dirty states). | - | ||||||||||||||||||||||||||||||
469 | // The growingItemsBoundingRect is updated in _q_emitUpdated. | - | ||||||||||||||||||||||||||||||
470 | for (int i = 0; i < topLevelItems.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
471 | resetDirtyItem(topLevelItems.at(i), /*recursive=*/true); never executed: resetDirtyItem(topLevelItems.at(i), true); | 0 | ||||||||||||||||||||||||||||||
472 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
473 | } | - | ||||||||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||||||||
475 | const bool wasPendingSceneUpdate = calledEmitUpdated; | - | ||||||||||||||||||||||||||||||
476 | const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; | - | ||||||||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||||||||
478 | // Process items recursively. | - | ||||||||||||||||||||||||||||||
479 | for (int i = 0; i < topLevelItems.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
480 | processDirtyItemsRecursive(topLevelItems.at(i)); never executed: processDirtyItemsRecursive(topLevelItems.at(i)); | 0 | ||||||||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||||||||
482 | dirtyGrowingItemsBoundingRect = false; | - | ||||||||||||||||||||||||||||||
483 | if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
| 0 | ||||||||||||||||||||||||||||||
484 | emit q_func()->sceneRectChanged(growingItemsBoundingRect); never executed: q_func()->sceneRectChanged(growingItemsBoundingRect); | 0 | ||||||||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||||||||
486 | if (wasPendingSceneUpdate)
| 0 | ||||||||||||||||||||||||||||||
487 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||||||||
489 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
490 | views.at(i)->d_func()->processPendingUpdates(); never executed: views.at(i)->d_func()->processPendingUpdates(); | 0 | ||||||||||||||||||||||||||||||
491 | - | |||||||||||||||||||||||||||||||
492 | if (calledEmitUpdated) {
| 0 | ||||||||||||||||||||||||||||||
493 | // We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive | - | ||||||||||||||||||||||||||||||
494 | // and we cannot wait for the control to reach the eventloop before the | - | ||||||||||||||||||||||||||||||
495 | // changed signal is emitted, so we emit it now. | - | ||||||||||||||||||||||||||||||
496 | _q_emitUpdated(); | - | ||||||||||||||||||||||||||||||
497 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||||||||
499 | // Immediately dispatch all pending update requests on the views. | - | ||||||||||||||||||||||||||||||
500 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
501 | views.at(i)->d_func()->dispatchPendingUpdateRequests(); never executed: views.at(i)->d_func()->dispatchPendingUpdateRequests(); | 0 | ||||||||||||||||||||||||||||||
502 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||||||||
504 | /*! | - | ||||||||||||||||||||||||||||||
505 | \internal | - | ||||||||||||||||||||||||||||||
506 | */ | - | ||||||||||||||||||||||||||||||
507 | void QGraphicsScenePrivate::setScenePosItemEnabled(QGraphicsItem *item, bool enabled) | - | ||||||||||||||||||||||||||||||
508 | { | - | ||||||||||||||||||||||||||||||
509 | QGraphicsItem *p = item->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
510 | while (p) {
| 0 | ||||||||||||||||||||||||||||||
511 | p->d_ptr->scenePosDescendants = enabled; | - | ||||||||||||||||||||||||||||||
512 | p = p->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
513 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
514 | if (!enabled && !scenePosDescendantsUpdatePending) {
| 0 | ||||||||||||||||||||||||||||||
515 | scenePosDescendantsUpdatePending = true; | - | ||||||||||||||||||||||||||||||
516 | QMetaObject::invokeMethod(q_func(), "_q_updateScenePosDescendants", Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
517 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
518 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
519 | - | |||||||||||||||||||||||||||||||
520 | /*! | - | ||||||||||||||||||||||||||||||
521 | \internal | - | ||||||||||||||||||||||||||||||
522 | */ | - | ||||||||||||||||||||||||||||||
523 | void QGraphicsScenePrivate::registerScenePosItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
524 | { | - | ||||||||||||||||||||||||||||||
525 | scenePosItems.insert(item); | - | ||||||||||||||||||||||||||||||
526 | setScenePosItemEnabled(item, true); | - | ||||||||||||||||||||||||||||||
527 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
528 | - | |||||||||||||||||||||||||||||||
529 | /*! | - | ||||||||||||||||||||||||||||||
530 | \internal | - | ||||||||||||||||||||||||||||||
531 | */ | - | ||||||||||||||||||||||||||||||
532 | void QGraphicsScenePrivate::unregisterScenePosItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
533 | { | - | ||||||||||||||||||||||||||||||
534 | scenePosItems.remove(item); | - | ||||||||||||||||||||||||||||||
535 | setScenePosItemEnabled(item, false); | - | ||||||||||||||||||||||||||||||
536 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||||||||
538 | /*! | - | ||||||||||||||||||||||||||||||
539 | \internal | - | ||||||||||||||||||||||||||||||
540 | */ | - | ||||||||||||||||||||||||||||||
541 | void QGraphicsScenePrivate::_q_updateScenePosDescendants() | - | ||||||||||||||||||||||||||||||
542 | { | - | ||||||||||||||||||||||||||||||
543 | foreach (QGraphicsItem *item, scenePosItems) { | - | ||||||||||||||||||||||||||||||
544 | QGraphicsItem *p = item->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
545 | while (p) {
| 0 | ||||||||||||||||||||||||||||||
546 | p->d_ptr->scenePosDescendants = 1; | - | ||||||||||||||||||||||||||||||
547 | p = p->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
548 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
549 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
550 | scenePosDescendantsUpdatePending = false; | - | ||||||||||||||||||||||||||||||
551 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||||||||
553 | /*! | - | ||||||||||||||||||||||||||||||
554 | \internal | - | ||||||||||||||||||||||||||||||
555 | - | |||||||||||||||||||||||||||||||
556 | Schedules an item for removal. This function leaves some stale indexes | - | ||||||||||||||||||||||||||||||
557 | around in the BSP tree if called from the item's destructor; these will | - | ||||||||||||||||||||||||||||||
558 | be cleaned up the next time someone triggers purgeRemovedItems(). | - | ||||||||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||||||||
560 | Note: This function might get called from QGraphicsItem's destructor. \a item is | - | ||||||||||||||||||||||||||||||
561 | being destroyed, so we cannot call any pure virtual functions on it (such | - | ||||||||||||||||||||||||||||||
562 | as boundingRect()). Also, it is unnecessary to update the item's own state | - | ||||||||||||||||||||||||||||||
563 | in any way. | - | ||||||||||||||||||||||||||||||
564 | */ | - | ||||||||||||||||||||||||||||||
565 | void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
566 | { | - | ||||||||||||||||||||||||||||||
567 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
568 | - | |||||||||||||||||||||||||||||||
569 | // Clear focus on the item to remove any reference in the focusWidget chain. | - | ||||||||||||||||||||||||||||||
570 | item->clearFocus(); | - | ||||||||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||||||||
572 | markDirty(item, QRectF(), /*invalidateChildren=*/false, /*force=*/false, | - | ||||||||||||||||||||||||||||||
573 | /*ignoreOpacity=*/false, /*removingItemFromScene=*/true); | - | ||||||||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||||||||
575 | if (item->d_ptr->inDestructor) {
| 0 | ||||||||||||||||||||||||||||||
576 | // The item is actually in its destructor, we call the special method in the index. | - | ||||||||||||||||||||||||||||||
577 | index->deleteItem(item); | - | ||||||||||||||||||||||||||||||
578 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
579 | // Can potentially call item->boundingRect() (virtual function), that's why | - | ||||||||||||||||||||||||||||||
580 | // we only can call this function if the item is not in its destructor. | - | ||||||||||||||||||||||||||||||
581 | index->removeItem(item); | - | ||||||||||||||||||||||||||||||
582 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||
584 | item->d_ptr->clearSubFocus(); | - | ||||||||||||||||||||||||||||||
585 | - | |||||||||||||||||||||||||||||||
586 | if (item->flags() & QGraphicsItem::ItemSendsScenePositionChanges)
| 0 | ||||||||||||||||||||||||||||||
587 | unregisterScenePosItem(item); never executed: unregisterScenePosItem(item); | 0 | ||||||||||||||||||||||||||||||
588 | - | |||||||||||||||||||||||||||||||
589 | QGraphicsScene *oldScene = item->d_func()->scene; | - | ||||||||||||||||||||||||||||||
590 | item->d_func()->scene = 0; | - | ||||||||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||||||||
592 | //We need to remove all children first because they might use their parent | - | ||||||||||||||||||||||||||||||
593 | //attributes (e.g. sceneTransform). | - | ||||||||||||||||||||||||||||||
594 | if (!item->d_ptr->inDestructor) {
| 0 | ||||||||||||||||||||||||||||||
595 | // Remove all children recursively | - | ||||||||||||||||||||||||||||||
596 | for (int i = 0; i < item->d_ptr->children.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
597 | q->removeItem(item->d_ptr->children.at(i)); never executed: q->removeItem(item->d_ptr->children.at(i)); | 0 | ||||||||||||||||||||||||||||||
598 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
599 | - | |||||||||||||||||||||||||||||||
600 | if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
601 | QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||||||||||||||
602 | widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0); | - | ||||||||||||||||||||||||||||||
603 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||||||||
605 | // Unregister focus proxy. | - | ||||||||||||||||||||||||||||||
606 | item->d_ptr->resetFocusProxy(); | - | ||||||||||||||||||||||||||||||
607 | - | |||||||||||||||||||||||||||||||
608 | // Remove from parent, or unregister from toplevels. | - | ||||||||||||||||||||||||||||||
609 | if (QGraphicsItem *parentItem = item->parentItem()) {
| 0 | ||||||||||||||||||||||||||||||
610 | if (parentItem->scene()) {
| 0 | ||||||||||||||||||||||||||||||
611 | Q_ASSERT_X(parentItem->scene() == q, "QGraphicsScene::removeItem", | - | ||||||||||||||||||||||||||||||
612 | "Parent item's scene is different from this item's scene"); | - | ||||||||||||||||||||||||||||||
613 | item->setParentItem(0); | - | ||||||||||||||||||||||||||||||
614 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
615 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
616 | unregisterTopLevelItem(item); | - | ||||||||||||||||||||||||||||||
617 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||||||||
619 | // Reset the mouse grabber and focus item data. | - | ||||||||||||||||||||||||||||||
620 | if (item == focusItem)
| 0 | ||||||||||||||||||||||||||||||
621 | focusItem = 0; never executed: focusItem = 0; | 0 | ||||||||||||||||||||||||||||||
622 | if (item == lastFocusItem)
| 0 | ||||||||||||||||||||||||||||||
623 | lastFocusItem = 0; never executed: lastFocusItem = 0; | 0 | ||||||||||||||||||||||||||||||
624 | if (item == passiveFocusItem)
| 0 | ||||||||||||||||||||||||||||||
625 | passiveFocusItem = 0; never executed: passiveFocusItem = 0; | 0 | ||||||||||||||||||||||||||||||
626 | if (item == activePanel) {
| 0 | ||||||||||||||||||||||||||||||
627 | // ### deactivate... | - | ||||||||||||||||||||||||||||||
628 | activePanel = 0; | - | ||||||||||||||||||||||||||||||
629 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
630 | if (item == lastActivePanel)
| 0 | ||||||||||||||||||||||||||||||
631 | lastActivePanel = 0; never executed: lastActivePanel = 0; | 0 | ||||||||||||||||||||||||||||||
632 | - | |||||||||||||||||||||||||||||||
633 | // Change tabFocusFirst to the next widget in focus chain if removing the current one. | - | ||||||||||||||||||||||||||||||
634 | if (item == tabFocusFirst) {
| 0 | ||||||||||||||||||||||||||||||
635 | QGraphicsWidgetPrivate *wd = tabFocusFirst->d_func(); | - | ||||||||||||||||||||||||||||||
636 | if (wd->focusNext && wd->focusNext != tabFocusFirst && wd->focusNext->scene() == q)
| 0 | ||||||||||||||||||||||||||||||
637 | tabFocusFirst = wd->focusNext; never executed: tabFocusFirst = wd->focusNext; | 0 | ||||||||||||||||||||||||||||||
638 | else | - | ||||||||||||||||||||||||||||||
639 | tabFocusFirst = 0; never executed: tabFocusFirst = 0; | 0 | ||||||||||||||||||||||||||||||
640 | } | - | ||||||||||||||||||||||||||||||
641 | - | |||||||||||||||||||||||||||||||
642 | // Cancel active touches | - | ||||||||||||||||||||||||||||||
643 | { | - | ||||||||||||||||||||||||||||||
644 | QMap<int, QGraphicsItem *>::iterator it = itemForTouchPointId.begin(); | - | ||||||||||||||||||||||||||||||
645 | while (it != itemForTouchPointId.end()) {
| 0 | ||||||||||||||||||||||||||||||
646 | if (it.value() == item) {
| 0 | ||||||||||||||||||||||||||||||
647 | sceneCurrentTouchPoints.remove(it.key()); | - | ||||||||||||||||||||||||||||||
648 | it = itemForTouchPointId.erase(it); | - | ||||||||||||||||||||||||||||||
649 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
650 | ++it; | - | ||||||||||||||||||||||||||||||
651 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
652 | } | - | ||||||||||||||||||||||||||||||
653 | } | - | ||||||||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||||||||
655 | // Disable selectionChanged() for individual items | - | ||||||||||||||||||||||||||||||
656 | ++selectionChanging; | - | ||||||||||||||||||||||||||||||
657 | int oldSelectedItemsSize = selectedItems.size(); | - | ||||||||||||||||||||||||||||||
658 | - | |||||||||||||||||||||||||||||||
659 | // Update selected & hovered item bookkeeping | - | ||||||||||||||||||||||||||||||
660 | selectedItems.remove(item); | - | ||||||||||||||||||||||||||||||
661 | hoverItems.removeAll(item); | - | ||||||||||||||||||||||||||||||
662 | cachedItemsUnderMouse.removeAll(item); | - | ||||||||||||||||||||||||||||||
663 | if (item->d_ptr->pendingPolish) {
| 0 | ||||||||||||||||||||||||||||||
664 | const int unpolishedIndex = unpolishedItems.indexOf(item); | - | ||||||||||||||||||||||||||||||
665 | if (unpolishedIndex != -1)
| 0 | ||||||||||||||||||||||||||||||
666 | unpolishedItems[unpolishedIndex] = 0; never executed: unpolishedItems[unpolishedIndex] = 0; | 0 | ||||||||||||||||||||||||||||||
667 | item->d_ptr->pendingPolish = false; | - | ||||||||||||||||||||||||||||||
668 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
669 | resetDirtyItem(item); | - | ||||||||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||||||||
671 | //We remove all references of item from the sceneEventFilter arrays | - | ||||||||||||||||||||||||||||||
672 | QMultiMap<QGraphicsItem*, QGraphicsItem*>::iterator iterator = sceneEventFilters.begin(); | - | ||||||||||||||||||||||||||||||
673 | while (iterator != sceneEventFilters.end()) {
| 0 | ||||||||||||||||||||||||||||||
674 | if (iterator.value() == item || iterator.key() == item)
| 0 | ||||||||||||||||||||||||||||||
675 | iterator = sceneEventFilters.erase(iterator); never executed: iterator = sceneEventFilters.erase(iterator); | 0 | ||||||||||||||||||||||||||||||
676 | else | - | ||||||||||||||||||||||||||||||
677 | ++iterator; never executed: ++iterator; | 0 | ||||||||||||||||||||||||||||||
678 | } | - | ||||||||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||||||||
680 | if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
| 0 | ||||||||||||||||||||||||||||||
681 | leaveModal(item); never executed: leaveModal(item); | 0 | ||||||||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||||||||
683 | // Reset the mouse grabber and focus item data. | - | ||||||||||||||||||||||||||||||
684 | if (mouseGrabberItems.contains(item))
| 0 | ||||||||||||||||||||||||||||||
685 | ungrabMouse(item, /* item is dying */ item->d_ptr->inDestructor); never executed: ungrabMouse(item, item->d_ptr->inDestructor); | 0 | ||||||||||||||||||||||||||||||
686 | - | |||||||||||||||||||||||||||||||
687 | // Reset the keyboard grabber | - | ||||||||||||||||||||||||||||||
688 | if (keyboardGrabberItems.contains(item))
| 0 | ||||||||||||||||||||||||||||||
689 | ungrabKeyboard(item, /* item is dying */ item->d_ptr->inDestructor); never executed: ungrabKeyboard(item, item->d_ptr->inDestructor); | 0 | ||||||||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||||||||
691 | // Reset the last mouse grabber item | - | ||||||||||||||||||||||||||||||
692 | if (item == lastMouseGrabberItem)
| 0 | ||||||||||||||||||||||||||||||
693 | lastMouseGrabberItem = 0; never executed: lastMouseGrabberItem = 0; | 0 | ||||||||||||||||||||||||||||||
694 | - | |||||||||||||||||||||||||||||||
695 | // Reset the current drop item | - | ||||||||||||||||||||||||||||||
696 | if (item == dragDropItem)
| 0 | ||||||||||||||||||||||||||||||
697 | dragDropItem = 0; never executed: dragDropItem = 0; | 0 | ||||||||||||||||||||||||||||||
698 | - | |||||||||||||||||||||||||||||||
699 | // Reenable selectionChanged() for individual items | - | ||||||||||||||||||||||||||||||
700 | --selectionChanging; | - | ||||||||||||||||||||||||||||||
701 | if (!selectionChanging && selectedItems.size() != oldSelectedItemsSize)
| 0 | ||||||||||||||||||||||||||||||
702 | emit q->selectionChanged(); never executed: q->selectionChanged(); | 0 | ||||||||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||||||||
704 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
705 | QHash<QGesture *, QGraphicsObject *>::iterator it; | - | ||||||||||||||||||||||||||||||
706 | for (it = gestureTargets.begin(); it != gestureTargets.end();) {
| 0 | ||||||||||||||||||||||||||||||
707 | if (it.value() == item)
| 0 | ||||||||||||||||||||||||||||||
708 | it = gestureTargets.erase(it); never executed: it = gestureTargets.erase(it); | 0 | ||||||||||||||||||||||||||||||
709 | else | - | ||||||||||||||||||||||||||||||
710 | ++it; never executed: ++it; | 0 | ||||||||||||||||||||||||||||||
711 | } | - | ||||||||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||||||||
713 | if (QGraphicsObject *dummy = item->toGraphicsObject()) {
| 0 | ||||||||||||||||||||||||||||||
714 | cachedTargetItems.removeOne(dummy); | - | ||||||||||||||||||||||||||||||
715 | cachedItemGestures.remove(dummy); | - | ||||||||||||||||||||||||||||||
716 | cachedAlreadyDeliveredGestures.remove(dummy); | - | ||||||||||||||||||||||||||||||
717 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||||||||
719 | foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys()) | - | ||||||||||||||||||||||||||||||
720 | ungrabGesture(item, gesture); never executed: ungrabGesture(item, gesture); | 0 | ||||||||||||||||||||||||||||||
721 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
722 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||||||||
724 | /*! | - | ||||||||||||||||||||||||||||||
725 | \internal | - | ||||||||||||||||||||||||||||||
726 | */ | - | ||||||||||||||||||||||||||||||
727 | void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent) | - | ||||||||||||||||||||||||||||||
728 | { | - | ||||||||||||||||||||||||||||||
729 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
730 | if (item && item->scene() != q) {
| 0 | ||||||||||||||||||||||||||||||
731 | qWarning("QGraphicsScene::setActivePanel: item %p must be part of this scene", | - | ||||||||||||||||||||||||||||||
732 | item); | - | ||||||||||||||||||||||||||||||
733 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
734 | } | - | ||||||||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||||||||
736 | // Ensure the scene has focus when we change panel activation. | - | ||||||||||||||||||||||||||||||
737 | q->setFocus(Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||||||||||||||
738 | - | |||||||||||||||||||||||||||||||
739 | // Find the item's panel. | - | ||||||||||||||||||||||||||||||
740 | QGraphicsItem *panel = item ? item->panel() : 0;
| 0 | ||||||||||||||||||||||||||||||
741 | lastActivePanel = panel ? activePanel : 0;
| 0 | ||||||||||||||||||||||||||||||
742 | if (panel == activePanel || (!q->isActive() && !duringActivationEvent))
| 0 | ||||||||||||||||||||||||||||||
743 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||||||||
745 | QGraphicsItem *oldFocusItem = focusItem; | - | ||||||||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||||||||
747 | // Deactivate the last active panel. | - | ||||||||||||||||||||||||||||||
748 | if (activePanel) {
| 0 | ||||||||||||||||||||||||||||||
749 | if (QGraphicsItem *fi = activePanel->focusItem()) {
| 0 | ||||||||||||||||||||||||||||||
750 | // Remove focus from the current focus item. | - | ||||||||||||||||||||||||||||||
751 | if (fi == q->focusItem())
| 0 | ||||||||||||||||||||||||||||||
752 | setFocusItemHelper(0, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); never executed: setFocusItemHelper(0, Qt::ActiveWindowFocusReason, false); | 0 | ||||||||||||||||||||||||||||||
753 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||||||||
755 | QEvent event(QEvent::WindowDeactivate); | - | ||||||||||||||||||||||||||||||
756 | q->sendEvent(activePanel, &event); | - | ||||||||||||||||||||||||||||||
757 | } else if (panel && !duringActivationEvent) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
758 | // Deactivate the scene if changing activation to a panel. | - | ||||||||||||||||||||||||||||||
759 | QEvent event(QEvent::WindowDeactivate); | - | ||||||||||||||||||||||||||||||
760 | foreach (QGraphicsItem *item, q->items()) { | - | ||||||||||||||||||||||||||||||
761 | if (item->isVisible() && !item->isPanel() && !item->parentItem())
| 0 | ||||||||||||||||||||||||||||||
762 | q->sendEvent(item, &event); never executed: q->sendEvent(item, &event); | 0 | ||||||||||||||||||||||||||||||
763 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
764 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||||||||
766 | // Update activate state. | - | ||||||||||||||||||||||||||||||
767 | activePanel = panel; | - | ||||||||||||||||||||||||||||||
768 | QEvent event(QEvent::ActivationChange); | - | ||||||||||||||||||||||||||||||
769 | QApplication::sendEvent(q, &event); | - | ||||||||||||||||||||||||||||||
770 | - | |||||||||||||||||||||||||||||||
771 | // Activate | - | ||||||||||||||||||||||||||||||
772 | if (panel) {
| 0 | ||||||||||||||||||||||||||||||
773 | QEvent event(QEvent::WindowActivate); | - | ||||||||||||||||||||||||||||||
774 | q->sendEvent(panel, &event); | - | ||||||||||||||||||||||||||||||
775 | - | |||||||||||||||||||||||||||||||
776 | // Set focus on the panel's focus item, or itself if it's | - | ||||||||||||||||||||||||||||||
777 | // focusable, or on the first focusable item in the panel's | - | ||||||||||||||||||||||||||||||
778 | // focus chain as a last resort. | - | ||||||||||||||||||||||||||||||
779 | if (QGraphicsItem *focusItem = panel->focusItem()) {
| 0 | ||||||||||||||||||||||||||||||
780 | setFocusItemHelper(focusItem, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); | - | ||||||||||||||||||||||||||||||
781 | } else if (panel->flags() & QGraphicsItem::ItemIsFocusable) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
782 | setFocusItemHelper(panel, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); | - | ||||||||||||||||||||||||||||||
783 | } else if (panel->isWidget()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
784 | QGraphicsWidget *fw = static_cast<QGraphicsWidget *>(panel)->d_func()->focusNext; | - | ||||||||||||||||||||||||||||||
785 | do { | - | ||||||||||||||||||||||||||||||
786 | if (fw->focusPolicy() & Qt::TabFocus) {
| 0 | ||||||||||||||||||||||||||||||
787 | setFocusItemHelper(fw, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); | - | ||||||||||||||||||||||||||||||
788 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
789 | } | - | ||||||||||||||||||||||||||||||
790 | fw = fw->d_func()->focusNext; | - | ||||||||||||||||||||||||||||||
791 | } while (fw != panel); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
792 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
793 | } else if (q->isActive()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
794 | // Activate the scene | - | ||||||||||||||||||||||||||||||
795 | QEvent event(QEvent::WindowActivate); | - | ||||||||||||||||||||||||||||||
796 | foreach (QGraphicsItem *item, q->items()) { | - | ||||||||||||||||||||||||||||||
797 | if (item->isVisible() && !item->isPanel() && !item->parentItem())
| 0 | ||||||||||||||||||||||||||||||
798 | q->sendEvent(item, &event); never executed: q->sendEvent(item, &event); | 0 | ||||||||||||||||||||||||||||||
799 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
800 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
801 | - | |||||||||||||||||||||||||||||||
802 | emit q->focusItemChanged(focusItem, oldFocusItem, Qt::ActiveWindowFocusReason); | - | ||||||||||||||||||||||||||||||
803 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||||||||
805 | /*! | - | ||||||||||||||||||||||||||||||
806 | \internal | - | ||||||||||||||||||||||||||||||
807 | - | |||||||||||||||||||||||||||||||
808 | \a emitFocusChanged needs to be false when focus passes from one | - | ||||||||||||||||||||||||||||||
809 | item to another through setActivePanel(); i.e. when activation | - | ||||||||||||||||||||||||||||||
810 | passes from one panel to another, to avoid getting two focusChanged() | - | ||||||||||||||||||||||||||||||
811 | emissions; one focusChanged(0, lastFocus), then one | - | ||||||||||||||||||||||||||||||
812 | focusChanged(newFocus, 0). Instead setActivePanel() emits the signal | - | ||||||||||||||||||||||||||||||
813 | once itself: focusChanged(newFocus, oldFocus). | - | ||||||||||||||||||||||||||||||
814 | */ | - | ||||||||||||||||||||||||||||||
815 | void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, | - | ||||||||||||||||||||||||||||||
816 | Qt::FocusReason focusReason, | - | ||||||||||||||||||||||||||||||
817 | bool emitFocusChanged) | - | ||||||||||||||||||||||||||||||
818 | { | - | ||||||||||||||||||||||||||||||
819 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
820 | if (item == focusItem)
| 0 | ||||||||||||||||||||||||||||||
821 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||||||||
823 | // Clear focus if asked to set focus on something that can't | - | ||||||||||||||||||||||||||||||
824 | // accept input focus. | - | ||||||||||||||||||||||||||||||
825 | if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
| 0 | ||||||||||||||||||||||||||||||
826 | || !item->isVisible() || !item->isEnabled())) {
| 0 | ||||||||||||||||||||||||||||||
827 | item = 0; | - | ||||||||||||||||||||||||||||||
828 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
829 | - | |||||||||||||||||||||||||||||||
830 | // Set focus on the scene if an item requests focus. | - | ||||||||||||||||||||||||||||||
831 | if (item) {
| 0 | ||||||||||||||||||||||||||||||
832 | q->setFocus(focusReason); | - | ||||||||||||||||||||||||||||||
833 | if (item == focusItem) {
| 0 | ||||||||||||||||||||||||||||||
834 | if (emitFocusChanged)
| 0 | ||||||||||||||||||||||||||||||
835 | emit q->focusItemChanged(focusItem, (QGraphicsItem *)0, focusReason); never executed: q->focusItemChanged(focusItem, (QGraphicsItem *)0, focusReason); | 0 | ||||||||||||||||||||||||||||||
836 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
837 | } | - | ||||||||||||||||||||||||||||||
838 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||||||||
840 | QGraphicsItem *oldFocusItem = focusItem; | - | ||||||||||||||||||||||||||||||
841 | if (focusItem) {
| 0 | ||||||||||||||||||||||||||||||
842 | lastFocusItem = focusItem; | - | ||||||||||||||||||||||||||||||
843 | - | |||||||||||||||||||||||||||||||
844 | #ifndef QT_NO_IM | - | ||||||||||||||||||||||||||||||
845 | if (lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod) {
| 0 | ||||||||||||||||||||||||||||||
846 | // Close any external input method panel. This happens | - | ||||||||||||||||||||||||||||||
847 | // automatically by removing WA_InputMethodEnabled on | - | ||||||||||||||||||||||||||||||
848 | // the views, but if we are changing focus, we have to | - | ||||||||||||||||||||||||||||||
849 | // do it ourselves. | - | ||||||||||||||||||||||||||||||
850 | if (qApp)
| 0 | ||||||||||||||||||||||||||||||
851 | QGuiApplication::inputMethod()->commit(); never executed: QGuiApplication::inputMethod()->commit(); | 0 | ||||||||||||||||||||||||||||||
852 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
853 | #endif //QT_NO_IM | - | ||||||||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||||||||
855 | focusItem = 0; | - | ||||||||||||||||||||||||||||||
856 | QFocusEvent event(QEvent::FocusOut, focusReason); | - | ||||||||||||||||||||||||||||||
857 | sendEvent(lastFocusItem, &event); | - | ||||||||||||||||||||||||||||||
858 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
859 | - | |||||||||||||||||||||||||||||||
860 | // This handles the case that the item has been removed from the | - | ||||||||||||||||||||||||||||||
861 | // scene in response to the FocusOut event. | - | ||||||||||||||||||||||||||||||
862 | if (item && item->scene() != q)
| 0 | ||||||||||||||||||||||||||||||
863 | item = 0; never executed: item = 0; | 0 | ||||||||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||||||||
865 | if (item)
| 0 | ||||||||||||||||||||||||||||||
866 | focusItem = item; never executed: focusItem = item; | 0 | ||||||||||||||||||||||||||||||
867 | updateInputMethodSensitivityInViews(); | - | ||||||||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||||||||
869 | if (item) {
| 0 | ||||||||||||||||||||||||||||||
870 | QFocusEvent event(QEvent::FocusIn, focusReason); | - | ||||||||||||||||||||||||||||||
871 | sendEvent(item, &event); | - | ||||||||||||||||||||||||||||||
872 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||||||||
874 | if (emitFocusChanged)
| 0 | ||||||||||||||||||||||||||||||
875 | emit q->focusItemChanged(focusItem, oldFocusItem, focusReason); never executed: q->focusItemChanged(focusItem, oldFocusItem, focusReason); | 0 | ||||||||||||||||||||||||||||||
876 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
877 | - | |||||||||||||||||||||||||||||||
878 | /*! | - | ||||||||||||||||||||||||||||||
879 | \internal | - | ||||||||||||||||||||||||||||||
880 | */ | - | ||||||||||||||||||||||||||||||
881 | void QGraphicsScenePrivate::addPopup(QGraphicsWidget *widget) | - | ||||||||||||||||||||||||||||||
882 | { | - | ||||||||||||||||||||||||||||||
883 | Q_ASSERT(widget); | - | ||||||||||||||||||||||||||||||
884 | Q_ASSERT(!popupWidgets.contains(widget)); | - | ||||||||||||||||||||||||||||||
885 | popupWidgets << widget; | - | ||||||||||||||||||||||||||||||
886 | if (QGraphicsWidget *focusWidget = widget->focusWidget()) {
| 0 | ||||||||||||||||||||||||||||||
887 | focusWidget->setFocus(Qt::PopupFocusReason); | - | ||||||||||||||||||||||||||||||
888 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
889 | grabKeyboard((QGraphicsItem *)widget); | - | ||||||||||||||||||||||||||||||
890 | if (focusItem && popupWidgets.size() == 1) {
| 0 | ||||||||||||||||||||||||||||||
891 | QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason); | - | ||||||||||||||||||||||||||||||
892 | sendEvent(focusItem, &event); | - | ||||||||||||||||||||||||||||||
893 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
894 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
895 | grabMouse((QGraphicsItem *)widget); | - | ||||||||||||||||||||||||||||||
896 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||||||||
898 | /*! | - | ||||||||||||||||||||||||||||||
899 | \internal | - | ||||||||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||||||||
901 | Remove \a widget from the popup list. Important notes: | - | ||||||||||||||||||||||||||||||
902 | - | |||||||||||||||||||||||||||||||
903 | \a widget is guaranteed to be in the list of popups, but it might not be | - | ||||||||||||||||||||||||||||||
904 | the last entry; you can hide any item in the pop list before the others, | - | ||||||||||||||||||||||||||||||
905 | and this must cause all later mouse grabbers to lose the grab. | - | ||||||||||||||||||||||||||||||
906 | */ | - | ||||||||||||||||||||||||||||||
907 | void QGraphicsScenePrivate::removePopup(QGraphicsWidget *widget, bool itemIsDying) | - | ||||||||||||||||||||||||||||||
908 | { | - | ||||||||||||||||||||||||||||||
909 | Q_ASSERT(widget); | - | ||||||||||||||||||||||||||||||
910 | int index = popupWidgets.indexOf(widget); | - | ||||||||||||||||||||||||||||||
911 | Q_ASSERT(index != -1); | - | ||||||||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||||||||
913 | for (int i = popupWidgets.size() - 1; i >= index; --i) {
| 0 | ||||||||||||||||||||||||||||||
914 | QGraphicsWidget *widget = popupWidgets.takeLast(); | - | ||||||||||||||||||||||||||||||
915 | ungrabMouse(widget, itemIsDying); | - | ||||||||||||||||||||||||||||||
916 | if (focusItem && popupWidgets.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
917 | QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason); | - | ||||||||||||||||||||||||||||||
918 | sendEvent(focusItem, &event); | - | ||||||||||||||||||||||||||||||
919 | } else if (keyboardGrabberItems.contains(static_cast<QGraphicsItem *>(widget))) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
920 | ungrabKeyboard(static_cast<QGraphicsItem *>(widget), itemIsDying); | - | ||||||||||||||||||||||||||||||
921 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
922 | if (!itemIsDying && widget->isVisible()) {
| 0 | ||||||||||||||||||||||||||||||
923 | widget->QGraphicsItem::d_ptr->setVisibleHelper(false, /* explicit = */ false); | - | ||||||||||||||||||||||||||||||
924 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
925 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
926 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||||||||
928 | /*! | - | ||||||||||||||||||||||||||||||
929 | \internal | - | ||||||||||||||||||||||||||||||
930 | */ | - | ||||||||||||||||||||||||||||||
931 | void QGraphicsScenePrivate::grabMouse(QGraphicsItem *item, bool implicit) | - | ||||||||||||||||||||||||||||||
932 | { | - | ||||||||||||||||||||||||||||||
933 | // Append to list of mouse grabber items, and send a mouse grab event. | - | ||||||||||||||||||||||||||||||
934 | if (mouseGrabberItems.contains(item)) {
| 0 | ||||||||||||||||||||||||||||||
935 | if (mouseGrabberItems.last() == item) {
| 0 | ||||||||||||||||||||||||||||||
936 | Q_ASSERT(!implicit); | - | ||||||||||||||||||||||||||||||
937 | if (!lastMouseGrabberItemHasImplicitMouseGrab) {
| 0 | ||||||||||||||||||||||||||||||
938 | qWarning("QGraphicsItem::grabMouse: already a mouse grabber"); | - | ||||||||||||||||||||||||||||||
939 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
940 | // Upgrade to an explicit mouse grab | - | ||||||||||||||||||||||||||||||
941 | lastMouseGrabberItemHasImplicitMouseGrab = false; | - | ||||||||||||||||||||||||||||||
942 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
943 | } else { | - | ||||||||||||||||||||||||||||||
944 | qWarning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p", | - | ||||||||||||||||||||||||||||||
945 | mouseGrabberItems.last()); | - | ||||||||||||||||||||||||||||||
946 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
947 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
948 | } | - | ||||||||||||||||||||||||||||||
949 | - | |||||||||||||||||||||||||||||||
950 | // Send ungrab event to the last grabber. | - | ||||||||||||||||||||||||||||||
951 | if (!mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
952 | QGraphicsItem *last = mouseGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
953 | if (lastMouseGrabberItemHasImplicitMouseGrab) {
| 0 | ||||||||||||||||||||||||||||||
954 | // Implicit mouse grab is immediately lost. | - | ||||||||||||||||||||||||||||||
955 | last->ungrabMouse(); | - | ||||||||||||||||||||||||||||||
956 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
957 | // Just send ungrab event to current grabber. | - | ||||||||||||||||||||||||||||||
958 | QEvent ungrabEvent(QEvent::UngrabMouse); | - | ||||||||||||||||||||||||||||||
959 | sendEvent(last, &ungrabEvent); | - | ||||||||||||||||||||||||||||||
960 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
961 | } | - | ||||||||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||||||||
963 | mouseGrabberItems << item; | - | ||||||||||||||||||||||||||||||
964 | lastMouseGrabberItemHasImplicitMouseGrab = implicit; | - | ||||||||||||||||||||||||||||||
965 | - | |||||||||||||||||||||||||||||||
966 | // Send grab event to current grabber. | - | ||||||||||||||||||||||||||||||
967 | QEvent grabEvent(QEvent::GrabMouse); | - | ||||||||||||||||||||||||||||||
968 | sendEvent(item, &grabEvent); | - | ||||||||||||||||||||||||||||||
969 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||||||||
971 | /*! | - | ||||||||||||||||||||||||||||||
972 | \internal | - | ||||||||||||||||||||||||||||||
973 | */ | - | ||||||||||||||||||||||||||||||
974 | void QGraphicsScenePrivate::ungrabMouse(QGraphicsItem *item, bool itemIsDying) | - | ||||||||||||||||||||||||||||||
975 | { | - | ||||||||||||||||||||||||||||||
976 | int index = mouseGrabberItems.indexOf(item); | - | ||||||||||||||||||||||||||||||
977 | if (index == -1) {
| 0 | ||||||||||||||||||||||||||||||
978 | qWarning("QGraphicsItem::ungrabMouse: not a mouse grabber"); | - | ||||||||||||||||||||||||||||||
979 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
980 | } | - | ||||||||||||||||||||||||||||||
981 | - | |||||||||||||||||||||||||||||||
982 | if (item != mouseGrabberItems.last()) {
| 0 | ||||||||||||||||||||||||||||||
983 | // Recursively ungrab the next mouse grabber until we reach this item | - | ||||||||||||||||||||||||||||||
984 | // to ensure state consistency. | - | ||||||||||||||||||||||||||||||
985 | ungrabMouse(mouseGrabberItems.at(index + 1), itemIsDying); | - | ||||||||||||||||||||||||||||||
986 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
987 | if (!popupWidgets.isEmpty() && item == popupWidgets.last()) {
| 0 | ||||||||||||||||||||||||||||||
988 | // If the item is a popup, go via removePopup to ensure state | - | ||||||||||||||||||||||||||||||
989 | // consistency and that it gets hidden correctly - beware that | - | ||||||||||||||||||||||||||||||
990 | // removePopup() reenters this function to continue removing the grab. | - | ||||||||||||||||||||||||||||||
991 | removePopup(popupWidgets.constLast(), itemIsDying); | - | ||||||||||||||||||||||||||||||
992 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
993 | } | - | ||||||||||||||||||||||||||||||
994 | - | |||||||||||||||||||||||||||||||
995 | // Send notification about mouse ungrab. | - | ||||||||||||||||||||||||||||||
996 | if (!itemIsDying) {
| 0 | ||||||||||||||||||||||||||||||
997 | QEvent event(QEvent::UngrabMouse); | - | ||||||||||||||||||||||||||||||
998 | sendEvent(item, &event); | - | ||||||||||||||||||||||||||||||
999 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1000 | - | |||||||||||||||||||||||||||||||
1001 | // Remove the item from the list of grabbers. Whenever this happens, we | - | ||||||||||||||||||||||||||||||
1002 | // reset the implicitGrab (there can be only ever be one implicit grabber | - | ||||||||||||||||||||||||||||||
1003 | // in a scene, and it is always the latest grabber; if the implicit grab | - | ||||||||||||||||||||||||||||||
1004 | // is lost, it is not automatically regained. | - | ||||||||||||||||||||||||||||||
1005 | mouseGrabberItems.takeLast(); | - | ||||||||||||||||||||||||||||||
1006 | lastMouseGrabberItemHasImplicitMouseGrab = false; | - | ||||||||||||||||||||||||||||||
1007 | - | |||||||||||||||||||||||||||||||
1008 | // Send notification about mouse regrab. ### It's unfortunate that all the | - | ||||||||||||||||||||||||||||||
1009 | // items get a GrabMouse event, but this is a rare case with a simple | - | ||||||||||||||||||||||||||||||
1010 | // implementation and it does ensure a consistent state. | - | ||||||||||||||||||||||||||||||
1011 | if (!itemIsDying && !mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1012 | QGraphicsItem *last = mouseGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
1013 | QEvent event(QEvent::GrabMouse); | - | ||||||||||||||||||||||||||||||
1014 | sendEvent(last, &event); | - | ||||||||||||||||||||||||||||||
1015 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1016 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1017 | - | |||||||||||||||||||||||||||||||
1018 | /*! | - | ||||||||||||||||||||||||||||||
1019 | \internal | - | ||||||||||||||||||||||||||||||
1020 | */ | - | ||||||||||||||||||||||||||||||
1021 | void QGraphicsScenePrivate::clearMouseGrabber() | - | ||||||||||||||||||||||||||||||
1022 | { | - | ||||||||||||||||||||||||||||||
1023 | if (!mouseGrabberItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
1024 | mouseGrabberItems.first()->ungrabMouse(); never executed: mouseGrabberItems.first()->ungrabMouse(); | 0 | ||||||||||||||||||||||||||||||
1025 | lastMouseGrabberItem = 0; | - | ||||||||||||||||||||||||||||||
1026 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1027 | - | |||||||||||||||||||||||||||||||
1028 | /*! | - | ||||||||||||||||||||||||||||||
1029 | \internal | - | ||||||||||||||||||||||||||||||
1030 | */ | - | ||||||||||||||||||||||||||||||
1031 | void QGraphicsScenePrivate::grabKeyboard(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
1032 | { | - | ||||||||||||||||||||||||||||||
1033 | if (keyboardGrabberItems.contains(item)) {
| 0 | ||||||||||||||||||||||||||||||
1034 | if (keyboardGrabberItems.last() == item)
| 0 | ||||||||||||||||||||||||||||||
1035 | qWarning("QGraphicsItem::grabKeyboard: already a keyboard grabber"); never executed: QMessageLogger(__FILE__, 1035, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: already a keyboard grabber"); | 0 | ||||||||||||||||||||||||||||||
1036 | else | - | ||||||||||||||||||||||||||||||
1037 | qWarning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p", never executed: QMessageLogger(__FILE__, 1037, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p", keyboardGrabberItems.last()); | 0 | ||||||||||||||||||||||||||||||
1038 | keyboardGrabberItems.last()); never executed: QMessageLogger(__FILE__, 1037, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p", keyboardGrabberItems.last()); | 0 | ||||||||||||||||||||||||||||||
1039 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1040 | } | - | ||||||||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||||||||
1042 | // Send ungrab event to the last grabber. | - | ||||||||||||||||||||||||||||||
1043 | if (!keyboardGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1044 | // Just send ungrab event to current grabber. | - | ||||||||||||||||||||||||||||||
1045 | QEvent ungrabEvent(QEvent::UngrabKeyboard); | - | ||||||||||||||||||||||||||||||
1046 | sendEvent(keyboardGrabberItems.last(), &ungrabEvent); | - | ||||||||||||||||||||||||||||||
1047 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||||||||
1049 | keyboardGrabberItems << item; | - | ||||||||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||||||||
1051 | // Send grab event to current grabber. | - | ||||||||||||||||||||||||||||||
1052 | QEvent grabEvent(QEvent::GrabKeyboard); | - | ||||||||||||||||||||||||||||||
1053 | sendEvent(item, &grabEvent); | - | ||||||||||||||||||||||||||||||
1054 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1055 | - | |||||||||||||||||||||||||||||||
1056 | /*! | - | ||||||||||||||||||||||||||||||
1057 | \internal | - | ||||||||||||||||||||||||||||||
1058 | */ | - | ||||||||||||||||||||||||||||||
1059 | void QGraphicsScenePrivate::ungrabKeyboard(QGraphicsItem *item, bool itemIsDying) | - | ||||||||||||||||||||||||||||||
1060 | { | - | ||||||||||||||||||||||||||||||
1061 | int index = keyboardGrabberItems.lastIndexOf(item); | - | ||||||||||||||||||||||||||||||
1062 | if (index == -1) {
| 0 | ||||||||||||||||||||||||||||||
1063 | qWarning("QGraphicsItem::ungrabKeyboard: not a keyboard grabber"); | - | ||||||||||||||||||||||||||||||
1064 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1065 | } | - | ||||||||||||||||||||||||||||||
1066 | if (item != keyboardGrabberItems.last()) {
| 0 | ||||||||||||||||||||||||||||||
1067 | // Recursively ungrab the topmost keyboard grabber until we reach this | - | ||||||||||||||||||||||||||||||
1068 | // item to ensure state consistency. | - | ||||||||||||||||||||||||||||||
1069 | ungrabKeyboard(keyboardGrabberItems.at(index + 1), itemIsDying); | - | ||||||||||||||||||||||||||||||
1070 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1071 | - | |||||||||||||||||||||||||||||||
1072 | // Send notification about keyboard ungrab. | - | ||||||||||||||||||||||||||||||
1073 | if (!itemIsDying) {
| 0 | ||||||||||||||||||||||||||||||
1074 | QEvent event(QEvent::UngrabKeyboard); | - | ||||||||||||||||||||||||||||||
1075 | sendEvent(item, &event); | - | ||||||||||||||||||||||||||||||
1076 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||||||||
1078 | // Remove the item from the list of grabbers. | - | ||||||||||||||||||||||||||||||
1079 | keyboardGrabberItems.takeLast(); | - | ||||||||||||||||||||||||||||||
1080 | - | |||||||||||||||||||||||||||||||
1081 | // Send notification about mouse regrab. | - | ||||||||||||||||||||||||||||||
1082 | if (!itemIsDying && !keyboardGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1083 | QGraphicsItem *last = keyboardGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
1084 | QEvent event(QEvent::GrabKeyboard); | - | ||||||||||||||||||||||||||||||
1085 | sendEvent(last, &event); | - | ||||||||||||||||||||||||||||||
1086 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1087 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1088 | - | |||||||||||||||||||||||||||||||
1089 | /*! | - | ||||||||||||||||||||||||||||||
1090 | \internal | - | ||||||||||||||||||||||||||||||
1091 | */ | - | ||||||||||||||||||||||||||||||
1092 | void QGraphicsScenePrivate::clearKeyboardGrabber() | - | ||||||||||||||||||||||||||||||
1093 | { | - | ||||||||||||||||||||||||||||||
1094 | if (!keyboardGrabberItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
1095 | ungrabKeyboard(keyboardGrabberItems.first()); never executed: ungrabKeyboard(keyboardGrabberItems.first()); | 0 | ||||||||||||||||||||||||||||||
1096 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1097 | - | |||||||||||||||||||||||||||||||
1098 | void QGraphicsScenePrivate::enableMouseTrackingOnViews() | - | ||||||||||||||||||||||||||||||
1099 | { | - | ||||||||||||||||||||||||||||||
1100 | foreach (QGraphicsView *view, views) | - | ||||||||||||||||||||||||||||||
1101 | view->viewport()->setMouseTracking(true); never executed: view->viewport()->setMouseTracking(true); | 0 | ||||||||||||||||||||||||||||||
1102 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||||||||
1104 | /*! | - | ||||||||||||||||||||||||||||||
1105 | Returns all items for the screen position in \a event. | - | ||||||||||||||||||||||||||||||
1106 | */ | - | ||||||||||||||||||||||||||||||
1107 | QList<QGraphicsItem *> QGraphicsScenePrivate::itemsAtPosition(const QPoint &screenPos, | - | ||||||||||||||||||||||||||||||
1108 | const QPointF &scenePos, | - | ||||||||||||||||||||||||||||||
1109 | QWidget *widget) const | - | ||||||||||||||||||||||||||||||
1110 | { | - | ||||||||||||||||||||||||||||||
1111 | Q_Q(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1112 | QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
| 0 | ||||||||||||||||||||||||||||||
1113 | if (!view)
| 0 | ||||||||||||||||||||||||||||||
1114 | return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder, QTransform()); never executed: return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder, QTransform()); | 0 | ||||||||||||||||||||||||||||||
1115 | - | |||||||||||||||||||||||||||||||
1116 | const QRectF pointRect(QPointF(widget->mapFromGlobal(screenPos)), QSizeF(1, 1)); | - | ||||||||||||||||||||||||||||||
1117 | if (!view->isTransformed())
| 0 | ||||||||||||||||||||||||||||||
1118 | return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder); never executed: return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder); | 0 | ||||||||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||||||||
1120 | const QTransform viewTransform = view->viewportTransform(); | - | ||||||||||||||||||||||||||||||
1121 | if (viewTransform.type() <= QTransform::TxScale) {
| 0 | ||||||||||||||||||||||||||||||
1122 | return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape, never executed: return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||
1123 | Qt::DescendingOrder, viewTransform); never executed: return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||
1124 | } | - | ||||||||||||||||||||||||||||||
1125 | return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape, never executed: return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||
1126 | Qt::DescendingOrder, viewTransform); never executed: return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform); | 0 | ||||||||||||||||||||||||||||||
1127 | } | - | ||||||||||||||||||||||||||||||
1128 | - | |||||||||||||||||||||||||||||||
1129 | /*! | - | ||||||||||||||||||||||||||||||
1130 | \internal | - | ||||||||||||||||||||||||||||||
1131 | */ | - | ||||||||||||||||||||||||||||||
1132 | void QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event) | - | ||||||||||||||||||||||||||||||
1133 | { | - | ||||||||||||||||||||||||||||||
1134 | for (int i = 0x1; i <= 0x10; i <<= 1) {
| 0 | ||||||||||||||||||||||||||||||
1135 | if (event->buttons() & i) {
| 0 | ||||||||||||||||||||||||||||||
1136 | mouseGrabberButtonDownPos.insert(Qt::MouseButton(i), | - | ||||||||||||||||||||||||||||||
1137 | mouseGrabberItems.last()->d_ptr->genericMapFromScene(event->scenePos(), | - | ||||||||||||||||||||||||||||||
1138 | event->widget())); | - | ||||||||||||||||||||||||||||||
1139 | mouseGrabberButtonDownScenePos.insert(Qt::MouseButton(i), event->scenePos()); | - | ||||||||||||||||||||||||||||||
1140 | mouseGrabberButtonDownScreenPos.insert(Qt::MouseButton(i), event->screenPos()); | - | ||||||||||||||||||||||||||||||
1141 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1142 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1143 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1144 | - | |||||||||||||||||||||||||||||||
1145 | /*! | - | ||||||||||||||||||||||||||||||
1146 | \internal | - | ||||||||||||||||||||||||||||||
1147 | */ | - | ||||||||||||||||||||||||||||||
1148 | void QGraphicsScenePrivate::installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) | - | ||||||||||||||||||||||||||||||
1149 | { | - | ||||||||||||||||||||||||||||||
1150 | sceneEventFilters.insert(watched, filter); | - | ||||||||||||||||||||||||||||||
1151 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1152 | - | |||||||||||||||||||||||||||||||
1153 | /*! | - | ||||||||||||||||||||||||||||||
1154 | \internal | - | ||||||||||||||||||||||||||||||
1155 | */ | - | ||||||||||||||||||||||||||||||
1156 | void QGraphicsScenePrivate::removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) | - | ||||||||||||||||||||||||||||||
1157 | { | - | ||||||||||||||||||||||||||||||
1158 | if (!sceneEventFilters.contains(watched))
| 0 | ||||||||||||||||||||||||||||||
1159 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1160 | - | |||||||||||||||||||||||||||||||
1161 | QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(watched); | - | ||||||||||||||||||||||||||||||
1162 | QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(watched); | - | ||||||||||||||||||||||||||||||
1163 | do { | - | ||||||||||||||||||||||||||||||
1164 | if (it.value() == filter)
| 0 | ||||||||||||||||||||||||||||||
1165 | it = sceneEventFilters.erase(it); never executed: it = sceneEventFilters.erase(it); | 0 | ||||||||||||||||||||||||||||||
1166 | else | - | ||||||||||||||||||||||||||||||
1167 | ++it; never executed: ++it; | 0 | ||||||||||||||||||||||||||||||
1168 | } while (it != end);
| 0 | ||||||||||||||||||||||||||||||
1169 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1170 | - | |||||||||||||||||||||||||||||||
1171 | /*! | - | ||||||||||||||||||||||||||||||
1172 | \internal | - | ||||||||||||||||||||||||||||||
1173 | */ | - | ||||||||||||||||||||||||||||||
1174 | bool QGraphicsScenePrivate::filterDescendantEvent(QGraphicsItem *item, QEvent *event) | - | ||||||||||||||||||||||||||||||
1175 | { | - | ||||||||||||||||||||||||||||||
1176 | if (item && (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents)) {
| 0 | ||||||||||||||||||||||||||||||
1177 | QGraphicsItem *parent = item->parentItem(); | - | ||||||||||||||||||||||||||||||
1178 | while (parent) {
| 0 | ||||||||||||||||||||||||||||||
1179 | if (parent->d_ptr->filtersDescendantEvents && parent->sceneEventFilter(item, event))
| 0 | ||||||||||||||||||||||||||||||
1180 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
1181 | if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents))
| 0 | ||||||||||||||||||||||||||||||
1182 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1183 | parent = parent->parentItem(); | - | ||||||||||||||||||||||||||||||
1184 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1185 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1186 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1187 | } | - | ||||||||||||||||||||||||||||||
1188 | - | |||||||||||||||||||||||||||||||
1189 | /*! | - | ||||||||||||||||||||||||||||||
1190 | \internal | - | ||||||||||||||||||||||||||||||
1191 | */ | - | ||||||||||||||||||||||||||||||
1192 | bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) | - | ||||||||||||||||||||||||||||||
1193 | { | - | ||||||||||||||||||||||||||||||
1194 | if (item && !sceneEventFilters.contains(item))
| 0 | ||||||||||||||||||||||||||||||
1195 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1196 | - | |||||||||||||||||||||||||||||||
1197 | QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(item); | - | ||||||||||||||||||||||||||||||
1198 | QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(item); | - | ||||||||||||||||||||||||||||||
1199 | while (it != end) {
| 0 | ||||||||||||||||||||||||||||||
1200 | // ### The filterer and filteree might both be deleted. | - | ||||||||||||||||||||||||||||||
1201 | if (it.value()->sceneEventFilter(it.key(), event))
| 0 | ||||||||||||||||||||||||||||||
1202 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
1203 | ++it; | - | ||||||||||||||||||||||||||||||
1204 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1205 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1206 | } | - | ||||||||||||||||||||||||||||||
1207 | - | |||||||||||||||||||||||||||||||
1208 | /*! | - | ||||||||||||||||||||||||||||||
1209 | \internal | - | ||||||||||||||||||||||||||||||
1210 | - | |||||||||||||||||||||||||||||||
1211 | This is the final dispatch point for any events from the scene to the | - | ||||||||||||||||||||||||||||||
1212 | item. It filters the event first - if the filter returns \c true, the event | - | ||||||||||||||||||||||||||||||
1213 | is considered to have been eaten by the filter, and is therefore stopped | - | ||||||||||||||||||||||||||||||
1214 | (the default filter returns \c false). Then/otherwise, if the item is | - | ||||||||||||||||||||||||||||||
1215 | enabled, the event is sent; otherwise it is stopped. | - | ||||||||||||||||||||||||||||||
1216 | */ | - | ||||||||||||||||||||||||||||||
1217 | bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) | - | ||||||||||||||||||||||||||||||
1218 | { | - | ||||||||||||||||||||||||||||||
1219 | if (QGraphicsObject *object = item->toGraphicsObject()) {
| 0 | ||||||||||||||||||||||||||||||
1220 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
1221 | QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; | - | ||||||||||||||||||||||||||||||
1222 | if (gestureManager) {
| 0 | ||||||||||||||||||||||||||||||
1223 | if (gestureManager->filterEvent(object, event))
| 0 | ||||||||||||||||||||||||||||||
1224 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
1225 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1226 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
1227 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1228 | - | |||||||||||||||||||||||||||||||
1229 | if (filterEvent(item, event))
| 0 | ||||||||||||||||||||||||||||||
1230 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1231 | if (filterDescendantEvent(item, event))
| 0 | ||||||||||||||||||||||||||||||
1232 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1233 | if (!item || !item->isEnabled())
| 0 | ||||||||||||||||||||||||||||||
1234 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1235 | if (QGraphicsObject *o = item->toGraphicsObject()) {
| 0 | ||||||||||||||||||||||||||||||
1236 | bool spont = event->spontaneous(); | - | ||||||||||||||||||||||||||||||
1237 | if (spont ? qt_sendSpontaneousEvent(o, event) : QApplication::sendEvent(o, event))
| 0 | ||||||||||||||||||||||||||||||
1238 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
1239 | event->spont = spont; | - | ||||||||||||||||||||||||||||||
1240 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1241 | return item->sceneEvent(event); never executed: return item->sceneEvent(event); | 0 | ||||||||||||||||||||||||||||||
1242 | } | - | ||||||||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||||||||
1244 | /*! | - | ||||||||||||||||||||||||||||||
1245 | \internal | - | ||||||||||||||||||||||||||||||
1246 | */ | - | ||||||||||||||||||||||||||||||
1247 | void QGraphicsScenePrivate::cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest, | - | ||||||||||||||||||||||||||||||
1248 | QGraphicsSceneDragDropEvent *source) | - | ||||||||||||||||||||||||||||||
1249 | { | - | ||||||||||||||||||||||||||||||
1250 | dest->setWidget(source->widget()); | - | ||||||||||||||||||||||||||||||
1251 | dest->setPos(source->pos()); | - | ||||||||||||||||||||||||||||||
1252 | dest->setScenePos(source->scenePos()); | - | ||||||||||||||||||||||||||||||
1253 | dest->setScreenPos(source->screenPos()); | - | ||||||||||||||||||||||||||||||
1254 | dest->setButtons(source->buttons()); | - | ||||||||||||||||||||||||||||||
1255 | dest->setModifiers(source->modifiers()); | - | ||||||||||||||||||||||||||||||
1256 | dest->setPossibleActions(source->possibleActions()); | - | ||||||||||||||||||||||||||||||
1257 | dest->setProposedAction(source->proposedAction()); | - | ||||||||||||||||||||||||||||||
1258 | dest->setDropAction(source->dropAction()); | - | ||||||||||||||||||||||||||||||
1259 | dest->setSource(source->source()); | - | ||||||||||||||||||||||||||||||
1260 | dest->setMimeData(source->mimeData()); | - | ||||||||||||||||||||||||||||||
1261 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1262 | - | |||||||||||||||||||||||||||||||
1263 | /*! | - | ||||||||||||||||||||||||||||||
1264 | \internal | - | ||||||||||||||||||||||||||||||
1265 | */ | - | ||||||||||||||||||||||||||||||
1266 | void QGraphicsScenePrivate::sendDragDropEvent(QGraphicsItem *item, | - | ||||||||||||||||||||||||||||||
1267 | QGraphicsSceneDragDropEvent *dragDropEvent) | - | ||||||||||||||||||||||||||||||
1268 | { | - | ||||||||||||||||||||||||||||||
1269 | dragDropEvent->setPos(item->d_ptr->genericMapFromScene(dragDropEvent->scenePos(), dragDropEvent->widget())); | - | ||||||||||||||||||||||||||||||
1270 | sendEvent(item, dragDropEvent); | - | ||||||||||||||||||||||||||||||
1271 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1272 | - | |||||||||||||||||||||||||||||||
1273 | /*! | - | ||||||||||||||||||||||||||||||
1274 | \internal | - | ||||||||||||||||||||||||||||||
1275 | */ | - | ||||||||||||||||||||||||||||||
1276 | void QGraphicsScenePrivate::sendHoverEvent(QEvent::Type type, QGraphicsItem *item, | - | ||||||||||||||||||||||||||||||
1277 | QGraphicsSceneHoverEvent *hoverEvent) | - | ||||||||||||||||||||||||||||||
1278 | { | - | ||||||||||||||||||||||||||||||
1279 | QGraphicsSceneHoverEvent event(type); | - | ||||||||||||||||||||||||||||||
1280 | event.setWidget(hoverEvent->widget()); | - | ||||||||||||||||||||||||||||||
1281 | event.setPos(item->d_ptr->genericMapFromScene(hoverEvent->scenePos(), hoverEvent->widget())); | - | ||||||||||||||||||||||||||||||
1282 | event.setScenePos(hoverEvent->scenePos()); | - | ||||||||||||||||||||||||||||||
1283 | event.setScreenPos(hoverEvent->screenPos()); | - | ||||||||||||||||||||||||||||||
1284 | event.setLastPos(item->d_ptr->genericMapFromScene(hoverEvent->lastScenePos(), hoverEvent->widget())); | - | ||||||||||||||||||||||||||||||
1285 | event.setLastScenePos(hoverEvent->lastScenePos()); | - | ||||||||||||||||||||||||||||||
1286 | event.setLastScreenPos(hoverEvent->lastScreenPos()); | - | ||||||||||||||||||||||||||||||
1287 | event.setModifiers(hoverEvent->modifiers()); | - | ||||||||||||||||||||||||||||||
1288 | sendEvent(item, &event); | - | ||||||||||||||||||||||||||||||
1289 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||||||||
1291 | /*! | - | ||||||||||||||||||||||||||||||
1292 | \internal | - | ||||||||||||||||||||||||||||||
1293 | */ | - | ||||||||||||||||||||||||||||||
1294 | void QGraphicsScenePrivate::sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
1295 | { | - | ||||||||||||||||||||||||||||||
1296 | if (mouseEvent->button() == 0 && mouseEvent->buttons() == 0 && lastMouseGrabberItemHasImplicitMouseGrab) {
| 0 | ||||||||||||||||||||||||||||||
1297 | // ### This is a temporary fix for until we get proper mouse | - | ||||||||||||||||||||||||||||||
1298 | // grab events. | - | ||||||||||||||||||||||||||||||
1299 | clearMouseGrabber(); | - | ||||||||||||||||||||||||||||||
1300 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1301 | } | - | ||||||||||||||||||||||||||||||
1302 | - | |||||||||||||||||||||||||||||||
1303 | QGraphicsItem *item = mouseGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
1304 | if (item->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
1305 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||||||||
1307 | for (int i = 0x1; i <= 0x10; i <<= 1) {
| 0 | ||||||||||||||||||||||||||||||
1308 | Qt::MouseButton button = Qt::MouseButton(i); | - | ||||||||||||||||||||||||||||||
1309 | mouseEvent->setButtonDownPos(button, mouseGrabberButtonDownPos.value(button, item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget()))); | - | ||||||||||||||||||||||||||||||
1310 | mouseEvent->setButtonDownScenePos(button, mouseGrabberButtonDownScenePos.value(button, mouseEvent->scenePos())); | - | ||||||||||||||||||||||||||||||
1311 | mouseEvent->setButtonDownScreenPos(button, mouseGrabberButtonDownScreenPos.value(button, mouseEvent->screenPos())); | - | ||||||||||||||||||||||||||||||
1312 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1313 | mouseEvent->setPos(item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget())); | - | ||||||||||||||||||||||||||||||
1314 | mouseEvent->setLastPos(item->d_ptr->genericMapFromScene(mouseEvent->lastScenePos(), mouseEvent->widget())); | - | ||||||||||||||||||||||||||||||
1315 | sendEvent(item, mouseEvent); | - | ||||||||||||||||||||||||||||||
1316 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1317 | - | |||||||||||||||||||||||||||||||
1318 | /*! | - | ||||||||||||||||||||||||||||||
1319 | \internal | - | ||||||||||||||||||||||||||||||
1320 | */ | - | ||||||||||||||||||||||||||||||
1321 | void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
1322 | { | - | ||||||||||||||||||||||||||||||
1323 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1324 | - | |||||||||||||||||||||||||||||||
1325 | // Ignore by default, unless we find a mouse grabber that accepts it. | - | ||||||||||||||||||||||||||||||
1326 | mouseEvent->ignore(); | - | ||||||||||||||||||||||||||||||
1327 | - | |||||||||||||||||||||||||||||||
1328 | // Deliver to any existing mouse grabber. | - | ||||||||||||||||||||||||||||||
1329 | if (!mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1330 | if (mouseGrabberItems.last()->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
1331 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1332 | // The event is ignored by default, but we disregard the event's | - | ||||||||||||||||||||||||||||||
1333 | // accepted state after delivery; the mouse is grabbed, after all. | - | ||||||||||||||||||||||||||||||
1334 | sendMouseEvent(mouseEvent); | - | ||||||||||||||||||||||||||||||
1335 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1336 | } | - | ||||||||||||||||||||||||||||||
1337 | - | |||||||||||||||||||||||||||||||
1338 | // Start by determining the number of items at the current position. | - | ||||||||||||||||||||||||||||||
1339 | // Reuse value from earlier calculations if possible. | - | ||||||||||||||||||||||||||||||
1340 | if (cachedItemsUnderMouse.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1341 | cachedItemsUnderMouse = itemsAtPosition(mouseEvent->screenPos(), | - | ||||||||||||||||||||||||||||||
1342 | mouseEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
1343 | mouseEvent->widget()); | - | ||||||||||||||||||||||||||||||
1344 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1345 | - | |||||||||||||||||||||||||||||||
1346 | // Update window activation. | - | ||||||||||||||||||||||||||||||
1347 | QGraphicsItem *topItem = cachedItemsUnderMouse.value(0); | - | ||||||||||||||||||||||||||||||
1348 | QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0;
| 0 | ||||||||||||||||||||||||||||||
1349 | if (newActiveWindow && newActiveWindow->isBlockedByModalPanel(&topItem)) {
| 0 | ||||||||||||||||||||||||||||||
1350 | // pass activation to the blocking modal window | - | ||||||||||||||||||||||||||||||
1351 | newActiveWindow = topItem ? topItem->window() : 0;
| 0 | ||||||||||||||||||||||||||||||
1352 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||||||||
1354 | if (newActiveWindow != q->activeWindow())
| 0 | ||||||||||||||||||||||||||||||
1355 | q->setActiveWindow(newActiveWindow); never executed: q->setActiveWindow(newActiveWindow); | 0 | ||||||||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||||||||
1357 | // Set focus on the topmost enabled item that can take focus. | - | ||||||||||||||||||||||||||||||
1358 | bool setFocus = false; | - | ||||||||||||||||||||||||||||||
1359 | - | |||||||||||||||||||||||||||||||
1360 | foreach (QGraphicsItem *item, cachedItemsUnderMouse) { | - | ||||||||||||||||||||||||||||||
1361 | if (item->isBlockedByModalPanel()
| 0 | ||||||||||||||||||||||||||||||
1362 | || (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling)) {
| 0 | ||||||||||||||||||||||||||||||
1363 | // Make sure we don't clear focus. | - | ||||||||||||||||||||||||||||||
1364 | setFocus = true; | - | ||||||||||||||||||||||||||||||
1365 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1366 | } | - | ||||||||||||||||||||||||||||||
1367 | if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable))) {
| 0 | ||||||||||||||||||||||||||||||
1368 | if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
| 0 | ||||||||||||||||||||||||||||||
1369 | setFocus = true; | - | ||||||||||||||||||||||||||||||
1370 | if (item != q->focusItem() && item->d_ptr->mouseSetsFocus)
| 0 | ||||||||||||||||||||||||||||||
1371 | q->setFocusItem(item, Qt::MouseFocusReason); never executed: q->setFocusItem(item, Qt::MouseFocusReason); | 0 | ||||||||||||||||||||||||||||||
1372 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1373 | } | - | ||||||||||||||||||||||||||||||
1374 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1375 | if (item->isPanel())
| 0 | ||||||||||||||||||||||||||||||
1376 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1377 | if (item->d_ptr->flags & QGraphicsItem::ItemStopsClickFocusPropagation)
| 0 | ||||||||||||||||||||||||||||||
1378 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1379 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1380 | - | |||||||||||||||||||||||||||||||
1381 | // Check for scene modality. | - | ||||||||||||||||||||||||||||||
1382 | bool sceneModality = false; | - | ||||||||||||||||||||||||||||||
1383 | for (int i = 0; i < modalPanels.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
1384 | if (modalPanels.at(i)->panelModality() == QGraphicsItem::SceneModal) {
| 0 | ||||||||||||||||||||||||||||||
1385 | sceneModality = true; | - | ||||||||||||||||||||||||||||||
1386 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1387 | } | - | ||||||||||||||||||||||||||||||
1388 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1389 | - | |||||||||||||||||||||||||||||||
1390 | // If nobody could take focus, clear it. | - | ||||||||||||||||||||||||||||||
1391 | if (!stickyFocus && !setFocus && !sceneModality)
| 0 | ||||||||||||||||||||||||||||||
1392 | q->setFocusItem(0, Qt::MouseFocusReason); never executed: q->setFocusItem(0, Qt::MouseFocusReason); | 0 | ||||||||||||||||||||||||||||||
1393 | - | |||||||||||||||||||||||||||||||
1394 | // Any item will do. | - | ||||||||||||||||||||||||||||||
1395 | if (sceneModality && cachedItemsUnderMouse.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
1396 | cachedItemsUnderMouse << modalPanels.first(); never executed: cachedItemsUnderMouse << modalPanels.first(); | 0 | ||||||||||||||||||||||||||||||
1397 | - | |||||||||||||||||||||||||||||||
1398 | // Find a mouse grabber by sending mouse press events to all mouse grabber | - | ||||||||||||||||||||||||||||||
1399 | // candidates one at a time, until the event is accepted. It's accepted by | - | ||||||||||||||||||||||||||||||
1400 | // default, so the receiver has to explicitly ignore it for it to pass | - | ||||||||||||||||||||||||||||||
1401 | // through. | - | ||||||||||||||||||||||||||||||
1402 | foreach (QGraphicsItem *item, cachedItemsUnderMouse) { | - | ||||||||||||||||||||||||||||||
1403 | if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
| 0 | ||||||||||||||||||||||||||||||
1404 | // Skip items that don't accept the event's mouse button. | - | ||||||||||||||||||||||||||||||
1405 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
1406 | } | - | ||||||||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||||||||
1408 | // Check if this item is blocked by a modal panel and deliver the mouse event to the | - | ||||||||||||||||||||||||||||||
1409 | // blocking panel instead of this item if blocked. | - | ||||||||||||||||||||||||||||||
1410 | (void) item->isBlockedByModalPanel(&item); | - | ||||||||||||||||||||||||||||||
1411 | - | |||||||||||||||||||||||||||||||
1412 | grabMouse(item, /* implicit = */ true); | - | ||||||||||||||||||||||||||||||
1413 | mouseEvent->accept(); | - | ||||||||||||||||||||||||||||||
1414 | - | |||||||||||||||||||||||||||||||
1415 | // check if the item we are sending to are disabled (before we send the event) | - | ||||||||||||||||||||||||||||||
1416 | bool disabled = !item->isEnabled(); | - | ||||||||||||||||||||||||||||||
1417 | bool isPanel = item->isPanel(); | - | ||||||||||||||||||||||||||||||
1418 | if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
| 0 | ||||||||||||||||||||||||||||||
1419 | && item != lastMouseGrabberItem && lastMouseGrabberItem) {
| 0 | ||||||||||||||||||||||||||||||
1420 | // If this item is different from the item that received the last | - | ||||||||||||||||||||||||||||||
1421 | // mouse event, and mouseEvent is a doubleclick event, then the | - | ||||||||||||||||||||||||||||||
1422 | // event is converted to a press. Known limitation: | - | ||||||||||||||||||||||||||||||
1423 | // Triple-clicking will not generate a doubleclick, though. | - | ||||||||||||||||||||||||||||||
1424 | QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress); | - | ||||||||||||||||||||||||||||||
1425 | mousePress.spont = mouseEvent->spont; | - | ||||||||||||||||||||||||||||||
1426 | mousePress.accept(); | - | ||||||||||||||||||||||||||||||
1427 | mousePress.setButton(mouseEvent->button()); | - | ||||||||||||||||||||||||||||||
1428 | mousePress.setButtons(mouseEvent->buttons()); | - | ||||||||||||||||||||||||||||||
1429 | mousePress.setScreenPos(mouseEvent->screenPos()); | - | ||||||||||||||||||||||||||||||
1430 | mousePress.setScenePos(mouseEvent->scenePos()); | - | ||||||||||||||||||||||||||||||
1431 | mousePress.setModifiers(mouseEvent->modifiers()); | - | ||||||||||||||||||||||||||||||
1432 | mousePress.setWidget(mouseEvent->widget()); | - | ||||||||||||||||||||||||||||||
1433 | mousePress.setButtonDownPos(mouseEvent->button(), | - | ||||||||||||||||||||||||||||||
1434 | mouseEvent->buttonDownPos(mouseEvent->button())); | - | ||||||||||||||||||||||||||||||
1435 | mousePress.setButtonDownScenePos(mouseEvent->button(), | - | ||||||||||||||||||||||||||||||
1436 | mouseEvent->buttonDownScenePos(mouseEvent->button())); | - | ||||||||||||||||||||||||||||||
1437 | mousePress.setButtonDownScreenPos(mouseEvent->button(), | - | ||||||||||||||||||||||||||||||
1438 | mouseEvent->buttonDownScreenPos(mouseEvent->button())); | - | ||||||||||||||||||||||||||||||
1439 | sendMouseEvent(&mousePress); | - | ||||||||||||||||||||||||||||||
1440 | mouseEvent->setAccepted(mousePress.isAccepted()); | - | ||||||||||||||||||||||||||||||
1441 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1442 | sendMouseEvent(mouseEvent); | - | ||||||||||||||||||||||||||||||
1443 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1444 | - | |||||||||||||||||||||||||||||||
1445 | bool dontSendUngrabEvents = mouseGrabberItems.isEmpty() || mouseGrabberItems.last() != item;
| 0 | ||||||||||||||||||||||||||||||
1446 | if (disabled) {
| 0 | ||||||||||||||||||||||||||||||
1447 | ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); | - | ||||||||||||||||||||||||||||||
1448 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1449 | } | - | ||||||||||||||||||||||||||||||
1450 | if (mouseEvent->isAccepted()) {
| 0 | ||||||||||||||||||||||||||||||
1451 | if (!mouseGrabberItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
1452 | storeMouseButtonsForMouseGrabber(mouseEvent); never executed: storeMouseButtonsForMouseGrabber(mouseEvent); | 0 | ||||||||||||||||||||||||||||||
1453 | lastMouseGrabberItem = item; | - | ||||||||||||||||||||||||||||||
1454 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1455 | } | - | ||||||||||||||||||||||||||||||
1456 | ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); | - | ||||||||||||||||||||||||||||||
1457 | - | |||||||||||||||||||||||||||||||
1458 | // Don't propagate through panels. | - | ||||||||||||||||||||||||||||||
1459 | if (isPanel)
| 0 | ||||||||||||||||||||||||||||||
1460 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1461 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1462 | - | |||||||||||||||||||||||||||||||
1463 | // Is the event still ignored? Then the mouse press goes to the scene. | - | ||||||||||||||||||||||||||||||
1464 | // Reset the mouse grabber, clear the selection, clear focus, and leave | - | ||||||||||||||||||||||||||||||
1465 | // the event ignored so that it can propagate through the originating | - | ||||||||||||||||||||||||||||||
1466 | // view. | - | ||||||||||||||||||||||||||||||
1467 | if (!mouseEvent->isAccepted()) {
| 0 | ||||||||||||||||||||||||||||||
1468 | clearMouseGrabber(); | - | ||||||||||||||||||||||||||||||
1469 | - | |||||||||||||||||||||||||||||||
1470 | QGraphicsView *view = mouseEvent->widget() ? qobject_cast<QGraphicsView *>(mouseEvent->widget()->parentWidget()) : 0;
| 0 | ||||||||||||||||||||||||||||||
1471 | bool dontClearSelection = view && view->dragMode() == QGraphicsView::ScrollHandDrag;
| 0 | ||||||||||||||||||||||||||||||
1472 | bool extendSelection = (mouseEvent->modifiers() & Qt::ControlModifier) != 0; | - | ||||||||||||||||||||||||||||||
1473 | dontClearSelection |= extendSelection; | - | ||||||||||||||||||||||||||||||
1474 | if (!dontClearSelection) {
| 0 | ||||||||||||||||||||||||||||||
1475 | // Clear the selection if the originating view isn't in scroll | - | ||||||||||||||||||||||||||||||
1476 | // hand drag mode. The view will clear the selection if no drag | - | ||||||||||||||||||||||||||||||
1477 | // happened. | - | ||||||||||||||||||||||||||||||
1478 | q->clearSelection(); | - | ||||||||||||||||||||||||||||||
1479 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1480 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1481 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1482 | - | |||||||||||||||||||||||||||||||
1483 | /*! | - | ||||||||||||||||||||||||||||||
1484 | \internal | - | ||||||||||||||||||||||||||||||
1485 | - | |||||||||||||||||||||||||||||||
1486 | Ensures that the list of toplevels is sorted by insertion order, and that | - | ||||||||||||||||||||||||||||||
1487 | the siblingIndexes are packed (no gaps), and start at 0. | - | ||||||||||||||||||||||||||||||
1488 | - | |||||||||||||||||||||||||||||||
1489 | ### This function is almost identical to | - | ||||||||||||||||||||||||||||||
1490 | QGraphicsItemPrivate::ensureSequentialSiblingIndex(). | - | ||||||||||||||||||||||||||||||
1491 | */ | - | ||||||||||||||||||||||||||||||
1492 | void QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes() | - | ||||||||||||||||||||||||||||||
1493 | { | - | ||||||||||||||||||||||||||||||
1494 | if (!topLevelSequentialOrdering) {
| 0 | ||||||||||||||||||||||||||||||
1495 | std::sort(topLevelItems.begin(), topLevelItems.end(), QGraphicsItemPrivate::insertionOrder); | - | ||||||||||||||||||||||||||||||
1496 | topLevelSequentialOrdering = true; | - | ||||||||||||||||||||||||||||||
1497 | needSortTopLevelItems = 1; | - | ||||||||||||||||||||||||||||||
1498 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1499 | if (holesInTopLevelSiblingIndex) {
| 0 | ||||||||||||||||||||||||||||||
1500 | holesInTopLevelSiblingIndex = 0; | - | ||||||||||||||||||||||||||||||
1501 | for (int i = 0; i < topLevelItems.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
1502 | topLevelItems[i]->d_ptr->siblingIndex = i; never executed: topLevelItems[i]->d_ptr->siblingIndex = i; | 0 | ||||||||||||||||||||||||||||||
1503 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1504 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1505 | - | |||||||||||||||||||||||||||||||
1506 | /*! | - | ||||||||||||||||||||||||||||||
1507 | \internal | - | ||||||||||||||||||||||||||||||
1508 | - | |||||||||||||||||||||||||||||||
1509 | Set the font and propagate the changes if the font is different from the | - | ||||||||||||||||||||||||||||||
1510 | current font. | - | ||||||||||||||||||||||||||||||
1511 | */ | - | ||||||||||||||||||||||||||||||
1512 | void QGraphicsScenePrivate::setFont_helper(const QFont &font) | - | ||||||||||||||||||||||||||||||
1513 | { | - | ||||||||||||||||||||||||||||||
1514 | if (this->font == font && this->font.resolve() == font.resolve())
| 0 | ||||||||||||||||||||||||||||||
1515 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1516 | updateFont(font); | - | ||||||||||||||||||||||||||||||
1517 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1518 | - | |||||||||||||||||||||||||||||||
1519 | /*! | - | ||||||||||||||||||||||||||||||
1520 | \internal | - | ||||||||||||||||||||||||||||||
1521 | - | |||||||||||||||||||||||||||||||
1522 | Resolve the scene's font against the application font, and propagate the | - | ||||||||||||||||||||||||||||||
1523 | changes too all items in the scene. | - | ||||||||||||||||||||||||||||||
1524 | */ | - | ||||||||||||||||||||||||||||||
1525 | void QGraphicsScenePrivate::resolveFont() | - | ||||||||||||||||||||||||||||||
1526 | { | - | ||||||||||||||||||||||||||||||
1527 | QFont naturalFont = QApplication::font(); | - | ||||||||||||||||||||||||||||||
1528 | naturalFont.resolve(0); | - | ||||||||||||||||||||||||||||||
1529 | QFont resolvedFont = font.resolve(naturalFont); | - | ||||||||||||||||||||||||||||||
1530 | updateFont(resolvedFont); | - | ||||||||||||||||||||||||||||||
1531 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1532 | - | |||||||||||||||||||||||||||||||
1533 | /*! | - | ||||||||||||||||||||||||||||||
1534 | \internal | - | ||||||||||||||||||||||||||||||
1535 | - | |||||||||||||||||||||||||||||||
1536 | Update the font, and whether or not it has changed, reresolve all fonts in | - | ||||||||||||||||||||||||||||||
1537 | the scene. | - | ||||||||||||||||||||||||||||||
1538 | */ | - | ||||||||||||||||||||||||||||||
1539 | void QGraphicsScenePrivate::updateFont(const QFont &font) | - | ||||||||||||||||||||||||||||||
1540 | { | - | ||||||||||||||||||||||||||||||
1541 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1542 | - | |||||||||||||||||||||||||||||||
1543 | // Update local font setting. | - | ||||||||||||||||||||||||||||||
1544 | this->font = font; | - | ||||||||||||||||||||||||||||||
1545 | - | |||||||||||||||||||||||||||||||
1546 | // Resolve the fonts of all top-level widget items, or widget items | - | ||||||||||||||||||||||||||||||
1547 | // whose parent is not a widget. | - | ||||||||||||||||||||||||||||||
1548 | foreach (QGraphicsItem *item, q->items()) { | - | ||||||||||||||||||||||||||||||
1549 | if (!item->parentItem()) {
| 0 | ||||||||||||||||||||||||||||||
1550 | // Resolvefont for an item is a noop operation, but | - | ||||||||||||||||||||||||||||||
1551 | // every item can be a widget, or can have a widget | - | ||||||||||||||||||||||||||||||
1552 | // childre. | - | ||||||||||||||||||||||||||||||
1553 | item->d_ptr->resolveFont(font.resolve()); | - | ||||||||||||||||||||||||||||||
1554 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1555 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1556 | - | |||||||||||||||||||||||||||||||
1557 | // Send the scene a FontChange event. | - | ||||||||||||||||||||||||||||||
1558 | QEvent event(QEvent::FontChange); | - | ||||||||||||||||||||||||||||||
1559 | QApplication::sendEvent(q, &event); | - | ||||||||||||||||||||||||||||||
1560 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1561 | - | |||||||||||||||||||||||||||||||
1562 | /*! | - | ||||||||||||||||||||||||||||||
1563 | \internal | - | ||||||||||||||||||||||||||||||
1564 | - | |||||||||||||||||||||||||||||||
1565 | Set the palette and propagate the changes if the palette is different from | - | ||||||||||||||||||||||||||||||
1566 | the current palette. | - | ||||||||||||||||||||||||||||||
1567 | */ | - | ||||||||||||||||||||||||||||||
1568 | void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette) | - | ||||||||||||||||||||||||||||||
1569 | { | - | ||||||||||||||||||||||||||||||
1570 | if (this->palette == palette && this->palette.resolve() == palette.resolve())
| 0 | ||||||||||||||||||||||||||||||
1571 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1572 | updatePalette(palette); | - | ||||||||||||||||||||||||||||||
1573 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1574 | - | |||||||||||||||||||||||||||||||
1575 | /*! | - | ||||||||||||||||||||||||||||||
1576 | \internal | - | ||||||||||||||||||||||||||||||
1577 | - | |||||||||||||||||||||||||||||||
1578 | Resolve the scene's palette against the application palette, and propagate | - | ||||||||||||||||||||||||||||||
1579 | the changes too all items in the scene. | - | ||||||||||||||||||||||||||||||
1580 | */ | - | ||||||||||||||||||||||||||||||
1581 | void QGraphicsScenePrivate::resolvePalette() | - | ||||||||||||||||||||||||||||||
1582 | { | - | ||||||||||||||||||||||||||||||
1583 | QPalette naturalPalette = QApplication::palette(); | - | ||||||||||||||||||||||||||||||
1584 | naturalPalette.resolve(0); | - | ||||||||||||||||||||||||||||||
1585 | QPalette resolvedPalette = palette.resolve(naturalPalette); | - | ||||||||||||||||||||||||||||||
1586 | updatePalette(resolvedPalette); | - | ||||||||||||||||||||||||||||||
1587 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1588 | - | |||||||||||||||||||||||||||||||
1589 | /*! | - | ||||||||||||||||||||||||||||||
1590 | \internal | - | ||||||||||||||||||||||||||||||
1591 | - | |||||||||||||||||||||||||||||||
1592 | Update the palette, and whether or not it has changed, reresolve all | - | ||||||||||||||||||||||||||||||
1593 | palettes in the scene. | - | ||||||||||||||||||||||||||||||
1594 | */ | - | ||||||||||||||||||||||||||||||
1595 | void QGraphicsScenePrivate::updatePalette(const QPalette &palette) | - | ||||||||||||||||||||||||||||||
1596 | { | - | ||||||||||||||||||||||||||||||
1597 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1598 | - | |||||||||||||||||||||||||||||||
1599 | // Update local palette setting. | - | ||||||||||||||||||||||||||||||
1600 | this->palette = palette; | - | ||||||||||||||||||||||||||||||
1601 | - | |||||||||||||||||||||||||||||||
1602 | // Resolve the palettes of all top-level widget items, or widget items | - | ||||||||||||||||||||||||||||||
1603 | // whose parent is not a widget. | - | ||||||||||||||||||||||||||||||
1604 | foreach (QGraphicsItem *item, q->items()) { | - | ||||||||||||||||||||||||||||||
1605 | if (!item->parentItem()) {
| 0 | ||||||||||||||||||||||||||||||
1606 | // ResolvePalette for an item is a noop operation, but | - | ||||||||||||||||||||||||||||||
1607 | // every item can be a widget, or can have a widget | - | ||||||||||||||||||||||||||||||
1608 | // children. | - | ||||||||||||||||||||||||||||||
1609 | item->d_ptr->resolvePalette(palette.resolve()); | - | ||||||||||||||||||||||||||||||
1610 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1611 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1612 | - | |||||||||||||||||||||||||||||||
1613 | // Send the scene a PaletteChange event. | - | ||||||||||||||||||||||||||||||
1614 | QEvent event(QEvent::PaletteChange); | - | ||||||||||||||||||||||||||||||
1615 | QApplication::sendEvent(q, &event); | - | ||||||||||||||||||||||||||||||
1616 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1617 | - | |||||||||||||||||||||||||||||||
1618 | /*! | - | ||||||||||||||||||||||||||||||
1619 | Constructs a QGraphicsScene object. The \a parent parameter is | - | ||||||||||||||||||||||||||||||
1620 | passed to QObject's constructor. | - | ||||||||||||||||||||||||||||||
1621 | */ | - | ||||||||||||||||||||||||||||||
1622 | QGraphicsScene::QGraphicsScene(QObject *parent) | - | ||||||||||||||||||||||||||||||
1623 | : QObject(*new QGraphicsScenePrivate, parent) | - | ||||||||||||||||||||||||||||||
1624 | { | - | ||||||||||||||||||||||||||||||
1625 | d_func()->init(); | - | ||||||||||||||||||||||||||||||
1626 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1627 | - | |||||||||||||||||||||||||||||||
1628 | /*! | - | ||||||||||||||||||||||||||||||
1629 | Constructs a QGraphicsScene object, using \a sceneRect for its | - | ||||||||||||||||||||||||||||||
1630 | scene rectangle. The \a parent parameter is passed to QObject's | - | ||||||||||||||||||||||||||||||
1631 | constructor. | - | ||||||||||||||||||||||||||||||
1632 | - | |||||||||||||||||||||||||||||||
1633 | \sa sceneRect | - | ||||||||||||||||||||||||||||||
1634 | */ | - | ||||||||||||||||||||||||||||||
1635 | QGraphicsScene::QGraphicsScene(const QRectF &sceneRect, QObject *parent) | - | ||||||||||||||||||||||||||||||
1636 | : QObject(*new QGraphicsScenePrivate, parent) | - | ||||||||||||||||||||||||||||||
1637 | { | - | ||||||||||||||||||||||||||||||
1638 | d_func()->init(); | - | ||||||||||||||||||||||||||||||
1639 | setSceneRect(sceneRect); | - | ||||||||||||||||||||||||||||||
1640 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1641 | - | |||||||||||||||||||||||||||||||
1642 | /*! | - | ||||||||||||||||||||||||||||||
1643 | Constructs a QGraphicsScene object, using the rectangle specified | - | ||||||||||||||||||||||||||||||
1644 | by (\a x, \a y), and the given \a width and \a height for its | - | ||||||||||||||||||||||||||||||
1645 | scene rectangle. The \a parent parameter is passed to QObject's | - | ||||||||||||||||||||||||||||||
1646 | constructor. | - | ||||||||||||||||||||||||||||||
1647 | - | |||||||||||||||||||||||||||||||
1648 | \sa sceneRect | - | ||||||||||||||||||||||||||||||
1649 | */ | - | ||||||||||||||||||||||||||||||
1650 | QGraphicsScene::QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent) | - | ||||||||||||||||||||||||||||||
1651 | : QObject(*new QGraphicsScenePrivate, parent) | - | ||||||||||||||||||||||||||||||
1652 | { | - | ||||||||||||||||||||||||||||||
1653 | d_func()->init(); | - | ||||||||||||||||||||||||||||||
1654 | setSceneRect(x, y, width, height); | - | ||||||||||||||||||||||||||||||
1655 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1656 | - | |||||||||||||||||||||||||||||||
1657 | /*! | - | ||||||||||||||||||||||||||||||
1658 | Removes and deletes all items from the scene object | - | ||||||||||||||||||||||||||||||
1659 | before destroying the scene object. The scene object | - | ||||||||||||||||||||||||||||||
1660 | is removed from the application's global scene list, | - | ||||||||||||||||||||||||||||||
1661 | and it is removed from all associated views. | - | ||||||||||||||||||||||||||||||
1662 | */ | - | ||||||||||||||||||||||||||||||
1663 | QGraphicsScene::~QGraphicsScene() | - | ||||||||||||||||||||||||||||||
1664 | { | - | ||||||||||||||||||||||||||||||
1665 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1666 | - | |||||||||||||||||||||||||||||||
1667 | // Remove this scene from qApp's global scene list. | - | ||||||||||||||||||||||||||||||
1668 | if (!QApplicationPrivate::is_app_closing)
| 0 | ||||||||||||||||||||||||||||||
1669 | qApp->d_func()->scene_list.removeAll(this); never executed: (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->scene_list.removeAll(this); | 0 | ||||||||||||||||||||||||||||||
1670 | - | |||||||||||||||||||||||||||||||
1671 | clear(); | - | ||||||||||||||||||||||||||||||
1672 | - | |||||||||||||||||||||||||||||||
1673 | // Remove this scene from all associated views. | - | ||||||||||||||||||||||||||||||
1674 | for (int j = 0; j < d->views.size(); ++j)
| 0 | ||||||||||||||||||||||||||||||
1675 | d->views.at(j)->setScene(0); never executed: d->views.at(j)->setScene(0); | 0 | ||||||||||||||||||||||||||||||
1676 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1677 | - | |||||||||||||||||||||||||||||||
1678 | /*! | - | ||||||||||||||||||||||||||||||
1679 | \property QGraphicsScene::sceneRect | - | ||||||||||||||||||||||||||||||
1680 | \brief the scene rectangle; the bounding rectangle of the scene | - | ||||||||||||||||||||||||||||||
1681 | - | |||||||||||||||||||||||||||||||
1682 | The scene rectangle defines the extent of the scene. It is | - | ||||||||||||||||||||||||||||||
1683 | primarily used by QGraphicsView to determine the view's default | - | ||||||||||||||||||||||||||||||
1684 | scrollable area, and by QGraphicsScene to manage item indexing. | - | ||||||||||||||||||||||||||||||
1685 | - | |||||||||||||||||||||||||||||||
1686 | If unset, or if set to a null QRectF, sceneRect() will return the largest | - | ||||||||||||||||||||||||||||||
1687 | bounding rect of all items on the scene since the scene was created (i.e., | - | ||||||||||||||||||||||||||||||
1688 | a rectangle that grows when items are added to or moved in the scene, but | - | ||||||||||||||||||||||||||||||
1689 | never shrinks). | - | ||||||||||||||||||||||||||||||
1690 | - | |||||||||||||||||||||||||||||||
1691 | \sa width(), height(), QGraphicsView::sceneRect | - | ||||||||||||||||||||||||||||||
1692 | */ | - | ||||||||||||||||||||||||||||||
1693 | QRectF QGraphicsScene::sceneRect() const | - | ||||||||||||||||||||||||||||||
1694 | { | - | ||||||||||||||||||||||||||||||
1695 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1696 | if (d->hasSceneRect)
| 0 | ||||||||||||||||||||||||||||||
1697 | return d->sceneRect; never executed: return d->sceneRect; | 0 | ||||||||||||||||||||||||||||||
1698 | - | |||||||||||||||||||||||||||||||
1699 | if (d->dirtyGrowingItemsBoundingRect) {
| 0 | ||||||||||||||||||||||||||||||
1700 | // Lazily update the growing items bounding rect | - | ||||||||||||||||||||||||||||||
1701 | QGraphicsScenePrivate *thatd = const_cast<QGraphicsScenePrivate *>(d); | - | ||||||||||||||||||||||||||||||
1702 | QRectF oldGrowingBoundingRect = thatd->growingItemsBoundingRect; | - | ||||||||||||||||||||||||||||||
1703 | thatd->growingItemsBoundingRect |= itemsBoundingRect(); | - | ||||||||||||||||||||||||||||||
1704 | thatd->dirtyGrowingItemsBoundingRect = false; | - | ||||||||||||||||||||||||||||||
1705 | if (oldGrowingBoundingRect != thatd->growingItemsBoundingRect)
| 0 | ||||||||||||||||||||||||||||||
1706 | emit const_cast<QGraphicsScene *>(this)->sceneRectChanged(thatd->growingItemsBoundingRect); never executed: const_cast<QGraphicsScene *>(this)->sceneRectChanged(thatd->growingItemsBoundingRect); | 0 | ||||||||||||||||||||||||||||||
1707 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1708 | return d->growingItemsBoundingRect; never executed: return d->growingItemsBoundingRect; | 0 | ||||||||||||||||||||||||||||||
1709 | } | - | ||||||||||||||||||||||||||||||
1710 | void QGraphicsScene::setSceneRect(const QRectF &rect) | - | ||||||||||||||||||||||||||||||
1711 | { | - | ||||||||||||||||||||||||||||||
1712 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1713 | if (rect != d->sceneRect) {
| 0 | ||||||||||||||||||||||||||||||
1714 | d->hasSceneRect = !rect.isNull(); | - | ||||||||||||||||||||||||||||||
1715 | d->sceneRect = rect; | - | ||||||||||||||||||||||||||||||
1716 | emit sceneRectChanged(d->hasSceneRect ? rect : d->growingItemsBoundingRect); | - | ||||||||||||||||||||||||||||||
1717 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1718 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1719 | - | |||||||||||||||||||||||||||||||
1720 | /*! | - | ||||||||||||||||||||||||||||||
1721 | \fn qreal QGraphicsScene::width() const | - | ||||||||||||||||||||||||||||||
1722 | - | |||||||||||||||||||||||||||||||
1723 | This convenience function is equivalent to calling sceneRect().width(). | - | ||||||||||||||||||||||||||||||
1724 | - | |||||||||||||||||||||||||||||||
1725 | \sa height() | - | ||||||||||||||||||||||||||||||
1726 | */ | - | ||||||||||||||||||||||||||||||
1727 | - | |||||||||||||||||||||||||||||||
1728 | /*! | - | ||||||||||||||||||||||||||||||
1729 | \fn qreal QGraphicsScene::height() const | - | ||||||||||||||||||||||||||||||
1730 | - | |||||||||||||||||||||||||||||||
1731 | This convenience function is equivalent to calling \c sceneRect().height(). | - | ||||||||||||||||||||||||||||||
1732 | - | |||||||||||||||||||||||||||||||
1733 | \sa width() | - | ||||||||||||||||||||||||||||||
1734 | */ | - | ||||||||||||||||||||||||||||||
1735 | - | |||||||||||||||||||||||||||||||
1736 | /*! | - | ||||||||||||||||||||||||||||||
1737 | Renders the \a source rect from scene into \a target, using \a painter. This | - | ||||||||||||||||||||||||||||||
1738 | function is useful for capturing the contents of the scene onto a paint | - | ||||||||||||||||||||||||||||||
1739 | device, such as a QImage (e.g., to take a screenshot), or for printing | - | ||||||||||||||||||||||||||||||
1740 | with QPrinter. For example: | - | ||||||||||||||||||||||||||||||
1741 | - | |||||||||||||||||||||||||||||||
1742 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 1 | - | ||||||||||||||||||||||||||||||
1743 | - | |||||||||||||||||||||||||||||||
1744 | If \a source is a null rect, this function will use sceneRect() to | - | ||||||||||||||||||||||||||||||
1745 | determine what to render. If \a target is a null rect, the dimensions of \a | - | ||||||||||||||||||||||||||||||
1746 | painter's paint device will be used. | - | ||||||||||||||||||||||||||||||
1747 | - | |||||||||||||||||||||||||||||||
1748 | The source rect contents will be transformed according to \a | - | ||||||||||||||||||||||||||||||
1749 | aspectRatioMode to fit into the target rect. By default, the aspect ratio | - | ||||||||||||||||||||||||||||||
1750 | is kept, and \a source is scaled to fit in \a target. | - | ||||||||||||||||||||||||||||||
1751 | - | |||||||||||||||||||||||||||||||
1752 | \sa QGraphicsView::render() | - | ||||||||||||||||||||||||||||||
1753 | */ | - | ||||||||||||||||||||||||||||||
1754 | void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRectF &source, | - | ||||||||||||||||||||||||||||||
1755 | Qt::AspectRatioMode aspectRatioMode) | - | ||||||||||||||||||||||||||||||
1756 | { | - | ||||||||||||||||||||||||||||||
1757 | // ### Switch to using the recursive rendering algorithm instead. | - | ||||||||||||||||||||||||||||||
1758 | - | |||||||||||||||||||||||||||||||
1759 | // Default source rect = scene rect | - | ||||||||||||||||||||||||||||||
1760 | QRectF sourceRect = source; | - | ||||||||||||||||||||||||||||||
1761 | if (sourceRect.isNull())
| 0 | ||||||||||||||||||||||||||||||
1762 | sourceRect = sceneRect(); never executed: sourceRect = sceneRect(); | 0 | ||||||||||||||||||||||||||||||
1763 | - | |||||||||||||||||||||||||||||||
1764 | // Default target rect = device rect | - | ||||||||||||||||||||||||||||||
1765 | QRectF targetRect = target; | - | ||||||||||||||||||||||||||||||
1766 | if (targetRect.isNull()) {
| 0 | ||||||||||||||||||||||||||||||
1767 | if (painter->device()->devType() == QInternal::Picture)
| 0 | ||||||||||||||||||||||||||||||
1768 | targetRect = sourceRect; never executed: targetRect = sourceRect; | 0 | ||||||||||||||||||||||||||||||
1769 | else | - | ||||||||||||||||||||||||||||||
1770 | targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); never executed: targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height()); | 0 | ||||||||||||||||||||||||||||||
1771 | } | - | ||||||||||||||||||||||||||||||
1772 | - | |||||||||||||||||||||||||||||||
1773 | // Find the ideal x / y scaling ratio to fit \a source into \a target. | - | ||||||||||||||||||||||||||||||
1774 | qreal xratio = targetRect.width() / sourceRect.width(); | - | ||||||||||||||||||||||||||||||
1775 | qreal yratio = targetRect.height() / sourceRect.height(); | - | ||||||||||||||||||||||||||||||
1776 | - | |||||||||||||||||||||||||||||||
1777 | // Scale according to the aspect ratio mode. | - | ||||||||||||||||||||||||||||||
1778 | switch (aspectRatioMode) { | - | ||||||||||||||||||||||||||||||
1779 | case Qt::KeepAspectRatio: never executed: case Qt::KeepAspectRatio: | 0 | ||||||||||||||||||||||||||||||
1780 | xratio = yratio = qMin(xratio, yratio); | - | ||||||||||||||||||||||||||||||
1781 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1782 | case Qt::KeepAspectRatioByExpanding: never executed: case Qt::KeepAspectRatioByExpanding: | 0 | ||||||||||||||||||||||||||||||
1783 | xratio = yratio = qMax(xratio, yratio); | - | ||||||||||||||||||||||||||||||
1784 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1785 | case Qt::IgnoreAspectRatio: never executed: case Qt::IgnoreAspectRatio: | 0 | ||||||||||||||||||||||||||||||
1786 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1787 | } | - | ||||||||||||||||||||||||||||||
1788 | - | |||||||||||||||||||||||||||||||
1789 | // Find all items to draw, and reverse the list (we want to draw | - | ||||||||||||||||||||||||||||||
1790 | // in reverse order). | - | ||||||||||||||||||||||||||||||
1791 | QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect); | - | ||||||||||||||||||||||||||||||
1792 | QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()]; | - | ||||||||||||||||||||||||||||||
1793 | int numItems = itemList.size(); | - | ||||||||||||||||||||||||||||||
1794 | for (int i = 0; i < numItems; ++i)
| 0 | ||||||||||||||||||||||||||||||
1795 | itemArray[numItems - i - 1] = itemList.at(i); never executed: itemArray[numItems - i - 1] = itemList.at(i); | 0 | ||||||||||||||||||||||||||||||
1796 | itemList.clear(); | - | ||||||||||||||||||||||||||||||
1797 | - | |||||||||||||||||||||||||||||||
1798 | painter->save(); | - | ||||||||||||||||||||||||||||||
1799 | - | |||||||||||||||||||||||||||||||
1800 | // Transform the painter. | - | ||||||||||||||||||||||||||||||
1801 | painter->setClipRect(targetRect, Qt::IntersectClip); | - | ||||||||||||||||||||||||||||||
1802 | QTransform painterTransform; | - | ||||||||||||||||||||||||||||||
1803 | painterTransform *= QTransform() | - | ||||||||||||||||||||||||||||||
1804 | .translate(targetRect.left(), targetRect.top()) | - | ||||||||||||||||||||||||||||||
1805 | .scale(xratio, yratio) | - | ||||||||||||||||||||||||||||||
1806 | .translate(-sourceRect.left(), -sourceRect.top()); | - | ||||||||||||||||||||||||||||||
1807 | painter->setWorldTransform(painterTransform, true); | - | ||||||||||||||||||||||||||||||
1808 | - | |||||||||||||||||||||||||||||||
1809 | // Generate the style options | - | ||||||||||||||||||||||||||||||
1810 | QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems]; | - | ||||||||||||||||||||||||||||||
1811 | for (int i = 0; i < numItems; ++i)
| 0 | ||||||||||||||||||||||||||||||
1812 | itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect()); never executed: itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect()); | 0 | ||||||||||||||||||||||||||||||
1813 | - | |||||||||||||||||||||||||||||||
1814 | // Render the scene. | - | ||||||||||||||||||||||||||||||
1815 | drawBackground(painter, sourceRect); | - | ||||||||||||||||||||||||||||||
1816 | drawItems(painter, numItems, itemArray, styleOptionArray); | - | ||||||||||||||||||||||||||||||
1817 | drawForeground(painter, sourceRect); | - | ||||||||||||||||||||||||||||||
1818 | - | |||||||||||||||||||||||||||||||
1819 | delete [] itemArray; | - | ||||||||||||||||||||||||||||||
1820 | delete [] styleOptionArray; | - | ||||||||||||||||||||||||||||||
1821 | - | |||||||||||||||||||||||||||||||
1822 | painter->restore(); | - | ||||||||||||||||||||||||||||||
1823 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1824 | - | |||||||||||||||||||||||||||||||
1825 | /*! | - | ||||||||||||||||||||||||||||||
1826 | \property QGraphicsScene::itemIndexMethod | - | ||||||||||||||||||||||||||||||
1827 | \brief the item indexing method. | - | ||||||||||||||||||||||||||||||
1828 | - | |||||||||||||||||||||||||||||||
1829 | QGraphicsScene applies an indexing algorithm to the scene, to speed up | - | ||||||||||||||||||||||||||||||
1830 | item discovery functions like items() and itemAt(). Indexing is most | - | ||||||||||||||||||||||||||||||
1831 | efficient for static scenes (i.e., where items don't move around). For | - | ||||||||||||||||||||||||||||||
1832 | dynamic scenes, or scenes with many animated items, the index bookkeeping | - | ||||||||||||||||||||||||||||||
1833 | can outweight the fast lookup speeds. | - | ||||||||||||||||||||||||||||||
1834 | - | |||||||||||||||||||||||||||||||
1835 | For the common case, the default index method BspTreeIndex works fine. If | - | ||||||||||||||||||||||||||||||
1836 | your scene uses many animations and you are experiencing slowness, you can | - | ||||||||||||||||||||||||||||||
1837 | disable indexing by calling \c setItemIndexMethod(NoIndex). | - | ||||||||||||||||||||||||||||||
1838 | - | |||||||||||||||||||||||||||||||
1839 | \sa bspTreeDepth | - | ||||||||||||||||||||||||||||||
1840 | */ | - | ||||||||||||||||||||||||||||||
1841 | QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod() const | - | ||||||||||||||||||||||||||||||
1842 | { | - | ||||||||||||||||||||||||||||||
1843 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1844 | return d->indexMethod; never executed: return d->indexMethod; | 0 | ||||||||||||||||||||||||||||||
1845 | } | - | ||||||||||||||||||||||||||||||
1846 | void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method) | - | ||||||||||||||||||||||||||||||
1847 | { | - | ||||||||||||||||||||||||||||||
1848 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1849 | if (d->indexMethod == method)
| 0 | ||||||||||||||||||||||||||||||
1850 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1851 | - | |||||||||||||||||||||||||||||||
1852 | d->indexMethod = method; | - | ||||||||||||||||||||||||||||||
1853 | - | |||||||||||||||||||||||||||||||
1854 | QList<QGraphicsItem *> oldItems = d->index->items(Qt::DescendingOrder); | - | ||||||||||||||||||||||||||||||
1855 | delete d->index; | - | ||||||||||||||||||||||||||||||
1856 | if (method == BspTreeIndex)
| 0 | ||||||||||||||||||||||||||||||
1857 | d->index = new QGraphicsSceneBspTreeIndex(this); never executed: d->index = new QGraphicsSceneBspTreeIndex(this); | 0 | ||||||||||||||||||||||||||||||
1858 | else | - | ||||||||||||||||||||||||||||||
1859 | d->index = new QGraphicsSceneLinearIndex(this); never executed: d->index = new QGraphicsSceneLinearIndex(this); | 0 | ||||||||||||||||||||||||||||||
1860 | for (int i = oldItems.size() - 1; i >= 0; --i)
| 0 | ||||||||||||||||||||||||||||||
1861 | d->index->addItem(oldItems.at(i)); never executed: d->index->addItem(oldItems.at(i)); | 0 | ||||||||||||||||||||||||||||||
1862 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1863 | - | |||||||||||||||||||||||||||||||
1864 | /*! | - | ||||||||||||||||||||||||||||||
1865 | \property QGraphicsScene::bspTreeDepth | - | ||||||||||||||||||||||||||||||
1866 | \brief the depth of QGraphicsScene's BSP index tree | - | ||||||||||||||||||||||||||||||
1867 | \since 4.3 | - | ||||||||||||||||||||||||||||||
1868 | - | |||||||||||||||||||||||||||||||
1869 | This property has no effect when NoIndex is used. | - | ||||||||||||||||||||||||||||||
1870 | - | |||||||||||||||||||||||||||||||
1871 | This value determines the depth of QGraphicsScene's BSP tree. The depth | - | ||||||||||||||||||||||||||||||
1872 | directly affects QGraphicsScene's performance and memory usage; the latter | - | ||||||||||||||||||||||||||||||
1873 | growing exponentially with the depth of the tree. With an optimal tree | - | ||||||||||||||||||||||||||||||
1874 | depth, QGraphicsScene can instantly determine the locality of items, even | - | ||||||||||||||||||||||||||||||
1875 | for scenes with thousands or millions of items. This also greatly improves | - | ||||||||||||||||||||||||||||||
1876 | rendering performance. | - | ||||||||||||||||||||||||||||||
1877 | - | |||||||||||||||||||||||||||||||
1878 | By default, the value is 0, in which case Qt will guess a reasonable | - | ||||||||||||||||||||||||||||||
1879 | default depth based on the size, location and number of items in the | - | ||||||||||||||||||||||||||||||
1880 | scene. If these parameters change frequently, however, you may experience | - | ||||||||||||||||||||||||||||||
1881 | slowdowns as QGraphicsScene retunes the depth internally. You can avoid | - | ||||||||||||||||||||||||||||||
1882 | potential slowdowns by fixating the tree depth through setting this | - | ||||||||||||||||||||||||||||||
1883 | property. | - | ||||||||||||||||||||||||||||||
1884 | - | |||||||||||||||||||||||||||||||
1885 | The depth of the tree and the size of the scene rectangle decide the | - | ||||||||||||||||||||||||||||||
1886 | granularity of the scene's partitioning. The size of each scene segment is | - | ||||||||||||||||||||||||||||||
1887 | determined by the following algorithm: | - | ||||||||||||||||||||||||||||||
1888 | - | |||||||||||||||||||||||||||||||
1889 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 2 | - | ||||||||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||||||||
1891 | The BSP tree has an optimal size when each segment contains between 0 and | - | ||||||||||||||||||||||||||||||
1892 | 10 items. | - | ||||||||||||||||||||||||||||||
1893 | - | |||||||||||||||||||||||||||||||
1894 | \sa itemIndexMethod | - | ||||||||||||||||||||||||||||||
1895 | */ | - | ||||||||||||||||||||||||||||||
1896 | int QGraphicsScene::bspTreeDepth() const | - | ||||||||||||||||||||||||||||||
1897 | { | - | ||||||||||||||||||||||||||||||
1898 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1899 | QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); | - | ||||||||||||||||||||||||||||||
1900 | return bspTree ? bspTree->bspTreeDepth() : 0; never executed: return bspTree ? bspTree->bspTreeDepth() : 0;
| 0 | ||||||||||||||||||||||||||||||
1901 | } | - | ||||||||||||||||||||||||||||||
1902 | void QGraphicsScene::setBspTreeDepth(int depth) | - | ||||||||||||||||||||||||||||||
1903 | { | - | ||||||||||||||||||||||||||||||
1904 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1905 | if (depth < 0) {
| 0 | ||||||||||||||||||||||||||||||
1906 | qWarning("QGraphicsScene::setBspTreeDepth: invalid depth %d ignored; must be >= 0", depth); | - | ||||||||||||||||||||||||||||||
1907 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1908 | } | - | ||||||||||||||||||||||||||||||
1909 | - | |||||||||||||||||||||||||||||||
1910 | QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); | - | ||||||||||||||||||||||||||||||
1911 | if (!bspTree) {
| 0 | ||||||||||||||||||||||||||||||
1912 | qWarning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP"); | - | ||||||||||||||||||||||||||||||
1913 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1914 | } | - | ||||||||||||||||||||||||||||||
1915 | bspTree->setBspTreeDepth(depth); | - | ||||||||||||||||||||||||||||||
1916 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1917 | - | |||||||||||||||||||||||||||||||
1918 | /*! | - | ||||||||||||||||||||||||||||||
1919 | \property QGraphicsScene::sortCacheEnabled | - | ||||||||||||||||||||||||||||||
1920 | \brief whether sort caching is enabled | - | ||||||||||||||||||||||||||||||
1921 | \since 4.5 | - | ||||||||||||||||||||||||||||||
1922 | \obsolete | - | ||||||||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||||||||
1924 | Since Qt 4.6, this property has no effect. | - | ||||||||||||||||||||||||||||||
1925 | */ | - | ||||||||||||||||||||||||||||||
1926 | bool QGraphicsScene::isSortCacheEnabled() const | - | ||||||||||||||||||||||||||||||
1927 | { | - | ||||||||||||||||||||||||||||||
1928 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1929 | return d->sortCacheEnabled; never executed: return d->sortCacheEnabled; | 0 | ||||||||||||||||||||||||||||||
1930 | } | - | ||||||||||||||||||||||||||||||
1931 | void QGraphicsScene::setSortCacheEnabled(bool enabled) | - | ||||||||||||||||||||||||||||||
1932 | { | - | ||||||||||||||||||||||||||||||
1933 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1934 | if (d->sortCacheEnabled == enabled)
| 0 | ||||||||||||||||||||||||||||||
1935 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1936 | d->sortCacheEnabled = enabled; | - | ||||||||||||||||||||||||||||||
1937 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1938 | - | |||||||||||||||||||||||||||||||
1939 | /*! | - | ||||||||||||||||||||||||||||||
1940 | Calculates and returns the bounding rect of all items on the scene. This | - | ||||||||||||||||||||||||||||||
1941 | function works by iterating over all items, and because of this, it can | - | ||||||||||||||||||||||||||||||
1942 | be slow for large scenes. | - | ||||||||||||||||||||||||||||||
1943 | - | |||||||||||||||||||||||||||||||
1944 | \sa sceneRect() | - | ||||||||||||||||||||||||||||||
1945 | */ | - | ||||||||||||||||||||||||||||||
1946 | QRectF QGraphicsScene::itemsBoundingRect() const | - | ||||||||||||||||||||||||||||||
1947 | { | - | ||||||||||||||||||||||||||||||
1948 | // Does not take untransformable items into account. | - | ||||||||||||||||||||||||||||||
1949 | QRectF boundingRect; | - | ||||||||||||||||||||||||||||||
1950 | foreach (QGraphicsItem *item, items()) | - | ||||||||||||||||||||||||||||||
1951 | boundingRect |= item->sceneBoundingRect(); never executed: boundingRect |= item->sceneBoundingRect(); | 0 | ||||||||||||||||||||||||||||||
1952 | return boundingRect; never executed: return boundingRect; | 0 | ||||||||||||||||||||||||||||||
1953 | } | - | ||||||||||||||||||||||||||||||
1954 | - | |||||||||||||||||||||||||||||||
1955 | /*! | - | ||||||||||||||||||||||||||||||
1956 | Returns an ordered list of all items on the scene. \a order decides the | - | ||||||||||||||||||||||||||||||
1957 | stacking order. | - | ||||||||||||||||||||||||||||||
1958 | - | |||||||||||||||||||||||||||||||
1959 | \sa addItem(), removeItem(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
1960 | */ | - | ||||||||||||||||||||||||||||||
1961 | QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const | - | ||||||||||||||||||||||||||||||
1962 | { | - | ||||||||||||||||||||||||||||||
1963 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
1964 | return d->index->items(order); never executed: return d->index->items(order); | 0 | ||||||||||||||||||||||||||||||
1965 | } | - | ||||||||||||||||||||||||||||||
1966 | - | |||||||||||||||||||||||||||||||
1967 | /*! | - | ||||||||||||||||||||||||||||||
1968 | \fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||
1969 | \obsolete | - | ||||||||||||||||||||||||||||||
1970 | \since 4.3 | - | ||||||||||||||||||||||||||||||
1971 | - | |||||||||||||||||||||||||||||||
1972 | This convenience function is equivalent to calling items(QRectF(\a x, \a y, \a w, \a h), \a mode). | - | ||||||||||||||||||||||||||||||
1973 | - | |||||||||||||||||||||||||||||||
1974 | This function is deprecated and returns incorrect results if the scene | - | ||||||||||||||||||||||||||||||
1975 | contains items that ignore transformations. Use the overload that takes | - | ||||||||||||||||||||||||||||||
1976 | a QTransform instead. | - | ||||||||||||||||||||||||||||||
1977 | */ | - | ||||||||||||||||||||||||||||||
1978 | - | |||||||||||||||||||||||||||||||
1979 | /*! | - | ||||||||||||||||||||||||||||||
1980 | \fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
1981 | \overload | - | ||||||||||||||||||||||||||||||
1982 | \since 4.6 | - | ||||||||||||||||||||||||||||||
1983 | - | |||||||||||||||||||||||||||||||
1984 | \brief Returns all visible items that, depending on \a mode, are | - | ||||||||||||||||||||||||||||||
1985 | either inside or intersect with the rectangle defined by \a x, \a y, | - | ||||||||||||||||||||||||||||||
1986 | \a w and \a h, in a list sorted using \a order. In this case, "visible" defines items for which: | - | ||||||||||||||||||||||||||||||
1987 | isVisible() returns \c true, effectiveOpacity() returns a value greater than 0.0 | - | ||||||||||||||||||||||||||||||
1988 | (which is fully transparent) and the parent item does not clip it. | - | ||||||||||||||||||||||||||||||
1989 | - | |||||||||||||||||||||||||||||||
1990 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
1991 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
1992 | */ | - | ||||||||||||||||||||||||||||||
1993 | - | |||||||||||||||||||||||||||||||
1994 | /*! | - | ||||||||||||||||||||||||||||||
1995 | \fn QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
1996 | \since 4.6 | - | ||||||||||||||||||||||||||||||
1997 | - | |||||||||||||||||||||||||||||||
1998 | \brief Returns all visible items that, depending on \a mode, are at | - | ||||||||||||||||||||||||||||||
1999 | the specified \a pos in a list sorted using \a order. In this case, "visible" defines items for which: | - | ||||||||||||||||||||||||||||||
2000 | isVisible() returns \c true, effectiveOpacity() returns a value greater than 0.0 | - | ||||||||||||||||||||||||||||||
2001 | (which is fully transparent) and the parent item does not clip it. | - | ||||||||||||||||||||||||||||||
2002 | - | |||||||||||||||||||||||||||||||
2003 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||
2004 | exact shape intersects with \a pos are returned. | - | ||||||||||||||||||||||||||||||
2005 | - | |||||||||||||||||||||||||||||||
2006 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2007 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2008 | - | |||||||||||||||||||||||||||||||
2009 | \sa itemAt(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2010 | */ | - | ||||||||||||||||||||||||||||||
2011 | QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos, Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2012 | Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2013 | { | - | ||||||||||||||||||||||||||||||
2014 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2015 | return d->index->items(pos, mode, order, deviceTransform); never executed: return d->index->items(pos, mode, order, deviceTransform); | 0 | ||||||||||||||||||||||||||||||
2016 | } | - | ||||||||||||||||||||||||||||||
2017 | - | |||||||||||||||||||||||||||||||
2018 | /*! | - | ||||||||||||||||||||||||||||||
2019 | \fn QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2020 | \overload | - | ||||||||||||||||||||||||||||||
2021 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2022 | - | |||||||||||||||||||||||||||||||
2023 | \brief Returns all visible items that, depending on \a mode, are | - | ||||||||||||||||||||||||||||||
2024 | either inside or intersect with the specified \a rect, in a | - | ||||||||||||||||||||||||||||||
2025 | list sorted using \a order. In this case, "visible" defines items for which: | - | ||||||||||||||||||||||||||||||
2026 | isVisible() returns \c true, effectiveOpacity() returns a value greater than 0.0 | - | ||||||||||||||||||||||||||||||
2027 | (which is fully transparent) and the parent item does not clip it. | - | ||||||||||||||||||||||||||||||
2028 | - | |||||||||||||||||||||||||||||||
2029 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||
2030 | exact shape intersects with or is contained by \a rect are returned. | - | ||||||||||||||||||||||||||||||
2031 | - | |||||||||||||||||||||||||||||||
2032 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2033 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2034 | - | |||||||||||||||||||||||||||||||
2035 | \sa itemAt(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2036 | */ | - | ||||||||||||||||||||||||||||||
2037 | QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2038 | Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2039 | { | - | ||||||||||||||||||||||||||||||
2040 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2041 | return d->index->items(rect, mode, order, deviceTransform); never executed: return d->index->items(rect, mode, order, deviceTransform); | 0 | ||||||||||||||||||||||||||||||
2042 | } | - | ||||||||||||||||||||||||||||||
2043 | - | |||||||||||||||||||||||||||||||
2044 | /*! | - | ||||||||||||||||||||||||||||||
2045 | \fn QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2046 | \overload | - | ||||||||||||||||||||||||||||||
2047 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2048 | - | |||||||||||||||||||||||||||||||
2049 | \brief Returns all visible items that, depending on \a mode, are | - | ||||||||||||||||||||||||||||||
2050 | either inside or intersect with the specified \a polygon, in | - | ||||||||||||||||||||||||||||||
2051 | a list sorted using \a order. In this case, "visible" defines items for which: | - | ||||||||||||||||||||||||||||||
2052 | isVisible() returns \c true, effectiveOpacity() returns a value greater than 0.0 | - | ||||||||||||||||||||||||||||||
2053 | (which is fully transparent) and the parent item does not clip it. | - | ||||||||||||||||||||||||||||||
2054 | - | |||||||||||||||||||||||||||||||
2055 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||
2056 | exact shape intersects with or is contained by \a polygon are returned. | - | ||||||||||||||||||||||||||||||
2057 | - | |||||||||||||||||||||||||||||||
2058 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2059 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2060 | - | |||||||||||||||||||||||||||||||
2061 | \sa itemAt(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2062 | */ | - | ||||||||||||||||||||||||||||||
2063 | QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2064 | Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2065 | { | - | ||||||||||||||||||||||||||||||
2066 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2067 | return d->index->items(polygon, mode, order, deviceTransform); never executed: return d->index->items(polygon, mode, order, deviceTransform); | 0 | ||||||||||||||||||||||||||||||
2068 | } | - | ||||||||||||||||||||||||||||||
2069 | - | |||||||||||||||||||||||||||||||
2070 | /*! | - | ||||||||||||||||||||||||||||||
2071 | \fn QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2072 | \overload | - | ||||||||||||||||||||||||||||||
2073 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2074 | - | |||||||||||||||||||||||||||||||
2075 | \brief Returns all visible items that, depending on \a mode, are | - | ||||||||||||||||||||||||||||||
2076 | either inside or intersect with the specified \a path, in a | - | ||||||||||||||||||||||||||||||
2077 | list sorted using \a order. In this case, "visible" defines items for which: | - | ||||||||||||||||||||||||||||||
2078 | isVisible() returns \c true, effectiveOpacity() returns a value greater than 0.0 | - | ||||||||||||||||||||||||||||||
2079 | (which is fully transparent) and the parent item does not clip it. | - | ||||||||||||||||||||||||||||||
2080 | - | |||||||||||||||||||||||||||||||
2081 | The default value for \a mode is Qt::IntersectsItemShape; all items whose | - | ||||||||||||||||||||||||||||||
2082 | exact shape intersects with or is contained by \a path are returned. | - | ||||||||||||||||||||||||||||||
2083 | - | |||||||||||||||||||||||||||||||
2084 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2085 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2086 | - | |||||||||||||||||||||||||||||||
2087 | \sa itemAt(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2088 | */ | - | ||||||||||||||||||||||||||||||
2089 | QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2090 | Qt::SortOrder order, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2091 | { | - | ||||||||||||||||||||||||||||||
2092 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2093 | return d->index->items(path, mode, order, deviceTransform); never executed: return d->index->items(path, mode, order, deviceTransform); | 0 | ||||||||||||||||||||||||||||||
2094 | } | - | ||||||||||||||||||||||||||||||
2095 | - | |||||||||||||||||||||||||||||||
2096 | /*! | - | ||||||||||||||||||||||||||||||
2097 | Returns a list of all items that collide with \a item. Collisions are | - | ||||||||||||||||||||||||||||||
2098 | determined by calling QGraphicsItem::collidesWithItem(); the collision | - | ||||||||||||||||||||||||||||||
2099 | detection is determined by \a mode. By default, all items whose shape | - | ||||||||||||||||||||||||||||||
2100 | intersects \a item or is contained inside \a item's shape are returned. | - | ||||||||||||||||||||||||||||||
2101 | - | |||||||||||||||||||||||||||||||
2102 | The items are returned in descending stacking order (i.e., the first item | - | ||||||||||||||||||||||||||||||
2103 | in the list is the uppermost item, and the last item is the lowermost | - | ||||||||||||||||||||||||||||||
2104 | item). | - | ||||||||||||||||||||||||||||||
2105 | - | |||||||||||||||||||||||||||||||
2106 | \sa items(), itemAt(), QGraphicsItem::collidesWithItem(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2107 | */ | - | ||||||||||||||||||||||||||||||
2108 | QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item, | - | ||||||||||||||||||||||||||||||
2109 | Qt::ItemSelectionMode mode) const | - | ||||||||||||||||||||||||||||||
2110 | { | - | ||||||||||||||||||||||||||||||
2111 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2112 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
2113 | qWarning("QGraphicsScene::collidingItems: cannot find collisions for null item"); | - | ||||||||||||||||||||||||||||||
2114 | return QList<QGraphicsItem *>(); never executed: return QList<QGraphicsItem *>(); | 0 | ||||||||||||||||||||||||||||||
2115 | } | - | ||||||||||||||||||||||||||||||
2116 | - | |||||||||||||||||||||||||||||||
2117 | // Does not support ItemIgnoresTransformations. | - | ||||||||||||||||||||||||||||||
2118 | QList<QGraphicsItem *> tmp; | - | ||||||||||||||||||||||||||||||
2119 | foreach (QGraphicsItem *itemInVicinity, d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder)) { | - | ||||||||||||||||||||||||||||||
2120 | if (item != itemInVicinity && item->collidesWithItem(itemInVicinity, mode))
| 0 | ||||||||||||||||||||||||||||||
2121 | tmp << itemInVicinity; never executed: tmp << itemInVicinity; | 0 | ||||||||||||||||||||||||||||||
2122 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2123 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||||||||||||||
2124 | } | - | ||||||||||||||||||||||||||||||
2125 | - | |||||||||||||||||||||||||||||||
2126 | /*! | - | ||||||||||||||||||||||||||||||
2127 | \fn QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position) const | - | ||||||||||||||||||||||||||||||
2128 | \overload | - | ||||||||||||||||||||||||||||||
2129 | \obsolete | - | ||||||||||||||||||||||||||||||
2130 | - | |||||||||||||||||||||||||||||||
2131 | Returns the topmost visible item at the specified \a position, or 0 if | - | ||||||||||||||||||||||||||||||
2132 | there are no items at this position. | - | ||||||||||||||||||||||||||||||
2133 | - | |||||||||||||||||||||||||||||||
2134 | This function is deprecated and returns incorrect results if the scene | - | ||||||||||||||||||||||||||||||
2135 | contains items that ignore transformations. Use the overload that takes | - | ||||||||||||||||||||||||||||||
2136 | a QTransform instead. | - | ||||||||||||||||||||||||||||||
2137 | - | |||||||||||||||||||||||||||||||
2138 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
2139 | - | |||||||||||||||||||||||||||||||
2140 | \sa items(), collidingItems(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2141 | */ | - | ||||||||||||||||||||||||||||||
2142 | - | |||||||||||||||||||||||||||||||
2143 | /*! | - | ||||||||||||||||||||||||||||||
2144 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2145 | - | |||||||||||||||||||||||||||||||
2146 | Returns the topmost visible item at the specified \a position, or 0 | - | ||||||||||||||||||||||||||||||
2147 | if there are no items at this position. | - | ||||||||||||||||||||||||||||||
2148 | - | |||||||||||||||||||||||||||||||
2149 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2150 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2151 | - | |||||||||||||||||||||||||||||||
2152 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
2153 | - | |||||||||||||||||||||||||||||||
2154 | \sa items(), collidingItems(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2155 | */ | - | ||||||||||||||||||||||||||||||
2156 | QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2157 | { | - | ||||||||||||||||||||||||||||||
2158 | QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape, | - | ||||||||||||||||||||||||||||||
2159 | Qt::DescendingOrder, deviceTransform); | - | ||||||||||||||||||||||||||||||
2160 | return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first(); never executed: return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
| 0 | ||||||||||||||||||||||||||||||
2161 | } | - | ||||||||||||||||||||||||||||||
2162 | - | |||||||||||||||||||||||||||||||
2163 | /*! | - | ||||||||||||||||||||||||||||||
2164 | \fn QGraphicsScene::itemAt(qreal x, qreal y, const QTransform &deviceTransform) const | - | ||||||||||||||||||||||||||||||
2165 | \overload | - | ||||||||||||||||||||||||||||||
2166 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2167 | - | |||||||||||||||||||||||||||||||
2168 | Returns the topmost visible item at the position specified by (\a x, \a | - | ||||||||||||||||||||||||||||||
2169 | y), or 0 if there are no items at this position. | - | ||||||||||||||||||||||||||||||
2170 | - | |||||||||||||||||||||||||||||||
2171 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2172 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2173 | - | |||||||||||||||||||||||||||||||
2174 | This convenience function is equivalent to calling \c | - | ||||||||||||||||||||||||||||||
2175 | {itemAt(QPointF(x, y), deviceTransform)}. | - | ||||||||||||||||||||||||||||||
2176 | - | |||||||||||||||||||||||||||||||
2177 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
2178 | */ | - | ||||||||||||||||||||||||||||||
2179 | - | |||||||||||||||||||||||||||||||
2180 | /*! | - | ||||||||||||||||||||||||||||||
2181 | \fn QGraphicsScene::itemAt(qreal x, qreal y) const | - | ||||||||||||||||||||||||||||||
2182 | \overload | - | ||||||||||||||||||||||||||||||
2183 | \obsolete | - | ||||||||||||||||||||||||||||||
2184 | - | |||||||||||||||||||||||||||||||
2185 | Returns the topmost visible item at the position specified by (\a x, \a | - | ||||||||||||||||||||||||||||||
2186 | y), or 0 if there are no items at this position. | - | ||||||||||||||||||||||||||||||
2187 | - | |||||||||||||||||||||||||||||||
2188 | This convenience function is equivalent to calling \c | - | ||||||||||||||||||||||||||||||
2189 | {itemAt(QPointF(x, y))}. | - | ||||||||||||||||||||||||||||||
2190 | - | |||||||||||||||||||||||||||||||
2191 | This function is deprecated and returns incorrect results if the scene | - | ||||||||||||||||||||||||||||||
2192 | contains items that ignore transformations. Use the overload that takes | - | ||||||||||||||||||||||||||||||
2193 | a QTransform instead. | - | ||||||||||||||||||||||||||||||
2194 | - | |||||||||||||||||||||||||||||||
2195 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
2196 | */ | - | ||||||||||||||||||||||||||||||
2197 | - | |||||||||||||||||||||||||||||||
2198 | /*! | - | ||||||||||||||||||||||||||||||
2199 | Returns a list of all currently selected items. The items are | - | ||||||||||||||||||||||||||||||
2200 | returned in no particular order. | - | ||||||||||||||||||||||||||||||
2201 | - | |||||||||||||||||||||||||||||||
2202 | \sa setSelectionArea() | - | ||||||||||||||||||||||||||||||
2203 | */ | - | ||||||||||||||||||||||||||||||
2204 | QList<QGraphicsItem *> QGraphicsScene::selectedItems() const | - | ||||||||||||||||||||||||||||||
2205 | { | - | ||||||||||||||||||||||||||||||
2206 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2207 | - | |||||||||||||||||||||||||||||||
2208 | // Optimization: Lazily removes items that are not selected. | - | ||||||||||||||||||||||||||||||
2209 | QGraphicsScene *that = const_cast<QGraphicsScene *>(this); | - | ||||||||||||||||||||||||||||||
2210 | QSet<QGraphicsItem *> actuallySelectedSet; | - | ||||||||||||||||||||||||||||||
2211 | foreach (QGraphicsItem *item, that->d_func()->selectedItems) { | - | ||||||||||||||||||||||||||||||
2212 | if (item->isSelected())
| 0 | ||||||||||||||||||||||||||||||
2213 | actuallySelectedSet << item; never executed: actuallySelectedSet << item; | 0 | ||||||||||||||||||||||||||||||
2214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2215 | - | |||||||||||||||||||||||||||||||
2216 | that->d_func()->selectedItems = actuallySelectedSet; | - | ||||||||||||||||||||||||||||||
2217 | - | |||||||||||||||||||||||||||||||
2218 | return d->selectedItems.values(); never executed: return d->selectedItems.values(); | 0 | ||||||||||||||||||||||||||||||
2219 | } | - | ||||||||||||||||||||||||||||||
2220 | - | |||||||||||||||||||||||||||||||
2221 | /*! | - | ||||||||||||||||||||||||||||||
2222 | Returns the selection area that was previously set with | - | ||||||||||||||||||||||||||||||
2223 | setSelectionArea(), or an empty QPainterPath if no selection area has been | - | ||||||||||||||||||||||||||||||
2224 | set. | - | ||||||||||||||||||||||||||||||
2225 | - | |||||||||||||||||||||||||||||||
2226 | \sa setSelectionArea() | - | ||||||||||||||||||||||||||||||
2227 | */ | - | ||||||||||||||||||||||||||||||
2228 | QPainterPath QGraphicsScene::selectionArea() const | - | ||||||||||||||||||||||||||||||
2229 | { | - | ||||||||||||||||||||||||||||||
2230 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2231 | return d->selectionArea; never executed: return d->selectionArea; | 0 | ||||||||||||||||||||||||||||||
2232 | } | - | ||||||||||||||||||||||||||||||
2233 | - | |||||||||||||||||||||||||||||||
2234 | /*! | - | ||||||||||||||||||||||||||||||
2235 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2236 | - | |||||||||||||||||||||||||||||||
2237 | Sets the selection area to \a path. All items within this area are | - | ||||||||||||||||||||||||||||||
2238 | immediately selected, and all items outside are unselected. You can get | - | ||||||||||||||||||||||||||||||
2239 | the list of all selected items by calling selectedItems(). | - | ||||||||||||||||||||||||||||||
2240 | - | |||||||||||||||||||||||||||||||
2241 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2242 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2243 | - | |||||||||||||||||||||||||||||||
2244 | For an item to be selected, it must be marked as \e selectable | - | ||||||||||||||||||||||||||||||
2245 | (QGraphicsItem::ItemIsSelectable). | - | ||||||||||||||||||||||||||||||
2246 | - | |||||||||||||||||||||||||||||||
2247 | \sa clearSelection(), selectionArea() | - | ||||||||||||||||||||||||||||||
2248 | */ | - | ||||||||||||||||||||||||||||||
2249 | void QGraphicsScene::setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform) | - | ||||||||||||||||||||||||||||||
2250 | { | - | ||||||||||||||||||||||||||||||
2251 | setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform); | - | ||||||||||||||||||||||||||||||
2252 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2253 | - | |||||||||||||||||||||||||||||||
2254 | /*! | - | ||||||||||||||||||||||||||||||
2255 | \overload | - | ||||||||||||||||||||||||||||||
2256 | \since 4.6 | - | ||||||||||||||||||||||||||||||
2257 | - | |||||||||||||||||||||||||||||||
2258 | Sets the selection area to \a path using \a mode to determine if items are | - | ||||||||||||||||||||||||||||||
2259 | included in the selection area. | - | ||||||||||||||||||||||||||||||
2260 | - | |||||||||||||||||||||||||||||||
2261 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2262 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2263 | - | |||||||||||||||||||||||||||||||
2264 | \sa clearSelection(), selectionArea() | - | ||||||||||||||||||||||||||||||
2265 | */ | - | ||||||||||||||||||||||||||||||
2266 | void QGraphicsScene::setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2267 | const QTransform &deviceTransform) | - | ||||||||||||||||||||||||||||||
2268 | { | - | ||||||||||||||||||||||||||||||
2269 | setSelectionArea(path, Qt::ReplaceSelection, mode, deviceTransform); | - | ||||||||||||||||||||||||||||||
2270 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2271 | - | |||||||||||||||||||||||||||||||
2272 | /*! | - | ||||||||||||||||||||||||||||||
2273 | \overload | - | ||||||||||||||||||||||||||||||
2274 | \since 5.5 | - | ||||||||||||||||||||||||||||||
2275 | - | |||||||||||||||||||||||||||||||
2276 | Sets the selection area to \a path using \a mode to determine if items are | - | ||||||||||||||||||||||||||||||
2277 | included in the selection area. | - | ||||||||||||||||||||||||||||||
2278 | - | |||||||||||||||||||||||||||||||
2279 | \a deviceTransform is the transformation that applies to the view, and needs to | - | ||||||||||||||||||||||||||||||
2280 | be provided if the scene contains items that ignore transformations. | - | ||||||||||||||||||||||||||||||
2281 | - | |||||||||||||||||||||||||||||||
2282 | \a selectionOperation determines what to do with the currently selected items. | - | ||||||||||||||||||||||||||||||
2283 | - | |||||||||||||||||||||||||||||||
2284 | \sa clearSelection(), selectionArea() | - | ||||||||||||||||||||||||||||||
2285 | */ | - | ||||||||||||||||||||||||||||||
2286 | void QGraphicsScene::setSelectionArea(const QPainterPath &path, | - | ||||||||||||||||||||||||||||||
2287 | Qt::ItemSelectionOperation selectionOperation, | - | ||||||||||||||||||||||||||||||
2288 | Qt::ItemSelectionMode mode, | - | ||||||||||||||||||||||||||||||
2289 | const QTransform &deviceTransform) | - | ||||||||||||||||||||||||||||||
2290 | { | - | ||||||||||||||||||||||||||||||
2291 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2292 | - | |||||||||||||||||||||||||||||||
2293 | // Note: with boolean path operations, we can improve performance here | - | ||||||||||||||||||||||||||||||
2294 | // quite a lot by "growing" the old path instead of replacing it. That | - | ||||||||||||||||||||||||||||||
2295 | // allows us to only check the intersect area for changes, instead of | - | ||||||||||||||||||||||||||||||
2296 | // reevaluating the whole path over again. | - | ||||||||||||||||||||||||||||||
2297 | d->selectionArea = path; | - | ||||||||||||||||||||||||||||||
2298 | - | |||||||||||||||||||||||||||||||
2299 | QSet<QGraphicsItem *> unselectItems = d->selectedItems; | - | ||||||||||||||||||||||||||||||
2300 | - | |||||||||||||||||||||||||||||||
2301 | // Disable emitting selectionChanged() for individual items. | - | ||||||||||||||||||||||||||||||
2302 | ++d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2303 | bool changed = false; | - | ||||||||||||||||||||||||||||||
2304 | - | |||||||||||||||||||||||||||||||
2305 | // Set all items in path to selected. | - | ||||||||||||||||||||||||||||||
2306 | foreach (QGraphicsItem *item, items(path, mode, Qt::DescendingOrder, deviceTransform)) { | - | ||||||||||||||||||||||||||||||
2307 | if (item->flags() & QGraphicsItem::ItemIsSelectable) {
| 0 | ||||||||||||||||||||||||||||||
2308 | if (!item->isSelected())
| 0 | ||||||||||||||||||||||||||||||
2309 | changed = true; never executed: changed = true; | 0 | ||||||||||||||||||||||||||||||
2310 | unselectItems.remove(item); | - | ||||||||||||||||||||||||||||||
2311 | item->setSelected(true); | - | ||||||||||||||||||||||||||||||
2312 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2313 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2314 | - | |||||||||||||||||||||||||||||||
2315 | switch (selectionOperation) { | - | ||||||||||||||||||||||||||||||
2316 | case Qt::ReplaceSelection: never executed: case Qt::ReplaceSelection: | 0 | ||||||||||||||||||||||||||||||
2317 | // Deselect all items outside path. | - | ||||||||||||||||||||||||||||||
2318 | foreach (QGraphicsItem *item, unselectItems) { | - | ||||||||||||||||||||||||||||||
2319 | item->setSelected(false); | - | ||||||||||||||||||||||||||||||
2320 | changed = true; | - | ||||||||||||||||||||||||||||||
2321 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2322 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
2323 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
2324 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
2325 | } | - | ||||||||||||||||||||||||||||||
2326 | - | |||||||||||||||||||||||||||||||
2327 | // Reenable emitting selectionChanged() for individual items. | - | ||||||||||||||||||||||||||||||
2328 | --d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2329 | - | |||||||||||||||||||||||||||||||
2330 | if (!d->selectionChanging && changed)
| 0 | ||||||||||||||||||||||||||||||
2331 | emit selectionChanged(); never executed: selectionChanged(); | 0 | ||||||||||||||||||||||||||||||
2332 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2333 | - | |||||||||||||||||||||||||||||||
2334 | /*! | - | ||||||||||||||||||||||||||||||
2335 | Clears the current selection. | - | ||||||||||||||||||||||||||||||
2336 | - | |||||||||||||||||||||||||||||||
2337 | \sa setSelectionArea(), selectedItems() | - | ||||||||||||||||||||||||||||||
2338 | */ | - | ||||||||||||||||||||||||||||||
2339 | void QGraphicsScene::clearSelection() | - | ||||||||||||||||||||||||||||||
2340 | { | - | ||||||||||||||||||||||||||||||
2341 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2342 | - | |||||||||||||||||||||||||||||||
2343 | // Disable emitting selectionChanged | - | ||||||||||||||||||||||||||||||
2344 | ++d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2345 | bool changed = !d->selectedItems.isEmpty(); | - | ||||||||||||||||||||||||||||||
2346 | - | |||||||||||||||||||||||||||||||
2347 | foreach (QGraphicsItem *item, d->selectedItems) | - | ||||||||||||||||||||||||||||||
2348 | item->setSelected(false); never executed: item->setSelected(false); | 0 | ||||||||||||||||||||||||||||||
2349 | d->selectedItems.clear(); | - | ||||||||||||||||||||||||||||||
2350 | - | |||||||||||||||||||||||||||||||
2351 | // Reenable emitting selectionChanged() for individual items. | - | ||||||||||||||||||||||||||||||
2352 | --d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2353 | - | |||||||||||||||||||||||||||||||
2354 | if (!d->selectionChanging && changed)
| 0 | ||||||||||||||||||||||||||||||
2355 | emit selectionChanged(); never executed: selectionChanged(); | 0 | ||||||||||||||||||||||||||||||
2356 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2357 | - | |||||||||||||||||||||||||||||||
2358 | /*! | - | ||||||||||||||||||||||||||||||
2359 | \since 4.4 | - | ||||||||||||||||||||||||||||||
2360 | - | |||||||||||||||||||||||||||||||
2361 | Removes and deletes all items from the scene, but otherwise leaves the | - | ||||||||||||||||||||||||||||||
2362 | state of the scene unchanged. | - | ||||||||||||||||||||||||||||||
2363 | - | |||||||||||||||||||||||||||||||
2364 | \sa addItem() | - | ||||||||||||||||||||||||||||||
2365 | */ | - | ||||||||||||||||||||||||||||||
2366 | void QGraphicsScene::clear() | - | ||||||||||||||||||||||||||||||
2367 | { | - | ||||||||||||||||||||||||||||||
2368 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2369 | // NB! We have to clear the index before deleting items; otherwise the | - | ||||||||||||||||||||||||||||||
2370 | // index might try to access dangling item pointers. | - | ||||||||||||||||||||||||||||||
2371 | d->index->clear(); | - | ||||||||||||||||||||||||||||||
2372 | // NB! QGraphicsScenePrivate::unregisterTopLevelItem() removes items | - | ||||||||||||||||||||||||||||||
2373 | while (!d->topLevelItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
2374 | delete d->topLevelItems.first(); never executed: delete d->topLevelItems.first(); | 0 | ||||||||||||||||||||||||||||||
2375 | Q_ASSERT(d->topLevelItems.isEmpty()); | - | ||||||||||||||||||||||||||||||
2376 | d->lastItemCount = 0; | - | ||||||||||||||||||||||||||||||
2377 | d->allItemsIgnoreHoverEvents = true; | - | ||||||||||||||||||||||||||||||
2378 | d->allItemsUseDefaultCursor = true; | - | ||||||||||||||||||||||||||||||
2379 | d->allItemsIgnoreTouchEvents = true; | - | ||||||||||||||||||||||||||||||
2380 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2381 | - | |||||||||||||||||||||||||||||||
2382 | /*! | - | ||||||||||||||||||||||||||||||
2383 | Groups all items in \a items into a new QGraphicsItemGroup, and returns a | - | ||||||||||||||||||||||||||||||
2384 | pointer to the group. The group is created with the common ancestor of \a | - | ||||||||||||||||||||||||||||||
2385 | items as its parent, and with position (0, 0). The items are all | - | ||||||||||||||||||||||||||||||
2386 | reparented to the group, and their positions and transformations are | - | ||||||||||||||||||||||||||||||
2387 | mapped to the group. If \a items is empty, this function will return an | - | ||||||||||||||||||||||||||||||
2388 | empty top-level QGraphicsItemGroup. | - | ||||||||||||||||||||||||||||||
2389 | - | |||||||||||||||||||||||||||||||
2390 | QGraphicsScene has ownership of the group item; you do not need to delete | - | ||||||||||||||||||||||||||||||
2391 | it. To dismantle (ungroup) a group, call destroyItemGroup(). | - | ||||||||||||||||||||||||||||||
2392 | - | |||||||||||||||||||||||||||||||
2393 | \sa destroyItemGroup(), QGraphicsItemGroup::addToGroup() | - | ||||||||||||||||||||||||||||||
2394 | */ | - | ||||||||||||||||||||||||||||||
2395 | QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *> &items) | - | ||||||||||||||||||||||||||||||
2396 | { | - | ||||||||||||||||||||||||||||||
2397 | // Build a list of the first item's ancestors | - | ||||||||||||||||||||||||||||||
2398 | QList<QGraphicsItem *> ancestors; | - | ||||||||||||||||||||||||||||||
2399 | int n = 0; | - | ||||||||||||||||||||||||||||||
2400 | if (!items.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
2401 | QGraphicsItem *parent = items.at(n++); | - | ||||||||||||||||||||||||||||||
2402 | while ((parent = parent->parentItem()))
| 0 | ||||||||||||||||||||||||||||||
2403 | ancestors.append(parent); never executed: ancestors.append(parent); | 0 | ||||||||||||||||||||||||||||||
2404 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2405 | - | |||||||||||||||||||||||||||||||
2406 | // Find the common ancestor for all items | - | ||||||||||||||||||||||||||||||
2407 | QGraphicsItem *commonAncestor = 0; | - | ||||||||||||||||||||||||||||||
2408 | if (!ancestors.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
2409 | while (n < items.size()) {
| 0 | ||||||||||||||||||||||||||||||
2410 | int commonIndex = -1; | - | ||||||||||||||||||||||||||||||
2411 | QGraphicsItem *parent = items.at(n++); | - | ||||||||||||||||||||||||||||||
2412 | do { | - | ||||||||||||||||||||||||||||||
2413 | int index = ancestors.indexOf(parent, qMax(0, commonIndex)); | - | ||||||||||||||||||||||||||||||
2414 | if (index != -1) {
| 0 | ||||||||||||||||||||||||||||||
2415 | commonIndex = index; | - | ||||||||||||||||||||||||||||||
2416 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
2417 | } | - | ||||||||||||||||||||||||||||||
2418 | } while ((parent = parent->parentItem())); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
2419 | - | |||||||||||||||||||||||||||||||
2420 | if (commonIndex == -1) {
| 0 | ||||||||||||||||||||||||||||||
2421 | commonAncestor = 0; | - | ||||||||||||||||||||||||||||||
2422 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
2423 | } | - | ||||||||||||||||||||||||||||||
2424 | - | |||||||||||||||||||||||||||||||
2425 | commonAncestor = ancestors.at(commonIndex); | - | ||||||||||||||||||||||||||||||
2426 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2427 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2428 | - | |||||||||||||||||||||||||||||||
2429 | // Create a new group at that level | - | ||||||||||||||||||||||||||||||
2430 | QGraphicsItemGroup *group = new QGraphicsItemGroup(commonAncestor); | - | ||||||||||||||||||||||||||||||
2431 | if (!commonAncestor)
| 0 | ||||||||||||||||||||||||||||||
2432 | addItem(group); never executed: addItem(group); | 0 | ||||||||||||||||||||||||||||||
2433 | foreach (QGraphicsItem *item, items) | - | ||||||||||||||||||||||||||||||
2434 | group->addToGroup(item); never executed: group->addToGroup(item); | 0 | ||||||||||||||||||||||||||||||
2435 | return group; never executed: return group; | 0 | ||||||||||||||||||||||||||||||
2436 | } | - | ||||||||||||||||||||||||||||||
2437 | - | |||||||||||||||||||||||||||||||
2438 | /*! | - | ||||||||||||||||||||||||||||||
2439 | Reparents all items in \a group to \a group's parent item, then removes \a | - | ||||||||||||||||||||||||||||||
2440 | group from the scene, and finally deletes it. The items' positions and | - | ||||||||||||||||||||||||||||||
2441 | transformations are mapped from the group to the group's parent. | - | ||||||||||||||||||||||||||||||
2442 | - | |||||||||||||||||||||||||||||||
2443 | \sa createItemGroup(), QGraphicsItemGroup::removeFromGroup() | - | ||||||||||||||||||||||||||||||
2444 | */ | - | ||||||||||||||||||||||||||||||
2445 | void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup *group) | - | ||||||||||||||||||||||||||||||
2446 | { | - | ||||||||||||||||||||||||||||||
2447 | foreach (QGraphicsItem *item, group->childItems()) | - | ||||||||||||||||||||||||||||||
2448 | group->removeFromGroup(item); never executed: group->removeFromGroup(item); | 0 | ||||||||||||||||||||||||||||||
2449 | removeItem(group); | - | ||||||||||||||||||||||||||||||
2450 | delete group; | - | ||||||||||||||||||||||||||||||
2451 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2452 | - | |||||||||||||||||||||||||||||||
2453 | /*! | - | ||||||||||||||||||||||||||||||
2454 | Adds or moves the \a item and all its childen to this scene. | - | ||||||||||||||||||||||||||||||
2455 | This scene takes ownership of the \a item. | - | ||||||||||||||||||||||||||||||
2456 | - | |||||||||||||||||||||||||||||||
2457 | If the item is visible (i.e., QGraphicsItem::isVisible() returns | - | ||||||||||||||||||||||||||||||
2458 | true), QGraphicsScene will emit changed() once control goes back | - | ||||||||||||||||||||||||||||||
2459 | to the event loop. | - | ||||||||||||||||||||||||||||||
2460 | - | |||||||||||||||||||||||||||||||
2461 | If the item is already in a different scene, it will first be | - | ||||||||||||||||||||||||||||||
2462 | removed from its old scene, and then added to this scene as a | - | ||||||||||||||||||||||||||||||
2463 | top-level. | - | ||||||||||||||||||||||||||||||
2464 | - | |||||||||||||||||||||||||||||||
2465 | QGraphicsScene will send ItemSceneChange notifications to \a item | - | ||||||||||||||||||||||||||||||
2466 | while it is added to the scene. If item does not currently belong | - | ||||||||||||||||||||||||||||||
2467 | to a scene, only one notification is sent. If it does belong to | - | ||||||||||||||||||||||||||||||
2468 | scene already (i.e., it is moved to this scene), QGraphicsScene | - | ||||||||||||||||||||||||||||||
2469 | will send an addition notification as the item is removed from its | - | ||||||||||||||||||||||||||||||
2470 | previous scene. | - | ||||||||||||||||||||||||||||||
2471 | - | |||||||||||||||||||||||||||||||
2472 | If the item is a panel, the scene is active, and there is no | - | ||||||||||||||||||||||||||||||
2473 | active panel in the scene, then the item will be activated. | - | ||||||||||||||||||||||||||||||
2474 | - | |||||||||||||||||||||||||||||||
2475 | \sa removeItem(), addEllipse(), addLine(), addPath(), addPixmap(), | - | ||||||||||||||||||||||||||||||
2476 | addRect(), addText(), addWidget(), {QGraphicsItem#Sorting}{Sorting} | - | ||||||||||||||||||||||||||||||
2477 | */ | - | ||||||||||||||||||||||||||||||
2478 | void QGraphicsScene::addItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
2479 | { | - | ||||||||||||||||||||||||||||||
2480 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2481 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
2482 | qWarning("QGraphicsScene::addItem: cannot add null item"); | - | ||||||||||||||||||||||||||||||
2483 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2484 | } | - | ||||||||||||||||||||||||||||||
2485 | if (item->d_ptr->scene == this) {
| 0 | ||||||||||||||||||||||||||||||
2486 | qWarning("QGraphicsScene::addItem: item has already been added to this scene"); | - | ||||||||||||||||||||||||||||||
2487 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2488 | } | - | ||||||||||||||||||||||||||||||
2489 | // Remove this item from its existing scene | - | ||||||||||||||||||||||||||||||
2490 | if (QGraphicsScene *oldScene = item->d_ptr->scene)
| 0 | ||||||||||||||||||||||||||||||
2491 | oldScene->removeItem(item); never executed: oldScene->removeItem(item); | 0 | ||||||||||||||||||||||||||||||
2492 | - | |||||||||||||||||||||||||||||||
2493 | // Notify the item that its scene is changing, and allow the item to | - | ||||||||||||||||||||||||||||||
2494 | // react. | - | ||||||||||||||||||||||||||||||
2495 | const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, | - | ||||||||||||||||||||||||||||||
2496 | QVariant::fromValue<QGraphicsScene *>(this))); | - | ||||||||||||||||||||||||||||||
2497 | QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant); | - | ||||||||||||||||||||||||||||||
2498 | if (targetScene != this) {
| 0 | ||||||||||||||||||||||||||||||
2499 | if (targetScene && item->d_ptr->scene != targetScene)
| 0 | ||||||||||||||||||||||||||||||
2500 | targetScene->addItem(item); never executed: targetScene->addItem(item); | 0 | ||||||||||||||||||||||||||||||
2501 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2502 | } | - | ||||||||||||||||||||||||||||||
2503 | - | |||||||||||||||||||||||||||||||
2504 | // QDeclarativeItems do not rely on initial itemChanged message, as the componentComplete | - | ||||||||||||||||||||||||||||||
2505 | // function allows far more opportunity for delayed-construction optimization. | - | ||||||||||||||||||||||||||||||
2506 | if (!item->d_ptr->isDeclarativeItem) {
| 0 | ||||||||||||||||||||||||||||||
2507 | if (d->unpolishedItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
2508 | QMetaMethod method = metaObject()->method(d->polishItemsIndex); | - | ||||||||||||||||||||||||||||||
2509 | method.invoke(this, Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
2510 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2511 | d->unpolishedItems.append(item); | - | ||||||||||||||||||||||||||||||
2512 | item->d_ptr->pendingPolish = true; | - | ||||||||||||||||||||||||||||||
2513 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2514 | - | |||||||||||||||||||||||||||||||
2515 | // Detach this item from its parent if the parent's scene is different | - | ||||||||||||||||||||||||||||||
2516 | // from this scene. | - | ||||||||||||||||||||||||||||||
2517 | if (QGraphicsItem *itemParent = item->d_ptr->parent) {
| 0 | ||||||||||||||||||||||||||||||
2518 | if (itemParent->d_ptr->scene != this)
| 0 | ||||||||||||||||||||||||||||||
2519 | item->setParentItem(0); never executed: item->setParentItem(0); | 0 | ||||||||||||||||||||||||||||||
2520 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2521 | - | |||||||||||||||||||||||||||||||
2522 | // Add the item to this scene | - | ||||||||||||||||||||||||||||||
2523 | item->d_func()->scene = targetScene; | - | ||||||||||||||||||||||||||||||
2524 | - | |||||||||||||||||||||||||||||||
2525 | // Add the item in the index | - | ||||||||||||||||||||||||||||||
2526 | d->index->addItem(item); | - | ||||||||||||||||||||||||||||||
2527 | - | |||||||||||||||||||||||||||||||
2528 | // Add to list of toplevels if this item is a toplevel. | - | ||||||||||||||||||||||||||||||
2529 | if (!item->d_ptr->parent)
| 0 | ||||||||||||||||||||||||||||||
2530 | d->registerTopLevelItem(item); never executed: d->registerTopLevelItem(item); | 0 | ||||||||||||||||||||||||||||||
2531 | - | |||||||||||||||||||||||||||||||
2532 | // Add to list of items that require an update. We cannot assume that the | - | ||||||||||||||||||||||||||||||
2533 | // item is fully constructed, so calling item->update() can lead to a pure | - | ||||||||||||||||||||||||||||||
2534 | // virtual function call to boundingRect(). | - | ||||||||||||||||||||||||||||||
2535 | d->markDirty(item); | - | ||||||||||||||||||||||||||||||
2536 | d->dirtyGrowingItemsBoundingRect = true; | - | ||||||||||||||||||||||||||||||
2537 | - | |||||||||||||||||||||||||||||||
2538 | // Disable selectionChanged() for individual items | - | ||||||||||||||||||||||||||||||
2539 | ++d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2540 | int oldSelectedItemSize = d->selectedItems.size(); | - | ||||||||||||||||||||||||||||||
2541 | - | |||||||||||||||||||||||||||||||
2542 | // Enable mouse tracking if the item accepts hover events or has a cursor set. | - | ||||||||||||||||||||||||||||||
2543 | if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
| 0 | ||||||||||||||||||||||||||||||
2544 | d->allItemsIgnoreHoverEvents = false; | - | ||||||||||||||||||||||||||||||
2545 | d->enableMouseTrackingOnViews(); | - | ||||||||||||||||||||||||||||||
2546 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2547 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||
2548 | if (d->allItemsUseDefaultCursor && item->d_ptr->hasCursor) {
| 0 | ||||||||||||||||||||||||||||||
2549 | d->allItemsUseDefaultCursor = false; | - | ||||||||||||||||||||||||||||||
2550 | if (d->allItemsIgnoreHoverEvents) // already enabled otherwise
| 0 | ||||||||||||||||||||||||||||||
2551 | d->enableMouseTrackingOnViews(); never executed: d->enableMouseTrackingOnViews(); | 0 | ||||||||||||||||||||||||||||||
2552 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2553 | #endif //QT_NO_CURSOR | - | ||||||||||||||||||||||||||||||
2554 | - | |||||||||||||||||||||||||||||||
2555 | // Enable touch events if the item accepts touch events. | - | ||||||||||||||||||||||||||||||
2556 | if (d->allItemsIgnoreTouchEvents && item->d_ptr->acceptTouchEvents) {
| 0 | ||||||||||||||||||||||||||||||
2557 | d->allItemsIgnoreTouchEvents = false; | - | ||||||||||||||||||||||||||||||
2558 | d->enableTouchEventsOnViews(); | - | ||||||||||||||||||||||||||||||
2559 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2560 | - | |||||||||||||||||||||||||||||||
2561 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
2562 | foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys()) | - | ||||||||||||||||||||||||||||||
2563 | d->grabGesture(item, gesture); never executed: d->grabGesture(item, gesture); | 0 | ||||||||||||||||||||||||||||||
2564 | #endif | - | ||||||||||||||||||||||||||||||
2565 | - | |||||||||||||||||||||||||||||||
2566 | // Update selection lists | - | ||||||||||||||||||||||||||||||
2567 | if (item->isSelected())
| 0 | ||||||||||||||||||||||||||||||
2568 | d->selectedItems << item; never executed: d->selectedItems << item; | 0 | ||||||||||||||||||||||||||||||
2569 | if (item->isWidget() && item->isVisible() && static_cast<QGraphicsWidget *>(item)->windowType() == Qt::Popup)
| 0 | ||||||||||||||||||||||||||||||
2570 | d->addPopup(static_cast<QGraphicsWidget *>(item)); never executed: d->addPopup(static_cast<QGraphicsWidget *>(item)); | 0 | ||||||||||||||||||||||||||||||
2571 | if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
| 0 | ||||||||||||||||||||||||||||||
2572 | d->enterModal(item); never executed: d->enterModal(item); | 0 | ||||||||||||||||||||||||||||||
2573 | - | |||||||||||||||||||||||||||||||
2574 | // Update creation order focus chain. Make sure to leave the widget's | - | ||||||||||||||||||||||||||||||
2575 | // internal tab order intact. | - | ||||||||||||||||||||||||||||||
2576 | if (item->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
2577 | QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||||||||||||||
2578 | if (!d->tabFocusFirst) {
| 0 | ||||||||||||||||||||||||||||||
2579 | // No first tab focus widget - make this the first tab focus | - | ||||||||||||||||||||||||||||||
2580 | // widget. | - | ||||||||||||||||||||||||||||||
2581 | d->tabFocusFirst = widget; | - | ||||||||||||||||||||||||||||||
2582 | } else if (!widget->parentWidget() && !widget->isPanel()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
2583 | // Adding a widget that is not part of a tab focus chain. | - | ||||||||||||||||||||||||||||||
2584 | QGraphicsWidget *myNewPrev = d->tabFocusFirst->d_func()->focusPrev; | - | ||||||||||||||||||||||||||||||
2585 | myNewPrev->d_func()->focusNext = widget; | - | ||||||||||||||||||||||||||||||
2586 | widget->d_func()->focusPrev->d_func()->focusNext = d->tabFocusFirst; | - | ||||||||||||||||||||||||||||||
2587 | d->tabFocusFirst->d_func()->focusPrev = widget->d_func()->focusPrev; | - | ||||||||||||||||||||||||||||||
2588 | widget->d_func()->focusPrev = myNewPrev; | - | ||||||||||||||||||||||||||||||
2589 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2590 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2591 | - | |||||||||||||||||||||||||||||||
2592 | // Add all children recursively | - | ||||||||||||||||||||||||||||||
2593 | item->d_ptr->ensureSortedChildren(); | - | ||||||||||||||||||||||||||||||
2594 | for (int i = 0; i < item->d_ptr->children.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
2595 | addItem(item->d_ptr->children.at(i)); never executed: addItem(item->d_ptr->children.at(i)); | 0 | ||||||||||||||||||||||||||||||
2596 | - | |||||||||||||||||||||||||||||||
2597 | // Resolve font and palette. | - | ||||||||||||||||||||||||||||||
2598 | item->d_ptr->resolveFont(d->font.resolve()); | - | ||||||||||||||||||||||||||||||
2599 | item->d_ptr->resolvePalette(d->palette.resolve()); | - | ||||||||||||||||||||||||||||||
2600 | - | |||||||||||||||||||||||||||||||
2601 | - | |||||||||||||||||||||||||||||||
2602 | // Reenable selectionChanged() for individual items | - | ||||||||||||||||||||||||||||||
2603 | --d->selectionChanging; | - | ||||||||||||||||||||||||||||||
2604 | if (!d->selectionChanging && d->selectedItems.size() != oldSelectedItemSize)
| 0 | ||||||||||||||||||||||||||||||
2605 | emit selectionChanged(); never executed: selectionChanged(); | 0 | ||||||||||||||||||||||||||||||
2606 | - | |||||||||||||||||||||||||||||||
2607 | // Deliver post-change notification | - | ||||||||||||||||||||||||||||||
2608 | item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); | - | ||||||||||||||||||||||||||||||
2609 | - | |||||||||||||||||||||||||||||||
2610 | // Update explicit activation | - | ||||||||||||||||||||||||||||||
2611 | bool autoActivate = true; | - | ||||||||||||||||||||||||||||||
2612 | if (!d->childExplicitActivation && item->d_ptr->explicitActivate)
| 0 | ||||||||||||||||||||||||||||||
2613 | d->childExplicitActivation = item->d_ptr->wantsActive ? 1 : 2; never executed: d->childExplicitActivation = item->d_ptr->wantsActive ? 1 : 2;
| 0 | ||||||||||||||||||||||||||||||
2614 | if (d->childExplicitActivation && item->isPanel()) {
| 0 | ||||||||||||||||||||||||||||||
2615 | if (d->childExplicitActivation == 1)
| 0 | ||||||||||||||||||||||||||||||
2616 | setActivePanel(item); never executed: setActivePanel(item); | 0 | ||||||||||||||||||||||||||||||
2617 | else | - | ||||||||||||||||||||||||||||||
2618 | autoActivate = false; never executed: autoActivate = false; | 0 | ||||||||||||||||||||||||||||||
2619 | d->childExplicitActivation = 0; | - | ||||||||||||||||||||||||||||||
2620 | } else if (!item->d_ptr->parent) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
2621 | d->childExplicitActivation = 0; | - | ||||||||||||||||||||||||||||||
2622 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2623 | - | |||||||||||||||||||||||||||||||
2624 | // Auto-activate this item's panel if nothing else has been activated | - | ||||||||||||||||||||||||||||||
2625 | if (autoActivate) {
| 0 | ||||||||||||||||||||||||||||||
2626 | if (!d->lastActivePanel && !d->activePanel && item->isPanel()) {
| 0 | ||||||||||||||||||||||||||||||
2627 | if (isActive())
| 0 | ||||||||||||||||||||||||||||||
2628 | setActivePanel(item); never executed: setActivePanel(item); | 0 | ||||||||||||||||||||||||||||||
2629 | else | - | ||||||||||||||||||||||||||||||
2630 | d->lastActivePanel = item; never executed: d->lastActivePanel = item; | 0 | ||||||||||||||||||||||||||||||
2631 | } | - | ||||||||||||||||||||||||||||||
2632 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2633 | - | |||||||||||||||||||||||||||||||
2634 | if (item->d_ptr->flags & QGraphicsItem::ItemSendsScenePositionChanges)
| 0 | ||||||||||||||||||||||||||||||
2635 | d->registerScenePosItem(item); never executed: d->registerScenePosItem(item); | 0 | ||||||||||||||||||||||||||||||
2636 | - | |||||||||||||||||||||||||||||||
2637 | // Ensure that newly added items that have subfocus set, gain | - | ||||||||||||||||||||||||||||||
2638 | // focus automatically if there isn't a focus item already. | - | ||||||||||||||||||||||||||||||
2639 | if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item)
| 0 | ||||||||||||||||||||||||||||||
2640 | item->focusItem()->setFocus(); never executed: item->focusItem()->setFocus(); | 0 | ||||||||||||||||||||||||||||||
2641 | - | |||||||||||||||||||||||||||||||
2642 | d->updateInputMethodSensitivityInViews(); | - | ||||||||||||||||||||||||||||||
2643 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2644 | - | |||||||||||||||||||||||||||||||
2645 | /*! | - | ||||||||||||||||||||||||||||||
2646 | Creates and adds an ellipse item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2647 | pointer. The geometry of the ellipse is defined by \a rect, and its pen | - | ||||||||||||||||||||||||||||||
2648 | and brush are initialized to \a pen and \a brush. | - | ||||||||||||||||||||||||||||||
2649 | - | |||||||||||||||||||||||||||||||
2650 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2651 | position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2652 | - | |||||||||||||||||||||||||||||||
2653 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2654 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2655 | loop. | - | ||||||||||||||||||||||||||||||
2656 | - | |||||||||||||||||||||||||||||||
2657 | \sa addLine(), addPath(), addPixmap(), addRect(), addText(), addItem(), | - | ||||||||||||||||||||||||||||||
2658 | addWidget() | - | ||||||||||||||||||||||||||||||
2659 | */ | - | ||||||||||||||||||||||||||||||
2660 | QGraphicsEllipseItem *QGraphicsScene::addEllipse(const QRectF &rect, const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2661 | { | - | ||||||||||||||||||||||||||||||
2662 | QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rect); | - | ||||||||||||||||||||||||||||||
2663 | item->setPen(pen); | - | ||||||||||||||||||||||||||||||
2664 | item->setBrush(brush); | - | ||||||||||||||||||||||||||||||
2665 | addItem(item); | - | ||||||||||||||||||||||||||||||
2666 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2667 | } | - | ||||||||||||||||||||||||||||||
2668 | - | |||||||||||||||||||||||||||||||
2669 | /*! | - | ||||||||||||||||||||||||||||||
2670 | \fn QGraphicsEllipseItem *QGraphicsScene::addEllipse(qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2671 | \since 4.3 | - | ||||||||||||||||||||||||||||||
2672 | - | |||||||||||||||||||||||||||||||
2673 | This convenience function is equivalent to calling addEllipse(QRectF(\a x, | - | ||||||||||||||||||||||||||||||
2674 | \a y, \a w, \a h), \a pen, \a brush). | - | ||||||||||||||||||||||||||||||
2675 | */ | - | ||||||||||||||||||||||||||||||
2676 | - | |||||||||||||||||||||||||||||||
2677 | /*! | - | ||||||||||||||||||||||||||||||
2678 | Creates and adds a line item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2679 | pointer. The geometry of the line is defined by \a line, and its pen | - | ||||||||||||||||||||||||||||||
2680 | is initialized to \a pen. | - | ||||||||||||||||||||||||||||||
2681 | - | |||||||||||||||||||||||||||||||
2682 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2683 | position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2684 | - | |||||||||||||||||||||||||||||||
2685 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2686 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2687 | loop. | - | ||||||||||||||||||||||||||||||
2688 | - | |||||||||||||||||||||||||||||||
2689 | \sa addEllipse(), addPath(), addPixmap(), addRect(), addText(), addItem(), | - | ||||||||||||||||||||||||||||||
2690 | addWidget() | - | ||||||||||||||||||||||||||||||
2691 | */ | - | ||||||||||||||||||||||||||||||
2692 | QGraphicsLineItem *QGraphicsScene::addLine(const QLineF &line, const QPen &pen) | - | ||||||||||||||||||||||||||||||
2693 | { | - | ||||||||||||||||||||||||||||||
2694 | QGraphicsLineItem *item = new QGraphicsLineItem(line); | - | ||||||||||||||||||||||||||||||
2695 | item->setPen(pen); | - | ||||||||||||||||||||||||||||||
2696 | addItem(item); | - | ||||||||||||||||||||||||||||||
2697 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2698 | } | - | ||||||||||||||||||||||||||||||
2699 | - | |||||||||||||||||||||||||||||||
2700 | /*! | - | ||||||||||||||||||||||||||||||
2701 | \fn QGraphicsLineItem *QGraphicsScene::addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen) | - | ||||||||||||||||||||||||||||||
2702 | \since 4.3 | - | ||||||||||||||||||||||||||||||
2703 | - | |||||||||||||||||||||||||||||||
2704 | This convenience function is equivalent to calling addLine(QLineF(\a x1, | - | ||||||||||||||||||||||||||||||
2705 | \a y1, \a x2, \a y2), \a pen). | - | ||||||||||||||||||||||||||||||
2706 | */ | - | ||||||||||||||||||||||||||||||
2707 | - | |||||||||||||||||||||||||||||||
2708 | /*! | - | ||||||||||||||||||||||||||||||
2709 | Creates and adds a path item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2710 | pointer. The geometry of the path is defined by \a path, and its pen and | - | ||||||||||||||||||||||||||||||
2711 | brush are initialized to \a pen and \a brush. | - | ||||||||||||||||||||||||||||||
2712 | - | |||||||||||||||||||||||||||||||
2713 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2714 | position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2715 | - | |||||||||||||||||||||||||||||||
2716 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2717 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2718 | loop. | - | ||||||||||||||||||||||||||||||
2719 | - | |||||||||||||||||||||||||||||||
2720 | \sa addEllipse(), addLine(), addPixmap(), addRect(), addText(), addItem(), | - | ||||||||||||||||||||||||||||||
2721 | addWidget() | - | ||||||||||||||||||||||||||||||
2722 | */ | - | ||||||||||||||||||||||||||||||
2723 | QGraphicsPathItem *QGraphicsScene::addPath(const QPainterPath &path, const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2724 | { | - | ||||||||||||||||||||||||||||||
2725 | QGraphicsPathItem *item = new QGraphicsPathItem(path); | - | ||||||||||||||||||||||||||||||
2726 | item->setPen(pen); | - | ||||||||||||||||||||||||||||||
2727 | item->setBrush(brush); | - | ||||||||||||||||||||||||||||||
2728 | addItem(item); | - | ||||||||||||||||||||||||||||||
2729 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2730 | } | - | ||||||||||||||||||||||||||||||
2731 | - | |||||||||||||||||||||||||||||||
2732 | /*! | - | ||||||||||||||||||||||||||||||
2733 | Creates and adds a pixmap item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2734 | pointer. The pixmap is defined by \a pixmap. | - | ||||||||||||||||||||||||||||||
2735 | - | |||||||||||||||||||||||||||||||
2736 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2737 | position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2738 | - | |||||||||||||||||||||||||||||||
2739 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2740 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2741 | loop. | - | ||||||||||||||||||||||||||||||
2742 | - | |||||||||||||||||||||||||||||||
2743 | \sa addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), | - | ||||||||||||||||||||||||||||||
2744 | addWidget() | - | ||||||||||||||||||||||||||||||
2745 | */ | - | ||||||||||||||||||||||||||||||
2746 | QGraphicsPixmapItem *QGraphicsScene::addPixmap(const QPixmap &pixmap) | - | ||||||||||||||||||||||||||||||
2747 | { | - | ||||||||||||||||||||||||||||||
2748 | QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap); | - | ||||||||||||||||||||||||||||||
2749 | addItem(item); | - | ||||||||||||||||||||||||||||||
2750 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2751 | } | - | ||||||||||||||||||||||||||||||
2752 | - | |||||||||||||||||||||||||||||||
2753 | /*! | - | ||||||||||||||||||||||||||||||
2754 | Creates and adds a polygon item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2755 | pointer. The polygon is defined by \a polygon, and its pen and | - | ||||||||||||||||||||||||||||||
2756 | brush are initialized to \a pen and \a brush. | - | ||||||||||||||||||||||||||||||
2757 | - | |||||||||||||||||||||||||||||||
2758 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2759 | position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2760 | - | |||||||||||||||||||||||||||||||
2761 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2762 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2763 | loop. | - | ||||||||||||||||||||||||||||||
2764 | - | |||||||||||||||||||||||||||||||
2765 | \sa addEllipse(), addLine(), addPath(), addRect(), addText(), addItem(), | - | ||||||||||||||||||||||||||||||
2766 | addWidget() | - | ||||||||||||||||||||||||||||||
2767 | */ | - | ||||||||||||||||||||||||||||||
2768 | QGraphicsPolygonItem *QGraphicsScene::addPolygon(const QPolygonF &polygon, | - | ||||||||||||||||||||||||||||||
2769 | const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2770 | { | - | ||||||||||||||||||||||||||||||
2771 | QGraphicsPolygonItem *item = new QGraphicsPolygonItem(polygon); | - | ||||||||||||||||||||||||||||||
2772 | item->setPen(pen); | - | ||||||||||||||||||||||||||||||
2773 | item->setBrush(brush); | - | ||||||||||||||||||||||||||||||
2774 | addItem(item); | - | ||||||||||||||||||||||||||||||
2775 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2776 | } | - | ||||||||||||||||||||||||||||||
2777 | - | |||||||||||||||||||||||||||||||
2778 | /*! | - | ||||||||||||||||||||||||||||||
2779 | Creates and adds a rectangle item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2780 | pointer. The geometry of the rectangle is defined by \a rect, and its pen | - | ||||||||||||||||||||||||||||||
2781 | and brush are initialized to \a pen and \a brush. | - | ||||||||||||||||||||||||||||||
2782 | - | |||||||||||||||||||||||||||||||
2783 | Note that the item's geometry is provided in item coordinates, and its | - | ||||||||||||||||||||||||||||||
2784 | position is initialized to (0, 0). For example, if a QRect(50, 50, 100, | - | ||||||||||||||||||||||||||||||
2785 | 100) is added, its top-left corner will be at (50, 50) relative to the | - | ||||||||||||||||||||||||||||||
2786 | origin in the items coordinate system. | - | ||||||||||||||||||||||||||||||
2787 | - | |||||||||||||||||||||||||||||||
2788 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2789 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2790 | loop. | - | ||||||||||||||||||||||||||||||
2791 | - | |||||||||||||||||||||||||||||||
2792 | \sa addEllipse(), addLine(), addPixmap(), addPixmap(), addText(), | - | ||||||||||||||||||||||||||||||
2793 | addItem(), addWidget() | - | ||||||||||||||||||||||||||||||
2794 | */ | - | ||||||||||||||||||||||||||||||
2795 | QGraphicsRectItem *QGraphicsScene::addRect(const QRectF &rect, const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2796 | { | - | ||||||||||||||||||||||||||||||
2797 | QGraphicsRectItem *item = new QGraphicsRectItem(rect); | - | ||||||||||||||||||||||||||||||
2798 | item->setPen(pen); | - | ||||||||||||||||||||||||||||||
2799 | item->setBrush(brush); | - | ||||||||||||||||||||||||||||||
2800 | addItem(item); | - | ||||||||||||||||||||||||||||||
2801 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2802 | } | - | ||||||||||||||||||||||||||||||
2803 | - | |||||||||||||||||||||||||||||||
2804 | /*! | - | ||||||||||||||||||||||||||||||
2805 | \fn QGraphicsRectItem *QGraphicsScene::addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush) | - | ||||||||||||||||||||||||||||||
2806 | \since 4.3 | - | ||||||||||||||||||||||||||||||
2807 | - | |||||||||||||||||||||||||||||||
2808 | This convenience function is equivalent to calling addRect(QRectF(\a x, | - | ||||||||||||||||||||||||||||||
2809 | \a y, \a w, \a h), \a pen, \a brush). | - | ||||||||||||||||||||||||||||||
2810 | */ | - | ||||||||||||||||||||||||||||||
2811 | - | |||||||||||||||||||||||||||||||
2812 | /*! | - | ||||||||||||||||||||||||||||||
2813 | Creates and adds a text item to the scene, and returns the item | - | ||||||||||||||||||||||||||||||
2814 | pointer. The text string is initialized to \a text, and its font | - | ||||||||||||||||||||||||||||||
2815 | is initialized to \a font. | - | ||||||||||||||||||||||||||||||
2816 | - | |||||||||||||||||||||||||||||||
2817 | The item's position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2818 | - | |||||||||||||||||||||||||||||||
2819 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2820 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2821 | loop. | - | ||||||||||||||||||||||||||||||
2822 | - | |||||||||||||||||||||||||||||||
2823 | \sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), | - | ||||||||||||||||||||||||||||||
2824 | addItem(), addWidget() | - | ||||||||||||||||||||||||||||||
2825 | */ | - | ||||||||||||||||||||||||||||||
2826 | QGraphicsTextItem *QGraphicsScene::addText(const QString &text, const QFont &font) | - | ||||||||||||||||||||||||||||||
2827 | { | - | ||||||||||||||||||||||||||||||
2828 | QGraphicsTextItem *item = new QGraphicsTextItem(text); | - | ||||||||||||||||||||||||||||||
2829 | item->setFont(font); | - | ||||||||||||||||||||||||||||||
2830 | addItem(item); | - | ||||||||||||||||||||||||||||||
2831 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2832 | } | - | ||||||||||||||||||||||||||||||
2833 | - | |||||||||||||||||||||||||||||||
2834 | /*! | - | ||||||||||||||||||||||||||||||
2835 | Creates and adds a QGraphicsSimpleTextItem to the scene, and returns the | - | ||||||||||||||||||||||||||||||
2836 | item pointer. The text string is initialized to \a text, and its font is | - | ||||||||||||||||||||||||||||||
2837 | initialized to \a font. | - | ||||||||||||||||||||||||||||||
2838 | - | |||||||||||||||||||||||||||||||
2839 | The item's position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2840 | - | |||||||||||||||||||||||||||||||
2841 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2842 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2843 | loop. | - | ||||||||||||||||||||||||||||||
2844 | - | |||||||||||||||||||||||||||||||
2845 | \sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), | - | ||||||||||||||||||||||||||||||
2846 | addItem(), addWidget() | - | ||||||||||||||||||||||||||||||
2847 | */ | - | ||||||||||||||||||||||||||||||
2848 | QGraphicsSimpleTextItem *QGraphicsScene::addSimpleText(const QString &text, const QFont &font) | - | ||||||||||||||||||||||||||||||
2849 | { | - | ||||||||||||||||||||||||||||||
2850 | QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text); | - | ||||||||||||||||||||||||||||||
2851 | item->setFont(font); | - | ||||||||||||||||||||||||||||||
2852 | addItem(item); | - | ||||||||||||||||||||||||||||||
2853 | return item; never executed: return item; | 0 | ||||||||||||||||||||||||||||||
2854 | } | - | ||||||||||||||||||||||||||||||
2855 | - | |||||||||||||||||||||||||||||||
2856 | /*! | - | ||||||||||||||||||||||||||||||
2857 | Creates a new QGraphicsProxyWidget for \a widget, adds it to the scene, | - | ||||||||||||||||||||||||||||||
2858 | and returns a pointer to the proxy. \a wFlags set the default window flags | - | ||||||||||||||||||||||||||||||
2859 | for the embedding proxy widget. | - | ||||||||||||||||||||||||||||||
2860 | - | |||||||||||||||||||||||||||||||
2861 | The item's position is initialized to (0, 0). | - | ||||||||||||||||||||||||||||||
2862 | - | |||||||||||||||||||||||||||||||
2863 | If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true), | - | ||||||||||||||||||||||||||||||
2864 | QGraphicsScene will emit changed() once control goes back to the event | - | ||||||||||||||||||||||||||||||
2865 | loop. | - | ||||||||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||||||||
2867 | Note that widgets with the Qt::WA_PaintOnScreen widget attribute | - | ||||||||||||||||||||||||||||||
2868 | set and widgets that wrap an external application or controller | - | ||||||||||||||||||||||||||||||
2869 | are not supported. Examples are QGLWidget and QAxWidget. | - | ||||||||||||||||||||||||||||||
2870 | - | |||||||||||||||||||||||||||||||
2871 | \sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(), | - | ||||||||||||||||||||||||||||||
2872 | addText(), addSimpleText(), addItem() | - | ||||||||||||||||||||||||||||||
2873 | */ | - | ||||||||||||||||||||||||||||||
2874 | QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags) | - | ||||||||||||||||||||||||||||||
2875 | { | - | ||||||||||||||||||||||||||||||
2876 | QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, wFlags); | - | ||||||||||||||||||||||||||||||
2877 | proxy->setWidget(widget); | - | ||||||||||||||||||||||||||||||
2878 | addItem(proxy); | - | ||||||||||||||||||||||||||||||
2879 | return proxy; never executed: return proxy; | 0 | ||||||||||||||||||||||||||||||
2880 | } | - | ||||||||||||||||||||||||||||||
2881 | - | |||||||||||||||||||||||||||||||
2882 | /*! | - | ||||||||||||||||||||||||||||||
2883 | Removes the item \a item and all its children from the scene. The | - | ||||||||||||||||||||||||||||||
2884 | ownership of \a item is passed on to the caller (i.e., | - | ||||||||||||||||||||||||||||||
2885 | QGraphicsScene will no longer delete \a item when destroyed). | - | ||||||||||||||||||||||||||||||
2886 | - | |||||||||||||||||||||||||||||||
2887 | \sa addItem() | - | ||||||||||||||||||||||||||||||
2888 | */ | - | ||||||||||||||||||||||||||||||
2889 | void QGraphicsScene::removeItem(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
2890 | { | - | ||||||||||||||||||||||||||||||
2891 | // ### Refactoring: This function shares much functionality with _q_removeItemLater() | - | ||||||||||||||||||||||||||||||
2892 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2893 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
2894 | qWarning("QGraphicsScene::removeItem: cannot remove 0-item"); | - | ||||||||||||||||||||||||||||||
2895 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2896 | } | - | ||||||||||||||||||||||||||||||
2897 | if (item->scene() != this) {
| 0 | ||||||||||||||||||||||||||||||
2898 | qWarning("QGraphicsScene::removeItem: item %p's scene (%p)" | - | ||||||||||||||||||||||||||||||
2899 | " is different from this scene (%p)", | - | ||||||||||||||||||||||||||||||
2900 | item, item->scene(), this); | - | ||||||||||||||||||||||||||||||
2901 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2902 | } | - | ||||||||||||||||||||||||||||||
2903 | - | |||||||||||||||||||||||||||||||
2904 | // Notify the item that it's scene is changing to 0, allowing the item to | - | ||||||||||||||||||||||||||||||
2905 | // react. | - | ||||||||||||||||||||||||||||||
2906 | const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, | - | ||||||||||||||||||||||||||||||
2907 | QVariant::fromValue<QGraphicsScene *>(0))); | - | ||||||||||||||||||||||||||||||
2908 | QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant); | - | ||||||||||||||||||||||||||||||
2909 | if (targetScene != 0 && targetScene != this) {
| 0 | ||||||||||||||||||||||||||||||
2910 | targetScene->addItem(item); | - | ||||||||||||||||||||||||||||||
2911 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2912 | } | - | ||||||||||||||||||||||||||||||
2913 | - | |||||||||||||||||||||||||||||||
2914 | d->removeItemHelper(item); | - | ||||||||||||||||||||||||||||||
2915 | - | |||||||||||||||||||||||||||||||
2916 | // Deliver post-change notification | - | ||||||||||||||||||||||||||||||
2917 | item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); | - | ||||||||||||||||||||||||||||||
2918 | - | |||||||||||||||||||||||||||||||
2919 | d->updateInputMethodSensitivityInViews(); | - | ||||||||||||||||||||||||||||||
2920 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2921 | - | |||||||||||||||||||||||||||||||
2922 | /*! | - | ||||||||||||||||||||||||||||||
2923 | When the scene is active, this functions returns the scene's current focus | - | ||||||||||||||||||||||||||||||
2924 | item, or 0 if no item currently has focus. When the scene is inactive, this | - | ||||||||||||||||||||||||||||||
2925 | functions returns the item that will gain input focus when the scene becomes | - | ||||||||||||||||||||||||||||||
2926 | active. | - | ||||||||||||||||||||||||||||||
2927 | - | |||||||||||||||||||||||||||||||
2928 | The focus item receives keyboard input when the scene receives a | - | ||||||||||||||||||||||||||||||
2929 | key event. | - | ||||||||||||||||||||||||||||||
2930 | - | |||||||||||||||||||||||||||||||
2931 | \sa setFocusItem(), QGraphicsItem::hasFocus(), isActive() | - | ||||||||||||||||||||||||||||||
2932 | */ | - | ||||||||||||||||||||||||||||||
2933 | QGraphicsItem *QGraphicsScene::focusItem() const | - | ||||||||||||||||||||||||||||||
2934 | { | - | ||||||||||||||||||||||||||||||
2935 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2936 | return isActive() ? d->focusItem : d->passiveFocusItem; never executed: return isActive() ? d->focusItem : d->passiveFocusItem;
| 0 | ||||||||||||||||||||||||||||||
2937 | } | - | ||||||||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||||||||
2939 | /*! | - | ||||||||||||||||||||||||||||||
2940 | Sets the scene's focus item to \a item, with the focus reason \a | - | ||||||||||||||||||||||||||||||
2941 | focusReason, after removing focus from any previous item that may have had | - | ||||||||||||||||||||||||||||||
2942 | focus. | - | ||||||||||||||||||||||||||||||
2943 | - | |||||||||||||||||||||||||||||||
2944 | If \a item is 0, or if it either does not accept focus (i.e., it does not | - | ||||||||||||||||||||||||||||||
2945 | have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible | - | ||||||||||||||||||||||||||||||
2946 | or not enabled, this function only removes focus from any previous | - | ||||||||||||||||||||||||||||||
2947 | focusitem. | - | ||||||||||||||||||||||||||||||
2948 | - | |||||||||||||||||||||||||||||||
2949 | If item is not 0, and the scene does not currently have focus (i.e., | - | ||||||||||||||||||||||||||||||
2950 | hasFocus() returns \c false), this function will call setFocus() | - | ||||||||||||||||||||||||||||||
2951 | automatically. | - | ||||||||||||||||||||||||||||||
2952 | - | |||||||||||||||||||||||||||||||
2953 | \sa focusItem(), hasFocus(), setFocus() | - | ||||||||||||||||||||||||||||||
2954 | */ | - | ||||||||||||||||||||||||||||||
2955 | void QGraphicsScene::setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason) | - | ||||||||||||||||||||||||||||||
2956 | { | - | ||||||||||||||||||||||||||||||
2957 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2958 | if (item)
| 0 | ||||||||||||||||||||||||||||||
2959 | item->setFocus(focusReason); never executed: item->setFocus(focusReason); | 0 | ||||||||||||||||||||||||||||||
2960 | else | - | ||||||||||||||||||||||||||||||
2961 | d->setFocusItemHelper(item, focusReason); never executed: d->setFocusItemHelper(item, focusReason); | 0 | ||||||||||||||||||||||||||||||
2962 | } | - | ||||||||||||||||||||||||||||||
2963 | - | |||||||||||||||||||||||||||||||
2964 | /*! | - | ||||||||||||||||||||||||||||||
2965 | Returns \c true if the scene has focus; otherwise returns \c false. If the scene | - | ||||||||||||||||||||||||||||||
2966 | has focus, it will will forward key events from QKeyEvent to any item that | - | ||||||||||||||||||||||||||||||
2967 | has focus. | - | ||||||||||||||||||||||||||||||
2968 | - | |||||||||||||||||||||||||||||||
2969 | \sa setFocus(), setFocusItem() | - | ||||||||||||||||||||||||||||||
2970 | */ | - | ||||||||||||||||||||||||||||||
2971 | bool QGraphicsScene::hasFocus() const | - | ||||||||||||||||||||||||||||||
2972 | { | - | ||||||||||||||||||||||||||||||
2973 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2974 | return d->hasFocus; never executed: return d->hasFocus; | 0 | ||||||||||||||||||||||||||||||
2975 | } | - | ||||||||||||||||||||||||||||||
2976 | - | |||||||||||||||||||||||||||||||
2977 | /*! | - | ||||||||||||||||||||||||||||||
2978 | Sets focus on the scene by sending a QFocusEvent to the scene, passing \a | - | ||||||||||||||||||||||||||||||
2979 | focusReason as the reason. If the scene regains focus after having | - | ||||||||||||||||||||||||||||||
2980 | previously lost it while an item had focus, the last focus item will | - | ||||||||||||||||||||||||||||||
2981 | receive focus with \a focusReason as the reason. | - | ||||||||||||||||||||||||||||||
2982 | - | |||||||||||||||||||||||||||||||
2983 | If the scene already has focus, this function does nothing. | - | ||||||||||||||||||||||||||||||
2984 | - | |||||||||||||||||||||||||||||||
2985 | \sa hasFocus(), clearFocus(), setFocusItem() | - | ||||||||||||||||||||||||||||||
2986 | */ | - | ||||||||||||||||||||||||||||||
2987 | void QGraphicsScene::setFocus(Qt::FocusReason focusReason) | - | ||||||||||||||||||||||||||||||
2988 | { | - | ||||||||||||||||||||||||||||||
2989 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
2990 | if (d->hasFocus || !isActive())
| 0 | ||||||||||||||||||||||||||||||
2991 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2992 | QFocusEvent event(QEvent::FocusIn, focusReason); | - | ||||||||||||||||||||||||||||||
2993 | QCoreApplication::sendEvent(this, &event); | - | ||||||||||||||||||||||||||||||
2994 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2995 | - | |||||||||||||||||||||||||||||||
2996 | /*! | - | ||||||||||||||||||||||||||||||
2997 | Clears focus from the scene. If any item has focus when this function is | - | ||||||||||||||||||||||||||||||
2998 | called, it will lose focus, and regain focus again once the scene regains | - | ||||||||||||||||||||||||||||||
2999 | focus. | - | ||||||||||||||||||||||||||||||
3000 | - | |||||||||||||||||||||||||||||||
3001 | A scene that does not have focus ignores key events. | - | ||||||||||||||||||||||||||||||
3002 | - | |||||||||||||||||||||||||||||||
3003 | \sa hasFocus(), setFocus(), setFocusItem() | - | ||||||||||||||||||||||||||||||
3004 | */ | - | ||||||||||||||||||||||||||||||
3005 | void QGraphicsScene::clearFocus() | - | ||||||||||||||||||||||||||||||
3006 | { | - | ||||||||||||||||||||||||||||||
3007 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3008 | if (d->hasFocus) {
| 0 | ||||||||||||||||||||||||||||||
3009 | d->hasFocus = false; | - | ||||||||||||||||||||||||||||||
3010 | d->passiveFocusItem = d->focusItem; | - | ||||||||||||||||||||||||||||||
3011 | setFocusItem(0, Qt::OtherFocusReason); | - | ||||||||||||||||||||||||||||||
3012 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3013 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3014 | - | |||||||||||||||||||||||||||||||
3015 | /*! | - | ||||||||||||||||||||||||||||||
3016 | \property QGraphicsScene::stickyFocus | - | ||||||||||||||||||||||||||||||
3017 | \brief whether clicking into the scene background will clear focus | - | ||||||||||||||||||||||||||||||
3018 | - | |||||||||||||||||||||||||||||||
3019 | \since 4.6 | - | ||||||||||||||||||||||||||||||
3020 | - | |||||||||||||||||||||||||||||||
3021 | In a QGraphicsScene with stickyFocus set to true, focus will remain | - | ||||||||||||||||||||||||||||||
3022 | unchanged when the user clicks into the scene background or on an item | - | ||||||||||||||||||||||||||||||
3023 | that does not accept focus. Otherwise, focus will be cleared. | - | ||||||||||||||||||||||||||||||
3024 | - | |||||||||||||||||||||||||||||||
3025 | By default, this property is \c false. | - | ||||||||||||||||||||||||||||||
3026 | - | |||||||||||||||||||||||||||||||
3027 | Focus changes in response to a mouse press. You can reimplement | - | ||||||||||||||||||||||||||||||
3028 | mousePressEvent() in a subclass of QGraphicsScene to toggle this property | - | ||||||||||||||||||||||||||||||
3029 | based on where the user has clicked. | - | ||||||||||||||||||||||||||||||
3030 | - | |||||||||||||||||||||||||||||||
3031 | \sa clearFocus(), setFocusItem() | - | ||||||||||||||||||||||||||||||
3032 | */ | - | ||||||||||||||||||||||||||||||
3033 | void QGraphicsScene::setStickyFocus(bool enabled) | - | ||||||||||||||||||||||||||||||
3034 | { | - | ||||||||||||||||||||||||||||||
3035 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3036 | d->stickyFocus = enabled; | - | ||||||||||||||||||||||||||||||
3037 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3038 | bool QGraphicsScene::stickyFocus() const | - | ||||||||||||||||||||||||||||||
3039 | { | - | ||||||||||||||||||||||||||||||
3040 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3041 | return d->stickyFocus; never executed: return d->stickyFocus; | 0 | ||||||||||||||||||||||||||||||
3042 | } | - | ||||||||||||||||||||||||||||||
3043 | - | |||||||||||||||||||||||||||||||
3044 | /*! | - | ||||||||||||||||||||||||||||||
3045 | Returns the current mouse grabber item, or 0 if no item is currently | - | ||||||||||||||||||||||||||||||
3046 | grabbing the mouse. The mouse grabber item is the item that receives all | - | ||||||||||||||||||||||||||||||
3047 | mouse events sent to the scene. | - | ||||||||||||||||||||||||||||||
3048 | - | |||||||||||||||||||||||||||||||
3049 | An item becomes a mouse grabber when it receives and accepts a | - | ||||||||||||||||||||||||||||||
3050 | mouse press event, and it stays the mouse grabber until either of | - | ||||||||||||||||||||||||||||||
3051 | the following events occur: | - | ||||||||||||||||||||||||||||||
3052 | - | |||||||||||||||||||||||||||||||
3053 | \list | - | ||||||||||||||||||||||||||||||
3054 | \li If the item receives a mouse release event when there are no other | - | ||||||||||||||||||||||||||||||
3055 | buttons pressed, it loses the mouse grab. | - | ||||||||||||||||||||||||||||||
3056 | \li If the item becomes invisible (i.e., someone calls \c {item->setVisible(false)}), | - | ||||||||||||||||||||||||||||||
3057 | or if it becomes disabled (i.e., someone calls \c {item->setEnabled(false)}), | - | ||||||||||||||||||||||||||||||
3058 | it loses the mouse grab. | - | ||||||||||||||||||||||||||||||
3059 | \li If the item is removed from the scene, it loses the mouse grab. | - | ||||||||||||||||||||||||||||||
3060 | \endlist | - | ||||||||||||||||||||||||||||||
3061 | - | |||||||||||||||||||||||||||||||
3062 | If the item loses its mouse grab, the scene will ignore all mouse events | - | ||||||||||||||||||||||||||||||
3063 | until a new item grabs the mouse (i.e., until a new item receives a mouse | - | ||||||||||||||||||||||||||||||
3064 | press event). | - | ||||||||||||||||||||||||||||||
3065 | */ | - | ||||||||||||||||||||||||||||||
3066 | QGraphicsItem *QGraphicsScene::mouseGrabberItem() const | - | ||||||||||||||||||||||||||||||
3067 | { | - | ||||||||||||||||||||||||||||||
3068 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3069 | return !d->mouseGrabberItems.isEmpty() ? d->mouseGrabberItems.last() : 0; never executed: return !d->mouseGrabberItems.isEmpty() ? d->mouseGrabberItems.last() : 0;
| 0 | ||||||||||||||||||||||||||||||
3070 | } | - | ||||||||||||||||||||||||||||||
3071 | - | |||||||||||||||||||||||||||||||
3072 | /*! | - | ||||||||||||||||||||||||||||||
3073 | \property QGraphicsScene::backgroundBrush | - | ||||||||||||||||||||||||||||||
3074 | \brief the background brush of the scene. | - | ||||||||||||||||||||||||||||||
3075 | - | |||||||||||||||||||||||||||||||
3076 | Set this property to changes the scene's background to a different color, | - | ||||||||||||||||||||||||||||||
3077 | gradient or texture. The default background brush is Qt::NoBrush. The | - | ||||||||||||||||||||||||||||||
3078 | background is drawn before (behind) the items. | - | ||||||||||||||||||||||||||||||
3079 | - | |||||||||||||||||||||||||||||||
3080 | Example: | - | ||||||||||||||||||||||||||||||
3081 | - | |||||||||||||||||||||||||||||||
3082 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 3 | - | ||||||||||||||||||||||||||||||
3083 | - | |||||||||||||||||||||||||||||||
3084 | QGraphicsScene::render() calls drawBackground() to draw the scene | - | ||||||||||||||||||||||||||||||
3085 | background. For more detailed control over how the background is drawn, | - | ||||||||||||||||||||||||||||||
3086 | you can reimplement drawBackground() in a subclass of QGraphicsScene. | - | ||||||||||||||||||||||||||||||
3087 | */ | - | ||||||||||||||||||||||||||||||
3088 | QBrush QGraphicsScene::backgroundBrush() const | - | ||||||||||||||||||||||||||||||
3089 | { | - | ||||||||||||||||||||||||||||||
3090 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3091 | return d->backgroundBrush; never executed: return d->backgroundBrush; | 0 | ||||||||||||||||||||||||||||||
3092 | } | - | ||||||||||||||||||||||||||||||
3093 | void QGraphicsScene::setBackgroundBrush(const QBrush &brush) | - | ||||||||||||||||||||||||||||||
3094 | { | - | ||||||||||||||||||||||||||||||
3095 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3096 | d->backgroundBrush = brush; | - | ||||||||||||||||||||||||||||||
3097 | foreach (QGraphicsView *view, d->views) { | - | ||||||||||||||||||||||||||||||
3098 | view->resetCachedContent(); | - | ||||||||||||||||||||||||||||||
3099 | view->viewport()->update(); | - | ||||||||||||||||||||||||||||||
3100 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3101 | update(); | - | ||||||||||||||||||||||||||||||
3102 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3103 | - | |||||||||||||||||||||||||||||||
3104 | /*! | - | ||||||||||||||||||||||||||||||
3105 | \property QGraphicsScene::foregroundBrush | - | ||||||||||||||||||||||||||||||
3106 | \brief the foreground brush of the scene. | - | ||||||||||||||||||||||||||||||
3107 | - | |||||||||||||||||||||||||||||||
3108 | Change this property to set the scene's foreground to a different | - | ||||||||||||||||||||||||||||||
3109 | color, gradient or texture. | - | ||||||||||||||||||||||||||||||
3110 | - | |||||||||||||||||||||||||||||||
3111 | The foreground is drawn after (on top of) the items. The default | - | ||||||||||||||||||||||||||||||
3112 | foreground brush is Qt::NoBrush ( i.e. the foreground is not | - | ||||||||||||||||||||||||||||||
3113 | drawn). | - | ||||||||||||||||||||||||||||||
3114 | - | |||||||||||||||||||||||||||||||
3115 | Example: | - | ||||||||||||||||||||||||||||||
3116 | - | |||||||||||||||||||||||||||||||
3117 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 4 | - | ||||||||||||||||||||||||||||||
3118 | - | |||||||||||||||||||||||||||||||
3119 | QGraphicsScene::render() calls drawForeground() to draw the scene | - | ||||||||||||||||||||||||||||||
3120 | foreground. For more detailed control over how the foreground is | - | ||||||||||||||||||||||||||||||
3121 | drawn, you can reimplement the drawForeground() function in a | - | ||||||||||||||||||||||||||||||
3122 | QGraphicsScene subclass. | - | ||||||||||||||||||||||||||||||
3123 | */ | - | ||||||||||||||||||||||||||||||
3124 | QBrush QGraphicsScene::foregroundBrush() const | - | ||||||||||||||||||||||||||||||
3125 | { | - | ||||||||||||||||||||||||||||||
3126 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3127 | return d->foregroundBrush; never executed: return d->foregroundBrush; | 0 | ||||||||||||||||||||||||||||||
3128 | } | - | ||||||||||||||||||||||||||||||
3129 | void QGraphicsScene::setForegroundBrush(const QBrush &brush) | - | ||||||||||||||||||||||||||||||
3130 | { | - | ||||||||||||||||||||||||||||||
3131 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3132 | d->foregroundBrush = brush; | - | ||||||||||||||||||||||||||||||
3133 | foreach (QGraphicsView *view, views()) | - | ||||||||||||||||||||||||||||||
3134 | view->viewport()->update(); never executed: view->viewport()->update(); | 0 | ||||||||||||||||||||||||||||||
3135 | update(); | - | ||||||||||||||||||||||||||||||
3136 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3137 | - | |||||||||||||||||||||||||||||||
3138 | /*! | - | ||||||||||||||||||||||||||||||
3139 | This method is used by input methods to query a set of properties of | - | ||||||||||||||||||||||||||||||
3140 | the scene to be able to support complex input method operations as support | - | ||||||||||||||||||||||||||||||
3141 | for surrounding text and reconversions. | - | ||||||||||||||||||||||||||||||
3142 | - | |||||||||||||||||||||||||||||||
3143 | The \a query parameter specifies which property is queried. | - | ||||||||||||||||||||||||||||||
3144 | - | |||||||||||||||||||||||||||||||
3145 | \sa QWidget::inputMethodQuery() | - | ||||||||||||||||||||||||||||||
3146 | */ | - | ||||||||||||||||||||||||||||||
3147 | QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||||||||||||||
3148 | { | - | ||||||||||||||||||||||||||||||
3149 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3150 | if (!d->focusItem || !(d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
| 0 | ||||||||||||||||||||||||||||||
3151 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||
3152 | const QTransform matrix = d->focusItem->sceneTransform(); | - | ||||||||||||||||||||||||||||||
3153 | QVariant value = d->focusItem->inputMethodQuery(query); | - | ||||||||||||||||||||||||||||||
3154 | if (value.type() == QVariant::RectF)
| 0 | ||||||||||||||||||||||||||||||
3155 | value = matrix.mapRect(value.toRectF()); never executed: value = matrix.mapRect(value.toRectF()); | 0 | ||||||||||||||||||||||||||||||
3156 | else if (value.type() == QVariant::PointF)
| 0 | ||||||||||||||||||||||||||||||
3157 | value = matrix.map(value.toPointF()); never executed: value = matrix.map(value.toPointF()); | 0 | ||||||||||||||||||||||||||||||
3158 | else if (value.type() == QVariant::Rect)
| 0 | ||||||||||||||||||||||||||||||
3159 | value = matrix.mapRect(value.toRect()); never executed: value = matrix.mapRect(value.toRect()); | 0 | ||||||||||||||||||||||||||||||
3160 | else if (value.type() == QVariant::Point)
| 0 | ||||||||||||||||||||||||||||||
3161 | value = matrix.map(value.toPoint()); never executed: value = matrix.map(value.toPoint()); | 0 | ||||||||||||||||||||||||||||||
3162 | return value; never executed: return value; | 0 | ||||||||||||||||||||||||||||||
3163 | } | - | ||||||||||||||||||||||||||||||
3164 | - | |||||||||||||||||||||||||||||||
3165 | /*! | - | ||||||||||||||||||||||||||||||
3166 | \fn void QGraphicsScene::update(const QRectF &rect) | - | ||||||||||||||||||||||||||||||
3167 | Schedules a redraw of the area \a rect on the scene. | - | ||||||||||||||||||||||||||||||
3168 | - | |||||||||||||||||||||||||||||||
3169 | \sa sceneRect(), changed() | - | ||||||||||||||||||||||||||||||
3170 | */ | - | ||||||||||||||||||||||||||||||
3171 | void QGraphicsScene::update(const QRectF &rect) | - | ||||||||||||||||||||||||||||||
3172 | { | - | ||||||||||||||||||||||||||||||
3173 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3174 | if (d->updateAll || (rect.isEmpty() && !rect.isNull()))
| 0 | ||||||||||||||||||||||||||||||
3175 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
3176 | - | |||||||||||||||||||||||||||||||
3177 | // Check if anyone's connected; if not, we can send updates directly to | - | ||||||||||||||||||||||||||||||
3178 | // the views. Otherwise or if there are no views, use old behavior. | - | ||||||||||||||||||||||||||||||
3179 | bool directUpdates = !(d->isSignalConnected(d->changedSignalIndex)) && !d->views.isEmpty();
| 0 | ||||||||||||||||||||||||||||||
3180 | if (rect.isNull()) {
| 0 | ||||||||||||||||||||||||||||||
3181 | d->updateAll = true; | - | ||||||||||||||||||||||||||||||
3182 | d->updatedRects.clear(); | - | ||||||||||||||||||||||||||||||
3183 | if (directUpdates) {
| 0 | ||||||||||||||||||||||||||||||
3184 | // Update all views. | - | ||||||||||||||||||||||||||||||
3185 | for (int i = 0; i < d->views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
3186 | d->views.at(i)->d_func()->fullUpdatePending = true; never executed: d->views.at(i)->d_func()->fullUpdatePending = true; | 0 | ||||||||||||||||||||||||||||||
3187 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3188 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3189 | if (directUpdates) {
| 0 | ||||||||||||||||||||||||||||||
3190 | // Update all views. | - | ||||||||||||||||||||||||||||||
3191 | for (int i = 0; i < d->views.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
3192 | QGraphicsView *view = d->views.at(i); | - | ||||||||||||||||||||||||||||||
3193 | if (view->isTransformed())
| 0 | ||||||||||||||||||||||||||||||
3194 | view->d_func()->updateRectF(view->viewportTransform().mapRect(rect)); never executed: view->d_func()->updateRectF(view->viewportTransform().mapRect(rect)); | 0 | ||||||||||||||||||||||||||||||
3195 | else | - | ||||||||||||||||||||||||||||||
3196 | view->d_func()->updateRectF(rect); never executed: view->d_func()->updateRectF(rect); | 0 | ||||||||||||||||||||||||||||||
3197 | } | - | ||||||||||||||||||||||||||||||
3198 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3199 | d->updatedRects << rect; | - | ||||||||||||||||||||||||||||||
3200 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3201 | } | - | ||||||||||||||||||||||||||||||
3202 | - | |||||||||||||||||||||||||||||||
3203 | if (!d->calledEmitUpdated) {
| 0 | ||||||||||||||||||||||||||||||
3204 | d->calledEmitUpdated = true; | - | ||||||||||||||||||||||||||||||
3205 | QMetaObject::invokeMethod(this, "_q_emitUpdated", Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
3206 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3207 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3208 | - | |||||||||||||||||||||||||||||||
3209 | /*! | - | ||||||||||||||||||||||||||||||
3210 | \fn void QGraphicsScene::update(qreal x, qreal y, qreal w, qreal h) | - | ||||||||||||||||||||||||||||||
3211 | \overload | - | ||||||||||||||||||||||||||||||
3212 | \since 4.3 | - | ||||||||||||||||||||||||||||||
3213 | - | |||||||||||||||||||||||||||||||
3214 | This function is equivalent to calling update(QRectF(\a x, \a y, \a w, | - | ||||||||||||||||||||||||||||||
3215 | \a h)); | - | ||||||||||||||||||||||||||||||
3216 | */ | - | ||||||||||||||||||||||||||||||
3217 | - | |||||||||||||||||||||||||||||||
3218 | /*! | - | ||||||||||||||||||||||||||||||
3219 | Invalidates and schedules a redraw of the \a layers in \a rect on the | - | ||||||||||||||||||||||||||||||
3220 | scene. Any cached content in \a layers is unconditionally invalidated and | - | ||||||||||||||||||||||||||||||
3221 | redrawn. | - | ||||||||||||||||||||||||||||||
3222 | - | |||||||||||||||||||||||||||||||
3223 | You can use this function overload to notify QGraphicsScene of changes to | - | ||||||||||||||||||||||||||||||
3224 | the background or the foreground of the scene. This function is commonly | - | ||||||||||||||||||||||||||||||
3225 | used for scenes with tile-based backgrounds to notify changes when | - | ||||||||||||||||||||||||||||||
3226 | QGraphicsView has enabled | - | ||||||||||||||||||||||||||||||
3227 | \l{QGraphicsView::CacheBackground}{CacheBackground}. | - | ||||||||||||||||||||||||||||||
3228 | - | |||||||||||||||||||||||||||||||
3229 | Example: | - | ||||||||||||||||||||||||||||||
3230 | - | |||||||||||||||||||||||||||||||
3231 | \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 5 | - | ||||||||||||||||||||||||||||||
3232 | - | |||||||||||||||||||||||||||||||
3233 | Note that QGraphicsView currently supports background caching only (see | - | ||||||||||||||||||||||||||||||
3234 | QGraphicsView::CacheBackground). This function is equivalent to calling | - | ||||||||||||||||||||||||||||||
3235 | update() if any layer but BackgroundLayer is passed. | - | ||||||||||||||||||||||||||||||
3236 | - | |||||||||||||||||||||||||||||||
3237 | \sa QGraphicsView::resetCachedContent() | - | ||||||||||||||||||||||||||||||
3238 | */ | - | ||||||||||||||||||||||||||||||
3239 | void QGraphicsScene::invalidate(const QRectF &rect, SceneLayers layers) | - | ||||||||||||||||||||||||||||||
3240 | { | - | ||||||||||||||||||||||||||||||
3241 | foreach (QGraphicsView *view, views()) | - | ||||||||||||||||||||||||||||||
3242 | view->invalidateScene(rect, layers); never executed: view->invalidateScene(rect, layers); | 0 | ||||||||||||||||||||||||||||||
3243 | update(rect); | - | ||||||||||||||||||||||||||||||
3244 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3245 | - | |||||||||||||||||||||||||||||||
3246 | /*! | - | ||||||||||||||||||||||||||||||
3247 | \fn void QGraphicsScene::invalidate(qreal x, qreal y, qreal w, qreal h, SceneLayers layers) | - | ||||||||||||||||||||||||||||||
3248 | \overload | - | ||||||||||||||||||||||||||||||
3249 | \since 4.3 | - | ||||||||||||||||||||||||||||||
3250 | - | |||||||||||||||||||||||||||||||
3251 | This convenience function is equivalent to calling invalidate(QRectF(\a x, \a | - | ||||||||||||||||||||||||||||||
3252 | y, \a w, \a h), \a layers); | - | ||||||||||||||||||||||||||||||
3253 | */ | - | ||||||||||||||||||||||||||||||
3254 | - | |||||||||||||||||||||||||||||||
3255 | /*! | - | ||||||||||||||||||||||||||||||
3256 | Returns a list of all the views that display this scene. | - | ||||||||||||||||||||||||||||||
3257 | - | |||||||||||||||||||||||||||||||
3258 | \sa QGraphicsView::scene() | - | ||||||||||||||||||||||||||||||
3259 | */ | - | ||||||||||||||||||||||||||||||
3260 | QList <QGraphicsView *> QGraphicsScene::views() const | - | ||||||||||||||||||||||||||||||
3261 | { | - | ||||||||||||||||||||||||||||||
3262 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3263 | return d->views; never executed: return d->views; | 0 | ||||||||||||||||||||||||||||||
3264 | } | - | ||||||||||||||||||||||||||||||
3265 | - | |||||||||||||||||||||||||||||||
3266 | /*! | - | ||||||||||||||||||||||||||||||
3267 | This slot \e advances the scene by one step, by calling | - | ||||||||||||||||||||||||||||||
3268 | QGraphicsItem::advance() for all items on the scene. This is done in two | - | ||||||||||||||||||||||||||||||
3269 | phases: in the first phase, all items are notified that the scene is about | - | ||||||||||||||||||||||||||||||
3270 | to change, and in the second phase all items are notified that they can | - | ||||||||||||||||||||||||||||||
3271 | move. In the first phase, QGraphicsItem::advance() is called passing a | - | ||||||||||||||||||||||||||||||
3272 | value of 0 as an argument, and 1 is passed in the second phase. | - | ||||||||||||||||||||||||||||||
3273 | - | |||||||||||||||||||||||||||||||
3274 | Note that you can also use the \l{The Animation Framework}{Animation | - | ||||||||||||||||||||||||||||||
3275 | Framework} for animations. | - | ||||||||||||||||||||||||||||||
3276 | - | |||||||||||||||||||||||||||||||
3277 | \sa QGraphicsItem::advance(), QTimeLine | - | ||||||||||||||||||||||||||||||
3278 | */ | - | ||||||||||||||||||||||||||||||
3279 | void QGraphicsScene::advance() | - | ||||||||||||||||||||||||||||||
3280 | { | - | ||||||||||||||||||||||||||||||
3281 | for (int i = 0; i < 2; ++i) {
| 0 | ||||||||||||||||||||||||||||||
3282 | foreach (QGraphicsItem *item, items()) | - | ||||||||||||||||||||||||||||||
3283 | item->advance(i); never executed: item->advance(i); | 0 | ||||||||||||||||||||||||||||||
3284 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3285 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3286 | - | |||||||||||||||||||||||||||||||
3287 | /*! | - | ||||||||||||||||||||||||||||||
3288 | Processes the event \a event, and dispatches it to the respective | - | ||||||||||||||||||||||||||||||
3289 | event handlers. | - | ||||||||||||||||||||||||||||||
3290 | - | |||||||||||||||||||||||||||||||
3291 | In addition to calling the convenience event handlers, this | - | ||||||||||||||||||||||||||||||
3292 | function is responsible for converting mouse move events to hover | - | ||||||||||||||||||||||||||||||
3293 | events for when there is no mouse grabber item. Hover events are | - | ||||||||||||||||||||||||||||||
3294 | delivered directly to items; there is no convenience function for | - | ||||||||||||||||||||||||||||||
3295 | them. | - | ||||||||||||||||||||||||||||||
3296 | - | |||||||||||||||||||||||||||||||
3297 | Unlike QWidget, QGraphicsScene does not have the convenience functions | - | ||||||||||||||||||||||||||||||
3298 | \l{QWidget::}{enterEvent()} and \l{QWidget::}{leaveEvent()}. Use this | - | ||||||||||||||||||||||||||||||
3299 | function to obtain those events instead. | - | ||||||||||||||||||||||||||||||
3300 | - | |||||||||||||||||||||||||||||||
3301 | \sa contextMenuEvent(), keyPressEvent(), keyReleaseEvent(), | - | ||||||||||||||||||||||||||||||
3302 | mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), | - | ||||||||||||||||||||||||||||||
3303 | mouseDoubleClickEvent(), focusInEvent(), focusOutEvent() | - | ||||||||||||||||||||||||||||||
3304 | */ | - | ||||||||||||||||||||||||||||||
3305 | bool QGraphicsScene::event(QEvent *event) | - | ||||||||||||||||||||||||||||||
3306 | { | - | ||||||||||||||||||||||||||||||
3307 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3308 | - | |||||||||||||||||||||||||||||||
3309 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||
3310 | case QEvent::GraphicsSceneMousePress: never executed: case QEvent::GraphicsSceneMousePress: | 0 | ||||||||||||||||||||||||||||||
3311 | case QEvent::GraphicsSceneMouseMove: never executed: case QEvent::GraphicsSceneMouseMove: | 0 | ||||||||||||||||||||||||||||||
3312 | case QEvent::GraphicsSceneMouseRelease: never executed: case QEvent::GraphicsSceneMouseRelease: | 0 | ||||||||||||||||||||||||||||||
3313 | case QEvent::GraphicsSceneMouseDoubleClick: never executed: case QEvent::GraphicsSceneMouseDoubleClick: | 0 | ||||||||||||||||||||||||||||||
3314 | case QEvent::GraphicsSceneHoverEnter: never executed: case QEvent::GraphicsSceneHoverEnter: | 0 | ||||||||||||||||||||||||||||||
3315 | case QEvent::GraphicsSceneHoverLeave: never executed: case QEvent::GraphicsSceneHoverLeave: | 0 | ||||||||||||||||||||||||||||||
3316 | case QEvent::GraphicsSceneHoverMove: never executed: case QEvent::GraphicsSceneHoverMove: | 0 | ||||||||||||||||||||||||||||||
3317 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||||||||||||||
3318 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||||||||||||||
3319 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||||||||||||||
3320 | // Reset the under-mouse list to ensure that this event gets fresh | - | ||||||||||||||||||||||||||||||
3321 | // item-under-mouse data. Be careful about this list; if people delete | - | ||||||||||||||||||||||||||||||
3322 | // items from inside event handlers, this list can quickly end up | - | ||||||||||||||||||||||||||||||
3323 | // having stale pointers in it. We need to clear it before dispatching | - | ||||||||||||||||||||||||||||||
3324 | // events that use it. | - | ||||||||||||||||||||||||||||||
3325 | // ### this should only be cleared if we received a new mouse move event, | - | ||||||||||||||||||||||||||||||
3326 | // which relies on us fixing the replay mechanism in QGraphicsView. | - | ||||||||||||||||||||||||||||||
3327 | d->cachedItemsUnderMouse.clear(); | - | ||||||||||||||||||||||||||||||
3328 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
3329 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3330 | } | - | ||||||||||||||||||||||||||||||
3331 | - | |||||||||||||||||||||||||||||||
3332 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||
3333 | case QEvent::GraphicsSceneDragEnter: never executed: case QEvent::GraphicsSceneDragEnter: | 0 | ||||||||||||||||||||||||||||||
3334 | dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3335 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3336 | case QEvent::GraphicsSceneDragMove: never executed: case QEvent::GraphicsSceneDragMove: | 0 | ||||||||||||||||||||||||||||||
3337 | dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3338 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3339 | case QEvent::GraphicsSceneDragLeave: never executed: case QEvent::GraphicsSceneDragLeave: | 0 | ||||||||||||||||||||||||||||||
3340 | dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3341 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3342 | case QEvent::GraphicsSceneDrop: never executed: case QEvent::GraphicsSceneDrop: | 0 | ||||||||||||||||||||||||||||||
3343 | dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3344 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3345 | case QEvent::GraphicsSceneContextMenu: never executed: case QEvent::GraphicsSceneContextMenu: | 0 | ||||||||||||||||||||||||||||||
3346 | contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3347 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3348 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||||||||
3349 | if (!d->focusItem) {
| 0 | ||||||||||||||||||||||||||||||
3350 | QKeyEvent *k = static_cast<QKeyEvent *>(event); | - | ||||||||||||||||||||||||||||||
3351 | if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
| 0 | ||||||||||||||||||||||||||||||
3352 | if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
| 0 | ||||||||||||||||||||||||||||||
3353 | bool res = false; | - | ||||||||||||||||||||||||||||||
3354 | if (k->key() == Qt::Key_Backtab
| 0 | ||||||||||||||||||||||||||||||
3355 | || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
| 0 | ||||||||||||||||||||||||||||||
3356 | res = focusNextPrevChild(false); | - | ||||||||||||||||||||||||||||||
3357 | } else if (k->key() == Qt::Key_Tab) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
3358 | res = focusNextPrevChild(true); | - | ||||||||||||||||||||||||||||||
3359 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3360 | if (!res)
| 0 | ||||||||||||||||||||||||||||||
3361 | event->ignore(); never executed: event->ignore(); | 0 | ||||||||||||||||||||||||||||||
3362 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
3363 | } | - | ||||||||||||||||||||||||||||||
3364 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3365 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3366 | keyPressEvent(static_cast<QKeyEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3367 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3368 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||||||||||||||
3369 | keyReleaseEvent(static_cast<QKeyEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3370 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3371 | case QEvent::ShortcutOverride: { never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||||||||||||||
3372 | QGraphicsItem *parent = focusItem(); | - | ||||||||||||||||||||||||||||||
3373 | while (parent) {
| 0 | ||||||||||||||||||||||||||||||
3374 | d->sendEvent(parent, event); | - | ||||||||||||||||||||||||||||||
3375 | if (event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||
3376 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
3377 | parent = parent->parentItem(); | - | ||||||||||||||||||||||||||||||
3378 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3379 | } | - | ||||||||||||||||||||||||||||||
3380 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3381 | case QEvent::GraphicsSceneMouseMove: never executed: case QEvent::GraphicsSceneMouseMove: | 0 | ||||||||||||||||||||||||||||||
3382 | { | - | ||||||||||||||||||||||||||||||
3383 | QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event); | - | ||||||||||||||||||||||||||||||
3384 | d->lastSceneMousePos = mouseEvent->scenePos(); | - | ||||||||||||||||||||||||||||||
3385 | mouseMoveEvent(mouseEvent); | - | ||||||||||||||||||||||||||||||
3386 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3387 | } | - | ||||||||||||||||||||||||||||||
3388 | case QEvent::GraphicsSceneMousePress: never executed: case QEvent::GraphicsSceneMousePress: | 0 | ||||||||||||||||||||||||||||||
3389 | mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3390 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3391 | case QEvent::GraphicsSceneMouseRelease: never executed: case QEvent::GraphicsSceneMouseRelease: | 0 | ||||||||||||||||||||||||||||||
3392 | mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3393 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3394 | case QEvent::GraphicsSceneMouseDoubleClick: never executed: case QEvent::GraphicsSceneMouseDoubleClick: | 0 | ||||||||||||||||||||||||||||||
3395 | mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3396 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3397 | case QEvent::GraphicsSceneWheel: never executed: case QEvent::GraphicsSceneWheel: | 0 | ||||||||||||||||||||||||||||||
3398 | wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3399 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3400 | case QEvent::FocusIn: never executed: case QEvent::FocusIn: | 0 | ||||||||||||||||||||||||||||||
3401 | focusInEvent(static_cast<QFocusEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3402 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3403 | case QEvent::FocusOut: never executed: case QEvent::FocusOut: | 0 | ||||||||||||||||||||||||||||||
3404 | focusOutEvent(static_cast<QFocusEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3405 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3406 | case QEvent::GraphicsSceneHoverEnter: never executed: case QEvent::GraphicsSceneHoverEnter: | 0 | ||||||||||||||||||||||||||||||
3407 | case QEvent::GraphicsSceneHoverLeave: never executed: case QEvent::GraphicsSceneHoverLeave: | 0 | ||||||||||||||||||||||||||||||
3408 | case QEvent::GraphicsSceneHoverMove: never executed: case QEvent::GraphicsSceneHoverMove: | 0 | ||||||||||||||||||||||||||||||
3409 | { | - | ||||||||||||||||||||||||||||||
3410 | QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event); | - | ||||||||||||||||||||||||||||||
3411 | d->lastSceneMousePos = hoverEvent->scenePos(); | - | ||||||||||||||||||||||||||||||
3412 | d->dispatchHoverEvent(hoverEvent); | - | ||||||||||||||||||||||||||||||
3413 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3414 | } | - | ||||||||||||||||||||||||||||||
3415 | case QEvent::Leave: never executed: case QEvent::Leave: | 0 | ||||||||||||||||||||||||||||||
3416 | // hackieshly unpacking the viewport pointer from the leave event. | - | ||||||||||||||||||||||||||||||
3417 | d->leaveScene(reinterpret_cast<QWidget *>(event->d)); | - | ||||||||||||||||||||||||||||||
3418 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3419 | case QEvent::GraphicsSceneHelp: never executed: case QEvent::GraphicsSceneHelp: | 0 | ||||||||||||||||||||||||||||||
3420 | helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3421 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3422 | case QEvent::InputMethod: never executed: case QEvent::InputMethod: | 0 | ||||||||||||||||||||||||||||||
3423 | inputMethodEvent(static_cast<QInputMethodEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3424 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3425 | case QEvent::WindowActivate: never executed: case QEvent::WindowActivate: | 0 | ||||||||||||||||||||||||||||||
3426 | if (!d->activationRefCount++) {
| 0 | ||||||||||||||||||||||||||||||
3427 | if (d->lastActivePanel) {
| 0 | ||||||||||||||||||||||||||||||
3428 | // Activate the last panel. | - | ||||||||||||||||||||||||||||||
3429 | d->setActivePanelHelper(d->lastActivePanel, true); | - | ||||||||||||||||||||||||||||||
3430 | } else if (d->tabFocusFirst && d->tabFocusFirst->isPanel()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
3431 | // Activate the panel of the first item in the tab focus | - | ||||||||||||||||||||||||||||||
3432 | // chain. | - | ||||||||||||||||||||||||||||||
3433 | d->setActivePanelHelper(d->tabFocusFirst, true); | - | ||||||||||||||||||||||||||||||
3434 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3435 | // Activate all toplevel items. | - | ||||||||||||||||||||||||||||||
3436 | QEvent event(QEvent::WindowActivate); | - | ||||||||||||||||||||||||||||||
3437 | foreach (QGraphicsItem *item, items()) { | - | ||||||||||||||||||||||||||||||
3438 | if (item->isVisible() && !item->isPanel() && !item->parentItem())
| 0 | ||||||||||||||||||||||||||||||
3439 | sendEvent(item, &event); never executed: sendEvent(item, &event); | 0 | ||||||||||||||||||||||||||||||
3440 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3441 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3442 | } | - | ||||||||||||||||||||||||||||||
3443 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3444 | case QEvent::WindowDeactivate: never executed: case QEvent::WindowDeactivate: | 0 | ||||||||||||||||||||||||||||||
3445 | if (!--d->activationRefCount) {
| 0 | ||||||||||||||||||||||||||||||
3446 | if (d->activePanel) {
| 0 | ||||||||||||||||||||||||||||||
3447 | // Deactivate the active panel (but keep it so we can | - | ||||||||||||||||||||||||||||||
3448 | // reactivate it later). | - | ||||||||||||||||||||||||||||||
3449 | QGraphicsItem *lastActivePanel = d->activePanel; | - | ||||||||||||||||||||||||||||||
3450 | d->setActivePanelHelper(0, true); | - | ||||||||||||||||||||||||||||||
3451 | d->lastActivePanel = lastActivePanel; | - | ||||||||||||||||||||||||||||||
3452 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3453 | // Activate all toplevel items. | - | ||||||||||||||||||||||||||||||
3454 | QEvent event(QEvent::WindowDeactivate); | - | ||||||||||||||||||||||||||||||
3455 | foreach (QGraphicsItem *item, items()) { | - | ||||||||||||||||||||||||||||||
3456 | if (item->isVisible() && !item->isPanel() && !item->parentItem())
| 0 | ||||||||||||||||||||||||||||||
3457 | sendEvent(item, &event); never executed: sendEvent(item, &event); | 0 | ||||||||||||||||||||||||||||||
3458 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3459 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3460 | } | - | ||||||||||||||||||||||||||||||
3461 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3462 | case QEvent::ApplicationFontChange: { never executed: case QEvent::ApplicationFontChange: | 0 | ||||||||||||||||||||||||||||||
3463 | // Resolve the existing scene font. | - | ||||||||||||||||||||||||||||||
3464 | d->resolveFont(); | - | ||||||||||||||||||||||||||||||
3465 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3466 | } | - | ||||||||||||||||||||||||||||||
3467 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||||||||
3468 | // Update the entire scene when the font changes. | - | ||||||||||||||||||||||||||||||
3469 | update(); | - | ||||||||||||||||||||||||||||||
3470 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3471 | case QEvent::ApplicationPaletteChange: { never executed: case QEvent::ApplicationPaletteChange: | 0 | ||||||||||||||||||||||||||||||
3472 | // Resolve the existing scene palette. | - | ||||||||||||||||||||||||||||||
3473 | d->resolvePalette(); | - | ||||||||||||||||||||||||||||||
3474 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3475 | } | - | ||||||||||||||||||||||||||||||
3476 | case QEvent::PaletteChange: never executed: case QEvent::PaletteChange: | 0 | ||||||||||||||||||||||||||||||
3477 | // Update the entire scene when the palette changes. | - | ||||||||||||||||||||||||||||||
3478 | update(); | - | ||||||||||||||||||||||||||||||
3479 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3480 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||||||||
3481 | // Reresolve all widgets' styles. Update all top-level widgets' | - | ||||||||||||||||||||||||||||||
3482 | // geometries that do not have an explicit style set. | - | ||||||||||||||||||||||||||||||
3483 | update(); | - | ||||||||||||||||||||||||||||||
3484 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3485 | case QEvent::StyleAnimationUpdate: never executed: case QEvent::StyleAnimationUpdate: | 0 | ||||||||||||||||||||||||||||||
3486 | // Because QGraphicsItem is not a QObject, QStyle driven | - | ||||||||||||||||||||||||||||||
3487 | // animations are forced to update the whole scene | - | ||||||||||||||||||||||||||||||
3488 | update(); | - | ||||||||||||||||||||||||||||||
3489 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3490 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||||||||||||||
3491 | case QEvent::TouchUpdate: never executed: case QEvent::TouchUpdate: | 0 | ||||||||||||||||||||||||||||||
3492 | case QEvent::TouchEnd: never executed: case QEvent::TouchEnd: | 0 | ||||||||||||||||||||||||||||||
3493 | d->touchEventHandler(static_cast<QTouchEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3494 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3495 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
3496 | case QEvent::Gesture: never executed: case QEvent::Gesture: | 0 | ||||||||||||||||||||||||||||||
3497 | case QEvent::GestureOverride: never executed: case QEvent::GestureOverride: | 0 | ||||||||||||||||||||||||||||||
3498 | d->gestureEventHandler(static_cast<QGestureEvent *>(event)); | - | ||||||||||||||||||||||||||||||
3499 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3500 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
3501 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
3502 | return QObject::event(event); never executed: return QObject::event(event); | 0 | ||||||||||||||||||||||||||||||
3503 | } | - | ||||||||||||||||||||||||||||||
3504 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
3505 | } | - | ||||||||||||||||||||||||||||||
3506 | - | |||||||||||||||||||||||||||||||
3507 | /*! | - | ||||||||||||||||||||||||||||||
3508 | \reimp | - | ||||||||||||||||||||||||||||||
3509 | - | |||||||||||||||||||||||||||||||
3510 | QGraphicsScene filters QApplication's events to detect palette and font | - | ||||||||||||||||||||||||||||||
3511 | changes. | - | ||||||||||||||||||||||||||||||
3512 | */ | - | ||||||||||||||||||||||||||||||
3513 | bool QGraphicsScene::eventFilter(QObject *watched, QEvent *event) | - | ||||||||||||||||||||||||||||||
3514 | { | - | ||||||||||||||||||||||||||||||
3515 | if (watched != qApp)
| 0 | ||||||||||||||||||||||||||||||
3516 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3517 | - | |||||||||||||||||||||||||||||||
3518 | switch (event->type()) { | - | ||||||||||||||||||||||||||||||
3519 | case QEvent::ApplicationPaletteChange: never executed: case QEvent::ApplicationPaletteChange: | 0 | ||||||||||||||||||||||||||||||
3520 | QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange)); | - | ||||||||||||||||||||||||||||||
3521 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3522 | case QEvent::ApplicationFontChange: never executed: case QEvent::ApplicationFontChange: | 0 | ||||||||||||||||||||||||||||||
3523 | QApplication::postEvent(this, new QEvent(QEvent::ApplicationFontChange)); | - | ||||||||||||||||||||||||||||||
3524 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3525 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
3526 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3527 | } | - | ||||||||||||||||||||||||||||||
3528 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3529 | } | - | ||||||||||||||||||||||||||||||
3530 | - | |||||||||||||||||||||||||||||||
3531 | /*! | - | ||||||||||||||||||||||||||||||
3532 | This event handler, for event \a contextMenuEvent, can be reimplemented in | - | ||||||||||||||||||||||||||||||
3533 | a subclass to receive context menu events. The default implementation | - | ||||||||||||||||||||||||||||||
3534 | forwards the event to the topmost visible item that accepts context menu events at | - | ||||||||||||||||||||||||||||||
3535 | the position of the event. If no items accept context menu events at this | - | ||||||||||||||||||||||||||||||
3536 | position, the event is ignored. | - | ||||||||||||||||||||||||||||||
3537 | - | |||||||||||||||||||||||||||||||
3538 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
3539 | - | |||||||||||||||||||||||||||||||
3540 | \sa QGraphicsItem::contextMenuEvent() | - | ||||||||||||||||||||||||||||||
3541 | */ | - | ||||||||||||||||||||||||||||||
3542 | void QGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) | - | ||||||||||||||||||||||||||||||
3543 | { | - | ||||||||||||||||||||||||||||||
3544 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3545 | // Ignore by default. | - | ||||||||||||||||||||||||||||||
3546 | contextMenuEvent->ignore(); | - | ||||||||||||||||||||||||||||||
3547 | - | |||||||||||||||||||||||||||||||
3548 | // Send the event to all items at this position until one item accepts the | - | ||||||||||||||||||||||||||||||
3549 | // event. | - | ||||||||||||||||||||||||||||||
3550 | foreach (QGraphicsItem *item, d->itemsAtPosition(contextMenuEvent->screenPos(), | - | ||||||||||||||||||||||||||||||
3551 | contextMenuEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
3552 | contextMenuEvent->widget())) { | - | ||||||||||||||||||||||||||||||
3553 | contextMenuEvent->setPos(item->d_ptr->genericMapFromScene(contextMenuEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
3554 | contextMenuEvent->widget())); | - | ||||||||||||||||||||||||||||||
3555 | contextMenuEvent->accept(); | - | ||||||||||||||||||||||||||||||
3556 | if (!d->sendEvent(item, contextMenuEvent))
| 0 | ||||||||||||||||||||||||||||||
3557 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3558 | - | |||||||||||||||||||||||||||||||
3559 | if (contextMenuEvent->isAccepted())
| 0 | ||||||||||||||||||||||||||||||
3560 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3561 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3562 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3563 | - | |||||||||||||||||||||||||||||||
3564 | /*! | - | ||||||||||||||||||||||||||||||
3565 | This event handler, for event \a event, can be reimplemented in a subclass | - | ||||||||||||||||||||||||||||||
3566 | to receive drag enter events for the scene. | - | ||||||||||||||||||||||||||||||
3567 | - | |||||||||||||||||||||||||||||||
3568 | The default implementation accepts the event and prepares the scene to | - | ||||||||||||||||||||||||||||||
3569 | accept drag move events. | - | ||||||||||||||||||||||||||||||
3570 | - | |||||||||||||||||||||||||||||||
3571 | \sa QGraphicsItem::dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), | - | ||||||||||||||||||||||||||||||
3572 | dropEvent() | - | ||||||||||||||||||||||||||||||
3573 | */ | - | ||||||||||||||||||||||||||||||
3574 | void QGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||||||||||||||
3575 | { | - | ||||||||||||||||||||||||||||||
3576 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3577 | d->dragDropItem = 0; | - | ||||||||||||||||||||||||||||||
3578 | d->lastDropAction = Qt::IgnoreAction; | - | ||||||||||||||||||||||||||||||
3579 | event->accept(); | - | ||||||||||||||||||||||||||||||
3580 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3581 | - | |||||||||||||||||||||||||||||||
3582 | /*! | - | ||||||||||||||||||||||||||||||
3583 | This event handler, for event \a event, can be reimplemented in a subclass | - | ||||||||||||||||||||||||||||||
3584 | to receive drag move events for the scene. | - | ||||||||||||||||||||||||||||||
3585 | - | |||||||||||||||||||||||||||||||
3586 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
3587 | - | |||||||||||||||||||||||||||||||
3588 | \sa QGraphicsItem::dragMoveEvent(), dragEnterEvent(), dragLeaveEvent(), | - | ||||||||||||||||||||||||||||||
3589 | dropEvent() | - | ||||||||||||||||||||||||||||||
3590 | */ | - | ||||||||||||||||||||||||||||||
3591 | void QGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||||||||||||||
3592 | { | - | ||||||||||||||||||||||||||||||
3593 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3594 | event->ignore(); | - | ||||||||||||||||||||||||||||||
3595 | - | |||||||||||||||||||||||||||||||
3596 | if (!d->mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
3597 | // Mouse grabbers that start drag events lose the mouse grab. | - | ||||||||||||||||||||||||||||||
3598 | d->clearMouseGrabber(); | - | ||||||||||||||||||||||||||||||
3599 | d->mouseGrabberButtonDownPos.clear(); | - | ||||||||||||||||||||||||||||||
3600 | d->mouseGrabberButtonDownScenePos.clear(); | - | ||||||||||||||||||||||||||||||
3601 | d->mouseGrabberButtonDownScreenPos.clear(); | - | ||||||||||||||||||||||||||||||
3602 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3603 | - | |||||||||||||||||||||||||||||||
3604 | bool eventDelivered = false; | - | ||||||||||||||||||||||||||||||
3605 | - | |||||||||||||||||||||||||||||||
3606 | // Find the topmost enabled items under the cursor. They are all | - | ||||||||||||||||||||||||||||||
3607 | // candidates for accepting drag & drop events. | - | ||||||||||||||||||||||||||||||
3608 | foreach (QGraphicsItem *item, d->itemsAtPosition(event->screenPos(), | - | ||||||||||||||||||||||||||||||
3609 | event->scenePos(), | - | ||||||||||||||||||||||||||||||
3610 | event->widget())) { | - | ||||||||||||||||||||||||||||||
3611 | if (!item->isEnabled() || !item->acceptDrops())
| 0 | ||||||||||||||||||||||||||||||
3612 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
3613 | - | |||||||||||||||||||||||||||||||
3614 | if (item != d->dragDropItem) {
| 0 | ||||||||||||||||||||||||||||||
3615 | // Enter the new drag drop item. If it accepts the event, we send | - | ||||||||||||||||||||||||||||||
3616 | // the leave to the parent item. | - | ||||||||||||||||||||||||||||||
3617 | QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); | - | ||||||||||||||||||||||||||||||
3618 | d->cloneDragDropEvent(&dragEnter, event); | - | ||||||||||||||||||||||||||||||
3619 | dragEnter.setDropAction(event->proposedAction()); | - | ||||||||||||||||||||||||||||||
3620 | d->sendDragDropEvent(item, &dragEnter); | - | ||||||||||||||||||||||||||||||
3621 | event->setAccepted(dragEnter.isAccepted()); | - | ||||||||||||||||||||||||||||||
3622 | event->setDropAction(dragEnter.dropAction()); | - | ||||||||||||||||||||||||||||||
3623 | if (!event->isAccepted()) {
| 0 | ||||||||||||||||||||||||||||||
3624 | // Propagate to the item under | - | ||||||||||||||||||||||||||||||
3625 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
3626 | } | - | ||||||||||||||||||||||||||||||
3627 | - | |||||||||||||||||||||||||||||||
3628 | d->lastDropAction = event->dropAction(); | - | ||||||||||||||||||||||||||||||
3629 | - | |||||||||||||||||||||||||||||||
3630 | if (d->dragDropItem) {
| 0 | ||||||||||||||||||||||||||||||
3631 | // Leave the last drag drop item. A perfect implementation | - | ||||||||||||||||||||||||||||||
3632 | // would set the position of this event to the point where | - | ||||||||||||||||||||||||||||||
3633 | // this event and the last event intersect with the item's | - | ||||||||||||||||||||||||||||||
3634 | // shape, but that's not easy to do. :-) | - | ||||||||||||||||||||||||||||||
3635 | QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); | - | ||||||||||||||||||||||||||||||
3636 | d->cloneDragDropEvent(&dragLeave, event); | - | ||||||||||||||||||||||||||||||
3637 | d->sendDragDropEvent(d->dragDropItem, &dragLeave); | - | ||||||||||||||||||||||||||||||
3638 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3639 | - | |||||||||||||||||||||||||||||||
3640 | // We've got a new drag & drop item | - | ||||||||||||||||||||||||||||||
3641 | d->dragDropItem = item; | - | ||||||||||||||||||||||||||||||
3642 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3643 | - | |||||||||||||||||||||||||||||||
3644 | // Send the move event. | - | ||||||||||||||||||||||||||||||
3645 | event->setDropAction(d->lastDropAction); | - | ||||||||||||||||||||||||||||||
3646 | event->accept(); | - | ||||||||||||||||||||||||||||||
3647 | d->sendDragDropEvent(item, event); | - | ||||||||||||||||||||||||||||||
3648 | if (event->isAccepted())
| 0 | ||||||||||||||||||||||||||||||
3649 | d->lastDropAction = event->dropAction(); never executed: d->lastDropAction = event->dropAction(); | 0 | ||||||||||||||||||||||||||||||
3650 | eventDelivered = true; | - | ||||||||||||||||||||||||||||||
3651 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3652 | } | - | ||||||||||||||||||||||||||||||
3653 | - | |||||||||||||||||||||||||||||||
3654 | if (!eventDelivered) {
| 0 | ||||||||||||||||||||||||||||||
3655 | if (d->dragDropItem) {
| 0 | ||||||||||||||||||||||||||||||
3656 | // Leave the last drag drop item | - | ||||||||||||||||||||||||||||||
3657 | QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); | - | ||||||||||||||||||||||||||||||
3658 | d->cloneDragDropEvent(&dragLeave, event); | - | ||||||||||||||||||||||||||||||
3659 | d->sendDragDropEvent(d->dragDropItem, &dragLeave); | - | ||||||||||||||||||||||||||||||
3660 | d->dragDropItem = 0; | - | ||||||||||||||||||||||||||||||
3661 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3662 | // Propagate | - | ||||||||||||||||||||||||||||||
3663 | event->setDropAction(Qt::IgnoreAction); | - | ||||||||||||||||||||||||||||||
3664 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3665 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3666 | - | |||||||||||||||||||||||||||||||
3667 | /*! | - | ||||||||||||||||||||||||||||||
3668 | This event handler, for event \a event, can be reimplemented in a subclass | - | ||||||||||||||||||||||||||||||
3669 | to receive drag leave events for the scene. | - | ||||||||||||||||||||||||||||||
3670 | - | |||||||||||||||||||||||||||||||
3671 | \sa QGraphicsItem::dragLeaveEvent(), dragEnterEvent(), dragMoveEvent(), | - | ||||||||||||||||||||||||||||||
3672 | dropEvent() | - | ||||||||||||||||||||||||||||||
3673 | */ | - | ||||||||||||||||||||||||||||||
3674 | void QGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||||||||||||||
3675 | { | - | ||||||||||||||||||||||||||||||
3676 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3677 | if (d->dragDropItem) {
| 0 | ||||||||||||||||||||||||||||||
3678 | // Leave the last drag drop item | - | ||||||||||||||||||||||||||||||
3679 | d->sendDragDropEvent(d->dragDropItem, event); | - | ||||||||||||||||||||||||||||||
3680 | d->dragDropItem = 0; | - | ||||||||||||||||||||||||||||||
3681 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3682 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3683 | - | |||||||||||||||||||||||||||||||
3684 | /*! | - | ||||||||||||||||||||||||||||||
3685 | This event handler, for event \a event, can be reimplemented in a subclass | - | ||||||||||||||||||||||||||||||
3686 | to receive drop events for the scene. | - | ||||||||||||||||||||||||||||||
3687 | - | |||||||||||||||||||||||||||||||
3688 | \sa QGraphicsItem::dropEvent(), dragEnterEvent(), dragMoveEvent(), | - | ||||||||||||||||||||||||||||||
3689 | dragLeaveEvent() | - | ||||||||||||||||||||||||||||||
3690 | */ | - | ||||||||||||||||||||||||||||||
3691 | void QGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event) | - | ||||||||||||||||||||||||||||||
3692 | { | - | ||||||||||||||||||||||||||||||
3693 | Q_UNUSED(event); | - | ||||||||||||||||||||||||||||||
3694 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3695 | if (d->dragDropItem) {
| 0 | ||||||||||||||||||||||||||||||
3696 | // Drop on the last drag drop item | - | ||||||||||||||||||||||||||||||
3697 | d->sendDragDropEvent(d->dragDropItem, event); | - | ||||||||||||||||||||||||||||||
3698 | d->dragDropItem = 0; | - | ||||||||||||||||||||||||||||||
3699 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3700 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3701 | - | |||||||||||||||||||||||||||||||
3702 | /*! | - | ||||||||||||||||||||||||||||||
3703 | This event handler, for event \a focusEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
3704 | subclass to receive focus in events. | - | ||||||||||||||||||||||||||||||
3705 | - | |||||||||||||||||||||||||||||||
3706 | The default implementation sets focus on the scene, and then on the last | - | ||||||||||||||||||||||||||||||
3707 | focus item. | - | ||||||||||||||||||||||||||||||
3708 | - | |||||||||||||||||||||||||||||||
3709 | \sa QGraphicsItem::focusOutEvent() | - | ||||||||||||||||||||||||||||||
3710 | */ | - | ||||||||||||||||||||||||||||||
3711 | void QGraphicsScene::focusInEvent(QFocusEvent *focusEvent) | - | ||||||||||||||||||||||||||||||
3712 | { | - | ||||||||||||||||||||||||||||||
3713 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3714 | - | |||||||||||||||||||||||||||||||
3715 | d->hasFocus = true; | - | ||||||||||||||||||||||||||||||
3716 | switch (focusEvent->reason()) { | - | ||||||||||||||||||||||||||||||
3717 | case Qt::TabFocusReason: never executed: case Qt::TabFocusReason: | 0 | ||||||||||||||||||||||||||||||
3718 | if (!focusNextPrevChild(true))
| 0 | ||||||||||||||||||||||||||||||
3719 | focusEvent->ignore(); never executed: focusEvent->ignore(); | 0 | ||||||||||||||||||||||||||||||
3720 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3721 | case Qt::BacktabFocusReason: never executed: case Qt::BacktabFocusReason: | 0 | ||||||||||||||||||||||||||||||
3722 | if (!focusNextPrevChild(false))
| 0 | ||||||||||||||||||||||||||||||
3723 | focusEvent->ignore(); never executed: focusEvent->ignore(); | 0 | ||||||||||||||||||||||||||||||
3724 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3725 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
3726 | if (d->passiveFocusItem) {
| 0 | ||||||||||||||||||||||||||||||
3727 | // Set focus on the last focus item | - | ||||||||||||||||||||||||||||||
3728 | setFocusItem(d->passiveFocusItem, focusEvent->reason()); | - | ||||||||||||||||||||||||||||||
3729 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3730 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3731 | } | - | ||||||||||||||||||||||||||||||
3732 | } | - | ||||||||||||||||||||||||||||||
3733 | - | |||||||||||||||||||||||||||||||
3734 | /*! | - | ||||||||||||||||||||||||||||||
3735 | This event handler, for event \a focusEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
3736 | subclass to receive focus out events. | - | ||||||||||||||||||||||||||||||
3737 | - | |||||||||||||||||||||||||||||||
3738 | The default implementation removes focus from any focus item, then removes | - | ||||||||||||||||||||||||||||||
3739 | focus from the scene. | - | ||||||||||||||||||||||||||||||
3740 | - | |||||||||||||||||||||||||||||||
3741 | \sa QGraphicsItem::focusInEvent() | - | ||||||||||||||||||||||||||||||
3742 | */ | - | ||||||||||||||||||||||||||||||
3743 | void QGraphicsScene::focusOutEvent(QFocusEvent *focusEvent) | - | ||||||||||||||||||||||||||||||
3744 | { | - | ||||||||||||||||||||||||||||||
3745 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3746 | d->hasFocus = false; | - | ||||||||||||||||||||||||||||||
3747 | d->passiveFocusItem = d->focusItem; | - | ||||||||||||||||||||||||||||||
3748 | setFocusItem(0, focusEvent->reason()); | - | ||||||||||||||||||||||||||||||
3749 | - | |||||||||||||||||||||||||||||||
3750 | // Remove all popups when the scene loses focus. | - | ||||||||||||||||||||||||||||||
3751 | if (!d->popupWidgets.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
3752 | d->removePopup(d->popupWidgets.first()); never executed: d->removePopup(d->popupWidgets.first()); | 0 | ||||||||||||||||||||||||||||||
3753 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3754 | - | |||||||||||||||||||||||||||||||
3755 | /*! | - | ||||||||||||||||||||||||||||||
3756 | This event handler, for event \a helpEvent, can be | - | ||||||||||||||||||||||||||||||
3757 | reimplemented in a subclass to receive help events. The events | - | ||||||||||||||||||||||||||||||
3758 | are of type QEvent::ToolTip, which are created when a tooltip is | - | ||||||||||||||||||||||||||||||
3759 | requested. | - | ||||||||||||||||||||||||||||||
3760 | - | |||||||||||||||||||||||||||||||
3761 | The default implementation shows the tooltip of the topmost | - | ||||||||||||||||||||||||||||||
3762 | visible item, i.e., the item with the highest z-value, at the mouse | - | ||||||||||||||||||||||||||||||
3763 | cursor position. If no item has a tooltip set, this function | - | ||||||||||||||||||||||||||||||
3764 | does nothing. | - | ||||||||||||||||||||||||||||||
3765 | - | |||||||||||||||||||||||||||||||
3766 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
3767 | - | |||||||||||||||||||||||||||||||
3768 | \sa QGraphicsItem::toolTip(), QGraphicsSceneHelpEvent | - | ||||||||||||||||||||||||||||||
3769 | */ | - | ||||||||||||||||||||||||||||||
3770 | void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent) | - | ||||||||||||||||||||||||||||||
3771 | { | - | ||||||||||||||||||||||||||||||
3772 | #ifdef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
3773 | Q_UNUSED(helpEvent); | - | ||||||||||||||||||||||||||||||
3774 | #else | - | ||||||||||||||||||||||||||||||
3775 | // Find the first item that does tooltips | - | ||||||||||||||||||||||||||||||
3776 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3777 | QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(), | - | ||||||||||||||||||||||||||||||
3778 | helpEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
3779 | helpEvent->widget()); | - | ||||||||||||||||||||||||||||||
3780 | QGraphicsItem *toolTipItem = 0; | - | ||||||||||||||||||||||||||||||
3781 | for (int i = 0; i < itemsAtPos.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
3782 | QGraphicsItem *tmp = itemsAtPos.at(i); | - | ||||||||||||||||||||||||||||||
3783 | if (tmp->d_func()->isProxyWidget()) {
| 0 | ||||||||||||||||||||||||||||||
3784 | // if the item is a proxy widget, the event is forwarded to it | - | ||||||||||||||||||||||||||||||
3785 | sendEvent(tmp, helpEvent); | - | ||||||||||||||||||||||||||||||
3786 | if (helpEvent->isAccepted())
| 0 | ||||||||||||||||||||||||||||||
3787 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
3788 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3789 | if (!tmp->toolTip().isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
3790 | toolTipItem = tmp; | - | ||||||||||||||||||||||||||||||
3791 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3792 | } | - | ||||||||||||||||||||||||||||||
3793 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3794 | - | |||||||||||||||||||||||||||||||
3795 | // Show or hide the tooltip | - | ||||||||||||||||||||||||||||||
3796 | QString text; | - | ||||||||||||||||||||||||||||||
3797 | QPoint point; | - | ||||||||||||||||||||||||||||||
3798 | if (toolTipItem && !toolTipItem->toolTip().isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
3799 | text = toolTipItem->toolTip(); | - | ||||||||||||||||||||||||||||||
3800 | point = helpEvent->screenPos(); | - | ||||||||||||||||||||||||||||||
3801 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3802 | QToolTip::showText(point, text, helpEvent->widget()); | - | ||||||||||||||||||||||||||||||
3803 | helpEvent->setAccepted(!text.isEmpty()); | - | ||||||||||||||||||||||||||||||
3804 | #endif | - | ||||||||||||||||||||||||||||||
3805 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3806 | - | |||||||||||||||||||||||||||||||
3807 | bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const | - | ||||||||||||||||||||||||||||||
3808 | { | - | ||||||||||||||||||||||||||||||
3809 | return (item->d_ptr->acceptsHover never executed: return (item->d_ptr->acceptsHover || (item->d_ptr->isWidget && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) && !item->isBlockedByModalPanel();
| 0 | ||||||||||||||||||||||||||||||
3810 | || (item->d_ptr->isWidget never executed: return (item->d_ptr->acceptsHover || (item->d_ptr->isWidget && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) && !item->isBlockedByModalPanel();
| 0 | ||||||||||||||||||||||||||||||
3811 | && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) never executed: return (item->d_ptr->acceptsHover || (item->d_ptr->isWidget && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) && !item->isBlockedByModalPanel();
| 0 | ||||||||||||||||||||||||||||||
3812 | && !item->isBlockedByModalPanel(); never executed: return (item->d_ptr->acceptsHover || (item->d_ptr->isWidget && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) && !item->isBlockedByModalPanel();
| 0 | ||||||||||||||||||||||||||||||
3813 | } | - | ||||||||||||||||||||||||||||||
3814 | - | |||||||||||||||||||||||||||||||
3815 | /*! | - | ||||||||||||||||||||||||||||||
3816 | This event handler, for event \a hoverEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
3817 | subclass to receive hover enter events. The default implementation | - | ||||||||||||||||||||||||||||||
3818 | forwards the event to the topmost visible item that accepts hover events at the | - | ||||||||||||||||||||||||||||||
3819 | scene position from the event. | - | ||||||||||||||||||||||||||||||
3820 | - | |||||||||||||||||||||||||||||||
3821 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
3822 | - | |||||||||||||||||||||||||||||||
3823 | \sa QGraphicsItem::hoverEvent(), QGraphicsItem::setAcceptHoverEvents() | - | ||||||||||||||||||||||||||||||
3824 | */ | - | ||||||||||||||||||||||||||||||
3825 | bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent) | - | ||||||||||||||||||||||||||||||
3826 | { | - | ||||||||||||||||||||||||||||||
3827 | if (allItemsIgnoreHoverEvents)
| 0 | ||||||||||||||||||||||||||||||
3828 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3829 | - | |||||||||||||||||||||||||||||||
3830 | // Find the first item that accepts hover events, reusing earlier | - | ||||||||||||||||||||||||||||||
3831 | // calculated data is possible. | - | ||||||||||||||||||||||||||||||
3832 | if (cachedItemsUnderMouse.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
3833 | cachedItemsUnderMouse = itemsAtPosition(hoverEvent->screenPos(), | - | ||||||||||||||||||||||||||||||
3834 | hoverEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
3835 | hoverEvent->widget()); | - | ||||||||||||||||||||||||||||||
3836 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3837 | - | |||||||||||||||||||||||||||||||
3838 | QGraphicsItem *item = 0; | - | ||||||||||||||||||||||||||||||
3839 | for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
3840 | QGraphicsItem *tmp = cachedItemsUnderMouse.at(i); | - | ||||||||||||||||||||||||||||||
3841 | if (itemAcceptsHoverEvents_helper(tmp)) {
| 0 | ||||||||||||||||||||||||||||||
3842 | item = tmp; | - | ||||||||||||||||||||||||||||||
3843 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3844 | } | - | ||||||||||||||||||||||||||||||
3845 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3846 | - | |||||||||||||||||||||||||||||||
3847 | // Find the common ancestor item for the new topmost hoverItem and the | - | ||||||||||||||||||||||||||||||
3848 | // last item in the hoverItem list. | - | ||||||||||||||||||||||||||||||
3849 | QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.last()) : 0;
| 0 | ||||||||||||||||||||||||||||||
3850 | while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem))
| 0 | ||||||||||||||||||||||||||||||
3851 | commonAncestorItem = commonAncestorItem->parentItem(); never executed: commonAncestorItem = commonAncestorItem->parentItem(); | 0 | ||||||||||||||||||||||||||||||
3852 | if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) {
| 0 | ||||||||||||||||||||||||||||||
3853 | // The common ancestor isn't in the same panel as the two hovered | - | ||||||||||||||||||||||||||||||
3854 | // items. | - | ||||||||||||||||||||||||||||||
3855 | commonAncestorItem = 0; | - | ||||||||||||||||||||||||||||||
3856 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3857 | - | |||||||||||||||||||||||||||||||
3858 | // Check if the common ancestor item is known. | - | ||||||||||||||||||||||||||||||
3859 | int index = commonAncestorItem ? hoverItems.indexOf(commonAncestorItem) : -1;
| 0 | ||||||||||||||||||||||||||||||
3860 | // Send hover leaves to any existing hovered children of the common | - | ||||||||||||||||||||||||||||||
3861 | // ancestor item. | - | ||||||||||||||||||||||||||||||
3862 | for (int i = hoverItems.size() - 1; i > index; --i) {
| 0 | ||||||||||||||||||||||||||||||
3863 | QGraphicsItem *lastItem = hoverItems.takeLast(); | - | ||||||||||||||||||||||||||||||
3864 | if (itemAcceptsHoverEvents_helper(lastItem))
| 0 | ||||||||||||||||||||||||||||||
3865 | sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, hoverEvent); never executed: sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, hoverEvent); | 0 | ||||||||||||||||||||||||||||||
3866 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3867 | - | |||||||||||||||||||||||||||||||
3868 | // Item is a child of a known item. Generate enter events for the | - | ||||||||||||||||||||||||||||||
3869 | // missing links. | - | ||||||||||||||||||||||||||||||
3870 | QList<QGraphicsItem *> parents; | - | ||||||||||||||||||||||||||||||
3871 | QGraphicsItem *parent = item; | - | ||||||||||||||||||||||||||||||
3872 | while (parent && parent != commonAncestorItem) {
| 0 | ||||||||||||||||||||||||||||||
3873 | parents.prepend(parent); | - | ||||||||||||||||||||||||||||||
3874 | if (parent->isPanel()) {
| 0 | ||||||||||||||||||||||||||||||
3875 | // Stop at the panel - we don't deliver beyond this point. | - | ||||||||||||||||||||||||||||||
3876 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3877 | } | - | ||||||||||||||||||||||||||||||
3878 | parent = parent->parentItem(); | - | ||||||||||||||||||||||||||||||
3879 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3880 | for (int i = 0; i < parents.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
3881 | parent = parents.at(i); | - | ||||||||||||||||||||||||||||||
3882 | hoverItems << parent; | - | ||||||||||||||||||||||||||||||
3883 | if (itemAcceptsHoverEvents_helper(parent))
| 0 | ||||||||||||||||||||||||||||||
3884 | sendHoverEvent(QEvent::GraphicsSceneHoverEnter, parent, hoverEvent); never executed: sendHoverEvent(QEvent::GraphicsSceneHoverEnter, parent, hoverEvent); | 0 | ||||||||||||||||||||||||||||||
3885 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3886 | - | |||||||||||||||||||||||||||||||
3887 | // Generate a move event for the item itself | - | ||||||||||||||||||||||||||||||
3888 | if (item
| 0 | ||||||||||||||||||||||||||||||
3889 | && !hoverItems.isEmpty()
| 0 | ||||||||||||||||||||||||||||||
3890 | && item == hoverItems.last()) {
| 0 | ||||||||||||||||||||||||||||||
3891 | sendHoverEvent(QEvent::GraphicsSceneHoverMove, item, hoverEvent); | - | ||||||||||||||||||||||||||||||
3892 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
3893 | } | - | ||||||||||||||||||||||||||||||
3894 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3895 | } | - | ||||||||||||||||||||||||||||||
3896 | - | |||||||||||||||||||||||||||||||
3897 | /*! | - | ||||||||||||||||||||||||||||||
3898 | \internal | - | ||||||||||||||||||||||||||||||
3899 | - | |||||||||||||||||||||||||||||||
3900 | Handles all actions necessary to clean up the scene when the mouse leaves | - | ||||||||||||||||||||||||||||||
3901 | the view. | - | ||||||||||||||||||||||||||||||
3902 | */ | - | ||||||||||||||||||||||||||||||
3903 | void QGraphicsScenePrivate::leaveScene(QWidget *viewport) | - | ||||||||||||||||||||||||||||||
3904 | { | - | ||||||||||||||||||||||||||||||
3905 | #ifndef QT_NO_TOOLTIP | - | ||||||||||||||||||||||||||||||
3906 | QToolTip::hideText(); | - | ||||||||||||||||||||||||||||||
3907 | #endif | - | ||||||||||||||||||||||||||||||
3908 | QGraphicsView *view = qobject_cast<QGraphicsView *>(viewport->parent()); | - | ||||||||||||||||||||||||||||||
3909 | // Send HoverLeave events to all existing hover items, topmost first. | - | ||||||||||||||||||||||||||||||
3910 | QGraphicsSceneHoverEvent hoverEvent; | - | ||||||||||||||||||||||||||||||
3911 | hoverEvent.setWidget(viewport); | - | ||||||||||||||||||||||||||||||
3912 | - | |||||||||||||||||||||||||||||||
3913 | if (view) {
| 0 | ||||||||||||||||||||||||||||||
3914 | QPoint cursorPos = QCursor::pos(); | - | ||||||||||||||||||||||||||||||
3915 | hoverEvent.setScenePos(view->mapToScene(viewport->mapFromGlobal(cursorPos))); | - | ||||||||||||||||||||||||||||||
3916 | hoverEvent.setLastScenePos(hoverEvent.scenePos()); | - | ||||||||||||||||||||||||||||||
3917 | hoverEvent.setScreenPos(cursorPos); | - | ||||||||||||||||||||||||||||||
3918 | hoverEvent.setLastScreenPos(hoverEvent.screenPos()); | - | ||||||||||||||||||||||||||||||
3919 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3920 | - | |||||||||||||||||||||||||||||||
3921 | while (!hoverItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
3922 | QGraphicsItem *lastItem = hoverItems.takeLast(); | - | ||||||||||||||||||||||||||||||
3923 | if (itemAcceptsHoverEvents_helper(lastItem))
| 0 | ||||||||||||||||||||||||||||||
3924 | sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, &hoverEvent); never executed: sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, &hoverEvent); | 0 | ||||||||||||||||||||||||||||||
3925 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3926 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3927 | - | |||||||||||||||||||||||||||||||
3928 | /*! | - | ||||||||||||||||||||||||||||||
3929 | This event handler, for event \a keyEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
3930 | subclass to receive keypress events. The default implementation forwards | - | ||||||||||||||||||||||||||||||
3931 | the event to current focus item. | - | ||||||||||||||||||||||||||||||
3932 | - | |||||||||||||||||||||||||||||||
3933 | \sa QGraphicsItem::keyPressEvent(), focusItem() | - | ||||||||||||||||||||||||||||||
3934 | */ | - | ||||||||||||||||||||||||||||||
3935 | void QGraphicsScene::keyPressEvent(QKeyEvent *keyEvent) | - | ||||||||||||||||||||||||||||||
3936 | { | - | ||||||||||||||||||||||||||||||
3937 | // ### Merge this function with keyReleaseEvent; they are identical | - | ||||||||||||||||||||||||||||||
3938 | // ### (except this comment). | - | ||||||||||||||||||||||||||||||
3939 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3940 | QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
| 0 | ||||||||||||||||||||||||||||||
3941 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
3942 | item = focusItem(); never executed: item = focusItem(); | 0 | ||||||||||||||||||||||||||||||
3943 | if (item) {
| 0 | ||||||||||||||||||||||||||||||
3944 | QGraphicsItem *p = item; | - | ||||||||||||||||||||||||||||||
3945 | do { | - | ||||||||||||||||||||||||||||||
3946 | // Accept the event by default | - | ||||||||||||||||||||||||||||||
3947 | keyEvent->accept(); | - | ||||||||||||||||||||||||||||||
3948 | // Send it; QGraphicsItem::keyPressEvent ignores it. If the event | - | ||||||||||||||||||||||||||||||
3949 | // is filtered out, stop propagating it. | - | ||||||||||||||||||||||||||||||
3950 | if (p->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
3951 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3952 | if (!d->sendEvent(p, keyEvent))
| 0 | ||||||||||||||||||||||||||||||
3953 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3954 | } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem())); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
3955 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3956 | keyEvent->ignore(); | - | ||||||||||||||||||||||||||||||
3957 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3958 | } | - | ||||||||||||||||||||||||||||||
3959 | - | |||||||||||||||||||||||||||||||
3960 | /*! | - | ||||||||||||||||||||||||||||||
3961 | This event handler, for event \a keyEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
3962 | subclass to receive key release events. The default implementation | - | ||||||||||||||||||||||||||||||
3963 | forwards the event to current focus item. | - | ||||||||||||||||||||||||||||||
3964 | - | |||||||||||||||||||||||||||||||
3965 | \sa QGraphicsItem::keyReleaseEvent(), focusItem() | - | ||||||||||||||||||||||||||||||
3966 | */ | - | ||||||||||||||||||||||||||||||
3967 | void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent) | - | ||||||||||||||||||||||||||||||
3968 | { | - | ||||||||||||||||||||||||||||||
3969 | // ### Merge this function with keyPressEvent; they are identical (except | - | ||||||||||||||||||||||||||||||
3970 | // ### this comment). | - | ||||||||||||||||||||||||||||||
3971 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
3972 | QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
| 0 | ||||||||||||||||||||||||||||||
3973 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
3974 | item = focusItem(); never executed: item = focusItem(); | 0 | ||||||||||||||||||||||||||||||
3975 | if (item) {
| 0 | ||||||||||||||||||||||||||||||
3976 | QGraphicsItem *p = item; | - | ||||||||||||||||||||||||||||||
3977 | do { | - | ||||||||||||||||||||||||||||||
3978 | // Accept the event by default | - | ||||||||||||||||||||||||||||||
3979 | keyEvent->accept(); | - | ||||||||||||||||||||||||||||||
3980 | // Send it; QGraphicsItem::keyPressEvent ignores it. If the event | - | ||||||||||||||||||||||||||||||
3981 | // is filtered out, stop propagating it. | - | ||||||||||||||||||||||||||||||
3982 | if (p->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
3983 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3984 | if (!d->sendEvent(p, keyEvent))
| 0 | ||||||||||||||||||||||||||||||
3985 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
3986 | } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem())); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
3987 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3988 | keyEvent->ignore(); | - | ||||||||||||||||||||||||||||||
3989 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3990 | } | - | ||||||||||||||||||||||||||||||
3991 | - | |||||||||||||||||||||||||||||||
3992 | /*! | - | ||||||||||||||||||||||||||||||
3993 | This event handler, for event \a mouseEvent, can be reimplemented | - | ||||||||||||||||||||||||||||||
3994 | in a subclass to receive mouse press events for the scene. | - | ||||||||||||||||||||||||||||||
3995 | - | |||||||||||||||||||||||||||||||
3996 | The default implementation depends on the state of the scene. If | - | ||||||||||||||||||||||||||||||
3997 | there is a mouse grabber item, then the event is sent to the mouse | - | ||||||||||||||||||||||||||||||
3998 | grabber. Otherwise, it is forwarded to the topmost visible item that | - | ||||||||||||||||||||||||||||||
3999 | accepts mouse events at the scene position from the event, and | - | ||||||||||||||||||||||||||||||
4000 | that item promptly becomes the mouse grabber item. | - | ||||||||||||||||||||||||||||||
4001 | - | |||||||||||||||||||||||||||||||
4002 | If there is no item at the given position on the scene, the | - | ||||||||||||||||||||||||||||||
4003 | selection area is reset, any focus item loses its input focus, and | - | ||||||||||||||||||||||||||||||
4004 | the event is then ignored. | - | ||||||||||||||||||||||||||||||
4005 | - | |||||||||||||||||||||||||||||||
4006 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
4007 | - | |||||||||||||||||||||||||||||||
4008 | \sa QGraphicsItem::mousePressEvent(), | - | ||||||||||||||||||||||||||||||
4009 | QGraphicsItem::setAcceptedMouseButtons() | - | ||||||||||||||||||||||||||||||
4010 | */ | - | ||||||||||||||||||||||||||||||
4011 | void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
4012 | { | - | ||||||||||||||||||||||||||||||
4013 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4014 | if (d->mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4015 | // Dispatch hover events | - | ||||||||||||||||||||||||||||||
4016 | QGraphicsSceneHoverEvent hover; | - | ||||||||||||||||||||||||||||||
4017 | _q_hoverFromMouseEvent(&hover, mouseEvent); | - | ||||||||||||||||||||||||||||||
4018 | d->dispatchHoverEvent(&hover); | - | ||||||||||||||||||||||||||||||
4019 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4020 | - | |||||||||||||||||||||||||||||||
4021 | d->mousePressEventHandler(mouseEvent); | - | ||||||||||||||||||||||||||||||
4022 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4023 | - | |||||||||||||||||||||||||||||||
4024 | /*! | - | ||||||||||||||||||||||||||||||
4025 | This event handler, for event \a mouseEvent, can be reimplemented | - | ||||||||||||||||||||||||||||||
4026 | in a subclass to receive mouse move events for the scene. | - | ||||||||||||||||||||||||||||||
4027 | - | |||||||||||||||||||||||||||||||
4028 | The default implementation depends on the mouse grabber state. If there is | - | ||||||||||||||||||||||||||||||
4029 | a mouse grabber item, the event is sent to the mouse grabber. If there | - | ||||||||||||||||||||||||||||||
4030 | are any items that accept hover events at the current position, the event | - | ||||||||||||||||||||||||||||||
4031 | is translated into a hover event and accepted; otherwise it's ignored. | - | ||||||||||||||||||||||||||||||
4032 | - | |||||||||||||||||||||||||||||||
4033 | \sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseReleaseEvent(), | - | ||||||||||||||||||||||||||||||
4034 | QGraphicsItem::mouseDoubleClickEvent(), QGraphicsItem::setAcceptedMouseButtons() | - | ||||||||||||||||||||||||||||||
4035 | */ | - | ||||||||||||||||||||||||||||||
4036 | void QGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
4037 | { | - | ||||||||||||||||||||||||||||||
4038 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4039 | if (d->mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4040 | if (mouseEvent->buttons())
| 0 | ||||||||||||||||||||||||||||||
4041 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4042 | QGraphicsSceneHoverEvent hover; | - | ||||||||||||||||||||||||||||||
4043 | _q_hoverFromMouseEvent(&hover, mouseEvent); | - | ||||||||||||||||||||||||||||||
4044 | mouseEvent->setAccepted(d->dispatchHoverEvent(&hover)); | - | ||||||||||||||||||||||||||||||
4045 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4046 | } | - | ||||||||||||||||||||||||||||||
4047 | - | |||||||||||||||||||||||||||||||
4048 | // Forward the event to the mouse grabber | - | ||||||||||||||||||||||||||||||
4049 | d->sendMouseEvent(mouseEvent); | - | ||||||||||||||||||||||||||||||
4050 | mouseEvent->accept(); | - | ||||||||||||||||||||||||||||||
4051 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4052 | - | |||||||||||||||||||||||||||||||
4053 | /*! | - | ||||||||||||||||||||||||||||||
4054 | This event handler, for event \a mouseEvent, can be reimplemented | - | ||||||||||||||||||||||||||||||
4055 | in a subclass to receive mouse release events for the scene. | - | ||||||||||||||||||||||||||||||
4056 | - | |||||||||||||||||||||||||||||||
4057 | The default implementation depends on the mouse grabber state. If | - | ||||||||||||||||||||||||||||||
4058 | there is no mouse grabber, the event is ignored. Otherwise, if | - | ||||||||||||||||||||||||||||||
4059 | there is a mouse grabber item, the event is sent to the mouse | - | ||||||||||||||||||||||||||||||
4060 | grabber. If this mouse release represents the last pressed button | - | ||||||||||||||||||||||||||||||
4061 | on the mouse, the mouse grabber item then loses the mouse grab. | - | ||||||||||||||||||||||||||||||
4062 | - | |||||||||||||||||||||||||||||||
4063 | \sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), | - | ||||||||||||||||||||||||||||||
4064 | QGraphicsItem::mouseDoubleClickEvent(), QGraphicsItem::setAcceptedMouseButtons() | - | ||||||||||||||||||||||||||||||
4065 | */ | - | ||||||||||||||||||||||||||||||
4066 | void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
4067 | { | - | ||||||||||||||||||||||||||||||
4068 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4069 | if (d->mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4070 | mouseEvent->ignore(); | - | ||||||||||||||||||||||||||||||
4071 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4072 | } | - | ||||||||||||||||||||||||||||||
4073 | - | |||||||||||||||||||||||||||||||
4074 | // Forward the event to the mouse grabber | - | ||||||||||||||||||||||||||||||
4075 | d->sendMouseEvent(mouseEvent); | - | ||||||||||||||||||||||||||||||
4076 | mouseEvent->accept(); | - | ||||||||||||||||||||||||||||||
4077 | - | |||||||||||||||||||||||||||||||
4078 | // Reset the mouse grabber when the last mouse button has been released. | - | ||||||||||||||||||||||||||||||
4079 | if (!mouseEvent->buttons()) {
| 0 | ||||||||||||||||||||||||||||||
4080 | if (!d->mouseGrabberItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4081 | d->lastMouseGrabberItem = d->mouseGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
4082 | if (d->lastMouseGrabberItemHasImplicitMouseGrab)
| 0 | ||||||||||||||||||||||||||||||
4083 | d->mouseGrabberItems.last()->ungrabMouse(); never executed: d->mouseGrabberItems.last()->ungrabMouse(); | 0 | ||||||||||||||||||||||||||||||
4084 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4085 | d->lastMouseGrabberItem = 0; | - | ||||||||||||||||||||||||||||||
4086 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4087 | - | |||||||||||||||||||||||||||||||
4088 | // Generate a hoverevent | - | ||||||||||||||||||||||||||||||
4089 | QGraphicsSceneHoverEvent hoverEvent; | - | ||||||||||||||||||||||||||||||
4090 | _q_hoverFromMouseEvent(&hoverEvent, mouseEvent); | - | ||||||||||||||||||||||||||||||
4091 | d->dispatchHoverEvent(&hoverEvent); | - | ||||||||||||||||||||||||||||||
4092 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4093 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4094 | - | |||||||||||||||||||||||||||||||
4095 | /*! | - | ||||||||||||||||||||||||||||||
4096 | This event handler, for event \a mouseEvent, can be reimplemented | - | ||||||||||||||||||||||||||||||
4097 | in a subclass to receive mouse doubleclick events for the scene. | - | ||||||||||||||||||||||||||||||
4098 | - | |||||||||||||||||||||||||||||||
4099 | If someone doubleclicks on the scene, the scene will first receive | - | ||||||||||||||||||||||||||||||
4100 | a mouse press event, followed by a release event (i.e., a click), | - | ||||||||||||||||||||||||||||||
4101 | then a doubleclick event, and finally a release event. If the | - | ||||||||||||||||||||||||||||||
4102 | doubleclick event is delivered to a different item than the one | - | ||||||||||||||||||||||||||||||
4103 | that received the first press and release, it will be delivered as | - | ||||||||||||||||||||||||||||||
4104 | a press event. However, tripleclick events are not delivered as | - | ||||||||||||||||||||||||||||||
4105 | doubleclick events in this case. | - | ||||||||||||||||||||||||||||||
4106 | - | |||||||||||||||||||||||||||||||
4107 | The default implementation is similar to mousePressEvent(). | - | ||||||||||||||||||||||||||||||
4108 | - | |||||||||||||||||||||||||||||||
4109 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
4110 | - | |||||||||||||||||||||||||||||||
4111 | \sa QGraphicsItem::mousePressEvent(), QGraphicsItem::mouseMoveEvent(), | - | ||||||||||||||||||||||||||||||
4112 | QGraphicsItem::mouseReleaseEvent(), QGraphicsItem::setAcceptedMouseButtons() | - | ||||||||||||||||||||||||||||||
4113 | */ | - | ||||||||||||||||||||||||||||||
4114 | void QGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) | - | ||||||||||||||||||||||||||||||
4115 | { | - | ||||||||||||||||||||||||||||||
4116 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4117 | d->mousePressEventHandler(mouseEvent); | - | ||||||||||||||||||||||||||||||
4118 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4119 | - | |||||||||||||||||||||||||||||||
4120 | /*! | - | ||||||||||||||||||||||||||||||
4121 | This event handler, for event \a wheelEvent, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
4122 | subclass to receive mouse wheel events for the scene. | - | ||||||||||||||||||||||||||||||
4123 | - | |||||||||||||||||||||||||||||||
4124 | By default, the event is delivered to the topmost visible item under the | - | ||||||||||||||||||||||||||||||
4125 | cursor. If ignored, the event propagates to the item beneath, and again | - | ||||||||||||||||||||||||||||||
4126 | until the event is accepted, or it reaches the scene. If no items accept | - | ||||||||||||||||||||||||||||||
4127 | the event, it is ignored. | - | ||||||||||||||||||||||||||||||
4128 | - | |||||||||||||||||||||||||||||||
4129 | Note: See items() for a definition of which items are considered visible by this function. | - | ||||||||||||||||||||||||||||||
4130 | - | |||||||||||||||||||||||||||||||
4131 | \sa QGraphicsItem::wheelEvent() | - | ||||||||||||||||||||||||||||||
4132 | */ | - | ||||||||||||||||||||||||||||||
4133 | void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) | - | ||||||||||||||||||||||||||||||
4134 | { | - | ||||||||||||||||||||||||||||||
4135 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4136 | QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(), | - | ||||||||||||||||||||||||||||||
4137 | wheelEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
4138 | wheelEvent->widget()); | - | ||||||||||||||||||||||||||||||
4139 | - | |||||||||||||||||||||||||||||||
4140 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||||||||
4141 | // On Mac, ignore the event if the first item under the mouse is not the last opened | - | ||||||||||||||||||||||||||||||
4142 | // popup (or one of its descendant) | - | ||||||||||||||||||||||||||||||
4143 | if (!d->popupWidgets.isEmpty() && !wheelCandidates.isEmpty() && wheelCandidates.first() != d->popupWidgets.back() && !d->popupWidgets.back()->isAncestorOf(wheelCandidates.first())) { | - | ||||||||||||||||||||||||||||||
4144 | wheelEvent->accept(); | - | ||||||||||||||||||||||||||||||
4145 | return; | - | ||||||||||||||||||||||||||||||
4146 | } | - | ||||||||||||||||||||||||||||||
4147 | #else | - | ||||||||||||||||||||||||||||||
4148 | // Find the first popup under the mouse (including the popup's descendants) starting from the last. | - | ||||||||||||||||||||||||||||||
4149 | // Remove all popups after the one found, or all or them if no popup is under the mouse. | - | ||||||||||||||||||||||||||||||
4150 | // Then continue with the event. | - | ||||||||||||||||||||||||||||||
4151 | QList<QGraphicsWidget *>::const_iterator iter = d->popupWidgets.constEnd(); | - | ||||||||||||||||||||||||||||||
4152 | while (--iter >= d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4153 | if (wheelCandidates.first() == *iter || (*iter)->isAncestorOf(wheelCandidates.first()))
| 0 | ||||||||||||||||||||||||||||||
4154 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4155 | d->removePopup(*iter); | - | ||||||||||||||||||||||||||||||
4156 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4157 | #endif | - | ||||||||||||||||||||||||||||||
4158 | - | |||||||||||||||||||||||||||||||
4159 | bool hasSetFocus = false; | - | ||||||||||||||||||||||||||||||
4160 | foreach (QGraphicsItem *item, wheelCandidates) { | - | ||||||||||||||||||||||||||||||
4161 | if (!hasSetFocus && item->isEnabled()
| 0 | ||||||||||||||||||||||||||||||
4162 | && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
| 0 | ||||||||||||||||||||||||||||||
4163 | if (item->isWidget() && static_cast<QGraphicsWidget *>(item)->focusPolicy() == Qt::WheelFocus) {
| 0 | ||||||||||||||||||||||||||||||
4164 | hasSetFocus = true; | - | ||||||||||||||||||||||||||||||
4165 | if (item != focusItem())
| 0 | ||||||||||||||||||||||||||||||
4166 | setFocusItem(item, Qt::MouseFocusReason); never executed: setFocusItem(item, Qt::MouseFocusReason); | 0 | ||||||||||||||||||||||||||||||
4167 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4168 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4169 | - | |||||||||||||||||||||||||||||||
4170 | wheelEvent->setPos(item->d_ptr->genericMapFromScene(wheelEvent->scenePos(), | - | ||||||||||||||||||||||||||||||
4171 | wheelEvent->widget())); | - | ||||||||||||||||||||||||||||||
4172 | wheelEvent->accept(); | - | ||||||||||||||||||||||||||||||
4173 | bool isPanel = item->isPanel(); | - | ||||||||||||||||||||||||||||||
4174 | bool ret = d->sendEvent(item, wheelEvent); | - | ||||||||||||||||||||||||||||||
4175 | - | |||||||||||||||||||||||||||||||
4176 | if (ret && (isPanel || wheelEvent->isAccepted()))
| 0 | ||||||||||||||||||||||||||||||
4177 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4178 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4179 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4180 | - | |||||||||||||||||||||||||||||||
4181 | /*! | - | ||||||||||||||||||||||||||||||
4182 | This event handler, for event \a event, can be reimplemented in a | - | ||||||||||||||||||||||||||||||
4183 | subclass to receive input method events for the scene. | - | ||||||||||||||||||||||||||||||
4184 | - | |||||||||||||||||||||||||||||||
4185 | The default implementation forwards the event to the focusItem(). | - | ||||||||||||||||||||||||||||||
4186 | If no item currently has focus or the current focus item does not | - | ||||||||||||||||||||||||||||||
4187 | accept input methods, this function does nothing. | - | ||||||||||||||||||||||||||||||
4188 | - | |||||||||||||||||||||||||||||||
4189 | \sa QGraphicsItem::inputMethodEvent() | - | ||||||||||||||||||||||||||||||
4190 | */ | - | ||||||||||||||||||||||||||||||
4191 | void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event) | - | ||||||||||||||||||||||||||||||
4192 | { | - | ||||||||||||||||||||||||||||||
4193 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4194 | if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
| 0 | ||||||||||||||||||||||||||||||
4195 | d->sendEvent(d->focusItem, event); never executed: d->sendEvent(d->focusItem, event); | 0 | ||||||||||||||||||||||||||||||
4196 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4197 | - | |||||||||||||||||||||||||||||||
4198 | /*! | - | ||||||||||||||||||||||||||||||
4199 | Draws the background of the scene using \a painter, before any items and | - | ||||||||||||||||||||||||||||||
4200 | the foreground are drawn. Reimplement this function to provide a custom | - | ||||||||||||||||||||||||||||||
4201 | background for the scene. | - | ||||||||||||||||||||||||||||||
4202 | - | |||||||||||||||||||||||||||||||
4203 | All painting is done in \e scene coordinates. The \a rect | - | ||||||||||||||||||||||||||||||
4204 | parameter is the exposed rectangle. | - | ||||||||||||||||||||||||||||||
4205 | - | |||||||||||||||||||||||||||||||
4206 | If all you want is to define a color, texture, or gradient for the | - | ||||||||||||||||||||||||||||||
4207 | background, you can call setBackgroundBrush() instead. | - | ||||||||||||||||||||||||||||||
4208 | - | |||||||||||||||||||||||||||||||
4209 | \sa drawForeground(), drawItems() | - | ||||||||||||||||||||||||||||||
4210 | */ | - | ||||||||||||||||||||||||||||||
4211 | void QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||||||||||||||
4212 | { | - | ||||||||||||||||||||||||||||||
4213 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4214 | - | |||||||||||||||||||||||||||||||
4215 | if (d->backgroundBrush.style() != Qt::NoBrush) {
| 0 | ||||||||||||||||||||||||||||||
4216 | if (d->painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4217 | painter->save(); never executed: painter->save(); | 0 | ||||||||||||||||||||||||||||||
4218 | painter->setBrushOrigin(0, 0); | - | ||||||||||||||||||||||||||||||
4219 | painter->fillRect(rect, backgroundBrush()); | - | ||||||||||||||||||||||||||||||
4220 | if (d->painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4221 | painter->restore(); never executed: painter->restore(); | 0 | ||||||||||||||||||||||||||||||
4222 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4223 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4224 | - | |||||||||||||||||||||||||||||||
4225 | /*! | - | ||||||||||||||||||||||||||||||
4226 | Draws the foreground of the scene using \a painter, after the background | - | ||||||||||||||||||||||||||||||
4227 | and all items have been drawn. Reimplement this function to provide a | - | ||||||||||||||||||||||||||||||
4228 | custom foreground for the scene. | - | ||||||||||||||||||||||||||||||
4229 | - | |||||||||||||||||||||||||||||||
4230 | All painting is done in \e scene coordinates. The \a rect | - | ||||||||||||||||||||||||||||||
4231 | parameter is the exposed rectangle. | - | ||||||||||||||||||||||||||||||
4232 | - | |||||||||||||||||||||||||||||||
4233 | If all you want is to define a color, texture or gradient for the | - | ||||||||||||||||||||||||||||||
4234 | foreground, you can call setForegroundBrush() instead. | - | ||||||||||||||||||||||||||||||
4235 | - | |||||||||||||||||||||||||||||||
4236 | \sa drawBackground(), drawItems() | - | ||||||||||||||||||||||||||||||
4237 | */ | - | ||||||||||||||||||||||||||||||
4238 | void QGraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) | - | ||||||||||||||||||||||||||||||
4239 | { | - | ||||||||||||||||||||||||||||||
4240 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
4241 | - | |||||||||||||||||||||||||||||||
4242 | if (d->foregroundBrush.style() != Qt::NoBrush) {
| 0 | ||||||||||||||||||||||||||||||
4243 | if (d->painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4244 | painter->save(); never executed: painter->save(); | 0 | ||||||||||||||||||||||||||||||
4245 | painter->setBrushOrigin(0, 0); | - | ||||||||||||||||||||||||||||||
4246 | painter->fillRect(rect, foregroundBrush()); | - | ||||||||||||||||||||||||||||||
4247 | if (d->painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4248 | painter->restore(); never executed: painter->restore(); | 0 | ||||||||||||||||||||||||||||||
4249 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4250 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4251 | - | |||||||||||||||||||||||||||||||
4252 | static void _q_paintItem(QGraphicsItem *item, QPainter *painter, | - | ||||||||||||||||||||||||||||||
4253 | const QStyleOptionGraphicsItem *option, QWidget *widget, | - | ||||||||||||||||||||||||||||||
4254 | bool useWindowOpacity, bool painterStateProtection) | - | ||||||||||||||||||||||||||||||
4255 | { | - | ||||||||||||||||||||||||||||||
4256 | if (!item->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
4257 | item->paint(painter, option, widget); | - | ||||||||||||||||||||||||||||||
4258 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4259 | } | - | ||||||||||||||||||||||||||||||
4260 | QGraphicsWidget *widgetItem = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||||||||||||||
4261 | QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(widgetItem); | - | ||||||||||||||||||||||||||||||
4262 | const qreal windowOpacity = (proxy && proxy->widget() && useWindowOpacity)
| 0 | ||||||||||||||||||||||||||||||
4263 | ? proxy->widget()->windowOpacity() : 1.0; | - | ||||||||||||||||||||||||||||||
4264 | const qreal oldPainterOpacity = painter->opacity(); | - | ||||||||||||||||||||||||||||||
4265 | - | |||||||||||||||||||||||||||||||
4266 | if (qFuzzyIsNull(windowOpacity))
| 0 | ||||||||||||||||||||||||||||||
4267 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4268 | // Set new painter opacity. | - | ||||||||||||||||||||||||||||||
4269 | if (windowOpacity < 1.0)
| 0 | ||||||||||||||||||||||||||||||
4270 | painter->setOpacity(oldPainterOpacity * windowOpacity); never executed: painter->setOpacity(oldPainterOpacity * windowOpacity); | 0 | ||||||||||||||||||||||||||||||
4271 | - | |||||||||||||||||||||||||||||||
4272 | // set layoutdirection on the painter | - | ||||||||||||||||||||||||||||||
4273 | Qt::LayoutDirection oldLayoutDirection = painter->layoutDirection(); | - | ||||||||||||||||||||||||||||||
4274 | painter->setLayoutDirection(widgetItem->layoutDirection()); | - | ||||||||||||||||||||||||||||||
4275 | - | |||||||||||||||||||||||||||||||
4276 | if (widgetItem->isWindow() && widgetItem->windowType() != Qt::Popup && widgetItem->windowType() != Qt::ToolTip
| 0 | ||||||||||||||||||||||||||||||
4277 | && !(widgetItem->windowFlags() & Qt::FramelessWindowHint)) {
| 0 | ||||||||||||||||||||||||||||||
4278 | if (painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4279 | painter->save(); never executed: painter->save(); | 0 | ||||||||||||||||||||||||||||||
4280 | widgetItem->paintWindowFrame(painter, option, widget); | - | ||||||||||||||||||||||||||||||
4281 | if (painterStateProtection)
| 0 | ||||||||||||||||||||||||||||||
4282 | painter->restore(); never executed: painter->restore(); | 0 | ||||||||||||||||||||||||||||||
4283 | } else if (widgetItem->autoFillBackground()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4284 | painter->fillRect(option->exposedRect, widgetItem->palette().window()); | - | ||||||||||||||||||||||||||||||
4285 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4286 | - | |||||||||||||||||||||||||||||||
4287 | widgetItem->paint(painter, option, widget); | - | ||||||||||||||||||||||||||||||
4288 | - | |||||||||||||||||||||||||||||||
4289 | // Restore layoutdirection on the painter. | - | ||||||||||||||||||||||||||||||
4290 | painter->setLayoutDirection(oldLayoutDirection); | - | ||||||||||||||||||||||||||||||
4291 | // Restore painter opacity. | - | ||||||||||||||||||||||||||||||
4292 | if (windowOpacity < 1.0)
| 0 | ||||||||||||||||||||||||||||||
4293 | painter->setOpacity(oldPainterOpacity); never executed: painter->setOpacity(oldPainterOpacity); | 0 | ||||||||||||||||||||||||||||||
4294 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4295 | - | |||||||||||||||||||||||||||||||
4296 | static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &pixmapExposed, | - | ||||||||||||||||||||||||||||||
4297 | const QTransform &itemToPixmap, QPainter::RenderHints renderHints, | - | ||||||||||||||||||||||||||||||
4298 | const QStyleOptionGraphicsItem *option, bool painterStateProtection) | - | ||||||||||||||||||||||||||||||
4299 | { | - | ||||||||||||||||||||||||||||||
4300 | QPixmap subPix; | - | ||||||||||||||||||||||||||||||
4301 | QPainter pixmapPainter; | - | ||||||||||||||||||||||||||||||
4302 | QRect br = pixmapExposed.boundingRect(); | - | ||||||||||||||||||||||||||||||
4303 | - | |||||||||||||||||||||||||||||||
4304 | // Don't use subpixmap if we get a full update. | - | ||||||||||||||||||||||||||||||
4305 | if (pixmapExposed.isEmpty() || (pixmapExposed.rectCount() == 1 && br.contains(pix->rect()))) {
| 0 | ||||||||||||||||||||||||||||||
4306 | pix->fill(Qt::transparent); | - | ||||||||||||||||||||||||||||||
4307 | pixmapPainter.begin(pix); | - | ||||||||||||||||||||||||||||||
4308 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4309 | subPix = QPixmap(br.size()); | - | ||||||||||||||||||||||||||||||
4310 | subPix.fill(Qt::transparent); | - | ||||||||||||||||||||||||||||||
4311 | pixmapPainter.begin(&subPix); | - | ||||||||||||||||||||||||||||||
4312 | pixmapPainter.translate(-br.topLeft()); | - | ||||||||||||||||||||||||||||||
4313 | if (!pixmapExposed.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4314 | // Applied to subPix; paint is adjusted to the coordinate space is | - | ||||||||||||||||||||||||||||||
4315 | // correct. | - | ||||||||||||||||||||||||||||||
4316 | pixmapPainter.setClipRegion(pixmapExposed); | - | ||||||||||||||||||||||||||||||
4317 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4318 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4319 | - | |||||||||||||||||||||||||||||||
4320 | pixmapPainter.setRenderHints(pixmapPainter.renderHints(), false); | - | ||||||||||||||||||||||||||||||
4321 | pixmapPainter.setRenderHints(renderHints, true); | - | ||||||||||||||||||||||||||||||
4322 | pixmapPainter.setWorldTransform(itemToPixmap, true); | - | ||||||||||||||||||||||||||||||
4323 | - | |||||||||||||||||||||||||||||||
4324 | // Render. | - | ||||||||||||||||||||||||||||||
4325 | _q_paintItem(item, &pixmapPainter, option, 0, false, painterStateProtection); | - | ||||||||||||||||||||||||||||||
4326 | pixmapPainter.end(); | - | ||||||||||||||||||||||||||||||
4327 | - | |||||||||||||||||||||||||||||||
4328 | if (!subPix.isNull()) {
| 0 | ||||||||||||||||||||||||||||||
4329 | // Blit the subpixmap into the main pixmap. | - | ||||||||||||||||||||||||||||||
4330 | pixmapPainter.begin(pix); | - | ||||||||||||||||||||||||||||||
4331 | pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||||||||||||||||||||
4332 | pixmapPainter.setClipRegion(pixmapExposed); | - | ||||||||||||||||||||||||||||||
4333 | pixmapPainter.drawPixmap(br.topLeft(), subPix); | - | ||||||||||||||||||||||||||||||
4334 | pixmapPainter.end(); | - | ||||||||||||||||||||||||||||||
4335 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4336 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4337 | - | |||||||||||||||||||||||||||||||
4338 | // Copied from qpaintengine_vg.cpp | - | ||||||||||||||||||||||||||||||
4339 | // Returns \c true for 90, 180, and 270 degree rotations. | - | ||||||||||||||||||||||||||||||
4340 | static inline bool transformIsSimple(const QTransform& transform) | - | ||||||||||||||||||||||||||||||
4341 | { | - | ||||||||||||||||||||||||||||||
4342 | QTransform::TransformationType type = transform.type(); | - | ||||||||||||||||||||||||||||||
4343 | if (type <= QTransform::TxScale) {
| 0 | ||||||||||||||||||||||||||||||
4344 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
4345 | } else if (type == QTransform::TxRotate) {
| 0 | ||||||||||||||||||||||||||||||
4346 | // Check for 90, and 270 degree rotations. | - | ||||||||||||||||||||||||||||||
4347 | qreal m11 = transform.m11(); | - | ||||||||||||||||||||||||||||||
4348 | qreal m12 = transform.m12(); | - | ||||||||||||||||||||||||||||||
4349 | qreal m21 = transform.m21(); | - | ||||||||||||||||||||||||||||||
4350 | qreal m22 = transform.m22(); | - | ||||||||||||||||||||||||||||||
4351 | if (m11 == 0.0f && m22 == 0.0f) {
| 0 | ||||||||||||||||||||||||||||||
4352 | if (m12 == 1.0f && m21 == -1.0f)
| 0 | ||||||||||||||||||||||||||||||
4353 | return true; // 90 degrees. never executed: return true; | 0 | ||||||||||||||||||||||||||||||
4354 | else if (m12 == -1.0f && m21 == 1.0f)
| 0 | ||||||||||||||||||||||||||||||
4355 | return true; // 270 degrees. never executed: return true; | 0 | ||||||||||||||||||||||||||||||
4356 | else if (m12 == -1.0f && m21 == -1.0f)
| 0 | ||||||||||||||||||||||||||||||
4357 | return true; // 90 degrees inverted y. never executed: return true; | 0 | ||||||||||||||||||||||||||||||
4358 | else if (m12 == 1.0f && m21 == 1.0f)
| 0 | ||||||||||||||||||||||||||||||
4359 | return true; // 270 degrees inverted y. never executed: return true; | 0 | ||||||||||||||||||||||||||||||
4360 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4361 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4362 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
4363 | } | - | ||||||||||||||||||||||||||||||
4364 | - | |||||||||||||||||||||||||||||||
4365 | /*! | - | ||||||||||||||||||||||||||||||
4366 | \internal | - | ||||||||||||||||||||||||||||||
4367 | - | |||||||||||||||||||||||||||||||
4368 | Draws items directly, or using cache. | - | ||||||||||||||||||||||||||||||
4369 | */ | - | ||||||||||||||||||||||||||||||
4370 | void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painter, | - | ||||||||||||||||||||||||||||||
4371 | const QStyleOptionGraphicsItem *option, QWidget *widget, | - | ||||||||||||||||||||||||||||||
4372 | bool painterStateProtection) | - | ||||||||||||||||||||||||||||||
4373 | { | - | ||||||||||||||||||||||||||||||
4374 | QGraphicsItemPrivate *itemd = item->d_ptr.data(); | - | ||||||||||||||||||||||||||||||
4375 | QGraphicsItem::CacheMode cacheMode = QGraphicsItem::CacheMode(itemd->cacheMode); | - | ||||||||||||||||||||||||||||||
4376 | - | |||||||||||||||||||||||||||||||
4377 | // Render directly, using no cache. | - | ||||||||||||||||||||||||||||||
4378 | if (cacheMode == QGraphicsItem::NoCache
| 0 | ||||||||||||||||||||||||||||||
4379 | #ifdef Q_DEAD_CODE_FROM_QT4_X11 | - | ||||||||||||||||||||||||||||||
4380 | || !X11->use_xrender | - | ||||||||||||||||||||||||||||||
4381 | #endif | - | ||||||||||||||||||||||||||||||
4382 | ) { | - | ||||||||||||||||||||||||||||||
4383 | _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, true, painterStateProtection); | - | ||||||||||||||||||||||||||||||
4384 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4385 | } | - | ||||||||||||||||||||||||||||||
4386 | - | |||||||||||||||||||||||||||||||
4387 | const qreal oldPainterOpacity = painter->opacity(); | - | ||||||||||||||||||||||||||||||
4388 | qreal newPainterOpacity = oldPainterOpacity; | - | ||||||||||||||||||||||||||||||
4389 | QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(item)) : 0;
| 0 | ||||||||||||||||||||||||||||||
4390 | if (proxy && proxy->widget()) {
| 0 | ||||||||||||||||||||||||||||||
4391 | const qreal windowOpacity = proxy->widget()->windowOpacity(); | - | ||||||||||||||||||||||||||||||
4392 | if (windowOpacity < 1.0)
| 0 | ||||||||||||||||||||||||||||||
4393 | newPainterOpacity *= windowOpacity; never executed: newPainterOpacity *= windowOpacity; | 0 | ||||||||||||||||||||||||||||||
4394 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4395 | - | |||||||||||||||||||||||||||||||
4396 | // Item's (local) bounding rect | - | ||||||||||||||||||||||||||||||
4397 | QRectF brect = item->boundingRect(); | - | ||||||||||||||||||||||||||||||
4398 | QRectF adjustedBrect(brect); | - | ||||||||||||||||||||||||||||||
4399 | _q_adjustRect(&adjustedBrect); | - | ||||||||||||||||||||||||||||||
4400 | if (adjustedBrect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
4401 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4402 | - | |||||||||||||||||||||||||||||||
4403 | // Fetch the off-screen transparent buffer and exposed area info. | - | ||||||||||||||||||||||||||||||
4404 | QPixmapCache::Key pixmapKey; | - | ||||||||||||||||||||||||||||||
4405 | QPixmap pix; | - | ||||||||||||||||||||||||||||||
4406 | bool pixmapFound; | - | ||||||||||||||||||||||||||||||
4407 | QGraphicsItemCache *itemCache = itemd->extraItemCache(); | - | ||||||||||||||||||||||||||||||
4408 | if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
| 0 | ||||||||||||||||||||||||||||||
4409 | pixmapKey = itemCache->key; | - | ||||||||||||||||||||||||||||||
4410 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4411 | pixmapKey = itemCache->deviceData.value(widget).key; | - | ||||||||||||||||||||||||||||||
4412 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4413 | - | |||||||||||||||||||||||||||||||
4414 | // Find pixmap in cache. | - | ||||||||||||||||||||||||||||||
4415 | pixmapFound = QPixmapCache::find(pixmapKey, &pix); | - | ||||||||||||||||||||||||||||||
4416 | - | |||||||||||||||||||||||||||||||
4417 | // Render using item coordinate cache mode. | - | ||||||||||||||||||||||||||||||
4418 | if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
| 0 | ||||||||||||||||||||||||||||||
4419 | QSize pixmapSize; | - | ||||||||||||||||||||||||||||||
4420 | bool fixedCacheSize = false; | - | ||||||||||||||||||||||||||||||
4421 | QRect br = brect.toAlignedRect(); | - | ||||||||||||||||||||||||||||||
4422 | if ((fixedCacheSize = itemCache->fixedSize.isValid())) {
| 0 | ||||||||||||||||||||||||||||||
4423 | pixmapSize = itemCache->fixedSize; | - | ||||||||||||||||||||||||||||||
4424 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4425 | pixmapSize = br.size(); | - | ||||||||||||||||||||||||||||||
4426 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4427 | - | |||||||||||||||||||||||||||||||
4428 | // Create or recreate the pixmap. | - | ||||||||||||||||||||||||||||||
4429 | int adjust = itemCache->fixedSize.isValid() ? 0 : 2;
| 0 | ||||||||||||||||||||||||||||||
4430 | QSize adjustSize(adjust*2, adjust*2); | - | ||||||||||||||||||||||||||||||
4431 | br.adjust(-adjust, -adjust, adjust, adjust); | - | ||||||||||||||||||||||||||||||
4432 | if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) {
| 0 | ||||||||||||||||||||||||||||||
4433 | pix = QPixmap(pixmapSize + adjustSize); | - | ||||||||||||||||||||||||||||||
4434 | itemCache->boundingRect = br; | - | ||||||||||||||||||||||||||||||
4435 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4436 | itemCache->allExposed = true; | - | ||||||||||||||||||||||||||||||
4437 | } else if (itemCache->boundingRect != br) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4438 | itemCache->boundingRect = br; | - | ||||||||||||||||||||||||||||||
4439 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4440 | itemCache->allExposed = true; | - | ||||||||||||||||||||||||||||||
4441 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4442 | - | |||||||||||||||||||||||||||||||
4443 | // Redraw any newly exposed areas. | - | ||||||||||||||||||||||||||||||
4444 | if (itemCache->allExposed || !itemCache->exposed.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4445 | - | |||||||||||||||||||||||||||||||
4446 | //We know that we will modify the pixmap, removing it from the cache | - | ||||||||||||||||||||||||||||||
4447 | //will detach the one we have and avoid a deep copy | - | ||||||||||||||||||||||||||||||
4448 | if (pixmapFound)
| 0 | ||||||||||||||||||||||||||||||
4449 | QPixmapCache::remove(pixmapKey); never executed: QPixmapCache::remove(pixmapKey); | 0 | ||||||||||||||||||||||||||||||
4450 | - | |||||||||||||||||||||||||||||||
4451 | // Fit the item's bounding rect into the pixmap's coordinates. | - | ||||||||||||||||||||||||||||||
4452 | QTransform itemToPixmap; | - | ||||||||||||||||||||||||||||||
4453 | if (fixedCacheSize) {
| 0 | ||||||||||||||||||||||||||||||
4454 | const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); | - | ||||||||||||||||||||||||||||||
4455 | itemToPixmap.scale(scale.x(), scale.y()); | - | ||||||||||||||||||||||||||||||
4456 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4457 | itemToPixmap.translate(-br.x(), -br.y()); | - | ||||||||||||||||||||||||||||||
4458 | - | |||||||||||||||||||||||||||||||
4459 | // Generate the item's exposedRect and map its list of expose | - | ||||||||||||||||||||||||||||||
4460 | // rects to device coordinates. | - | ||||||||||||||||||||||||||||||
4461 | styleOptionTmp = *option; | - | ||||||||||||||||||||||||||||||
4462 | QRegion pixmapExposed; | - | ||||||||||||||||||||||||||||||
4463 | QRectF exposedRect; | - | ||||||||||||||||||||||||||||||
4464 | if (!itemCache->allExposed) {
| 0 | ||||||||||||||||||||||||||||||
4465 | for (int i = 0; i < itemCache->exposed.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
4466 | QRectF r = itemCache->exposed.at(i); | - | ||||||||||||||||||||||||||||||
4467 | exposedRect |= r; | - | ||||||||||||||||||||||||||||||
4468 | pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect(); | - | ||||||||||||||||||||||||||||||
4469 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4470 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4471 | exposedRect = brect; | - | ||||||||||||||||||||||||||||||
4472 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4473 | styleOptionTmp.exposedRect = exposedRect; | - | ||||||||||||||||||||||||||||||
4474 | - | |||||||||||||||||||||||||||||||
4475 | // Render. | - | ||||||||||||||||||||||||||||||
4476 | _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), | - | ||||||||||||||||||||||||||||||
4477 | &styleOptionTmp, painterStateProtection); | - | ||||||||||||||||||||||||||||||
4478 | - | |||||||||||||||||||||||||||||||
4479 | // insert this pixmap into the cache. | - | ||||||||||||||||||||||||||||||
4480 | itemCache->key = QPixmapCache::insert(pix); | - | ||||||||||||||||||||||||||||||
4481 | - | |||||||||||||||||||||||||||||||
4482 | // Reset expose data. | - | ||||||||||||||||||||||||||||||
4483 | itemCache->allExposed = false; | - | ||||||||||||||||||||||||||||||
4484 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4485 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4486 | - | |||||||||||||||||||||||||||||||
4487 | // Redraw the exposed area using the transformed painter. Depending on | - | ||||||||||||||||||||||||||||||
4488 | // the hardware, this may be a server-side operation, or an expensive | - | ||||||||||||||||||||||||||||||
4489 | // qpixmap-image-transform-pixmap roundtrip. | - | ||||||||||||||||||||||||||||||
4490 | if (newPainterOpacity != oldPainterOpacity) {
| 0 | ||||||||||||||||||||||||||||||
4491 | painter->setOpacity(newPainterOpacity); | - | ||||||||||||||||||||||||||||||
4492 | painter->drawPixmap(br.topLeft(), pix); | - | ||||||||||||||||||||||||||||||
4493 | painter->setOpacity(oldPainterOpacity); | - | ||||||||||||||||||||||||||||||
4494 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4495 | painter->drawPixmap(br.topLeft(), pix); | - | ||||||||||||||||||||||||||||||
4496 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4497 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4498 | } | - | ||||||||||||||||||||||||||||||
4499 | - | |||||||||||||||||||||||||||||||
4500 | // Render using device coordinate cache mode. | - | ||||||||||||||||||||||||||||||
4501 | if (cacheMode == QGraphicsItem::DeviceCoordinateCache) {
| 0 | ||||||||||||||||||||||||||||||
4502 | // Find the item's bounds in device coordinates. | - | ||||||||||||||||||||||||||||||
4503 | QRectF deviceBounds = painter->worldTransform().mapRect(brect); | - | ||||||||||||||||||||||||||||||
4504 | QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1); | - | ||||||||||||||||||||||||||||||
4505 | if (deviceRect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
4506 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4507 | QRect viewRect = widget ? widget->rect() : QRect();
| 0 | ||||||||||||||||||||||||||||||
4508 | if (widget && !viewRect.intersects(deviceRect))
| 0 | ||||||||||||||||||||||||||||||
4509 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4510 | - | |||||||||||||||||||||||||||||||
4511 | // Resort to direct rendering if the device rect exceeds the | - | ||||||||||||||||||||||||||||||
4512 | // (optional) maximum bounds. (QGraphicsSvgItem uses this). | - | ||||||||||||||||||||||||||||||
4513 | QSize maximumCacheSize = | - | ||||||||||||||||||||||||||||||
4514 | itemd->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize(); | - | ||||||||||||||||||||||||||||||
4515 | if (!maximumCacheSize.isEmpty()
| 0 | ||||||||||||||||||||||||||||||
4516 | && (deviceRect.width() > maximumCacheSize.width()
| 0 | ||||||||||||||||||||||||||||||
4517 | || deviceRect.height() > maximumCacheSize.height())) {
| 0 | ||||||||||||||||||||||||||||||
4518 | _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, | - | ||||||||||||||||||||||||||||||
4519 | oldPainterOpacity != newPainterOpacity, painterStateProtection); | - | ||||||||||||||||||||||||||||||
4520 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4521 | } | - | ||||||||||||||||||||||||||||||
4522 | - | |||||||||||||||||||||||||||||||
4523 | // Create or reuse offscreen pixmap, possibly scroll/blit from the old one. | - | ||||||||||||||||||||||||||||||
4524 | // If the world transform is rotated we always recreate the cache to avoid | - | ||||||||||||||||||||||||||||||
4525 | // wrong blending. | - | ||||||||||||||||||||||||||||||
4526 | bool pixModified = false; | - | ||||||||||||||||||||||||||||||
4527 | QGraphicsItemCache::DeviceData *deviceData = &itemCache->deviceData[widget]; | - | ||||||||||||||||||||||||||||||
4528 | bool invertable = true; | - | ||||||||||||||||||||||||||||||
4529 | QTransform diff = deviceData->lastTransform.inverted(&invertable); | - | ||||||||||||||||||||||||||||||
4530 | if (invertable)
| 0 | ||||||||||||||||||||||||||||||
4531 | diff *= painter->worldTransform(); never executed: diff *= painter->worldTransform(); | 0 | ||||||||||||||||||||||||||||||
4532 | deviceData->lastTransform = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
4533 | bool allowPartialCacheExposure = false; | - | ||||||||||||||||||||||||||||||
4534 | bool simpleTransform = invertable && diff.type() <= QTransform::TxTranslate
| 0 | ||||||||||||||||||||||||||||||
4535 | && transformIsSimple(painter->worldTransform());
| 0 | ||||||||||||||||||||||||||||||
4536 | if (!simpleTransform) {
| 0 | ||||||||||||||||||||||||||||||
4537 | pixModified = true; | - | ||||||||||||||||||||||||||||||
4538 | itemCache->allExposed = true; | - | ||||||||||||||||||||||||||||||
4539 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4540 | deviceData->cacheIndent = QPoint(); | - | ||||||||||||||||||||||||||||||
4541 | pix = QPixmap(); | - | ||||||||||||||||||||||||||||||
4542 | } else if (!viewRect.isNull()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4543 | allowPartialCacheExposure = deviceData->cacheIndent != QPoint(); | - | ||||||||||||||||||||||||||||||
4544 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4545 | - | |||||||||||||||||||||||||||||||
4546 | // Allow partial cache exposure if the device rect isn't fully contained and | - | ||||||||||||||||||||||||||||||
4547 | // deviceRect is 20% taller or wider than the viewRect. | - | ||||||||||||||||||||||||||||||
4548 | if (!allowPartialCacheExposure && !viewRect.isNull() && !viewRect.contains(deviceRect)) {
| 0 | ||||||||||||||||||||||||||||||
4549 | allowPartialCacheExposure = (viewRect.width() * 1.2 < deviceRect.width())
| 0 | ||||||||||||||||||||||||||||||
4550 | || (viewRect.height() * 1.2 < deviceRect.height());
| 0 | ||||||||||||||||||||||||||||||
4551 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4552 | - | |||||||||||||||||||||||||||||||
4553 | QRegion scrollExposure; | - | ||||||||||||||||||||||||||||||
4554 | if (allowPartialCacheExposure) {
| 0 | ||||||||||||||||||||||||||||||
4555 | // Part of pixmap is drawn. Either device contains viewrect (big | - | ||||||||||||||||||||||||||||||
4556 | // item covers whole screen) or parts of device are outside the | - | ||||||||||||||||||||||||||||||
4557 | // viewport. In either case the device rect must be the intersect | - | ||||||||||||||||||||||||||||||
4558 | // between the two. | - | ||||||||||||||||||||||||||||||
4559 | int dx = deviceRect.left() < viewRect.left() ? viewRect.left() - deviceRect.left() : 0;
| 0 | ||||||||||||||||||||||||||||||
4560 | int dy = deviceRect.top() < viewRect.top() ? viewRect.top() - deviceRect.top() : 0;
| 0 | ||||||||||||||||||||||||||||||
4561 | QPoint newCacheIndent(dx, dy); | - | ||||||||||||||||||||||||||||||
4562 | deviceRect &= viewRect; | - | ||||||||||||||||||||||||||||||
4563 | - | |||||||||||||||||||||||||||||||
4564 | if (pix.isNull()) {
| 0 | ||||||||||||||||||||||||||||||
4565 | deviceData->cacheIndent = QPoint(); | - | ||||||||||||||||||||||||||||||
4566 | itemCache->allExposed = true; | - | ||||||||||||||||||||||||||||||
4567 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4568 | pixModified = true; | - | ||||||||||||||||||||||||||||||
4569 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4570 | - | |||||||||||||||||||||||||||||||
4571 | // Copy / "scroll" the old pixmap onto the new ole and calculate | - | ||||||||||||||||||||||||||||||
4572 | // scrolled exposure. | - | ||||||||||||||||||||||||||||||
4573 | if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size()) {
| 0 | ||||||||||||||||||||||||||||||
4574 | QPoint diff = newCacheIndent - deviceData->cacheIndent; | - | ||||||||||||||||||||||||||||||
4575 | QPixmap newPix(deviceRect.size()); | - | ||||||||||||||||||||||||||||||
4576 | // ### Investigate removing this fill (test with Plasma and | - | ||||||||||||||||||||||||||||||
4577 | // graphicssystem raster). | - | ||||||||||||||||||||||||||||||
4578 | newPix.fill(Qt::transparent); | - | ||||||||||||||||||||||||||||||
4579 | if (!pix.isNull()) {
| 0 | ||||||||||||||||||||||||||||||
4580 | QPainter newPixPainter(&newPix); | - | ||||||||||||||||||||||||||||||
4581 | newPixPainter.drawPixmap(-diff, pix); | - | ||||||||||||||||||||||||||||||
4582 | newPixPainter.end(); | - | ||||||||||||||||||||||||||||||
4583 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4584 | QRegion exposed; | - | ||||||||||||||||||||||||||||||
4585 | exposed += newPix.rect(); | - | ||||||||||||||||||||||||||||||
4586 | if (!pix.isNull())
| 0 | ||||||||||||||||||||||||||||||
4587 | exposed -= QRect(-diff, pix.size()); never executed: exposed -= QRect(-diff, pix.size()); | 0 | ||||||||||||||||||||||||||||||
4588 | scrollExposure = exposed; | - | ||||||||||||||||||||||||||||||
4589 | - | |||||||||||||||||||||||||||||||
4590 | pix = newPix; | - | ||||||||||||||||||||||||||||||
4591 | pixModified = true; | - | ||||||||||||||||||||||||||||||
4592 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4593 | deviceData->cacheIndent = newCacheIndent; | - | ||||||||||||||||||||||||||||||
4594 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4595 | // Full pixmap is drawn. | - | ||||||||||||||||||||||||||||||
4596 | deviceData->cacheIndent = QPoint(); | - | ||||||||||||||||||||||||||||||
4597 | - | |||||||||||||||||||||||||||||||
4598 | // Auto-adjust the pixmap size. | - | ||||||||||||||||||||||||||||||
4599 | if (deviceRect.size() != pix.size()) {
| 0 | ||||||||||||||||||||||||||||||
4600 | // exposed needs to cover the whole pixmap | - | ||||||||||||||||||||||||||||||
4601 | pix = QPixmap(deviceRect.size()); | - | ||||||||||||||||||||||||||||||
4602 | pixModified = true; | - | ||||||||||||||||||||||||||||||
4603 | itemCache->allExposed = true; | - | ||||||||||||||||||||||||||||||
4604 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4605 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4606 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4607 | - | |||||||||||||||||||||||||||||||
4608 | // Check for newly invalidated areas. | - | ||||||||||||||||||||||||||||||
4609 | if (itemCache->allExposed || !itemCache->exposed.isEmpty() || !scrollExposure.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
4610 | //We know that we will modify the pixmap, removing it from the cache | - | ||||||||||||||||||||||||||||||
4611 | //will detach the one we have and avoid a deep copy | - | ||||||||||||||||||||||||||||||
4612 | if (pixmapFound)
| 0 | ||||||||||||||||||||||||||||||
4613 | QPixmapCache::remove(pixmapKey); never executed: QPixmapCache::remove(pixmapKey); | 0 | ||||||||||||||||||||||||||||||
4614 | - | |||||||||||||||||||||||||||||||
4615 | // Construct an item-to-pixmap transform. | - | ||||||||||||||||||||||||||||||
4616 | QPointF p = deviceRect.topLeft(); | - | ||||||||||||||||||||||||||||||
4617 | QTransform itemToPixmap = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
4618 | if (!p.isNull())
| 0 | ||||||||||||||||||||||||||||||
4619 | itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y()); never executed: itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y()); | 0 | ||||||||||||||||||||||||||||||
4620 | - | |||||||||||||||||||||||||||||||
4621 | // Map the item's logical expose to pixmap coordinates. | - | ||||||||||||||||||||||||||||||
4622 | QRegion pixmapExposed = scrollExposure; | - | ||||||||||||||||||||||||||||||
4623 | if (!itemCache->allExposed) {
| 0 | ||||||||||||||||||||||||||||||
4624 | const QVector<QRectF> &exposed = itemCache->exposed; | - | ||||||||||||||||||||||||||||||
4625 | for (int i = 0; i < exposed.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
4626 | pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1); never executed: pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1); | 0 | ||||||||||||||||||||||||||||||
4627 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4628 | - | |||||||||||||||||||||||||||||||
4629 | // Calculate the style option's exposedRect. | - | ||||||||||||||||||||||||||||||
4630 | QRectF br; | - | ||||||||||||||||||||||||||||||
4631 | if (itemCache->allExposed) {
| 0 | ||||||||||||||||||||||||||||||
4632 | br = item->boundingRect(); | - | ||||||||||||||||||||||||||||||
4633 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4634 | const QVector<QRectF> &exposed = itemCache->exposed; | - | ||||||||||||||||||||||||||||||
4635 | for (int i = 0; i < exposed.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
4636 | br |= exposed.at(i); never executed: br |= exposed.at(i); | 0 | ||||||||||||||||||||||||||||||
4637 | QTransform pixmapToItem = itemToPixmap.inverted(); | - | ||||||||||||||||||||||||||||||
4638 | foreach (const QRect &r, scrollExposure.rects()) | - | ||||||||||||||||||||||||||||||
4639 | br |= pixmapToItem.mapRect(r); never executed: br |= pixmapToItem.mapRect(r); | 0 | ||||||||||||||||||||||||||||||
4640 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4641 | styleOptionTmp = *option; | - | ||||||||||||||||||||||||||||||
4642 | styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1); | - | ||||||||||||||||||||||||||||||
4643 | - | |||||||||||||||||||||||||||||||
4644 | // Render the exposed areas. | - | ||||||||||||||||||||||||||||||
4645 | _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), | - | ||||||||||||||||||||||||||||||
4646 | &styleOptionTmp, painterStateProtection); | - | ||||||||||||||||||||||||||||||
4647 | - | |||||||||||||||||||||||||||||||
4648 | // Reset expose data. | - | ||||||||||||||||||||||||||||||
4649 | pixModified = true; | - | ||||||||||||||||||||||||||||||
4650 | itemCache->allExposed = false; | - | ||||||||||||||||||||||||||||||
4651 | itemCache->exposed.clear(); | - | ||||||||||||||||||||||||||||||
4652 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4653 | - | |||||||||||||||||||||||||||||||
4654 | if (pixModified) {
| 0 | ||||||||||||||||||||||||||||||
4655 | // Insert this pixmap into the cache. | - | ||||||||||||||||||||||||||||||
4656 | deviceData->key = QPixmapCache::insert(pix); | - | ||||||||||||||||||||||||||||||
4657 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4658 | - | |||||||||||||||||||||||||||||||
4659 | // Redraw the exposed area using an untransformed painter. This | - | ||||||||||||||||||||||||||||||
4660 | // effectively becomes a bitblit that does not transform the cache. | - | ||||||||||||||||||||||||||||||
4661 | QTransform restoreTransform = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
4662 | painter->setWorldTransform(QTransform()); | - | ||||||||||||||||||||||||||||||
4663 | if (newPainterOpacity != oldPainterOpacity) {
| 0 | ||||||||||||||||||||||||||||||
4664 | painter->setOpacity(newPainterOpacity); | - | ||||||||||||||||||||||||||||||
4665 | painter->drawPixmap(deviceRect.topLeft(), pix); | - | ||||||||||||||||||||||||||||||
4666 | painter->setOpacity(oldPainterOpacity); | - | ||||||||||||||||||||||||||||||
4667 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4668 | painter->drawPixmap(deviceRect.topLeft(), pix); | - | ||||||||||||||||||||||||||||||
4669 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4670 | painter->setWorldTransform(restoreTransform); | - | ||||||||||||||||||||||||||||||
4671 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4672 | } | - | ||||||||||||||||||||||||||||||
4673 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4674 | - | |||||||||||||||||||||||||||||||
4675 | void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const viewTransform, | - | ||||||||||||||||||||||||||||||
4676 | QRegion *exposedRegion, QWidget *widget) | - | ||||||||||||||||||||||||||||||
4677 | { | - | ||||||||||||||||||||||||||||||
4678 | // Make sure we don't have unpolished items before we draw. | - | ||||||||||||||||||||||||||||||
4679 | if (!unpolishedItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
4680 | _q_polishItems(); never executed: _q_polishItems(); | 0 | ||||||||||||||||||||||||||||||
4681 | - | |||||||||||||||||||||||||||||||
4682 | updateAll = false; | - | ||||||||||||||||||||||||||||||
4683 | QRectF exposedSceneRect; | - | ||||||||||||||||||||||||||||||
4684 | if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) {
| 0 | ||||||||||||||||||||||||||||||
4685 | exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1); | - | ||||||||||||||||||||||||||||||
4686 | if (viewTransform)
| 0 | ||||||||||||||||||||||||||||||
4687 | exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect); never executed: exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect); | 0 | ||||||||||||||||||||||||||||||
4688 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4689 | const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder); | - | ||||||||||||||||||||||||||||||
4690 | for (int i = 0; i < tli.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
4691 | drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget); never executed: drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget); | 0 | ||||||||||||||||||||||||||||||
4692 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4693 | - | |||||||||||||||||||||||||||||||
4694 | void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, | - | ||||||||||||||||||||||||||||||
4695 | const QTransform *const viewTransform, | - | ||||||||||||||||||||||||||||||
4696 | QRegion *exposedRegion, QWidget *widget, | - | ||||||||||||||||||||||||||||||
4697 | qreal parentOpacity, const QTransform *const effectTransform) | - | ||||||||||||||||||||||||||||||
4698 | { | - | ||||||||||||||||||||||||||||||
4699 | Q_ASSERT(item); | - | ||||||||||||||||||||||||||||||
4700 | - | |||||||||||||||||||||||||||||||
4701 | if (!item->d_ptr->visible)
| 0 | ||||||||||||||||||||||||||||||
4702 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4703 | - | |||||||||||||||||||||||||||||||
4704 | const bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); | - | ||||||||||||||||||||||||||||||
4705 | const bool itemHasChildren = !item->d_ptr->children.isEmpty(); | - | ||||||||||||||||||||||||||||||
4706 | if (!itemHasContents && !itemHasChildren)
| 0 | ||||||||||||||||||||||||||||||
4707 | return; // Item has neither contents nor children!(?) never executed: return; | 0 | ||||||||||||||||||||||||||||||
4708 | - | |||||||||||||||||||||||||||||||
4709 | const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); | - | ||||||||||||||||||||||||||||||
4710 | const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); | - | ||||||||||||||||||||||||||||||
4711 | if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity()))
| 0 | ||||||||||||||||||||||||||||||
4712 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4713 | - | |||||||||||||||||||||||||||||||
4714 | QTransform transform(Qt::Uninitialized); | - | ||||||||||||||||||||||||||||||
4715 | QTransform *transformPtr = 0; | - | ||||||||||||||||||||||||||||||
4716 | bool translateOnlyTransform = false; | - | ||||||||||||||||||||||||||||||
4717 | #define ENSURE_TRANSFORM_PTR \ | - | ||||||||||||||||||||||||||||||
4718 | if (!transformPtr) { \ | - | ||||||||||||||||||||||||||||||
4719 | Q_ASSERT(!itemIsUntransformable); \ | - | ||||||||||||||||||||||||||||||
4720 | if (viewTransform) { \ | - | ||||||||||||||||||||||||||||||
4721 | transform = item->d_ptr->sceneTransform; \ | - | ||||||||||||||||||||||||||||||
4722 | transform *= *viewTransform; \ | - | ||||||||||||||||||||||||||||||
4723 | transformPtr = &transform; \ | - | ||||||||||||||||||||||||||||||
4724 | } else { \ | - | ||||||||||||||||||||||||||||||
4725 | transformPtr = &item->d_ptr->sceneTransform; \ | - | ||||||||||||||||||||||||||||||
4726 | translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; \ | - | ||||||||||||||||||||||||||||||
4727 | } \ | - | ||||||||||||||||||||||||||||||
4728 | } | - | ||||||||||||||||||||||||||||||
4729 | - | |||||||||||||||||||||||||||||||
4730 | // Update the item's scene transform if the item is transformable; | - | ||||||||||||||||||||||||||||||
4731 | // otherwise calculate the full transform, | - | ||||||||||||||||||||||||||||||
4732 | bool wasDirtyParentSceneTransform = false; | - | ||||||||||||||||||||||||||||||
4733 | const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); | - | ||||||||||||||||||||||||||||||
4734 | if (itemIsUntransformable) {
| 0 | ||||||||||||||||||||||||||||||
4735 | transform = item->deviceTransform(viewTransform ? *viewTransform : QTransform()); | - | ||||||||||||||||||||||||||||||
4736 | transformPtr = &transform; | - | ||||||||||||||||||||||||||||||
4737 | } else if (item->d_ptr->dirtySceneTransform) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4738 | item->d_ptr->updateSceneTransformFromParent(); | - | ||||||||||||||||||||||||||||||
4739 | Q_ASSERT(!item->d_ptr->dirtySceneTransform); | - | ||||||||||||||||||||||||||||||
4740 | wasDirtyParentSceneTransform = true; | - | ||||||||||||||||||||||||||||||
4741 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4742 | - | |||||||||||||||||||||||||||||||
4743 | const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape
| 0 | ||||||||||||||||||||||||||||||
4744 | || item->d_ptr->flags & QGraphicsItem::ItemContainsChildrenInShape);
| 0 | ||||||||||||||||||||||||||||||
4745 | bool drawItem = itemHasContents && !itemIsFullyTransparent;
| 0 | ||||||||||||||||||||||||||||||
4746 | if (drawItem || minimumRenderSize > 0.0) {
| 0 | ||||||||||||||||||||||||||||||
4747 | const QRectF brect = adjustedItemEffectiveBoundingRect(item); | - | ||||||||||||||||||||||||||||||
4748 | ENSURE_TRANSFORM_PTR never executed: end of block never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4749 | QRectF preciseViewBoundingRect = translateOnlyTransform ? brect.translated(transformPtr->dx(), transformPtr->dy())
| 0 | ||||||||||||||||||||||||||||||
4750 | : transformPtr->mapRect(brect); | - | ||||||||||||||||||||||||||||||
4751 | - | |||||||||||||||||||||||||||||||
4752 | bool itemIsTooSmallToRender = false; | - | ||||||||||||||||||||||||||||||
4753 | if (minimumRenderSize > 0.0
| 0 | ||||||||||||||||||||||||||||||
4754 | && (preciseViewBoundingRect.width() < minimumRenderSize
| 0 | ||||||||||||||||||||||||||||||
4755 | || preciseViewBoundingRect.height() < minimumRenderSize)) {
| 0 | ||||||||||||||||||||||||||||||
4756 | itemIsTooSmallToRender = true; | - | ||||||||||||||||||||||||||||||
4757 | drawItem = false; | - | ||||||||||||||||||||||||||||||
4758 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4759 | - | |||||||||||||||||||||||||||||||
4760 | bool itemIsOutsideVisibleRect = false; | - | ||||||||||||||||||||||||||||||
4761 | if (drawItem) {
| 0 | ||||||||||||||||||||||||||||||
4762 | QRect viewBoundingRect = preciseViewBoundingRect.toAlignedRect(); | - | ||||||||||||||||||||||||||||||
4763 | viewBoundingRect.adjust(-int(rectAdjust), -int(rectAdjust), rectAdjust, rectAdjust); | - | ||||||||||||||||||||||||||||||
4764 | if (widget)
| 0 | ||||||||||||||||||||||||||||||
4765 | item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect); never executed: item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect); | 0 | ||||||||||||||||||||||||||||||
4766 | drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect)
| 0 | ||||||||||||||||||||||||||||||
4767 | : !viewBoundingRect.normalized().isEmpty(); | - | ||||||||||||||||||||||||||||||
4768 | itemIsOutsideVisibleRect = !drawItem; | - | ||||||||||||||||||||||||||||||
4769 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4770 | - | |||||||||||||||||||||||||||||||
4771 | if (itemIsTooSmallToRender || itemIsOutsideVisibleRect) {
| 0 | ||||||||||||||||||||||||||||||
4772 | // We cannot simply use !drawItem here. If we did it is possible | - | ||||||||||||||||||||||||||||||
4773 | // to enter the outter if statement with drawItem == false and minimumRenderSize > 0 | - | ||||||||||||||||||||||||||||||
4774 | // and finally end up inside this inner if, even though none of the above two | - | ||||||||||||||||||||||||||||||
4775 | // conditions are met. In that case we should not return from this function | - | ||||||||||||||||||||||||||||||
4776 | // but call draw() instead. | - | ||||||||||||||||||||||||||||||
4777 | if (!itemHasChildren)
| 0 | ||||||||||||||||||||||||||||||
4778 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4779 | if (itemClipsChildrenToShape) {
| 0 | ||||||||||||||||||||||||||||||
4780 | if (wasDirtyParentSceneTransform)
| 0 | ||||||||||||||||||||||||||||||
4781 | item->d_ptr->invalidateChildrenSceneTransform(); never executed: item->d_ptr->invalidateChildrenSceneTransform(); | 0 | ||||||||||||||||||||||||||||||
4782 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4783 | } | - | ||||||||||||||||||||||||||||||
4784 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4785 | } // else we know for sure this item has children we must process. never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4786 | - | |||||||||||||||||||||||||||||||
4787 | if (itemHasChildren && itemClipsChildrenToShape)
| 0 | ||||||||||||||||||||||||||||||
4788 | ENSURE_TRANSFORM_PTR; never executed: end of block never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4789 | - | |||||||||||||||||||||||||||||||
4790 | #ifndef QT_NO_GRAPHICSEFFECT | - | ||||||||||||||||||||||||||||||
4791 | if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) {
| 0 | ||||||||||||||||||||||||||||||
4792 | ENSURE_TRANSFORM_PTR; never executed: end of block never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4793 | QGraphicsItemPaintInfo info(viewTransform, transformPtr, effectTransform, exposedRegion, widget, &styleOptionTmp, | - | ||||||||||||||||||||||||||||||
4794 | painter, opacity, wasDirtyParentSceneTransform, itemHasContents && !itemIsFullyTransparent); | - | ||||||||||||||||||||||||||||||
4795 | QGraphicsEffectSource *source = item->d_ptr->graphicsEffect->d_func()->source; | - | ||||||||||||||||||||||||||||||
4796 | QGraphicsItemEffectSourcePrivate *sourced = static_cast<QGraphicsItemEffectSourcePrivate *> | - | ||||||||||||||||||||||||||||||
4797 | (source->d_func()); | - | ||||||||||||||||||||||||||||||
4798 | sourced->info = &info; | - | ||||||||||||||||||||||||||||||
4799 | const QTransform restoreTransform = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
4800 | if (effectTransform)
| 0 | ||||||||||||||||||||||||||||||
4801 | painter->setWorldTransform(*transformPtr * *effectTransform); never executed: painter->setWorldTransform(*transformPtr * *effectTransform); | 0 | ||||||||||||||||||||||||||||||
4802 | else | - | ||||||||||||||||||||||||||||||
4803 | painter->setWorldTransform(*transformPtr); never executed: painter->setWorldTransform(*transformPtr); | 0 | ||||||||||||||||||||||||||||||
4804 | painter->setOpacity(opacity); | - | ||||||||||||||||||||||||||||||
4805 | - | |||||||||||||||||||||||||||||||
4806 | if (sourced->currentCachedSystem() != Qt::LogicalCoordinates
| 0 | ||||||||||||||||||||||||||||||
4807 | && sourced->lastEffectTransform != painter->worldTransform())
| 0 | ||||||||||||||||||||||||||||||
4808 | { | - | ||||||||||||||||||||||||||||||
4809 | if (sourced->lastEffectTransform.type() <= QTransform::TxTranslate
| 0 | ||||||||||||||||||||||||||||||
4810 | && painter->worldTransform().type() <= QTransform::TxTranslate)
| 0 | ||||||||||||||||||||||||||||||
4811 | { | - | ||||||||||||||||||||||||||||||
4812 | QRectF sourceRect = sourced->boundingRect(Qt::DeviceCoordinates); | - | ||||||||||||||||||||||||||||||
4813 | QRect effectRect = sourced->paddedEffectRect(Qt::DeviceCoordinates, sourced->currentCachedMode(), sourceRect); | - | ||||||||||||||||||||||||||||||
4814 | - | |||||||||||||||||||||||||||||||
4815 | sourced->setCachedOffset(effectRect.topLeft()); | - | ||||||||||||||||||||||||||||||
4816 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4817 | sourced->invalidateCache(QGraphicsEffectSourcePrivate::TransformChanged); | - | ||||||||||||||||||||||||||||||
4818 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4819 | - | |||||||||||||||||||||||||||||||
4820 | sourced->lastEffectTransform = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
4821 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4822 | - | |||||||||||||||||||||||||||||||
4823 | item->d_ptr->graphicsEffect->draw(painter); | - | ||||||||||||||||||||||||||||||
4824 | painter->setWorldTransform(restoreTransform); | - | ||||||||||||||||||||||||||||||
4825 | sourced->info = 0; | - | ||||||||||||||||||||||||||||||
4826 | } else never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4827 | #endif //QT_NO_GRAPHICSEFFECT | - | ||||||||||||||||||||||||||||||
4828 | { | - | ||||||||||||||||||||||||||||||
4829 | draw(item, painter, viewTransform, transformPtr, exposedRegion, widget, opacity, | - | ||||||||||||||||||||||||||||||
4830 | effectTransform, wasDirtyParentSceneTransform, drawItem); | - | ||||||||||||||||||||||||||||||
4831 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4832 | } | - | ||||||||||||||||||||||||||||||
4833 | - | |||||||||||||||||||||||||||||||
4834 | static inline void setClip(QPainter *painter, QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
4835 | { | - | ||||||||||||||||||||||||||||||
4836 | painter->save(); | - | ||||||||||||||||||||||||||||||
4837 | QRectF clipRect; | - | ||||||||||||||||||||||||||||||
4838 | const QPainterPath clipPath(item->shape()); | - | ||||||||||||||||||||||||||||||
4839 | if (QPathClipper::pathToRect(clipPath, &clipRect))
| 0 | ||||||||||||||||||||||||||||||
4840 | painter->setClipRect(clipRect, Qt::IntersectClip); never executed: painter->setClipRect(clipRect, Qt::IntersectClip); | 0 | ||||||||||||||||||||||||||||||
4841 | else | - | ||||||||||||||||||||||||||||||
4842 | painter->setClipPath(clipPath, Qt::IntersectClip); never executed: painter->setClipPath(clipPath, Qt::IntersectClip); | 0 | ||||||||||||||||||||||||||||||
4843 | } | - | ||||||||||||||||||||||||||||||
4844 | - | |||||||||||||||||||||||||||||||
4845 | static inline void setWorldTransform(QPainter *painter, const QTransform *const transformPtr, | - | ||||||||||||||||||||||||||||||
4846 | const QTransform *effectTransform) | - | ||||||||||||||||||||||||||||||
4847 | { | - | ||||||||||||||||||||||||||||||
4848 | Q_ASSERT(transformPtr); | - | ||||||||||||||||||||||||||||||
4849 | if (effectTransform)
| 0 | ||||||||||||||||||||||||||||||
4850 | painter->setWorldTransform(*transformPtr * *effectTransform); never executed: painter->setWorldTransform(*transformPtr * *effectTransform); | 0 | ||||||||||||||||||||||||||||||
4851 | else | - | ||||||||||||||||||||||||||||||
4852 | painter->setWorldTransform(*transformPtr); never executed: painter->setWorldTransform(*transformPtr); | 0 | ||||||||||||||||||||||||||||||
4853 | } | - | ||||||||||||||||||||||||||||||
4854 | - | |||||||||||||||||||||||||||||||
4855 | void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const QTransform *const viewTransform, | - | ||||||||||||||||||||||||||||||
4856 | const QTransform *const transformPtr, QRegion *exposedRegion, QWidget *widget, | - | ||||||||||||||||||||||||||||||
4857 | qreal opacity, const QTransform *effectTransform, | - | ||||||||||||||||||||||||||||||
4858 | bool wasDirtyParentSceneTransform, bool drawItem) | - | ||||||||||||||||||||||||||||||
4859 | { | - | ||||||||||||||||||||||||||||||
4860 | const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); | - | ||||||||||||||||||||||||||||||
4861 | const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); | - | ||||||||||||||||||||||||||||||
4862 | const bool itemHasChildren = !item->d_ptr->children.isEmpty(); | - | ||||||||||||||||||||||||||||||
4863 | bool setChildClip = itemClipsChildrenToShape; | - | ||||||||||||||||||||||||||||||
4864 | bool itemHasChildrenStackedBehind = false; | - | ||||||||||||||||||||||||||||||
4865 | - | |||||||||||||||||||||||||||||||
4866 | int i = 0; | - | ||||||||||||||||||||||||||||||
4867 | if (itemHasChildren) {
| 0 | ||||||||||||||||||||||||||||||
4868 | if (itemClipsChildrenToShape)
| 0 | ||||||||||||||||||||||||||||||
4869 | setWorldTransform(painter, transformPtr, effectTransform); never executed: setWorldTransform(painter, transformPtr, effectTransform); | 0 | ||||||||||||||||||||||||||||||
4870 | - | |||||||||||||||||||||||||||||||
4871 | item->d_ptr->ensureSortedChildren(); | - | ||||||||||||||||||||||||||||||
4872 | // Items with the 'ItemStacksBehindParent' flag are put in front of the list | - | ||||||||||||||||||||||||||||||
4873 | // so all we have to do is to check the first item. | - | ||||||||||||||||||||||||||||||
4874 | itemHasChildrenStackedBehind = (item->d_ptr->children.at(0)->d_ptr->flags | - | ||||||||||||||||||||||||||||||
4875 | & QGraphicsItem::ItemStacksBehindParent); | - | ||||||||||||||||||||||||||||||
4876 | - | |||||||||||||||||||||||||||||||
4877 | if (itemHasChildrenStackedBehind) {
| 0 | ||||||||||||||||||||||||||||||
4878 | if (itemClipsChildrenToShape) {
| 0 | ||||||||||||||||||||||||||||||
4879 | setClip(painter, item); | - | ||||||||||||||||||||||||||||||
4880 | setChildClip = false; | - | ||||||||||||||||||||||||||||||
4881 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4882 | - | |||||||||||||||||||||||||||||||
4883 | // Draw children behind | - | ||||||||||||||||||||||||||||||
4884 | for (i = 0; i < item->d_ptr->children.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
4885 | QGraphicsItem *child = item->d_ptr->children.at(i); | - | ||||||||||||||||||||||||||||||
4886 | if (wasDirtyParentSceneTransform)
| 0 | ||||||||||||||||||||||||||||||
4887 | child->d_ptr->dirtySceneTransform = 1; never executed: child->d_ptr->dirtySceneTransform = 1; | 0 | ||||||||||||||||||||||||||||||
4888 | if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
| 0 | ||||||||||||||||||||||||||||||
4889 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4890 | if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
| 0 | ||||||||||||||||||||||||||||||
4891 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
4892 | drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); | - | ||||||||||||||||||||||||||||||
4893 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4894 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4895 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4896 | - | |||||||||||||||||||||||||||||||
4897 | // Draw item | - | ||||||||||||||||||||||||||||||
4898 | if (drawItem) {
| 0 | ||||||||||||||||||||||||||||||
4899 | Q_ASSERT(!itemIsFullyTransparent); | - | ||||||||||||||||||||||||||||||
4900 | Q_ASSERT(!(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents)); | - | ||||||||||||||||||||||||||||||
4901 | Q_ASSERT(transformPtr); | - | ||||||||||||||||||||||||||||||
4902 | item->d_ptr->initStyleOption(&styleOptionTmp, *transformPtr, exposedRegion | - | ||||||||||||||||||||||||||||||
4903 | ? *exposedRegion : QRegion(), exposedRegion == 0); | - | ||||||||||||||||||||||||||||||
4904 | - | |||||||||||||||||||||||||||||||
4905 | const bool itemClipsToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsToShape; | - | ||||||||||||||||||||||||||||||
4906 | bool restorePainterClip = false; | - | ||||||||||||||||||||||||||||||
4907 | - | |||||||||||||||||||||||||||||||
4908 | if (!itemHasChildren || !itemClipsChildrenToShape) {
| 0 | ||||||||||||||||||||||||||||||
4909 | // Item does not have children or clip children to shape. | - | ||||||||||||||||||||||||||||||
4910 | setWorldTransform(painter, transformPtr, effectTransform); | - | ||||||||||||||||||||||||||||||
4911 | if ((restorePainterClip = itemClipsToShape))
| 0 | ||||||||||||||||||||||||||||||
4912 | setClip(painter, item); never executed: setClip(painter, item); | 0 | ||||||||||||||||||||||||||||||
4913 | } else if (itemHasChildrenStackedBehind){ never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
4914 | // Item clips children to shape and has children stacked behind, which means | - | ||||||||||||||||||||||||||||||
4915 | // the painter is already clipped to the item's shape. | - | ||||||||||||||||||||||||||||||
4916 | if (itemClipsToShape) {
| 0 | ||||||||||||||||||||||||||||||
4917 | // The clip is already correct. Ensure correct world transform. | - | ||||||||||||||||||||||||||||||
4918 | setWorldTransform(painter, transformPtr, effectTransform); | - | ||||||||||||||||||||||||||||||
4919 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4920 | // Remove clip (this also ensures correct world transform). | - | ||||||||||||||||||||||||||||||
4921 | painter->restore(); | - | ||||||||||||||||||||||||||||||
4922 | setChildClip = true; | - | ||||||||||||||||||||||||||||||
4923 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4924 | } else if (itemClipsToShape) {
| 0 | ||||||||||||||||||||||||||||||
4925 | // Item clips children and itself to shape. It does not have hildren stacked | - | ||||||||||||||||||||||||||||||
4926 | // behind, which means the clip has not yet been set. We set it now and re-use it | - | ||||||||||||||||||||||||||||||
4927 | // for the children. | - | ||||||||||||||||||||||||||||||
4928 | setClip(painter, item); | - | ||||||||||||||||||||||||||||||
4929 | setChildClip = false; | - | ||||||||||||||||||||||||||||||
4930 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4931 | - | |||||||||||||||||||||||||||||||
4932 | if (painterStateProtection && !restorePainterClip)
| 0 | ||||||||||||||||||||||||||||||
4933 | painter->save(); never executed: painter->save(); | 0 | ||||||||||||||||||||||||||||||
4934 | - | |||||||||||||||||||||||||||||||
4935 | painter->setOpacity(opacity); | - | ||||||||||||||||||||||||||||||
4936 | if (!item->d_ptr->cacheMode && !item->d_ptr->isWidget)
| 0 | ||||||||||||||||||||||||||||||
4937 | item->paint(painter, &styleOptionTmp, widget); never executed: item->paint(painter, &styleOptionTmp, widget); | 0 | ||||||||||||||||||||||||||||||
4938 | else | - | ||||||||||||||||||||||||||||||
4939 | drawItemHelper(item, painter, &styleOptionTmp, widget, painterStateProtection); never executed: drawItemHelper(item, painter, &styleOptionTmp, widget, painterStateProtection); | 0 | ||||||||||||||||||||||||||||||
4940 | - | |||||||||||||||||||||||||||||||
4941 | if (painterStateProtection || restorePainterClip)
| 0 | ||||||||||||||||||||||||||||||
4942 | painter->restore(); never executed: painter->restore(); | 0 | ||||||||||||||||||||||||||||||
4943 | - | |||||||||||||||||||||||||||||||
4944 | static int drawRect = qEnvironmentVariableIntValue("QT_DRAW_SCENE_ITEM_RECTS"); | - | ||||||||||||||||||||||||||||||
4945 | if (drawRect) {
| 0 | ||||||||||||||||||||||||||||||
4946 | QPen oldPen = painter->pen(); | - | ||||||||||||||||||||||||||||||
4947 | QBrush oldBrush = painter->brush(); | - | ||||||||||||||||||||||||||||||
4948 | quintptr ptr = reinterpret_cast<quintptr>(item); | - | ||||||||||||||||||||||||||||||
4949 | const QColor color = QColor::fromHsv(ptr % 255, 255, 255); | - | ||||||||||||||||||||||||||||||
4950 | painter->setPen(color); | - | ||||||||||||||||||||||||||||||
4951 | painter->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||
4952 | painter->drawRect(adjustedItemBoundingRect(item)); | - | ||||||||||||||||||||||||||||||
4953 | painter->setPen(oldPen); | - | ||||||||||||||||||||||||||||||
4954 | painter->setBrush(oldBrush); | - | ||||||||||||||||||||||||||||||
4955 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4956 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4957 | - | |||||||||||||||||||||||||||||||
4958 | // Draw children in front | - | ||||||||||||||||||||||||||||||
4959 | if (itemHasChildren) {
| 0 | ||||||||||||||||||||||||||||||
4960 | if (setChildClip)
| 0 | ||||||||||||||||||||||||||||||
4961 | setClip(painter, item); never executed: setClip(painter, item); | 0 | ||||||||||||||||||||||||||||||
4962 | - | |||||||||||||||||||||||||||||||
4963 | for (; i < item->d_ptr->children.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
4964 | QGraphicsItem *child = item->d_ptr->children.at(i); | - | ||||||||||||||||||||||||||||||
4965 | if (wasDirtyParentSceneTransform)
| 0 | ||||||||||||||||||||||||||||||
4966 | child->d_ptr->dirtySceneTransform = 1; never executed: child->d_ptr->dirtySceneTransform = 1; | 0 | ||||||||||||||||||||||||||||||
4967 | if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
| 0 | ||||||||||||||||||||||||||||||
4968 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
4969 | drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); | - | ||||||||||||||||||||||||||||||
4970 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4971 | - | |||||||||||||||||||||||||||||||
4972 | // Restore child clip | - | ||||||||||||||||||||||||||||||
4973 | if (itemClipsChildrenToShape)
| 0 | ||||||||||||||||||||||||||||||
4974 | painter->restore(); never executed: painter->restore(); | 0 | ||||||||||||||||||||||||||||||
4975 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4976 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
4977 | - | |||||||||||||||||||||||||||||||
4978 | void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, bool invalidateChildren, | - | ||||||||||||||||||||||||||||||
4979 | bool force, bool ignoreOpacity, bool removingItemFromScene, | - | ||||||||||||||||||||||||||||||
4980 | bool updateBoundingRect) | - | ||||||||||||||||||||||||||||||
4981 | { | - | ||||||||||||||||||||||||||||||
4982 | Q_ASSERT(item); | - | ||||||||||||||||||||||||||||||
4983 | if (updateAll)
| 0 | ||||||||||||||||||||||||||||||
4984 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
4985 | - | |||||||||||||||||||||||||||||||
4986 | if (removingItemFromScene && !ignoreOpacity && !item->d_ptr->ignoreOpacity) {
| 0 | ||||||||||||||||||||||||||||||
4987 | // If any of the item's ancestors ignore opacity, it means that the opacity | - | ||||||||||||||||||||||||||||||
4988 | // was set to 0 (and the update request has not yet been processed). That | - | ||||||||||||||||||||||||||||||
4989 | // also means that we have to ignore the opacity for the item itself; otherwise | - | ||||||||||||||||||||||||||||||
4990 | // things like: parent->setOpacity(0); scene->removeItem(child) won't work. | - | ||||||||||||||||||||||||||||||
4991 | // Note that we only do this when removing items from the scene. In all other | - | ||||||||||||||||||||||||||||||
4992 | // cases the ignoreOpacity bit propagates properly in processDirtyItems, but | - | ||||||||||||||||||||||||||||||
4993 | // since the item is removed immediately it won't be processed there. | - | ||||||||||||||||||||||||||||||
4994 | QGraphicsItem *p = item->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
4995 | while (p) {
| 0 | ||||||||||||||||||||||||||||||
4996 | if (p->d_ptr->ignoreOpacity) {
| 0 | ||||||||||||||||||||||||||||||
4997 | item->d_ptr->ignoreOpacity = true; | - | ||||||||||||||||||||||||||||||
4998 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4999 | } | - | ||||||||||||||||||||||||||||||
5000 | p = p->d_ptr->parent; | - | ||||||||||||||||||||||||||||||
5001 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5002 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5003 | - | |||||||||||||||||||||||||||||||
5004 | if (item->d_ptr->discardUpdateRequest(/*ignoreVisibleBit=*/force,
| 0 | ||||||||||||||||||||||||||||||
5005 | /*ignoreDirtyBit=*/removingItemFromScene || invalidateChildren,
| 0 | ||||||||||||||||||||||||||||||
5006 | /*ignoreOpacity=*/ignoreOpacity)) {
| 0 | ||||||||||||||||||||||||||||||
5007 | if (item->d_ptr->dirty) {
| 0 | ||||||||||||||||||||||||||||||
5008 | // The item is already marked as dirty and will be processed later. However, | - | ||||||||||||||||||||||||||||||
5009 | // we have to make sure ignoreVisible and ignoreOpacity are set properly; | - | ||||||||||||||||||||||||||||||
5010 | // otherwise things like: item->update(); item->hide() (force is now true) | - | ||||||||||||||||||||||||||||||
5011 | // won't work as expected. | - | ||||||||||||||||||||||||||||||
5012 | if (force)
| 0 | ||||||||||||||||||||||||||||||
5013 | item->d_ptr->ignoreVisible = 1; never executed: item->d_ptr->ignoreVisible = 1; | 0 | ||||||||||||||||||||||||||||||
5014 | if (ignoreOpacity)
| 0 | ||||||||||||||||||||||||||||||
5015 | item->d_ptr->ignoreOpacity = 1; never executed: item->d_ptr->ignoreOpacity = 1; | 0 | ||||||||||||||||||||||||||||||
5016 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5017 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5018 | } | - | ||||||||||||||||||||||||||||||
5019 | - | |||||||||||||||||||||||||||||||
5020 | const bool fullItemUpdate = rect.isNull(); | - | ||||||||||||||||||||||||||||||
5021 | if (!fullItemUpdate && rect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
5022 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5023 | - | |||||||||||||||||||||||||||||||
5024 | if (!processDirtyItemsEmitted) {
| 0 | ||||||||||||||||||||||||||||||
5025 | QMetaMethod method = q_ptr->metaObject()->method(processDirtyItemsIndex); | - | ||||||||||||||||||||||||||||||
5026 | method.invoke(q_ptr, Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
5027 | // QMetaObject::invokeMethod(q_ptr, "_q_processDirtyItems", Qt::QueuedConnection); | - | ||||||||||||||||||||||||||||||
5028 | processDirtyItemsEmitted = true; | - | ||||||||||||||||||||||||||||||
5029 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5030 | - | |||||||||||||||||||||||||||||||
5031 | if (removingItemFromScene) {
| 0 | ||||||||||||||||||||||||||||||
5032 | // Note that this function can be called from the item's destructor, so | - | ||||||||||||||||||||||||||||||
5033 | // do NOT call any virtual functions on it within this block. | - | ||||||||||||||||||||||||||||||
5034 | if (isSignalConnected(changedSignalIndex) || views.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
5035 | // This block of code is kept for compatibility. Since 4.5, by default | - | ||||||||||||||||||||||||||||||
5036 | // QGraphicsView does not connect the signal and we use the below | - | ||||||||||||||||||||||||||||||
5037 | // method of delivering updates. | - | ||||||||||||||||||||||||||||||
5038 | q_func()->update(); | - | ||||||||||||||||||||||||||||||
5039 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5040 | } | - | ||||||||||||||||||||||||||||||
5041 | - | |||||||||||||||||||||||||||||||
5042 | for (int i = 0; i < views.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
5043 | QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func(); | - | ||||||||||||||||||||||||||||||
5044 | QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport); | - | ||||||||||||||||||||||||||||||
5045 | rect.translate(viewPrivate->dirtyScrollOffset); | - | ||||||||||||||||||||||||||||||
5046 | viewPrivate->updateRect(rect); | - | ||||||||||||||||||||||||||||||
5047 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5048 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5049 | } | - | ||||||||||||||||||||||||||||||
5050 | - | |||||||||||||||||||||||||||||||
5051 | bool hasNoContents = item->d_ptr->flags & QGraphicsItem::ItemHasNoContents; | - | ||||||||||||||||||||||||||||||
5052 | if (!hasNoContents) {
| 0 | ||||||||||||||||||||||||||||||
5053 | item->d_ptr->dirty = 1; | - | ||||||||||||||||||||||||||||||
5054 | if (fullItemUpdate)
| 0 | ||||||||||||||||||||||||||||||
5055 | item->d_ptr->fullUpdatePending = 1; never executed: item->d_ptr->fullUpdatePending = 1; | 0 | ||||||||||||||||||||||||||||||
5056 | else if (!item->d_ptr->fullUpdatePending)
| 0 | ||||||||||||||||||||||||||||||
5057 | item->d_ptr->needsRepaint |= rect; never executed: item->d_ptr->needsRepaint |= rect; | 0 | ||||||||||||||||||||||||||||||
5058 | } else if (item->d_ptr->graphicsEffect) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
5059 | invalidateChildren = true; | - | ||||||||||||||||||||||||||||||
5060 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5061 | - | |||||||||||||||||||||||||||||||
5062 | if (invalidateChildren) {
| 0 | ||||||||||||||||||||||||||||||
5063 | item->d_ptr->allChildrenDirty = 1; | - | ||||||||||||||||||||||||||||||
5064 | item->d_ptr->dirtyChildren = 1; | - | ||||||||||||||||||||||||||||||
5065 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5066 | - | |||||||||||||||||||||||||||||||
5067 | if (force)
| 0 | ||||||||||||||||||||||||||||||
5068 | item->d_ptr->ignoreVisible = 1; never executed: item->d_ptr->ignoreVisible = 1; | 0 | ||||||||||||||||||||||||||||||
5069 | if (ignoreOpacity)
| 0 | ||||||||||||||||||||||||||||||
5070 | item->d_ptr->ignoreOpacity = 1; never executed: item->d_ptr->ignoreOpacity = 1; | 0 | ||||||||||||||||||||||||||||||
5071 | - | |||||||||||||||||||||||||||||||
5072 | if (!updateBoundingRect)
| 0 | ||||||||||||||||||||||||||||||
5073 | item->d_ptr->markParentDirty(); never executed: item->d_ptr->markParentDirty(); | 0 | ||||||||||||||||||||||||||||||
5074 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5075 | - | |||||||||||||||||||||||||||||||
5076 | static inline bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item, | - | ||||||||||||||||||||||||||||||
5077 | const QRectF &rect, bool itemIsUntransformable) | - | ||||||||||||||||||||||||||||||
5078 | { | - | ||||||||||||||||||||||||||||||
5079 | Q_ASSERT(view); | - | ||||||||||||||||||||||||||||||
5080 | Q_ASSERT(item); | - | ||||||||||||||||||||||||||||||
5081 | - | |||||||||||||||||||||||||||||||
5082 | QGraphicsItem *itemq = static_cast<QGraphicsItem *>(item->q_ptr); | - | ||||||||||||||||||||||||||||||
5083 | QGraphicsView *viewq = static_cast<QGraphicsView *>(view->q_ptr); | - | ||||||||||||||||||||||||||||||
5084 | - | |||||||||||||||||||||||||||||||
5085 | if (itemIsUntransformable) {
| 0 | ||||||||||||||||||||||||||||||
5086 | const QTransform xform = itemq->deviceTransform(viewq->viewportTransform()); | - | ||||||||||||||||||||||||||||||
5087 | if (!item->hasBoundingRegionGranularity)
| 0 | ||||||||||||||||||||||||||||||
5088 | return view->updateRectF(xform.mapRect(rect)); never executed: return view->updateRectF(xform.mapRect(rect)); | 0 | ||||||||||||||||||||||||||||||
5089 | return view->updateRegion(rect, xform); never executed: return view->updateRegion(rect, xform); | 0 | ||||||||||||||||||||||||||||||
5090 | } | - | ||||||||||||||||||||||||||||||
5091 | - | |||||||||||||||||||||||||||||||
5092 | if (item->sceneTransformTranslateOnly && view->identityMatrix) {
| 0 | ||||||||||||||||||||||||||||||
5093 | const qreal dx = item->sceneTransform.dx(); | - | ||||||||||||||||||||||||||||||
5094 | const qreal dy = item->sceneTransform.dy(); | - | ||||||||||||||||||||||||||||||
5095 | QRectF r(rect); | - | ||||||||||||||||||||||||||||||
5096 | r.translate(dx - view->horizontalScroll(), dy - view->verticalScroll()); | - | ||||||||||||||||||||||||||||||
5097 | return view->updateRectF(r); never executed: return view->updateRectF(r); | 0 | ||||||||||||||||||||||||||||||
5098 | } | - | ||||||||||||||||||||||||||||||
5099 | - | |||||||||||||||||||||||||||||||
5100 | if (!viewq->isTransformed()) {
| 0 | ||||||||||||||||||||||||||||||
5101 | if (!item->hasBoundingRegionGranularity)
| 0 | ||||||||||||||||||||||||||||||
5102 | return view->updateRectF(item->sceneTransform.mapRect(rect)); never executed: return view->updateRectF(item->sceneTransform.mapRect(rect)); | 0 | ||||||||||||||||||||||||||||||
5103 | return view->updateRegion(rect, item->sceneTransform); never executed: return view->updateRegion(rect, item->sceneTransform); | 0 | ||||||||||||||||||||||||||||||
5104 | } | - | ||||||||||||||||||||||||||||||
5105 | - | |||||||||||||||||||||||||||||||
5106 | QTransform xform = item->sceneTransform; | - | ||||||||||||||||||||||||||||||
5107 | xform *= viewq->viewportTransform(); | - | ||||||||||||||||||||||||||||||
5108 | if (!item->hasBoundingRegionGranularity)
| 0 | ||||||||||||||||||||||||||||||
5109 | return view->updateRectF(xform.mapRect(rect)); never executed: return view->updateRectF(xform.mapRect(rect)); | 0 | ||||||||||||||||||||||||||||||
5110 | return view->updateRegion(rect, xform); never executed: return view->updateRegion(rect, xform); | 0 | ||||||||||||||||||||||||||||||
5111 | } | - | ||||||||||||||||||||||||||||||
5112 | - | |||||||||||||||||||||||||||||||
5113 | void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren, | - | ||||||||||||||||||||||||||||||
5114 | qreal parentOpacity) | - | ||||||||||||||||||||||||||||||
5115 | { | - | ||||||||||||||||||||||||||||||
5116 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5117 | Q_ASSERT(item); | - | ||||||||||||||||||||||||||||||
5118 | Q_ASSERT(!updateAll); | - | ||||||||||||||||||||||||||||||
5119 | - | |||||||||||||||||||||||||||||||
5120 | if (!item->d_ptr->dirty && !item->d_ptr->dirtyChildren) {
| 0 | ||||||||||||||||||||||||||||||
5121 | resetDirtyItem(item); | - | ||||||||||||||||||||||||||||||
5122 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5123 | } | - | ||||||||||||||||||||||||||||||
5124 | - | |||||||||||||||||||||||||||||||
5125 | const bool itemIsHidden = !item->d_ptr->ignoreVisible && !item->d_ptr->visible;
| 0 | ||||||||||||||||||||||||||||||
5126 | if (itemIsHidden) {
| 0 | ||||||||||||||||||||||||||||||
5127 | resetDirtyItem(item, /*recursive=*/true); | - | ||||||||||||||||||||||||||||||
5128 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5129 | } | - | ||||||||||||||||||||||||||||||
5130 | - | |||||||||||||||||||||||||||||||
5131 | bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); | - | ||||||||||||||||||||||||||||||
5132 | const bool itemHasChildren = !item->d_ptr->children.isEmpty(); | - | ||||||||||||||||||||||||||||||
5133 | if (!itemHasContents) {
| 0 | ||||||||||||||||||||||||||||||
5134 | if (!itemHasChildren) {
| 0 | ||||||||||||||||||||||||||||||
5135 | resetDirtyItem(item); | - | ||||||||||||||||||||||||||||||
5136 | return; // Item has neither contents nor children!(?) never executed: return; | 0 | ||||||||||||||||||||||||||||||
5137 | } | - | ||||||||||||||||||||||||||||||
5138 | if (item->d_ptr->graphicsEffect)
| 0 | ||||||||||||||||||||||||||||||
5139 | itemHasContents = true; never executed: itemHasContents = true; | 0 | ||||||||||||||||||||||||||||||
5140 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5141 | - | |||||||||||||||||||||||||||||||
5142 | const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); | - | ||||||||||||||||||||||||||||||
5143 | const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity
| 0 | ||||||||||||||||||||||||||||||
5144 | && QGraphicsItemPrivate::isOpacityNull(opacity);
| 0 | ||||||||||||||||||||||||||||||
5145 | if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) {
| 0 | ||||||||||||||||||||||||||||||
5146 | resetDirtyItem(item, /*recursive=*/itemHasChildren); | - | ||||||||||||||||||||||||||||||
5147 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5148 | } | - | ||||||||||||||||||||||||||||||
5149 | - | |||||||||||||||||||||||||||||||
5150 | bool wasDirtyParentSceneTransform = item->d_ptr->dirtySceneTransform; | - | ||||||||||||||||||||||||||||||
5151 | const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); | - | ||||||||||||||||||||||||||||||
5152 | if (wasDirtyParentSceneTransform && !itemIsUntransformable) {
| 0 | ||||||||||||||||||||||||||||||
5153 | item->d_ptr->updateSceneTransformFromParent(); | - | ||||||||||||||||||||||||||||||
5154 | Q_ASSERT(!item->d_ptr->dirtySceneTransform); | - | ||||||||||||||||||||||||||||||
5155 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5156 | - | |||||||||||||||||||||||||||||||
5157 | const bool wasDirtyParentViewBoundingRects = item->d_ptr->paintedViewBoundingRectsNeedRepaint; | - | ||||||||||||||||||||||||||||||
5158 | if (itemIsFullyTransparent || !itemHasContents || dirtyAncestorContainsChildren) {
| 0 | ||||||||||||||||||||||||||||||
5159 | // Make sure we don't process invisible items or items with no content. | - | ||||||||||||||||||||||||||||||
5160 | item->d_ptr->dirty = 0; | - | ||||||||||||||||||||||||||||||
5161 | item->d_ptr->fullUpdatePending = 0; | - | ||||||||||||||||||||||||||||||
5162 | // Might have a dirty view bounding rect otherwise. | - | ||||||||||||||||||||||||||||||
5163 | if (itemIsFullyTransparent || !itemHasContents)
| 0 | ||||||||||||||||||||||||||||||
5164 | item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0; never executed: item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0; | 0 | ||||||||||||||||||||||||||||||
5165 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5166 | - | |||||||||||||||||||||||||||||||
5167 | if (!hasSceneRect && item->d_ptr->geometryChanged && item->d_ptr->visible) {
| 0 | ||||||||||||||||||||||||||||||
5168 | // Update growingItemsBoundingRect. | - | ||||||||||||||||||||||||||||||
5169 | if (item->d_ptr->sceneTransformTranslateOnly) {
| 0 | ||||||||||||||||||||||||||||||
5170 | growingItemsBoundingRect |= item->boundingRect().translated(item->d_ptr->sceneTransform.dx(), | - | ||||||||||||||||||||||||||||||
5171 | item->d_ptr->sceneTransform.dy()); | - | ||||||||||||||||||||||||||||||
5172 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5173 | growingItemsBoundingRect |= item->d_ptr->sceneTransform.mapRect(item->boundingRect()); | - | ||||||||||||||||||||||||||||||
5174 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5175 | } | - | ||||||||||||||||||||||||||||||
5176 | - | |||||||||||||||||||||||||||||||
5177 | // Process item. | - | ||||||||||||||||||||||||||||||
5178 | if (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
| 0 | ||||||||||||||||||||||||||||||
5179 | const bool useCompatUpdate = views.isEmpty() || isSignalConnected(changedSignalIndex);
| 0 | ||||||||||||||||||||||||||||||
5180 | const QRectF itemBoundingRect = adjustedItemEffectiveBoundingRect(item); | - | ||||||||||||||||||||||||||||||
5181 | - | |||||||||||||||||||||||||||||||
5182 | if (useCompatUpdate && !itemIsUntransformable && qFuzzyIsNull(item->boundingRegionGranularity())) {
| 0 | ||||||||||||||||||||||||||||||
5183 | // This block of code is kept for compatibility. Since 4.5, by default | - | ||||||||||||||||||||||||||||||
5184 | // QGraphicsView does not connect the signal and we use the below | - | ||||||||||||||||||||||||||||||
5185 | // method of delivering updates. | - | ||||||||||||||||||||||||||||||
5186 | if (item->d_ptr->sceneTransformTranslateOnly) {
| 0 | ||||||||||||||||||||||||||||||
5187 | q->update(itemBoundingRect.translated(item->d_ptr->sceneTransform.dx(), | - | ||||||||||||||||||||||||||||||
5188 | item->d_ptr->sceneTransform.dy())); | - | ||||||||||||||||||||||||||||||
5189 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5190 | QRectF rect = item->d_ptr->sceneTransform.mapRect(itemBoundingRect); | - | ||||||||||||||||||||||||||||||
5191 | if (!rect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
5192 | q->update(rect); never executed: q->update(rect); | 0 | ||||||||||||||||||||||||||||||
5193 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5194 | } else { | - | ||||||||||||||||||||||||||||||
5195 | QRectF dirtyRect; | - | ||||||||||||||||||||||||||||||
5196 | bool uninitializedDirtyRect = true; | - | ||||||||||||||||||||||||||||||
5197 | - | |||||||||||||||||||||||||||||||
5198 | for (int j = 0; j < views.size(); ++j) {
| 0 | ||||||||||||||||||||||||||||||
5199 | QGraphicsView *view = views.at(j); | - | ||||||||||||||||||||||||||||||
5200 | QGraphicsViewPrivate *viewPrivate = view->d_func(); | - | ||||||||||||||||||||||||||||||
5201 | QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport]; | - | ||||||||||||||||||||||||||||||
5202 | if (viewPrivate->fullUpdatePending
| 0 | ||||||||||||||||||||||||||||||
5203 | || viewPrivate->viewportUpdateMode == QGraphicsView::NoViewportUpdate) {
| 0 | ||||||||||||||||||||||||||||||
5204 | // Okay, if we have a full update pending or no viewport update, this item's | - | ||||||||||||||||||||||||||||||
5205 | // paintedViewBoundingRect will be updated correctly in the next paintEvent if | - | ||||||||||||||||||||||||||||||
5206 | // it is inside the viewport, but for now we can pretend that it is outside. | - | ||||||||||||||||||||||||||||||
5207 | paintedViewBoundingRect = QRect(-1, -1, -1, -1); | - | ||||||||||||||||||||||||||||||
5208 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5209 | } | - | ||||||||||||||||||||||||||||||
5210 | - | |||||||||||||||||||||||||||||||
5211 | if (item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
| 0 | ||||||||||||||||||||||||||||||
5212 | paintedViewBoundingRect.translate(viewPrivate->dirtyScrollOffset); | - | ||||||||||||||||||||||||||||||
5213 | if (!viewPrivate->updateRect(paintedViewBoundingRect))
| 0 | ||||||||||||||||||||||||||||||
5214 | paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport. never executed: paintedViewBoundingRect = QRect(-1, -1, -1, -1); | 0 | ||||||||||||||||||||||||||||||
5215 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5216 | - | |||||||||||||||||||||||||||||||
5217 | if (!item->d_ptr->dirty)
| 0 | ||||||||||||||||||||||||||||||
5218 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5219 | - | |||||||||||||||||||||||||||||||
5220 | if (!item->d_ptr->paintedViewBoundingRectsNeedRepaint
| 0 | ||||||||||||||||||||||||||||||
5221 | && paintedViewBoundingRect.x() == -1 && paintedViewBoundingRect.y() == -1
| 0 | ||||||||||||||||||||||||||||||
5222 | && paintedViewBoundingRect.width() == -1 && paintedViewBoundingRect.height() == -1) {
| 0 | ||||||||||||||||||||||||||||||
5223 | continue; // Outside viewport. never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5224 | } | - | ||||||||||||||||||||||||||||||
5225 | - | |||||||||||||||||||||||||||||||
5226 | if (uninitializedDirtyRect) {
| 0 | ||||||||||||||||||||||||||||||
5227 | dirtyRect = itemBoundingRect; | - | ||||||||||||||||||||||||||||||
5228 | if (!item->d_ptr->fullUpdatePending) {
| 0 | ||||||||||||||||||||||||||||||
5229 | _q_adjustRect(&item->d_ptr->needsRepaint); | - | ||||||||||||||||||||||||||||||
5230 | dirtyRect &= item->d_ptr->needsRepaint; | - | ||||||||||||||||||||||||||||||
5231 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5232 | uninitializedDirtyRect = false; | - | ||||||||||||||||||||||||||||||
5233 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5234 | - | |||||||||||||||||||||||||||||||
5235 | if (dirtyRect.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
5236 | continue; // Discard updates outside the bounding rect. never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5237 | - | |||||||||||||||||||||||||||||||
5238 | if (!updateHelper(viewPrivate, item->d_ptr.data(), dirtyRect, itemIsUntransformable)
| 0 | ||||||||||||||||||||||||||||||
5239 | && item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
| 0 | ||||||||||||||||||||||||||||||
5240 | paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport. | - | ||||||||||||||||||||||||||||||
5241 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5242 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5243 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5244 | } | - | ||||||||||||||||||||||||||||||
5245 | - | |||||||||||||||||||||||||||||||
5246 | // Process children. | - | ||||||||||||||||||||||||||||||
5247 | if (itemHasChildren && item->d_ptr->dirtyChildren) {
| 0 | ||||||||||||||||||||||||||||||
5248 | const bool itemClipsChildrenToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape
| 0 | ||||||||||||||||||||||||||||||
5249 | || item->d_ptr->flags & QGraphicsItem::ItemContainsChildrenInShape;
| 0 | ||||||||||||||||||||||||||||||
5250 | // Items with no content are threated as 'dummy' items which means they are never drawn and | - | ||||||||||||||||||||||||||||||
5251 | // 'processed', so the painted view bounding rect is never up-to-date. This means that whenever | - | ||||||||||||||||||||||||||||||
5252 | // such an item changes geometry, its children have to take care of the update regardless | - | ||||||||||||||||||||||||||||||
5253 | // of whether the item clips children to shape or not. | - | ||||||||||||||||||||||||||||||
5254 | const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
| 0 | ||||||||||||||||||||||||||||||
5255 | if (itemClipsChildrenToShape && !bypassUpdateClip) {
| 0 | ||||||||||||||||||||||||||||||
5256 | // Make sure child updates are clipped to the item's bounding rect. | - | ||||||||||||||||||||||||||||||
5257 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
5258 | views.at(i)->d_func()->setUpdateClip(item); never executed: views.at(i)->d_func()->setUpdateClip(item); | 0 | ||||||||||||||||||||||||||||||
5259 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5260 | if (!dirtyAncestorContainsChildren) {
| 0 | ||||||||||||||||||||||||||||||
5261 | dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
| 0 | ||||||||||||||||||||||||||||||
5262 | && itemClipsChildrenToShape;
| 0 | ||||||||||||||||||||||||||||||
5263 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5264 | const bool allChildrenDirty = item->d_ptr->allChildrenDirty; | - | ||||||||||||||||||||||||||||||
5265 | const bool parentIgnoresVisible = item->d_ptr->ignoreVisible; | - | ||||||||||||||||||||||||||||||
5266 | const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity; | - | ||||||||||||||||||||||||||||||
5267 | for (int i = 0; i < item->d_ptr->children.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
5268 | QGraphicsItem *child = item->d_ptr->children.at(i); | - | ||||||||||||||||||||||||||||||
5269 | if (wasDirtyParentSceneTransform)
| 0 | ||||||||||||||||||||||||||||||
5270 | child->d_ptr->dirtySceneTransform = 1; never executed: child->d_ptr->dirtySceneTransform = 1; | 0 | ||||||||||||||||||||||||||||||
5271 | if (wasDirtyParentViewBoundingRects)
| 0 | ||||||||||||||||||||||||||||||
5272 | child->d_ptr->paintedViewBoundingRectsNeedRepaint = 1; never executed: child->d_ptr->paintedViewBoundingRectsNeedRepaint = 1; | 0 | ||||||||||||||||||||||||||||||
5273 | if (parentIgnoresVisible)
| 0 | ||||||||||||||||||||||||||||||
5274 | child->d_ptr->ignoreVisible = 1; never executed: child->d_ptr->ignoreVisible = 1; | 0 | ||||||||||||||||||||||||||||||
5275 | if (parentIgnoresOpacity)
| 0 | ||||||||||||||||||||||||||||||
5276 | child->d_ptr->ignoreOpacity = 1; never executed: child->d_ptr->ignoreOpacity = 1; | 0 | ||||||||||||||||||||||||||||||
5277 | if (allChildrenDirty) {
| 0 | ||||||||||||||||||||||||||||||
5278 | child->d_ptr->dirty = 1; | - | ||||||||||||||||||||||||||||||
5279 | child->d_ptr->fullUpdatePending = 1; | - | ||||||||||||||||||||||||||||||
5280 | child->d_ptr->dirtyChildren = 1; | - | ||||||||||||||||||||||||||||||
5281 | child->d_ptr->allChildrenDirty = 1; | - | ||||||||||||||||||||||||||||||
5282 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5283 | processDirtyItemsRecursive(child, dirtyAncestorContainsChildren, opacity); | - | ||||||||||||||||||||||||||||||
5284 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5285 | - | |||||||||||||||||||||||||||||||
5286 | if (itemClipsChildrenToShape) {
| 0 | ||||||||||||||||||||||||||||||
5287 | // Reset updateClip. | - | ||||||||||||||||||||||||||||||
5288 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
5289 | views.at(i)->d_func()->setUpdateClip(0); never executed: views.at(i)->d_func()->setUpdateClip(0); | 0 | ||||||||||||||||||||||||||||||
5290 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5291 | } else if (wasDirtyParentSceneTransform) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
5292 | item->d_ptr->invalidateChildrenSceneTransform(); | - | ||||||||||||||||||||||||||||||
5293 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5294 | - | |||||||||||||||||||||||||||||||
5295 | resetDirtyItem(item); | - | ||||||||||||||||||||||||||||||
5296 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5297 | - | |||||||||||||||||||||||||||||||
5298 | /*! | - | ||||||||||||||||||||||||||||||
5299 | \obsolete | - | ||||||||||||||||||||||||||||||
5300 | - | |||||||||||||||||||||||||||||||
5301 | Paints the given \a items using the provided \a painter, after the | - | ||||||||||||||||||||||||||||||
5302 | background has been drawn, and before the foreground has been | - | ||||||||||||||||||||||||||||||
5303 | drawn. All painting is done in \e scene coordinates. Before | - | ||||||||||||||||||||||||||||||
5304 | drawing each item, the painter must be transformed using | - | ||||||||||||||||||||||||||||||
5305 | QGraphicsItem::sceneTransform(). | - | ||||||||||||||||||||||||||||||
5306 | - | |||||||||||||||||||||||||||||||
5307 | The \a options parameter is the list of style option objects for | - | ||||||||||||||||||||||||||||||
5308 | each item in \a items. The \a numItems parameter is the number of | - | ||||||||||||||||||||||||||||||
5309 | items in \a items and options in \a options. The \a widget | - | ||||||||||||||||||||||||||||||
5310 | parameter is optional; if specified, it should point to the widget | - | ||||||||||||||||||||||||||||||
5311 | that is being painted on. | - | ||||||||||||||||||||||||||||||
5312 | - | |||||||||||||||||||||||||||||||
5313 | The default implementation prepares the painter matrix, and calls | - | ||||||||||||||||||||||||||||||
5314 | QGraphicsItem::paint() on all items. Reimplement this function to | - | ||||||||||||||||||||||||||||||
5315 | provide custom painting of all items for the scene; gaining | - | ||||||||||||||||||||||||||||||
5316 | complete control over how each item is drawn. In some cases this | - | ||||||||||||||||||||||||||||||
5317 | can increase drawing performance significantly. | - | ||||||||||||||||||||||||||||||
5318 | - | |||||||||||||||||||||||||||||||
5319 | Example: | - | ||||||||||||||||||||||||||||||
5320 | - | |||||||||||||||||||||||||||||||
5321 | \snippet graphicssceneadditemsnippet.cpp 0 | - | ||||||||||||||||||||||||||||||
5322 | - | |||||||||||||||||||||||||||||||
5323 | Since Qt 4.6, this function is not called anymore unless | - | ||||||||||||||||||||||||||||||
5324 | the QGraphicsView::IndirectPainting flag is given as an Optimization | - | ||||||||||||||||||||||||||||||
5325 | flag. | - | ||||||||||||||||||||||||||||||
5326 | - | |||||||||||||||||||||||||||||||
5327 | \sa drawBackground(), drawForeground() | - | ||||||||||||||||||||||||||||||
5328 | */ | - | ||||||||||||||||||||||||||||||
5329 | void QGraphicsScene::drawItems(QPainter *painter, | - | ||||||||||||||||||||||||||||||
5330 | int numItems, | - | ||||||||||||||||||||||||||||||
5331 | QGraphicsItem *items[], | - | ||||||||||||||||||||||||||||||
5332 | const QStyleOptionGraphicsItem options[], QWidget *widget) | - | ||||||||||||||||||||||||||||||
5333 | { | - | ||||||||||||||||||||||||||||||
5334 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5335 | // Make sure we don't have unpolished items before we draw. | - | ||||||||||||||||||||||||||||||
5336 | if (!d->unpolishedItems.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
5337 | d->_q_polishItems(); never executed: d->_q_polishItems(); | 0 | ||||||||||||||||||||||||||||||
5338 | - | |||||||||||||||||||||||||||||||
5339 | const qreal opacity = painter->opacity(); | - | ||||||||||||||||||||||||||||||
5340 | QTransform viewTransform = painter->worldTransform(); | - | ||||||||||||||||||||||||||||||
5341 | Q_UNUSED(options); | - | ||||||||||||||||||||||||||||||
5342 | - | |||||||||||||||||||||||||||||||
5343 | // Determine view, expose and flags. | - | ||||||||||||||||||||||||||||||
5344 | QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
| 0 | ||||||||||||||||||||||||||||||
5345 | QRegion *expose = 0; | - | ||||||||||||||||||||||||||||||
5346 | const quint32 oldRectAdjust = d->rectAdjust; | - | ||||||||||||||||||||||||||||||
5347 | if (view) {
| 0 | ||||||||||||||||||||||||||||||
5348 | d->updateAll = false; | - | ||||||||||||||||||||||||||||||
5349 | expose = &view->d_func()->exposedRegion; | - | ||||||||||||||||||||||||||||||
5350 | if (view->d_func()->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
| 0 | ||||||||||||||||||||||||||||||
5351 | d->rectAdjust = 1; never executed: d->rectAdjust = 1; | 0 | ||||||||||||||||||||||||||||||
5352 | else | - | ||||||||||||||||||||||||||||||
5353 | d->rectAdjust = 2; never executed: d->rectAdjust = 2; | 0 | ||||||||||||||||||||||||||||||
5354 | } | - | ||||||||||||||||||||||||||||||
5355 | - | |||||||||||||||||||||||||||||||
5356 | // Find all toplevels, they are already sorted. | - | ||||||||||||||||||||||||||||||
5357 | QList<QGraphicsItem *> topLevelItems; | - | ||||||||||||||||||||||||||||||
5358 | for (int i = 0; i < numItems; ++i) {
| 0 | ||||||||||||||||||||||||||||||
5359 | QGraphicsItem *item = items[i]->topLevelItem(); | - | ||||||||||||||||||||||||||||||
5360 | if (!item->d_ptr->itemDiscovered) {
| 0 | ||||||||||||||||||||||||||||||
5361 | topLevelItems << item; | - | ||||||||||||||||||||||||||||||
5362 | item->d_ptr->itemDiscovered = 1; | - | ||||||||||||||||||||||||||||||
5363 | d->drawSubtreeRecursive(item, painter, &viewTransform, expose, widget); | - | ||||||||||||||||||||||||||||||
5364 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5365 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5366 | - | |||||||||||||||||||||||||||||||
5367 | d->rectAdjust = oldRectAdjust; | - | ||||||||||||||||||||||||||||||
5368 | // Reset discovery bits. | - | ||||||||||||||||||||||||||||||
5369 | for (int i = 0; i < topLevelItems.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
5370 | topLevelItems.at(i)->d_ptr->itemDiscovered = 0; never executed: topLevelItems.at(i)->d_ptr->itemDiscovered = 0; | 0 | ||||||||||||||||||||||||||||||
5371 | - | |||||||||||||||||||||||||||||||
5372 | painter->setWorldTransform(viewTransform); | - | ||||||||||||||||||||||||||||||
5373 | painter->setOpacity(opacity); | - | ||||||||||||||||||||||||||||||
5374 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5375 | - | |||||||||||||||||||||||||||||||
5376 | /*! | - | ||||||||||||||||||||||||||||||
5377 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5378 | - | |||||||||||||||||||||||||||||||
5379 | Finds a new widget to give the keyboard focus to, as appropriate for Tab | - | ||||||||||||||||||||||||||||||
5380 | and Shift+Tab, and returns \c true if it can find a new widget, or false if | - | ||||||||||||||||||||||||||||||
5381 | it cannot. If \a next is true, this function searches forward; if \a next | - | ||||||||||||||||||||||||||||||
5382 | is false, it searches backward. | - | ||||||||||||||||||||||||||||||
5383 | - | |||||||||||||||||||||||||||||||
5384 | You can reimplement this function in a subclass of QGraphicsScene to | - | ||||||||||||||||||||||||||||||
5385 | provide fine-grained control over how tab focus passes inside your | - | ||||||||||||||||||||||||||||||
5386 | scene. The default implementation is based on the tab focus chain defined | - | ||||||||||||||||||||||||||||||
5387 | by QGraphicsWidget::setTabOrder(). | - | ||||||||||||||||||||||||||||||
5388 | */ | - | ||||||||||||||||||||||||||||||
5389 | bool QGraphicsScene::focusNextPrevChild(bool next) | - | ||||||||||||||||||||||||||||||
5390 | { | - | ||||||||||||||||||||||||||||||
5391 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5392 | - | |||||||||||||||||||||||||||||||
5393 | QGraphicsItem *item = focusItem(); | - | ||||||||||||||||||||||||||||||
5394 | if (item && !item->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
5395 | // Tab out of the scene. | - | ||||||||||||||||||||||||||||||
5396 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5397 | } | - | ||||||||||||||||||||||||||||||
5398 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
5399 | if (d->lastFocusItem && !d->lastFocusItem->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
5400 | // Restore focus to the last focusable non-widget item that had | - | ||||||||||||||||||||||||||||||
5401 | // focus. | - | ||||||||||||||||||||||||||||||
5402 | setFocusItem(d->lastFocusItem, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); | - | ||||||||||||||||||||||||||||||
5403 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
5404 | } | - | ||||||||||||||||||||||||||||||
5405 | if (d->activePanel) {
| 0 | ||||||||||||||||||||||||||||||
5406 | if (d->activePanel->flags() & QGraphicsItem::ItemIsFocusable) {
| 0 | ||||||||||||||||||||||||||||||
5407 | setFocusItem(d->activePanel, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); | - | ||||||||||||||||||||||||||||||
5408 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
5409 | } | - | ||||||||||||||||||||||||||||||
5410 | if (d->activePanel->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
5411 | QGraphicsWidget *fw = static_cast<QGraphicsWidget *>(d->activePanel)->d_func()->focusNext; | - | ||||||||||||||||||||||||||||||
5412 | do { | - | ||||||||||||||||||||||||||||||
5413 | if (fw->focusPolicy() & Qt::TabFocus) {
| 0 | ||||||||||||||||||||||||||||||
5414 | setFocusItem(fw, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); | - | ||||||||||||||||||||||||||||||
5415 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
5416 | } | - | ||||||||||||||||||||||||||||||
5417 | } while (fw != d->activePanel); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
5418 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5419 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5420 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5421 | if (!item && !d->tabFocusFirst) {
| 0 | ||||||||||||||||||||||||||||||
5422 | // No widgets... | - | ||||||||||||||||||||||||||||||
5423 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5424 | } | - | ||||||||||||||||||||||||||||||
5425 | - | |||||||||||||||||||||||||||||||
5426 | // The item must be a widget. | - | ||||||||||||||||||||||||||||||
5427 | QGraphicsWidget *widget = 0; | - | ||||||||||||||||||||||||||||||
5428 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
5429 | widget = next ? d->tabFocusFirst : d->tabFocusFirst->d_func()->focusPrev;
| 0 | ||||||||||||||||||||||||||||||
5430 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5431 | QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||||||||||||||
5432 | widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev;
| 0 | ||||||||||||||||||||||||||||||
5433 | if (!widget->panel() && ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))) {
| 0 | ||||||||||||||||||||||||||||||
5434 | // Tab out of the scene. | - | ||||||||||||||||||||||||||||||
5435 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5436 | } | - | ||||||||||||||||||||||||||||||
5437 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5438 | QGraphicsWidget *widgetThatHadFocus = widget; | - | ||||||||||||||||||||||||||||||
5439 | - | |||||||||||||||||||||||||||||||
5440 | // Run around the focus chain until we find a widget that can take tab focus. | - | ||||||||||||||||||||||||||||||
5441 | do { | - | ||||||||||||||||||||||||||||||
5442 | if (widget->flags() & QGraphicsItem::ItemIsFocusable
| 0 | ||||||||||||||||||||||||||||||
5443 | && widget->isEnabled() && widget->isVisibleTo(0)
| 0 | ||||||||||||||||||||||||||||||
5444 | && (widget->focusPolicy() & Qt::TabFocus)
| 0 | ||||||||||||||||||||||||||||||
5445 | && (!item || !item->isPanel() || item->isAncestorOf(widget))
| 0 | ||||||||||||||||||||||||||||||
5446 | ) { | - | ||||||||||||||||||||||||||||||
5447 | setFocusItem(widget, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); | - | ||||||||||||||||||||||||||||||
5448 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
5449 | } | - | ||||||||||||||||||||||||||||||
5450 | widget = next ? widget->d_func()->focusNext : widget->d_func()->focusPrev;
| 0 | ||||||||||||||||||||||||||||||
5451 | if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
| 0 | ||||||||||||||||||||||||||||||
5452 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5453 | } while (widget != widgetThatHadFocus); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
5454 | - | |||||||||||||||||||||||||||||||
5455 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5456 | } | - | ||||||||||||||||||||||||||||||
5457 | - | |||||||||||||||||||||||||||||||
5458 | /*! | - | ||||||||||||||||||||||||||||||
5459 | \fn QGraphicsScene::changed(const QList<QRectF> ®ion) | - | ||||||||||||||||||||||||||||||
5460 | - | |||||||||||||||||||||||||||||||
5461 | This signal is emitted by QGraphicsScene when control reaches the | - | ||||||||||||||||||||||||||||||
5462 | event loop, if the scene content changes. The \a region parameter | - | ||||||||||||||||||||||||||||||
5463 | contains a list of scene rectangles that indicate the area that | - | ||||||||||||||||||||||||||||||
5464 | has been changed. | - | ||||||||||||||||||||||||||||||
5465 | - | |||||||||||||||||||||||||||||||
5466 | \sa QGraphicsView::updateScene() | - | ||||||||||||||||||||||||||||||
5467 | */ | - | ||||||||||||||||||||||||||||||
5468 | - | |||||||||||||||||||||||||||||||
5469 | /*! | - | ||||||||||||||||||||||||||||||
5470 | \fn QGraphicsScene::sceneRectChanged(const QRectF &rect) | - | ||||||||||||||||||||||||||||||
5471 | - | |||||||||||||||||||||||||||||||
5472 | This signal is emitted by QGraphicsScene whenever the scene rect changes. | - | ||||||||||||||||||||||||||||||
5473 | The \a rect parameter is the new scene rectangle. | - | ||||||||||||||||||||||||||||||
5474 | - | |||||||||||||||||||||||||||||||
5475 | \sa QGraphicsView::updateSceneRect() | - | ||||||||||||||||||||||||||||||
5476 | */ | - | ||||||||||||||||||||||||||||||
5477 | - | |||||||||||||||||||||||||||||||
5478 | /*! | - | ||||||||||||||||||||||||||||||
5479 | \fn QGraphicsScene::selectionChanged() | - | ||||||||||||||||||||||||||||||
5480 | \since 4.3 | - | ||||||||||||||||||||||||||||||
5481 | - | |||||||||||||||||||||||||||||||
5482 | This signal is emitted by QGraphicsScene whenever the selection | - | ||||||||||||||||||||||||||||||
5483 | changes. You can call selectedItems() to get the new list of selected | - | ||||||||||||||||||||||||||||||
5484 | items. | - | ||||||||||||||||||||||||||||||
5485 | - | |||||||||||||||||||||||||||||||
5486 | The selection changes whenever an item is selected or unselected, a | - | ||||||||||||||||||||||||||||||
5487 | selection area is set, cleared or otherwise changed, if a preselected item | - | ||||||||||||||||||||||||||||||
5488 | is added to the scene, or if a selected item is removed from the scene. | - | ||||||||||||||||||||||||||||||
5489 | - | |||||||||||||||||||||||||||||||
5490 | QGraphicsScene emits this signal only once for group selection operations. | - | ||||||||||||||||||||||||||||||
5491 | For example, if you set a selection area, select or unselect a | - | ||||||||||||||||||||||||||||||
5492 | QGraphicsItemGroup, or if you add or remove from the scene a parent item | - | ||||||||||||||||||||||||||||||
5493 | that contains several selected items, selectionChanged() is emitted only | - | ||||||||||||||||||||||||||||||
5494 | once after the operation has completed (instead of once for each item). | - | ||||||||||||||||||||||||||||||
5495 | - | |||||||||||||||||||||||||||||||
5496 | \sa setSelectionArea(), selectedItems(), QGraphicsItem::setSelected() | - | ||||||||||||||||||||||||||||||
5497 | */ | - | ||||||||||||||||||||||||||||||
5498 | - | |||||||||||||||||||||||||||||||
5499 | /*! | - | ||||||||||||||||||||||||||||||
5500 | \fn QGraphicsScene::focusItemChanged(QGraphicsItem *newFocusItem, QGraphicsItem *oldFocusItem, Qt::FocusReason reason) | - | ||||||||||||||||||||||||||||||
5501 | - | |||||||||||||||||||||||||||||||
5502 | This signal is emitted by QGraphicsScene whenever focus changes in the | - | ||||||||||||||||||||||||||||||
5503 | scene (i.e., when an item gains or loses input focus, or when focus | - | ||||||||||||||||||||||||||||||
5504 | passes from one item to another). You can connect to this signal if you | - | ||||||||||||||||||||||||||||||
5505 | need to keep track of when other items gain input focus. It is | - | ||||||||||||||||||||||||||||||
5506 | particularly useful for implementing virtual keyboards, input methods, | - | ||||||||||||||||||||||||||||||
5507 | and cursor items. | - | ||||||||||||||||||||||||||||||
5508 | - | |||||||||||||||||||||||||||||||
5509 | \a oldFocusItem is a pointer to the item that previously had focus, or | - | ||||||||||||||||||||||||||||||
5510 | 0 if no item had focus before the signal was emitted. \a newFocusItem | - | ||||||||||||||||||||||||||||||
5511 | is a pointer to the item that gained input focus, or 0 if focus was lost. | - | ||||||||||||||||||||||||||||||
5512 | \a reason is the reason for the focus change (e.g., if the scene was | - | ||||||||||||||||||||||||||||||
5513 | deactivated while an input field had focus, \a oldFocusItem would point | - | ||||||||||||||||||||||||||||||
5514 | to the input field item, \a newFocusItem would be 0, and \a reason would be | - | ||||||||||||||||||||||||||||||
5515 | Qt::ActiveWindowFocusReason. | - | ||||||||||||||||||||||||||||||
5516 | */ | - | ||||||||||||||||||||||||||||||
5517 | - | |||||||||||||||||||||||||||||||
5518 | /*! | - | ||||||||||||||||||||||||||||||
5519 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5520 | - | |||||||||||||||||||||||||||||||
5521 | Returns the scene's style, or the same as QApplication::style() if the | - | ||||||||||||||||||||||||||||||
5522 | scene has not been explicitly assigned a style. | - | ||||||||||||||||||||||||||||||
5523 | - | |||||||||||||||||||||||||||||||
5524 | \sa setStyle() | - | ||||||||||||||||||||||||||||||
5525 | */ | - | ||||||||||||||||||||||||||||||
5526 | QStyle *QGraphicsScene::style() const | - | ||||||||||||||||||||||||||||||
5527 | { | - | ||||||||||||||||||||||||||||||
5528 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5529 | // ### This function, and the use of styles in general, is non-reentrant. | - | ||||||||||||||||||||||||||||||
5530 | return d->style ? d->style : QApplication::style(); never executed: return d->style ? d->style : QApplication::style();
| 0 | ||||||||||||||||||||||||||||||
5531 | } | - | ||||||||||||||||||||||||||||||
5532 | - | |||||||||||||||||||||||||||||||
5533 | /*! | - | ||||||||||||||||||||||||||||||
5534 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5535 | - | |||||||||||||||||||||||||||||||
5536 | Sets or replaces the style of the scene to \a style, and reparents the | - | ||||||||||||||||||||||||||||||
5537 | style to this scene. Any previously assigned style is deleted. The scene's | - | ||||||||||||||||||||||||||||||
5538 | style defaults to QApplication::style(), and serves as the default for all | - | ||||||||||||||||||||||||||||||
5539 | QGraphicsWidget items in the scene. | - | ||||||||||||||||||||||||||||||
5540 | - | |||||||||||||||||||||||||||||||
5541 | Changing the style, either directly by calling this function, or | - | ||||||||||||||||||||||||||||||
5542 | indirectly by calling QApplication::setStyle(), will automatically update | - | ||||||||||||||||||||||||||||||
5543 | the style for all widgets in the scene that do not have a style explicitly | - | ||||||||||||||||||||||||||||||
5544 | assigned to them. | - | ||||||||||||||||||||||||||||||
5545 | - | |||||||||||||||||||||||||||||||
5546 | If \a style is 0, QGraphicsScene will revert to QApplication::style(). | - | ||||||||||||||||||||||||||||||
5547 | - | |||||||||||||||||||||||||||||||
5548 | \sa style() | - | ||||||||||||||||||||||||||||||
5549 | */ | - | ||||||||||||||||||||||||||||||
5550 | void QGraphicsScene::setStyle(QStyle *style) | - | ||||||||||||||||||||||||||||||
5551 | { | - | ||||||||||||||||||||||||||||||
5552 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5553 | // ### This function, and the use of styles in general, is non-reentrant. | - | ||||||||||||||||||||||||||||||
5554 | if (style == d->style)
| 0 | ||||||||||||||||||||||||||||||
5555 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5556 | - | |||||||||||||||||||||||||||||||
5557 | // Delete the old style, | - | ||||||||||||||||||||||||||||||
5558 | delete d->style; | - | ||||||||||||||||||||||||||||||
5559 | if ((d->style = style))
| 0 | ||||||||||||||||||||||||||||||
5560 | d->style->setParent(this); never executed: d->style->setParent(this); | 0 | ||||||||||||||||||||||||||||||
5561 | - | |||||||||||||||||||||||||||||||
5562 | // Notify the scene. | - | ||||||||||||||||||||||||||||||
5563 | QEvent event(QEvent::StyleChange); | - | ||||||||||||||||||||||||||||||
5564 | QApplication::sendEvent(this, &event); | - | ||||||||||||||||||||||||||||||
5565 | - | |||||||||||||||||||||||||||||||
5566 | // Notify all widgets that don't have a style explicitly set. | - | ||||||||||||||||||||||||||||||
5567 | foreach (QGraphicsItem *item, items()) { | - | ||||||||||||||||||||||||||||||
5568 | if (item->isWidget()) {
| 0 | ||||||||||||||||||||||||||||||
5569 | QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||||||||||||||
5570 | if (!widget->testAttribute(Qt::WA_SetStyle))
| 0 | ||||||||||||||||||||||||||||||
5571 | QApplication::sendEvent(widget, &event); never executed: QApplication::sendEvent(widget, &event); | 0 | ||||||||||||||||||||||||||||||
5572 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5573 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5574 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5575 | - | |||||||||||||||||||||||||||||||
5576 | /*! | - | ||||||||||||||||||||||||||||||
5577 | \property QGraphicsScene::font | - | ||||||||||||||||||||||||||||||
5578 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5579 | \brief the scene's default font | - | ||||||||||||||||||||||||||||||
5580 | - | |||||||||||||||||||||||||||||||
5581 | This property provides the scene's font. The scene font defaults to, | - | ||||||||||||||||||||||||||||||
5582 | and resolves all its entries from, QApplication::font. | - | ||||||||||||||||||||||||||||||
5583 | - | |||||||||||||||||||||||||||||||
5584 | If the scene's font changes, either directly through setFont() or | - | ||||||||||||||||||||||||||||||
5585 | indirectly when the application font changes, QGraphicsScene first | - | ||||||||||||||||||||||||||||||
5586 | sends itself a \l{QEvent::FontChange}{FontChange} event, and it then | - | ||||||||||||||||||||||||||||||
5587 | sends \l{QEvent::FontChange}{FontChange} events to all top-level | - | ||||||||||||||||||||||||||||||
5588 | widget items in the scene. These items respond by resolving their own | - | ||||||||||||||||||||||||||||||
5589 | fonts to the scene, and they then notify their children, who again | - | ||||||||||||||||||||||||||||||
5590 | notify their children, and so on, until all widget items have updated | - | ||||||||||||||||||||||||||||||
5591 | their fonts. | - | ||||||||||||||||||||||||||||||
5592 | - | |||||||||||||||||||||||||||||||
5593 | Changing the scene font, (directly or indirectly through | - | ||||||||||||||||||||||||||||||
5594 | QApplication::setFont(),) automatically schedules a redraw the entire | - | ||||||||||||||||||||||||||||||
5595 | scene. | - | ||||||||||||||||||||||||||||||
5596 | - | |||||||||||||||||||||||||||||||
5597 | \sa QWidget::font, QApplication::setFont(), palette, style() | - | ||||||||||||||||||||||||||||||
5598 | */ | - | ||||||||||||||||||||||||||||||
5599 | QFont QGraphicsScene::font() const | - | ||||||||||||||||||||||||||||||
5600 | { | - | ||||||||||||||||||||||||||||||
5601 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5602 | return d->font; never executed: return d->font; | 0 | ||||||||||||||||||||||||||||||
5603 | } | - | ||||||||||||||||||||||||||||||
5604 | void QGraphicsScene::setFont(const QFont &font) | - | ||||||||||||||||||||||||||||||
5605 | { | - | ||||||||||||||||||||||||||||||
5606 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5607 | QFont naturalFont = QApplication::font(); | - | ||||||||||||||||||||||||||||||
5608 | naturalFont.resolve(0); | - | ||||||||||||||||||||||||||||||
5609 | QFont resolvedFont = font.resolve(naturalFont); | - | ||||||||||||||||||||||||||||||
5610 | d->setFont_helper(resolvedFont); | - | ||||||||||||||||||||||||||||||
5611 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5612 | - | |||||||||||||||||||||||||||||||
5613 | /*! | - | ||||||||||||||||||||||||||||||
5614 | \property QGraphicsScene::palette | - | ||||||||||||||||||||||||||||||
5615 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5616 | \brief the scene's default palette | - | ||||||||||||||||||||||||||||||
5617 | - | |||||||||||||||||||||||||||||||
5618 | This property provides the scene's palette. The scene palette defaults to, | - | ||||||||||||||||||||||||||||||
5619 | and resolves all its entries from, QApplication::palette. | - | ||||||||||||||||||||||||||||||
5620 | - | |||||||||||||||||||||||||||||||
5621 | If the scene's palette changes, either directly through setPalette() or | - | ||||||||||||||||||||||||||||||
5622 | indirectly when the application palette changes, QGraphicsScene first | - | ||||||||||||||||||||||||||||||
5623 | sends itself a \l{QEvent::PaletteChange}{PaletteChange} event, and it then | - | ||||||||||||||||||||||||||||||
5624 | sends \l{QEvent::PaletteChange}{PaletteChange} events to all top-level | - | ||||||||||||||||||||||||||||||
5625 | widget items in the scene. These items respond by resolving their own | - | ||||||||||||||||||||||||||||||
5626 | palettes to the scene, and they then notify their children, who again | - | ||||||||||||||||||||||||||||||
5627 | notify their children, and so on, until all widget items have updated | - | ||||||||||||||||||||||||||||||
5628 | their palettes. | - | ||||||||||||||||||||||||||||||
5629 | - | |||||||||||||||||||||||||||||||
5630 | Changing the scene palette, (directly or indirectly through | - | ||||||||||||||||||||||||||||||
5631 | QApplication::setPalette(),) automatically schedules a redraw the entire | - | ||||||||||||||||||||||||||||||
5632 | scene. | - | ||||||||||||||||||||||||||||||
5633 | - | |||||||||||||||||||||||||||||||
5634 | \sa QWidget::palette, QApplication::setPalette(), font, style() | - | ||||||||||||||||||||||||||||||
5635 | */ | - | ||||||||||||||||||||||||||||||
5636 | QPalette QGraphicsScene::palette() const | - | ||||||||||||||||||||||||||||||
5637 | { | - | ||||||||||||||||||||||||||||||
5638 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5639 | return d->palette; never executed: return d->palette; | 0 | ||||||||||||||||||||||||||||||
5640 | } | - | ||||||||||||||||||||||||||||||
5641 | void QGraphicsScene::setPalette(const QPalette &palette) | - | ||||||||||||||||||||||||||||||
5642 | { | - | ||||||||||||||||||||||||||||||
5643 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5644 | QPalette naturalPalette = QApplication::palette(); | - | ||||||||||||||||||||||||||||||
5645 | naturalPalette.resolve(0); | - | ||||||||||||||||||||||||||||||
5646 | QPalette resolvedPalette = palette.resolve(naturalPalette); | - | ||||||||||||||||||||||||||||||
5647 | d->setPalette_helper(resolvedPalette); | - | ||||||||||||||||||||||||||||||
5648 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5649 | - | |||||||||||||||||||||||||||||||
5650 | /*! | - | ||||||||||||||||||||||||||||||
5651 | \since 4.6 | - | ||||||||||||||||||||||||||||||
5652 | - | |||||||||||||||||||||||||||||||
5653 | Returns \c true if the scene is active (e.g., it's viewed by | - | ||||||||||||||||||||||||||||||
5654 | at least one QGraphicsView that is active); otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
5655 | - | |||||||||||||||||||||||||||||||
5656 | \sa QGraphicsItem::isActive(), QWidget::isActiveWindow() | - | ||||||||||||||||||||||||||||||
5657 | */ | - | ||||||||||||||||||||||||||||||
5658 | bool QGraphicsScene::isActive() const | - | ||||||||||||||||||||||||||||||
5659 | { | - | ||||||||||||||||||||||||||||||
5660 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5661 | return d->activationRefCount > 0; never executed: return d->activationRefCount > 0; | 0 | ||||||||||||||||||||||||||||||
5662 | } | - | ||||||||||||||||||||||||||||||
5663 | - | |||||||||||||||||||||||||||||||
5664 | /*! | - | ||||||||||||||||||||||||||||||
5665 | \since 4.6 | - | ||||||||||||||||||||||||||||||
5666 | Returns the current active panel, or 0 if no panel is currently active. | - | ||||||||||||||||||||||||||||||
5667 | - | |||||||||||||||||||||||||||||||
5668 | \sa QGraphicsScene::setActivePanel() | - | ||||||||||||||||||||||||||||||
5669 | */ | - | ||||||||||||||||||||||||||||||
5670 | QGraphicsItem *QGraphicsScene::activePanel() const | - | ||||||||||||||||||||||||||||||
5671 | { | - | ||||||||||||||||||||||||||||||
5672 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5673 | return d->activePanel; never executed: return d->activePanel; | 0 | ||||||||||||||||||||||||||||||
5674 | } | - | ||||||||||||||||||||||||||||||
5675 | - | |||||||||||||||||||||||||||||||
5676 | /*! | - | ||||||||||||||||||||||||||||||
5677 | \since 4.6 | - | ||||||||||||||||||||||||||||||
5678 | Activates \a item, which must be an item in this scene. You | - | ||||||||||||||||||||||||||||||
5679 | can also pass 0 for \a item, in which case QGraphicsScene will | - | ||||||||||||||||||||||||||||||
5680 | deactivate any currently active panel. | - | ||||||||||||||||||||||||||||||
5681 | - | |||||||||||||||||||||||||||||||
5682 | If the scene is currently inactive, \a item remains inactive until the | - | ||||||||||||||||||||||||||||||
5683 | scene becomes active (or, ir \a item is 0, no item will be activated). | - | ||||||||||||||||||||||||||||||
5684 | - | |||||||||||||||||||||||||||||||
5685 | \sa activePanel(), isActive(), QGraphicsItem::isActive() | - | ||||||||||||||||||||||||||||||
5686 | */ | - | ||||||||||||||||||||||||||||||
5687 | void QGraphicsScene::setActivePanel(QGraphicsItem *item) | - | ||||||||||||||||||||||||||||||
5688 | { | - | ||||||||||||||||||||||||||||||
5689 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5690 | d->setActivePanelHelper(item, false); | - | ||||||||||||||||||||||||||||||
5691 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5692 | - | |||||||||||||||||||||||||||||||
5693 | /*! | - | ||||||||||||||||||||||||||||||
5694 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5695 | - | |||||||||||||||||||||||||||||||
5696 | Returns the current active window, or 0 if no window is currently | - | ||||||||||||||||||||||||||||||
5697 | active. | - | ||||||||||||||||||||||||||||||
5698 | - | |||||||||||||||||||||||||||||||
5699 | \sa QGraphicsScene::setActiveWindow() | - | ||||||||||||||||||||||||||||||
5700 | */ | - | ||||||||||||||||||||||||||||||
5701 | QGraphicsWidget *QGraphicsScene::activeWindow() const | - | ||||||||||||||||||||||||||||||
5702 | { | - | ||||||||||||||||||||||||||||||
5703 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5704 | if (d->activePanel && d->activePanel->isWindow())
| 0 | ||||||||||||||||||||||||||||||
5705 | return static_cast<QGraphicsWidget *>(d->activePanel); never executed: return static_cast<QGraphicsWidget *>(d->activePanel); | 0 | ||||||||||||||||||||||||||||||
5706 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
5707 | } | - | ||||||||||||||||||||||||||||||
5708 | - | |||||||||||||||||||||||||||||||
5709 | /*! | - | ||||||||||||||||||||||||||||||
5710 | \since 4.4 | - | ||||||||||||||||||||||||||||||
5711 | Activates \a widget, which must be a widget in this scene. You can also | - | ||||||||||||||||||||||||||||||
5712 | pass 0 for \a widget, in which case QGraphicsScene will deactivate any | - | ||||||||||||||||||||||||||||||
5713 | currently active window. | - | ||||||||||||||||||||||||||||||
5714 | - | |||||||||||||||||||||||||||||||
5715 | \sa activeWindow(), QGraphicsWidget::isActiveWindow() | - | ||||||||||||||||||||||||||||||
5716 | */ | - | ||||||||||||||||||||||||||||||
5717 | void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget) | - | ||||||||||||||||||||||||||||||
5718 | { | - | ||||||||||||||||||||||||||||||
5719 | if (widget && widget->scene() != this) {
| 0 | ||||||||||||||||||||||||||||||
5720 | qWarning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene", | - | ||||||||||||||||||||||||||||||
5721 | widget); | - | ||||||||||||||||||||||||||||||
5722 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5723 | } | - | ||||||||||||||||||||||||||||||
5724 | - | |||||||||||||||||||||||||||||||
5725 | // Activate the widget's panel (all windows are panels). | - | ||||||||||||||||||||||||||||||
5726 | QGraphicsItem *panel = widget ? widget->panel() : 0;
| 0 | ||||||||||||||||||||||||||||||
5727 | setActivePanel(panel); | - | ||||||||||||||||||||||||||||||
5728 | - | |||||||||||||||||||||||||||||||
5729 | // Raise | - | ||||||||||||||||||||||||||||||
5730 | if (panel) {
| 0 | ||||||||||||||||||||||||||||||
5731 | QList<QGraphicsItem *> siblingWindows; | - | ||||||||||||||||||||||||||||||
5732 | QGraphicsItem *parent = panel->parentItem(); | - | ||||||||||||||||||||||||||||||
5733 | // Raise ### inefficient for toplevels | - | ||||||||||||||||||||||||||||||
5734 | foreach (QGraphicsItem *sibling, parent ? parent->childItems() : items()) { | - | ||||||||||||||||||||||||||||||
5735 | if (sibling != panel && sibling->isWindow())
| 0 | ||||||||||||||||||||||||||||||
5736 | siblingWindows << sibling; never executed: siblingWindows << sibling; | 0 | ||||||||||||||||||||||||||||||
5737 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5738 | - | |||||||||||||||||||||||||||||||
5739 | // Find the highest z value. | - | ||||||||||||||||||||||||||||||
5740 | qreal z = panel->zValue(); | - | ||||||||||||||||||||||||||||||
5741 | for (int i = 0; i < siblingWindows.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
5742 | z = qMax(z, siblingWindows.at(i)->zValue()); never executed: z = qMax(z, siblingWindows.at(i)->zValue()); | 0 | ||||||||||||||||||||||||||||||
5743 | - | |||||||||||||||||||||||||||||||
5744 | // This will probably never overflow. | - | ||||||||||||||||||||||||||||||
5745 | const qreal litt = qreal(0.001); | - | ||||||||||||||||||||||||||||||
5746 | panel->setZValue(z + litt); | - | ||||||||||||||||||||||||||||||
5747 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5748 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5749 | - | |||||||||||||||||||||||||||||||
5750 | /*! | - | ||||||||||||||||||||||||||||||
5751 | \since 4.6 | - | ||||||||||||||||||||||||||||||
5752 | - | |||||||||||||||||||||||||||||||
5753 | Sends event \a event to item \a item through possible event filters. | - | ||||||||||||||||||||||||||||||
5754 | - | |||||||||||||||||||||||||||||||
5755 | The event is sent only if the item is enabled. | - | ||||||||||||||||||||||||||||||
5756 | - | |||||||||||||||||||||||||||||||
5757 | Returns \c false if the event was filtered or if the item is disabled. | - | ||||||||||||||||||||||||||||||
5758 | Otherwise returns the value that was returned from the event handler. | - | ||||||||||||||||||||||||||||||
5759 | - | |||||||||||||||||||||||||||||||
5760 | \sa QGraphicsItem::sceneEvent(), QGraphicsItem::sceneEventFilter() | - | ||||||||||||||||||||||||||||||
5761 | */ | - | ||||||||||||||||||||||||||||||
5762 | bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event) | - | ||||||||||||||||||||||||||||||
5763 | { | - | ||||||||||||||||||||||||||||||
5764 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5765 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
5766 | qWarning("QGraphicsScene::sendEvent: cannot send event to a null item"); | - | ||||||||||||||||||||||||||||||
5767 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5768 | } | - | ||||||||||||||||||||||||||||||
5769 | if (item->scene() != this) {
| 0 | ||||||||||||||||||||||||||||||
5770 | qWarning("QGraphicsScene::sendEvent: item %p's scene (%p)" | - | ||||||||||||||||||||||||||||||
5771 | " is different from this scene (%p)", | - | ||||||||||||||||||||||||||||||
5772 | item, item->scene(), this); | - | ||||||||||||||||||||||||||||||
5773 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
5774 | } | - | ||||||||||||||||||||||||||||||
5775 | return d->sendEvent(item, event); never executed: return d->sendEvent(item, event); | 0 | ||||||||||||||||||||||||||||||
5776 | } | - | ||||||||||||||||||||||||||||||
5777 | - | |||||||||||||||||||||||||||||||
5778 | /*! | - | ||||||||||||||||||||||||||||||
5779 | \property QGraphicsScene::minimumRenderSize | - | ||||||||||||||||||||||||||||||
5780 | \since 5.4 | - | ||||||||||||||||||||||||||||||
5781 | \brief the minimal view-transformed size an item must have to be drawn | - | ||||||||||||||||||||||||||||||
5782 | - | |||||||||||||||||||||||||||||||
5783 | When the scene is rendered, any item whose width or height, transformed | - | ||||||||||||||||||||||||||||||
5784 | to the target view, is smaller that minimumRenderSize(), will not be | - | ||||||||||||||||||||||||||||||
5785 | rendered. If an item is not rendered and it clips its children items | - | ||||||||||||||||||||||||||||||
5786 | they will also not be rendered. Set this value to speed up rendering | - | ||||||||||||||||||||||||||||||
5787 | of scenes with many objects rendered on a zoomed out view. | - | ||||||||||||||||||||||||||||||
5788 | - | |||||||||||||||||||||||||||||||
5789 | The default value is 0. If unset, or if set to 0 or a negative value, | - | ||||||||||||||||||||||||||||||
5790 | all items will always be rendered. | - | ||||||||||||||||||||||||||||||
5791 | - | |||||||||||||||||||||||||||||||
5792 | For example, setting this property can be especially useful if a scene | - | ||||||||||||||||||||||||||||||
5793 | is rendered by multiple views, one of which serves as an overview which | - | ||||||||||||||||||||||||||||||
5794 | always displays all items. In scenes with many items, such a view will | - | ||||||||||||||||||||||||||||||
5795 | use a high scaling factor so that all items can be shown. Due to the | - | ||||||||||||||||||||||||||||||
5796 | scaling, smaller items will only make an insignificant contribution to | - | ||||||||||||||||||||||||||||||
5797 | the final rendered scene. To avoid drawing these items and reduce the | - | ||||||||||||||||||||||||||||||
5798 | time necessary to render the scene, you can call setMinimumRenderSize() | - | ||||||||||||||||||||||||||||||
5799 | with a non-negative value. | - | ||||||||||||||||||||||||||||||
5800 | - | |||||||||||||||||||||||||||||||
5801 | \note Items that are not drawn as a result of being too small, are still | - | ||||||||||||||||||||||||||||||
5802 | returned by methods such as items() and itemAt(), and participate in | - | ||||||||||||||||||||||||||||||
5803 | collision detection and interactions. It is recommended that you set | - | ||||||||||||||||||||||||||||||
5804 | minimumRenderSize() to a value less than or equal to 1 in order to | - | ||||||||||||||||||||||||||||||
5805 | avoid large unrendered items that are interactive. | - | ||||||||||||||||||||||||||||||
5806 | - | |||||||||||||||||||||||||||||||
5807 | \sa QStyleOptionGraphicsItem::levelOfDetailFromTransform() | - | ||||||||||||||||||||||||||||||
5808 | */ | - | ||||||||||||||||||||||||||||||
5809 | qreal QGraphicsScene::minimumRenderSize() const | - | ||||||||||||||||||||||||||||||
5810 | { | - | ||||||||||||||||||||||||||||||
5811 | Q_D(const QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5812 | return d->minimumRenderSize; never executed: return d->minimumRenderSize; | 0 | ||||||||||||||||||||||||||||||
5813 | } | - | ||||||||||||||||||||||||||||||
5814 | void QGraphicsScene::setMinimumRenderSize(qreal minSize) | - | ||||||||||||||||||||||||||||||
5815 | { | - | ||||||||||||||||||||||||||||||
5816 | Q_D(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5817 | d->minimumRenderSize = minSize; | - | ||||||||||||||||||||||||||||||
5818 | update(); | - | ||||||||||||||||||||||||||||||
5819 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5820 | - | |||||||||||||||||||||||||||||||
5821 | void QGraphicsScenePrivate::addView(QGraphicsView *view) | - | ||||||||||||||||||||||||||||||
5822 | { | - | ||||||||||||||||||||||||||||||
5823 | views << view; | - | ||||||||||||||||||||||||||||||
5824 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
5825 | foreach (Qt::GestureType gesture, grabbedGestures.keys()) | - | ||||||||||||||||||||||||||||||
5826 | view->viewport()->grabGesture(gesture); never executed: view->viewport()->grabGesture(gesture); | 0 | ||||||||||||||||||||||||||||||
5827 | #endif | - | ||||||||||||||||||||||||||||||
5828 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5829 | - | |||||||||||||||||||||||||||||||
5830 | void QGraphicsScenePrivate::removeView(QGraphicsView *view) | - | ||||||||||||||||||||||||||||||
5831 | { | - | ||||||||||||||||||||||||||||||
5832 | views.removeAll(view); | - | ||||||||||||||||||||||||||||||
5833 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5834 | - | |||||||||||||||||||||||||||||||
5835 | void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent) | - | ||||||||||||||||||||||||||||||
5836 | { | - | ||||||||||||||||||||||||||||||
5837 | QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); | - | ||||||||||||||||||||||||||||||
5838 | for (int i = 0; i < touchPoints.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
5839 | QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; | - | ||||||||||||||||||||||||||||||
5840 | touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); | - | ||||||||||||||||||||||||||||||
5841 | touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), static_cast<QWidget *>(touchEvent->target()))); | - | ||||||||||||||||||||||||||||||
5842 | touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), static_cast<QWidget *>(touchEvent->target()))); | - | ||||||||||||||||||||||||||||||
5843 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5844 | touchEvent->setTouchPoints(touchPoints); | - | ||||||||||||||||||||||||||||||
5845 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5846 | - | |||||||||||||||||||||||||||||||
5847 | int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) | - | ||||||||||||||||||||||||||||||
5848 | { | - | ||||||||||||||||||||||||||||||
5849 | int closestTouchPointId = -1; | - | ||||||||||||||||||||||||||||||
5850 | qreal closestDistance = qreal(0.); | - | ||||||||||||||||||||||||||||||
5851 | foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) { | - | ||||||||||||||||||||||||||||||
5852 | qreal distance = QLineF(scenePos, touchPoint.scenePos()).length(); | - | ||||||||||||||||||||||||||||||
5853 | if (closestTouchPointId == -1|| distance < closestDistance) {
| 0 | ||||||||||||||||||||||||||||||
5854 | closestTouchPointId = touchPoint.id(); | - | ||||||||||||||||||||||||||||||
5855 | closestDistance = distance; | - | ||||||||||||||||||||||||||||||
5856 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5857 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5858 | return closestTouchPointId; never executed: return closestTouchPointId; | 0 | ||||||||||||||||||||||||||||||
5859 | } | - | ||||||||||||||||||||||||||||||
5860 | - | |||||||||||||||||||||||||||||||
5861 | void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) | - | ||||||||||||||||||||||||||||||
5862 | { | - | ||||||||||||||||||||||||||||||
5863 | typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints; | - | ||||||||||||||||||||||||||||||
5864 | QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents; | - | ||||||||||||||||||||||||||||||
5865 | - | |||||||||||||||||||||||||||||||
5866 | for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
5867 | const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i); | - | ||||||||||||||||||||||||||||||
5868 | - | |||||||||||||||||||||||||||||||
5869 | // update state | - | ||||||||||||||||||||||||||||||
5870 | QGraphicsItem *item = 0; | - | ||||||||||||||||||||||||||||||
5871 | if (touchPoint.state() == Qt::TouchPointPressed) {
| 0 | ||||||||||||||||||||||||||||||
5872 | if (sceneTouchEvent->device()->type() == QTouchDevice::TouchPad) {
| 0 | ||||||||||||||||||||||||||||||
5873 | // on touch-pad devices, send all touch points to the same item | - | ||||||||||||||||||||||||||||||
5874 | item = itemForTouchPointId.isEmpty()
| 0 | ||||||||||||||||||||||||||||||
5875 | ? 0 | - | ||||||||||||||||||||||||||||||
5876 | : itemForTouchPointId.constBegin().value(); | - | ||||||||||||||||||||||||||||||
5877 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5878 | - | |||||||||||||||||||||||||||||||
5879 | if (!item) {
| 0 | ||||||||||||||||||||||||||||||
5880 | // determine which item this touch point will go to | - | ||||||||||||||||||||||||||||||
5881 | cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(), | - | ||||||||||||||||||||||||||||||
5882 | touchPoint.scenePos(), | - | ||||||||||||||||||||||||||||||
5883 | static_cast<QWidget *>(sceneTouchEvent->target())); | - | ||||||||||||||||||||||||||||||
5884 | item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first();
| 0 | ||||||||||||||||||||||||||||||
5885 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5886 | - | |||||||||||||||||||||||||||||||
5887 | if (sceneTouchEvent->device()->type() == QTouchDevice::TouchScreen) {
| 0 | ||||||||||||||||||||||||||||||
5888 | // on touch-screens, combine this touch point with the closest one we find | - | ||||||||||||||||||||||||||||||
5889 | int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos()); | - | ||||||||||||||||||||||||||||||
5890 | QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId); | - | ||||||||||||||||||||||||||||||
5891 | if (!item || (closestItem && cachedItemsUnderMouse.contains(closestItem)))
| 0 | ||||||||||||||||||||||||||||||
5892 | item = closestItem; never executed: item = closestItem; | 0 | ||||||||||||||||||||||||||||||
5893 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5894 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
5895 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5896 | - | |||||||||||||||||||||||||||||||
5897 | itemForTouchPointId.insert(touchPoint.id(), item); | - | ||||||||||||||||||||||||||||||
5898 | sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint); | - | ||||||||||||||||||||||||||||||
5899 | } else if (touchPoint.state() == Qt::TouchPointReleased) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
5900 | item = itemForTouchPointId.take(touchPoint.id()); | - | ||||||||||||||||||||||||||||||
5901 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
5902 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5903 | - | |||||||||||||||||||||||||||||||
5904 | sceneCurrentTouchPoints.remove(touchPoint.id()); | - | ||||||||||||||||||||||||||||||
5905 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5906 | item = itemForTouchPointId.value(touchPoint.id()); | - | ||||||||||||||||||||||||||||||
5907 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
5908 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5909 | Q_ASSERT(sceneCurrentTouchPoints.contains(touchPoint.id())); | - | ||||||||||||||||||||||||||||||
5910 | sceneCurrentTouchPoints[touchPoint.id()] = touchPoint; | - | ||||||||||||||||||||||||||||||
5911 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5912 | - | |||||||||||||||||||||||||||||||
5913 | StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item]; | - | ||||||||||||||||||||||||||||||
5914 | statesAndTouchPoints.first |= touchPoint.state(); | - | ||||||||||||||||||||||||||||||
5915 | statesAndTouchPoints.second.append(touchPoint); | - | ||||||||||||||||||||||||||||||
5916 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5917 | - | |||||||||||||||||||||||||||||||
5918 | if (itemsNeedingEvents.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
5919 | sceneTouchEvent->ignore(); | - | ||||||||||||||||||||||||||||||
5920 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
5921 | } | - | ||||||||||||||||||||||||||||||
5922 | - | |||||||||||||||||||||||||||||||
5923 | bool ignoreSceneTouchEvent = true; | - | ||||||||||||||||||||||||||||||
5924 | QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator it = itemsNeedingEvents.constBegin(); | - | ||||||||||||||||||||||||||||||
5925 | const QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator end = itemsNeedingEvents.constEnd(); | - | ||||||||||||||||||||||||||||||
5926 | for (; it != end; ++it) {
| 0 | ||||||||||||||||||||||||||||||
5927 | QGraphicsItem *item = it.key(); | - | ||||||||||||||||||||||||||||||
5928 | - | |||||||||||||||||||||||||||||||
5929 | (void) item->isBlockedByModalPanel(&item); | - | ||||||||||||||||||||||||||||||
5930 | - | |||||||||||||||||||||||||||||||
5931 | // determine event type from the state mask | - | ||||||||||||||||||||||||||||||
5932 | QEvent::Type eventType; | - | ||||||||||||||||||||||||||||||
5933 | switch (it.value().first) { | - | ||||||||||||||||||||||||||||||
5934 | case Qt::TouchPointPressed: never executed: case Qt::TouchPointPressed: | 0 | ||||||||||||||||||||||||||||||
5935 | // all touch points have pressed state | - | ||||||||||||||||||||||||||||||
5936 | eventType = QEvent::TouchBegin; | - | ||||||||||||||||||||||||||||||
5937 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
5938 | case Qt::TouchPointReleased: never executed: case Qt::TouchPointReleased: | 0 | ||||||||||||||||||||||||||||||
5939 | // all touch points have released state | - | ||||||||||||||||||||||||||||||
5940 | eventType = QEvent::TouchEnd; | - | ||||||||||||||||||||||||||||||
5941 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
5942 | case Qt::TouchPointStationary: never executed: case Qt::TouchPointStationary: | 0 | ||||||||||||||||||||||||||||||
5943 | // don't send the event if nothing changed | - | ||||||||||||||||||||||||||||||
5944 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
5945 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
5946 | // all other combinations | - | ||||||||||||||||||||||||||||||
5947 | eventType = QEvent::TouchUpdate; | - | ||||||||||||||||||||||||||||||
5948 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
5949 | } | - | ||||||||||||||||||||||||||||||
5950 | - | |||||||||||||||||||||||||||||||
5951 | QTouchEvent touchEvent(eventType); | - | ||||||||||||||||||||||||||||||
5952 | touchEvent.setWindow(sceneTouchEvent->window()); | - | ||||||||||||||||||||||||||||||
5953 | touchEvent.setTarget(sceneTouchEvent->target()); | - | ||||||||||||||||||||||||||||||
5954 | touchEvent.setDevice(sceneTouchEvent->device()); | - | ||||||||||||||||||||||||||||||
5955 | touchEvent.setModifiers(sceneTouchEvent->modifiers()); | - | ||||||||||||||||||||||||||||||
5956 | touchEvent.setTouchPointStates(it.value().first); | - | ||||||||||||||||||||||||||||||
5957 | touchEvent.setTouchPoints(it.value().second); | - | ||||||||||||||||||||||||||||||
5958 | touchEvent.setTimestamp(sceneTouchEvent->timestamp()); | - | ||||||||||||||||||||||||||||||
5959 | - | |||||||||||||||||||||||||||||||
5960 | switch (touchEvent.type()) { | - | ||||||||||||||||||||||||||||||
5961 | case QEvent::TouchBegin: never executed: case QEvent::TouchBegin: | 0 | ||||||||||||||||||||||||||||||
5962 | { | - | ||||||||||||||||||||||||||||||
5963 | // if the TouchBegin handler recurses, we assume that means the event | - | ||||||||||||||||||||||||||||||
5964 | // has been implicitly accepted and continue to send touch events | - | ||||||||||||||||||||||||||||||
5965 | item->d_ptr->acceptedTouchBeginEvent = true; | - | ||||||||||||||||||||||||||||||
5966 | bool res = sendTouchBeginEvent(item, &touchEvent)
| 0 | ||||||||||||||||||||||||||||||
5967 | && touchEvent.isAccepted();
| 0 | ||||||||||||||||||||||||||||||
5968 | if (!res) {
| 0 | ||||||||||||||||||||||||||||||
5969 | // forget about these touch points, we didn't handle them | - | ||||||||||||||||||||||||||||||
5970 | for (int i = 0; i < touchEvent.touchPoints().count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
5971 | const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i); | - | ||||||||||||||||||||||||||||||
5972 | itemForTouchPointId.remove(touchPoint.id()); | - | ||||||||||||||||||||||||||||||
5973 | sceneCurrentTouchPoints.remove(touchPoint.id()); | - | ||||||||||||||||||||||||||||||
5974 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5975 | ignoreSceneTouchEvent = false; | - | ||||||||||||||||||||||||||||||
5976 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5977 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
5978 | } | - | ||||||||||||||||||||||||||||||
5979 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
5980 | if (item->d_ptr->acceptedTouchBeginEvent) {
| 0 | ||||||||||||||||||||||||||||||
5981 | updateTouchPointsForItem(item, &touchEvent); | - | ||||||||||||||||||||||||||||||
5982 | (void) sendEvent(item, &touchEvent); | - | ||||||||||||||||||||||||||||||
5983 | ignoreSceneTouchEvent = false; | - | ||||||||||||||||||||||||||||||
5984 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5985 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
5986 | } | - | ||||||||||||||||||||||||||||||
5987 | } | - | ||||||||||||||||||||||||||||||
5988 | sceneTouchEvent->setAccepted(ignoreSceneTouchEvent); | - | ||||||||||||||||||||||||||||||
5989 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
5990 | - | |||||||||||||||||||||||||||||||
5991 | bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent) | - | ||||||||||||||||||||||||||||||
5992 | { | - | ||||||||||||||||||||||||||||||
5993 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
5994 | - | |||||||||||||||||||||||||||||||
5995 | if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) {
| 0 | ||||||||||||||||||||||||||||||
5996 | const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); | - | ||||||||||||||||||||||||||||||
5997 | cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), | - | ||||||||||||||||||||||||||||||
5998 | firstTouchPoint.scenePos(), | - | ||||||||||||||||||||||||||||||
5999 | static_cast<QWidget *>(touchEvent->target())); | - | ||||||||||||||||||||||||||||||
6000 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6001 | - | |||||||||||||||||||||||||||||||
6002 | // Set focus on the topmost enabled item that can take focus. | - | ||||||||||||||||||||||||||||||
6003 | bool setFocus = false; | - | ||||||||||||||||||||||||||||||
6004 | - | |||||||||||||||||||||||||||||||
6005 | foreach (QGraphicsItem *item, cachedItemsUnderMouse) { | - | ||||||||||||||||||||||||||||||
6006 | if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
| 0 | ||||||||||||||||||||||||||||||
6007 | if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
| 0 | ||||||||||||||||||||||||||||||
6008 | setFocus = true; | - | ||||||||||||||||||||||||||||||
6009 | if (item != q->focusItem())
| 0 | ||||||||||||||||||||||||||||||
6010 | q->setFocusItem(item, Qt::MouseFocusReason); never executed: q->setFocusItem(item, Qt::MouseFocusReason); | 0 | ||||||||||||||||||||||||||||||
6011 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6012 | } | - | ||||||||||||||||||||||||||||||
6013 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6014 | if (item->isPanel())
| 0 | ||||||||||||||||||||||||||||||
6015 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6016 | if (item->d_ptr->flags & QGraphicsItem::ItemStopsClickFocusPropagation)
| 0 | ||||||||||||||||||||||||||||||
6017 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6018 | if (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling) {
| 0 | ||||||||||||||||||||||||||||||
6019 | // Make sure we don't clear focus. | - | ||||||||||||||||||||||||||||||
6020 | setFocus = true; | - | ||||||||||||||||||||||||||||||
6021 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6022 | } | - | ||||||||||||||||||||||||||||||
6023 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6024 | - | |||||||||||||||||||||||||||||||
6025 | // If nobody could take focus, clear it. | - | ||||||||||||||||||||||||||||||
6026 | if (!stickyFocus && !setFocus)
| 0 | ||||||||||||||||||||||||||||||
6027 | q->setFocusItem(0, Qt::MouseFocusReason); never executed: q->setFocusItem(0, Qt::MouseFocusReason); | 0 | ||||||||||||||||||||||||||||||
6028 | - | |||||||||||||||||||||||||||||||
6029 | bool res = false; | - | ||||||||||||||||||||||||||||||
6030 | bool eventAccepted = touchEvent->isAccepted(); | - | ||||||||||||||||||||||||||||||
6031 | foreach (QGraphicsItem *item, cachedItemsUnderMouse) { | - | ||||||||||||||||||||||||||||||
6032 | // first, try to deliver the touch event | - | ||||||||||||||||||||||||||||||
6033 | updateTouchPointsForItem(item, touchEvent); | - | ||||||||||||||||||||||||||||||
6034 | bool acceptTouchEvents = item->acceptTouchEvents(); | - | ||||||||||||||||||||||||||||||
6035 | touchEvent->setAccepted(acceptTouchEvents); | - | ||||||||||||||||||||||||||||||
6036 | res = acceptTouchEvents && sendEvent(item, touchEvent);
| 0 | ||||||||||||||||||||||||||||||
6037 | eventAccepted = touchEvent->isAccepted(); | - | ||||||||||||||||||||||||||||||
6038 | if (itemForTouchPointId.value(touchEvent->touchPoints().first().id()) == 0) {
| 0 | ||||||||||||||||||||||||||||||
6039 | // item was deleted | - | ||||||||||||||||||||||||||||||
6040 | item = 0; | - | ||||||||||||||||||||||||||||||
6041 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6042 | item->d_ptr->acceptedTouchBeginEvent = (res && eventAccepted);
| 0 | ||||||||||||||||||||||||||||||
6043 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6044 | touchEvent->spont = false; | - | ||||||||||||||||||||||||||||||
6045 | if (res && eventAccepted) {
| 0 | ||||||||||||||||||||||||||||||
6046 | // the first item to accept the TouchBegin gets an implicit grab. | - | ||||||||||||||||||||||||||||||
6047 | for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6048 | const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); | - | ||||||||||||||||||||||||||||||
6049 | itemForTouchPointId[touchPoint.id()] = item; // can be zero | - | ||||||||||||||||||||||||||||||
6050 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6051 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6052 | } | - | ||||||||||||||||||||||||||||||
6053 | if (item && item->isPanel())
| 0 | ||||||||||||||||||||||||||||||
6054 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6055 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6056 | - | |||||||||||||||||||||||||||||||
6057 | touchEvent->setAccepted(eventAccepted); | - | ||||||||||||||||||||||||||||||
6058 | return res; never executed: return res; | 0 | ||||||||||||||||||||||||||||||
6059 | } | - | ||||||||||||||||||||||||||||||
6060 | - | |||||||||||||||||||||||||||||||
6061 | void QGraphicsScenePrivate::enableTouchEventsOnViews() | - | ||||||||||||||||||||||||||||||
6062 | { | - | ||||||||||||||||||||||||||||||
6063 | foreach (QGraphicsView *view, views) | - | ||||||||||||||||||||||||||||||
6064 | view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true); never executed: view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true); | 0 | ||||||||||||||||||||||||||||||
6065 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6066 | - | |||||||||||||||||||||||||||||||
6067 | void QGraphicsScenePrivate::updateInputMethodSensitivityInViews() | - | ||||||||||||||||||||||||||||||
6068 | { | - | ||||||||||||||||||||||||||||||
6069 | for (int i = 0; i < views.size(); ++i)
| 0 | ||||||||||||||||||||||||||||||
6070 | views.at(i)->d_func()->updateInputMethodSensitivity(); never executed: views.at(i)->d_func()->updateInputMethodSensitivity(); | 0 | ||||||||||||||||||||||||||||||
6071 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6072 | - | |||||||||||||||||||||||||||||||
6073 | void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality) | - | ||||||||||||||||||||||||||||||
6074 | { | - | ||||||||||||||||||||||||||||||
6075 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
6076 | Q_ASSERT(panel && panel->isPanel()); | - | ||||||||||||||||||||||||||||||
6077 | - | |||||||||||||||||||||||||||||||
6078 | QGraphicsItem::PanelModality panelModality = panel->d_ptr->panelModality; | - | ||||||||||||||||||||||||||||||
6079 | if (previousModality != QGraphicsItem::NonModal) {
| 0 | ||||||||||||||||||||||||||||||
6080 | // the panel is changing from one modality type to another... temporarily set it back so | - | ||||||||||||||||||||||||||||||
6081 | // that blockedPanels is populated correctly | - | ||||||||||||||||||||||||||||||
6082 | panel->d_ptr->panelModality = previousModality; | - | ||||||||||||||||||||||||||||||
6083 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6084 | - | |||||||||||||||||||||||||||||||
6085 | QSet<QGraphicsItem *> blockedPanels; | - | ||||||||||||||||||||||||||||||
6086 | QList<QGraphicsItem *> items = q->items(); // ### store panels separately | - | ||||||||||||||||||||||||||||||
6087 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6088 | QGraphicsItem *item = items.at(i); | - | ||||||||||||||||||||||||||||||
6089 | if (item->isPanel() && item->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
6090 | blockedPanels.insert(item); never executed: blockedPanels.insert(item); | 0 | ||||||||||||||||||||||||||||||
6091 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6092 | // blockedPanels contains all currently blocked panels | - | ||||||||||||||||||||||||||||||
6093 | - | |||||||||||||||||||||||||||||||
6094 | if (previousModality != QGraphicsItem::NonModal) {
| 0 | ||||||||||||||||||||||||||||||
6095 | // reset the modality to the proper value, since we changed it above | - | ||||||||||||||||||||||||||||||
6096 | panel->d_ptr->panelModality = panelModality; | - | ||||||||||||||||||||||||||||||
6097 | // remove this panel so that it will be reinserted at the front of the stack | - | ||||||||||||||||||||||||||||||
6098 | modalPanels.removeAll(panel); | - | ||||||||||||||||||||||||||||||
6099 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6100 | - | |||||||||||||||||||||||||||||||
6101 | modalPanels.prepend(panel); | - | ||||||||||||||||||||||||||||||
6102 | - | |||||||||||||||||||||||||||||||
6103 | if (!hoverItems.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
6104 | // send GraphicsSceneHoverLeave events to newly blocked hoverItems | - | ||||||||||||||||||||||||||||||
6105 | QGraphicsSceneHoverEvent hoverEvent; | - | ||||||||||||||||||||||||||||||
6106 | hoverEvent.setScenePos(lastSceneMousePos); | - | ||||||||||||||||||||||||||||||
6107 | dispatchHoverEvent(&hoverEvent); | - | ||||||||||||||||||||||||||||||
6108 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6109 | - | |||||||||||||||||||||||||||||||
6110 | if (!mouseGrabberItems.isEmpty() && lastMouseGrabberItemHasImplicitMouseGrab) {
| 0 | ||||||||||||||||||||||||||||||
6111 | QGraphicsItem *item = mouseGrabberItems.last(); | - | ||||||||||||||||||||||||||||||
6112 | if (item->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
6113 | ungrabMouse(item, /*itemIsDying =*/ false); never executed: ungrabMouse(item, false); | 0 | ||||||||||||||||||||||||||||||
6114 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6115 | - | |||||||||||||||||||||||||||||||
6116 | QEvent windowBlockedEvent(QEvent::WindowBlocked); | - | ||||||||||||||||||||||||||||||
6117 | QEvent windowUnblockedEvent(QEvent::WindowUnblocked); | - | ||||||||||||||||||||||||||||||
6118 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6119 | QGraphicsItem *item = items.at(i); | - | ||||||||||||||||||||||||||||||
6120 | if (item->isPanel()) {
| 0 | ||||||||||||||||||||||||||||||
6121 | if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
| 0 | ||||||||||||||||||||||||||||||
6122 | // send QEvent::WindowBlocked to newly blocked panels | - | ||||||||||||||||||||||||||||||
6123 | sendEvent(item, &windowBlockedEvent); | - | ||||||||||||||||||||||||||||||
6124 | } else if (blockedPanels.contains(item) && !item->isBlockedByModalPanel()) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
6125 | // send QEvent::WindowUnblocked to unblocked panels when downgrading | - | ||||||||||||||||||||||||||||||
6126 | // a panel from SceneModal to PanelModal | - | ||||||||||||||||||||||||||||||
6127 | sendEvent(item, &windowUnblockedEvent); | - | ||||||||||||||||||||||||||||||
6128 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6129 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6130 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6131 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6132 | - | |||||||||||||||||||||||||||||||
6133 | void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel) | - | ||||||||||||||||||||||||||||||
6134 | { | - | ||||||||||||||||||||||||||||||
6135 | Q_Q(QGraphicsScene); | - | ||||||||||||||||||||||||||||||
6136 | Q_ASSERT(panel && panel->isPanel()); | - | ||||||||||||||||||||||||||||||
6137 | - | |||||||||||||||||||||||||||||||
6138 | QSet<QGraphicsItem *> blockedPanels; | - | ||||||||||||||||||||||||||||||
6139 | QList<QGraphicsItem *> items = q->items(); // ### same as above | - | ||||||||||||||||||||||||||||||
6140 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6141 | QGraphicsItem *item = items.at(i); | - | ||||||||||||||||||||||||||||||
6142 | if (item->isPanel() && item->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
6143 | blockedPanels.insert(item); never executed: blockedPanels.insert(item); | 0 | ||||||||||||||||||||||||||||||
6144 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6145 | - | |||||||||||||||||||||||||||||||
6146 | modalPanels.removeAll(panel); | - | ||||||||||||||||||||||||||||||
6147 | - | |||||||||||||||||||||||||||||||
6148 | QEvent e(QEvent::WindowUnblocked); | - | ||||||||||||||||||||||||||||||
6149 | for (int i = 0; i < items.count(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6150 | QGraphicsItem *item = items.at(i); | - | ||||||||||||||||||||||||||||||
6151 | if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
| 0 | ||||||||||||||||||||||||||||||
6152 | sendEvent(item, &e); never executed: sendEvent(item, &e); | 0 | ||||||||||||||||||||||||||||||
6153 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6154 | - | |||||||||||||||||||||||||||||||
6155 | // send GraphicsSceneHoverEnter events to newly unblocked items | - | ||||||||||||||||||||||||||||||
6156 | QGraphicsSceneHoverEvent hoverEvent; | - | ||||||||||||||||||||||||||||||
6157 | hoverEvent.setScenePos(lastSceneMousePos); | - | ||||||||||||||||||||||||||||||
6158 | dispatchHoverEvent(&hoverEvent); | - | ||||||||||||||||||||||||||||||
6159 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6160 | - | |||||||||||||||||||||||||||||||
6161 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
6162 | void QGraphicsScenePrivate::gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures, | - | ||||||||||||||||||||||||||||||
6163 | Qt::GestureFlag flag, | - | ||||||||||||||||||||||||||||||
6164 | QHash<QGraphicsObject *, QSet<QGesture *> > *targets, | - | ||||||||||||||||||||||||||||||
6165 | QSet<QGraphicsObject *> *itemsSet, | - | ||||||||||||||||||||||||||||||
6166 | QSet<QGesture *> *normal, | - | ||||||||||||||||||||||||||||||
6167 | QSet<QGesture *> *conflicts) | - | ||||||||||||||||||||||||||||||
6168 | { | - | ||||||||||||||||||||||||||||||
6169 | QSet<QGesture *> normalGestures; // that are not in conflicted state. | - | ||||||||||||||||||||||||||||||
6170 | foreach (QGesture *gesture, gestures) { | - | ||||||||||||||||||||||||||||||
6171 | if (!gesture->hasHotSpot())
| 0 | ||||||||||||||||||||||||||||||
6172 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6173 | const Qt::GestureType gestureType = gesture->gestureType(); | - | ||||||||||||||||||||||||||||||
6174 | QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, 0); | - | ||||||||||||||||||||||||||||||
6175 | for (int j = 0; j < items.size(); ++j) {
| 0 | ||||||||||||||||||||||||||||||
6176 | QGraphicsItem *item = items.at(j); | - | ||||||||||||||||||||||||||||||
6177 | - | |||||||||||||||||||||||||||||||
6178 | // Check if the item is blocked by a modal panel and use it as | - | ||||||||||||||||||||||||||||||
6179 | // a target instead of this item. | - | ||||||||||||||||||||||||||||||
6180 | (void) item->isBlockedByModalPanel(&item); | - | ||||||||||||||||||||||||||||||
6181 | - | |||||||||||||||||||||||||||||||
6182 | if (QGraphicsObject *itemobj = item->toGraphicsObject()) {
| 0 | ||||||||||||||||||||||||||||||
6183 | QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); | - | ||||||||||||||||||||||||||||||
6184 | QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it = | - | ||||||||||||||||||||||||||||||
6185 | d->gestureContext.constFind(gestureType); | - | ||||||||||||||||||||||||||||||
6186 | if (it != d->gestureContext.constEnd() && (!flag || (it.value() & flag))) {
| 0 | ||||||||||||||||||||||||||||||
6187 | if (normalGestures.contains(gesture)) {
| 0 | ||||||||||||||||||||||||||||||
6188 | normalGestures.remove(gesture); | - | ||||||||||||||||||||||||||||||
6189 | if (conflicts)
| 0 | ||||||||||||||||||||||||||||||
6190 | conflicts->insert(gesture); never executed: conflicts->insert(gesture); | 0 | ||||||||||||||||||||||||||||||
6191 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6192 | normalGestures.insert(gesture); | - | ||||||||||||||||||||||||||||||
6193 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6194 | if (targets)
| 0 | ||||||||||||||||||||||||||||||
6195 | (*targets)[itemobj].insert(gesture); never executed: (*targets)[itemobj].insert(gesture); | 0 | ||||||||||||||||||||||||||||||
6196 | if (itemsSet)
| 0 | ||||||||||||||||||||||||||||||
6197 | (*itemsSet).insert(itemobj); never executed: (*itemsSet).insert(itemobj); | 0 | ||||||||||||||||||||||||||||||
6198 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6199 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6200 | // Don't propagate through panels. | - | ||||||||||||||||||||||||||||||
6201 | if (item->isPanel())
| 0 | ||||||||||||||||||||||||||||||
6202 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6203 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6204 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6205 | if (normal)
| 0 | ||||||||||||||||||||||||||||||
6206 | *normal = normalGestures; never executed: *normal = normalGestures; | 0 | ||||||||||||||||||||||||||||||
6207 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6208 | - | |||||||||||||||||||||||||||||||
6209 | void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) | - | ||||||||||||||||||||||||||||||
6210 | { | - | ||||||||||||||||||||||||||||||
6211 | QWidget *viewport = event->widget(); | - | ||||||||||||||||||||||||||||||
6212 | if (!viewport)
| 0 | ||||||||||||||||||||||||||||||
6213 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
6214 | QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(viewport->parent()); | - | ||||||||||||||||||||||||||||||
6215 | if (!graphicsView)
| 0 | ||||||||||||||||||||||||||||||
6216 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
6217 | - | |||||||||||||||||||||||||||||||
6218 | QList<QGesture *> allGestures = event->gestures(); | - | ||||||||||||||||||||||||||||||
6219 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6219, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "Gestures:" << allGestures; | - | ||||||||||||||||||||||||||||||
6220 | << "Gestures:" << allGestures; dead code: QMessageLogger(__FILE__, 6219, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "Gestures:" << allGestures; | - | ||||||||||||||||||||||||||||||
6221 | - | |||||||||||||||||||||||||||||||
6222 | QSet<QGesture *> startedGestures; | - | ||||||||||||||||||||||||||||||
6223 | QPoint delta = viewport->mapFromGlobal(QPoint()); | - | ||||||||||||||||||||||||||||||
6224 | QTransform toScene = QTransform::fromTranslate(delta.x(), delta.y()) | - | ||||||||||||||||||||||||||||||
6225 | * graphicsView->viewportTransform().inverted(); | - | ||||||||||||||||||||||||||||||
6226 | foreach (QGesture *gesture, allGestures) { | - | ||||||||||||||||||||||||||||||
6227 | // cache scene coordinates of the hot spot | - | ||||||||||||||||||||||||||||||
6228 | if (gesture->hasHotSpot()) {
| 0 | ||||||||||||||||||||||||||||||
6229 | gesture->d_func()->sceneHotSpot = toScene.map(gesture->hotSpot()); | - | ||||||||||||||||||||||||||||||
6230 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6231 | gesture->d_func()->sceneHotSpot = QPointF(); | - | ||||||||||||||||||||||||||||||
6232 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6233 | - | |||||||||||||||||||||||||||||||
6234 | QGraphicsObject *target = gestureTargets.value(gesture, 0); | - | ||||||||||||||||||||||||||||||
6235 | if (!target) {
| 0 | ||||||||||||||||||||||||||||||
6236 | // when we are not in started mode but don't have a target | - | ||||||||||||||||||||||||||||||
6237 | // then the only one interested in gesture is the view/scene | - | ||||||||||||||||||||||||||||||
6238 | if (gesture->state() == Qt::GestureStarted)
| 0 | ||||||||||||||||||||||||||||||
6239 | startedGestures.insert(gesture); never executed: startedGestures.insert(gesture); | 0 | ||||||||||||||||||||||||||||||
6240 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6241 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6242 | - | |||||||||||||||||||||||||||||||
6243 | if (!startedGestures.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
6244 | QSet<QGesture *> normalGestures; // that have just one target | - | ||||||||||||||||||||||||||||||
6245 | QSet<QGesture *> conflictedGestures; // that have multiple possible targets | - | ||||||||||||||||||||||||||||||
6246 | gestureTargetsAtHotSpots(startedGestures, Qt::GestureFlag(0), &cachedItemGestures, 0, | - | ||||||||||||||||||||||||||||||
6247 | &normalGestures, &conflictedGestures); | - | ||||||||||||||||||||||||||||||
6248 | cachedTargetItems = cachedItemGestures.keys(); | - | ||||||||||||||||||||||||||||||
6249 | std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); | - | ||||||||||||||||||||||||||||||
6250 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6250, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "Normal gestures:" << normalGestures << "Conflicting gestures:" << conflictedGestures; | - | ||||||||||||||||||||||||||||||
6251 | << "Normal gestures:" << normalGestures dead code: QMessageLogger(__FILE__, 6250, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "Normal gestures:" << normalGestures << "Conflicting gestures:" << conflictedGestures; | - | ||||||||||||||||||||||||||||||
6252 | << "Conflicting gestures:" << conflictedGestures; dead code: QMessageLogger(__FILE__, 6250, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "Normal gestures:" << normalGestures << "Conflicting gestures:" << conflictedGestures; | - | ||||||||||||||||||||||||||||||
6253 | - | |||||||||||||||||||||||||||||||
6254 | // deliver conflicted gestures as override events AND remember | - | ||||||||||||||||||||||||||||||
6255 | // initial gesture targets | - | ||||||||||||||||||||||||||||||
6256 | if (!conflictedGestures.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
6257 | for (int i = 0; i < cachedTargetItems.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6258 | QPointer<QGraphicsObject> item = cachedTargetItems.at(i); | - | ||||||||||||||||||||||||||||||
6259 | - | |||||||||||||||||||||||||||||||
6260 | // get gestures to deliver to the current item | - | ||||||||||||||||||||||||||||||
6261 | QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data()); | - | ||||||||||||||||||||||||||||||
6262 | if (gestures.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
6263 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6264 | - | |||||||||||||||||||||||||||||||
6265 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6265, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering override to" << item.data() << gestures; | - | ||||||||||||||||||||||||||||||
6266 | << "delivering override to" dead code: QMessageLogger(__FILE__, 6265, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering override to" << item.data() << gestures; | - | ||||||||||||||||||||||||||||||
6267 | << item.data() << gestures; dead code: QMessageLogger(__FILE__, 6265, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering override to" << item.data() << gestures; | - | ||||||||||||||||||||||||||||||
6268 | // send gesture override | - | ||||||||||||||||||||||||||||||
6269 | QGestureEvent ev(gestures.toList()); | - | ||||||||||||||||||||||||||||||
6270 | ev.t = QEvent::GestureOverride; | - | ||||||||||||||||||||||||||||||
6271 | ev.setWidget(event->widget()); | - | ||||||||||||||||||||||||||||||
6272 | // mark event and individual gestures as ignored | - | ||||||||||||||||||||||||||||||
6273 | ev.ignore(); | - | ||||||||||||||||||||||||||||||
6274 | foreach(QGesture *g, gestures) | - | ||||||||||||||||||||||||||||||
6275 | ev.setAccepted(g, false); never executed: ev.setAccepted(g, false); | 0 | ||||||||||||||||||||||||||||||
6276 | sendEvent(item.data(), &ev); | - | ||||||||||||||||||||||||||||||
6277 | // mark all accepted gestures to deliver them as normal gesture events | - | ||||||||||||||||||||||||||||||
6278 | foreach (QGesture *g, gestures) { | - | ||||||||||||||||||||||||||||||
6279 | if (ev.isAccepted() || ev.isAccepted(g)) {
| 0 | ||||||||||||||||||||||||||||||
6280 | conflictedGestures.remove(g); | - | ||||||||||||||||||||||||||||||
6281 | // mark the item as a gesture target | - | ||||||||||||||||||||||||||||||
6282 | if (item) {
| 0 | ||||||||||||||||||||||||||||||
6283 | gestureTargets.insert(g, item.data()); | - | ||||||||||||||||||||||||||||||
6284 | QHash<QGraphicsObject *, QSet<QGesture *> >::iterator it, e; | - | ||||||||||||||||||||||||||||||
6285 | it = cachedItemGestures.begin(); | - | ||||||||||||||||||||||||||||||
6286 | e = cachedItemGestures.end(); | - | ||||||||||||||||||||||||||||||
6287 | for(; it != e; ++it)
| 0 | ||||||||||||||||||||||||||||||
6288 | it.value().remove(g); never executed: it.value().remove(g); | 0 | ||||||||||||||||||||||||||||||
6289 | cachedItemGestures[item.data()].insert(g); | - | ||||||||||||||||||||||||||||||
6290 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6291 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6291, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "override was accepted:" << g << item.data(); | - | ||||||||||||||||||||||||||||||
6292 | << "override was accepted:" dead code: QMessageLogger(__FILE__, 6291, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "override was accepted:" << g << item.data(); | - | ||||||||||||||||||||||||||||||
6293 | << g << item.data(); dead code: QMessageLogger(__FILE__, 6291, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "override was accepted:" << g << item.data(); | - | ||||||||||||||||||||||||||||||
6294 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6295 | // remember the first item that received the override event | - | ||||||||||||||||||||||||||||||
6296 | // as it most likely become a target if no one else accepts | - | ||||||||||||||||||||||||||||||
6297 | // the override event | - | ||||||||||||||||||||||||||||||
6298 | if (!gestureTargets.contains(g) && item)
| 0 | ||||||||||||||||||||||||||||||
6299 | gestureTargets.insert(g, item.data()); never executed: gestureTargets.insert(g, item.data()); | 0 | ||||||||||||||||||||||||||||||
6300 | - | |||||||||||||||||||||||||||||||
6301 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6302 | if (conflictedGestures.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
6303 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6304 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6305 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6306 | // remember the initial target item for each gesture that was not in | - | ||||||||||||||||||||||||||||||
6307 | // the conflicted state. | - | ||||||||||||||||||||||||||||||
6308 | if (!normalGestures.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
6309 | for (int i = 0; i < cachedTargetItems.size() && !normalGestures.isEmpty(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6310 | QGraphicsObject *item = cachedTargetItems.at(i); | - | ||||||||||||||||||||||||||||||
6311 | - | |||||||||||||||||||||||||||||||
6312 | // get gestures to deliver to the current item | - | ||||||||||||||||||||||||||||||
6313 | foreach (QGesture *g, cachedItemGestures.value(item)) { | - | ||||||||||||||||||||||||||||||
6314 | if (!gestureTargets.contains(g)) {
| 0 | ||||||||||||||||||||||||||||||
6315 | gestureTargets.insert(g, item); | - | ||||||||||||||||||||||||||||||
6316 | normalGestures.remove(g); | - | ||||||||||||||||||||||||||||||
6317 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6318 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6319 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6320 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6321 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6322 | - | |||||||||||||||||||||||||||||||
6323 | - | |||||||||||||||||||||||||||||||
6324 | // deliver all gesture events | - | ||||||||||||||||||||||||||||||
6325 | QSet<QGesture *> undeliveredGestures; | - | ||||||||||||||||||||||||||||||
6326 | QSet<QGesture *> parentPropagatedGestures; | - | ||||||||||||||||||||||||||||||
6327 | foreach (QGesture *gesture, allGestures) { | - | ||||||||||||||||||||||||||||||
6328 | if (QGraphicsObject *target = gestureTargets.value(gesture, 0)) {
| 0 | ||||||||||||||||||||||||||||||
6329 | cachedItemGestures[target].insert(gesture); | - | ||||||||||||||||||||||||||||||
6330 | cachedTargetItems.append(target); | - | ||||||||||||||||||||||||||||||
6331 | undeliveredGestures.insert(gesture); | - | ||||||||||||||||||||||||||||||
6332 | QGraphicsItemPrivate *d = target->QGraphicsItem::d_func(); | - | ||||||||||||||||||||||||||||||
6333 | const Qt::GestureFlags flags = d->gestureContext.value(gesture->gestureType()); | - | ||||||||||||||||||||||||||||||
6334 | if (flags & Qt::IgnoredGesturesPropagateToParent)
| 0 | ||||||||||||||||||||||||||||||
6335 | parentPropagatedGestures.insert(gesture); never executed: parentPropagatedGestures.insert(gesture); | 0 | ||||||||||||||||||||||||||||||
6336 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6337 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6337, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "no target for" << gesture << "at" << gesture->hotSpot() << gesture->d_func()->sceneHotSpot; | - | ||||||||||||||||||||||||||||||
6338 | << "no target for" << gesture << "at" dead code: QMessageLogger(__FILE__, 6337, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "no target for" << gesture << "at" << gesture->hotSpot() << gesture->d_func()->sceneHotSpot; | - | ||||||||||||||||||||||||||||||
6339 | << gesture->hotSpot() << gesture->d_func()->sceneHotSpot; dead code: QMessageLogger(__FILE__, 6337, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "no target for" << gesture << "at" << gesture->hotSpot() << gesture->d_func()->sceneHotSpot; | - | ||||||||||||||||||||||||||||||
6340 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6341 | } | - | ||||||||||||||||||||||||||||||
6342 | std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); | - | ||||||||||||||||||||||||||||||
6343 | for (int i = 0; i < cachedTargetItems.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
6344 | QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i); | - | ||||||||||||||||||||||||||||||
6345 | QSet<QGesture *> gestures = | - | ||||||||||||||||||||||||||||||
6346 | undeliveredGestures & cachedItemGestures.value(receiver.data()); | - | ||||||||||||||||||||||||||||||
6347 | gestures -= cachedAlreadyDeliveredGestures.value(receiver.data()); | - | ||||||||||||||||||||||||||||||
6348 | - | |||||||||||||||||||||||||||||||
6349 | if (gestures.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
6350 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6351 | - | |||||||||||||||||||||||||||||||
6352 | cachedAlreadyDeliveredGestures[receiver.data()] += gestures; | - | ||||||||||||||||||||||||||||||
6353 | const bool isPanel = receiver.data()->isPanel(); | - | ||||||||||||||||||||||||||||||
6354 | - | |||||||||||||||||||||||||||||||
6355 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6355, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering to" << receiver.data() << gestures; | - | ||||||||||||||||||||||||||||||
6356 | << "delivering to" dead code: QMessageLogger(__FILE__, 6355, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering to" << receiver.data() << gestures; | - | ||||||||||||||||||||||||||||||
6357 | << receiver.data() << gestures; dead code: QMessageLogger(__FILE__, 6355, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "delivering to" << receiver.data() << gestures; | - | ||||||||||||||||||||||||||||||
6358 | QGestureEvent ev(gestures.toList()); | - | ||||||||||||||||||||||||||||||
6359 | ev.setWidget(event->widget()); | - | ||||||||||||||||||||||||||||||
6360 | sendEvent(receiver.data(), &ev); | - | ||||||||||||||||||||||||||||||
6361 | QSet<QGesture *> ignoredGestures; | - | ||||||||||||||||||||||||||||||
6362 | foreach (QGesture *g, gestures) { | - | ||||||||||||||||||||||||||||||
6363 | if (!ev.isAccepted() && !ev.isAccepted(g)) {
| 0 | ||||||||||||||||||||||||||||||
6364 | // if the gesture was ignored by its target, we will update the | - | ||||||||||||||||||||||||||||||
6365 | // targetItems list with a possible target items (items that | - | ||||||||||||||||||||||||||||||
6366 | // want to receive partial gestures). | - | ||||||||||||||||||||||||||||||
6367 | // ### won't work if the target was destroyed in the event | - | ||||||||||||||||||||||||||||||
6368 | // we will just stop delivering it. | - | ||||||||||||||||||||||||||||||
6369 | if (receiver && receiver.data() == gestureTargets.value(g, 0))
| 0 | ||||||||||||||||||||||||||||||
6370 | ignoredGestures.insert(g); never executed: ignoredGestures.insert(g); | 0 | ||||||||||||||||||||||||||||||
6371 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6372 | if (receiver && g->state() == Qt::GestureStarted) {
| 0 | ||||||||||||||||||||||||||||||
6373 | // someone accepted the propagated initial GestureStarted | - | ||||||||||||||||||||||||||||||
6374 | // event, let it be the new target for all following events. | - | ||||||||||||||||||||||||||||||
6375 | gestureTargets[g] = receiver.data(); | - | ||||||||||||||||||||||||||||||
6376 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6377 | undeliveredGestures.remove(g); | - | ||||||||||||||||||||||||||||||
6378 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6379 | } | - | ||||||||||||||||||||||||||||||
6380 | if (undeliveredGestures.isEmpty())
| 0 | ||||||||||||||||||||||||||||||
6381 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6382 | - | |||||||||||||||||||||||||||||||
6383 | // ignoredGestures list is only filled when delivering to the gesture | - | ||||||||||||||||||||||||||||||
6384 | // target item, so it is safe to assume item == target. | - | ||||||||||||||||||||||||||||||
6385 | if (!ignoredGestures.isEmpty() && !isPanel) {
| 0 | ||||||||||||||||||||||||||||||
6386 | // look for new potential targets for gestures that were ignored | - | ||||||||||||||||||||||||||||||
6387 | // and should be propagated. | - | ||||||||||||||||||||||||||||||
6388 | - | |||||||||||||||||||||||||||||||
6389 | QSet<QGraphicsObject *> targetsSet = cachedTargetItems.toSet(); | - | ||||||||||||||||||||||||||||||
6390 | - | |||||||||||||||||||||||||||||||
6391 | if (receiver) {
| 0 | ||||||||||||||||||||||||||||||
6392 | // first if the gesture should be propagated to parents only | - | ||||||||||||||||||||||||||||||
6393 | for (QSet<QGesture *>::iterator it = ignoredGestures.begin(); | - | ||||||||||||||||||||||||||||||
6394 | it != ignoredGestures.end();) {
| 0 | ||||||||||||||||||||||||||||||
6395 | if (parentPropagatedGestures.contains(*it)) {
| 0 | ||||||||||||||||||||||||||||||
6396 | QGesture *gesture = *it; | - | ||||||||||||||||||||||||||||||
6397 | const Qt::GestureType gestureType = gesture->gestureType(); | - | ||||||||||||||||||||||||||||||
6398 | QGraphicsItem *item = receiver.data(); | - | ||||||||||||||||||||||||||||||
6399 | while (item) {
| 0 | ||||||||||||||||||||||||||||||
6400 | if (QGraphicsObject *obj = item->toGraphicsObject()) {
| 0 | ||||||||||||||||||||||||||||||
6401 | if (item->d_func()->gestureContext.contains(gestureType)) {
| 0 | ||||||||||||||||||||||||||||||
6402 | targetsSet.insert(obj); | - | ||||||||||||||||||||||||||||||
6403 | cachedItemGestures[obj].insert(gesture); | - | ||||||||||||||||||||||||||||||
6404 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6405 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6406 | if (item->isPanel())
| 0 | ||||||||||||||||||||||||||||||
6407 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6408 | item = item->parentItem(); | - | ||||||||||||||||||||||||||||||
6409 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6410 | - | |||||||||||||||||||||||||||||||
6411 | it = ignoredGestures.erase(it); | - | ||||||||||||||||||||||||||||||
6412 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6413 | } | - | ||||||||||||||||||||||||||||||
6414 | ++it; | - | ||||||||||||||||||||||||||||||
6415 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6416 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6417 | - | |||||||||||||||||||||||||||||||
6418 | gestureTargetsAtHotSpots(ignoredGestures, Qt::ReceivePartialGestures, | - | ||||||||||||||||||||||||||||||
6419 | &cachedItemGestures, &targetsSet, 0, 0); | - | ||||||||||||||||||||||||||||||
6420 | - | |||||||||||||||||||||||||||||||
6421 | cachedTargetItems = targetsSet.toList(); | - | ||||||||||||||||||||||||||||||
6422 | std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); | - | ||||||||||||||||||||||||||||||
6423 | DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" dead code: QMessageLogger(__FILE__, 6423, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "new targets:" << cachedTargetItems; | - | ||||||||||||||||||||||||||||||
6424 | << "new targets:" << cachedTargetItems; dead code: QMessageLogger(__FILE__, 6423, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:" << "new targets:" << cachedTargetItems; | - | ||||||||||||||||||||||||||||||
6425 | i = -1; // start delivery again | - | ||||||||||||||||||||||||||||||
6426 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6427 | } | - | ||||||||||||||||||||||||||||||
6428 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6429 | - | |||||||||||||||||||||||||||||||
6430 | foreach (QGesture *g, startedGestures) { | - | ||||||||||||||||||||||||||||||
6431 | if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
| 0 | ||||||||||||||||||||||||||||||
6432 | DEBUG() << "lets try to cancel some"; dead code: QMessageLogger(__FILE__, 6432, __PRETTY_FUNCTION__).debug() << "lets try to cancel some"; | - | ||||||||||||||||||||||||||||||
6433 | // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them | - | ||||||||||||||||||||||||||||||
6434 | cancelGesturesForChildren(g); | - | ||||||||||||||||||||||||||||||
6435 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6436 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6437 | - | |||||||||||||||||||||||||||||||
6438 | // forget about targets for gestures that have ended | - | ||||||||||||||||||||||||||||||
6439 | foreach (QGesture *g, allGestures) { | - | ||||||||||||||||||||||||||||||
6440 | switch (g->state()) { | - | ||||||||||||||||||||||||||||||
6441 | case Qt::GestureFinished: never executed: case Qt::GestureFinished: | 0 | ||||||||||||||||||||||||||||||
6442 | case Qt::GestureCanceled: never executed: case Qt::GestureCanceled: | 0 | ||||||||||||||||||||||||||||||
6443 | gestureTargets.remove(g); | - | ||||||||||||||||||||||||||||||
6444 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6445 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
6446 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
6447 | } | - | ||||||||||||||||||||||||||||||
6448 | } | - | ||||||||||||||||||||||||||||||
6449 | - | |||||||||||||||||||||||||||||||
6450 | cachedTargetItems.clear(); | - | ||||||||||||||||||||||||||||||
6451 | cachedItemGestures.clear(); | - | ||||||||||||||||||||||||||||||
6452 | cachedAlreadyDeliveredGestures.clear(); | - | ||||||||||||||||||||||||||||||
6453 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6454 | - | |||||||||||||||||||||||||||||||
6455 | void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original) | - | ||||||||||||||||||||||||||||||
6456 | { | - | ||||||||||||||||||||||||||||||
6457 | Q_ASSERT(original); | - | ||||||||||||||||||||||||||||||
6458 | QGraphicsItem *originalItem = gestureTargets.value(original); | - | ||||||||||||||||||||||||||||||
6459 | if (originalItem == 0) // we only act on accepted gestures, which implies it has a target.
| 0 | ||||||||||||||||||||||||||||||
6460 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
6461 | - | |||||||||||||||||||||||||||||||
6462 | // iterate over all active gestures and for each find the owner | - | ||||||||||||||||||||||||||||||
6463 | // if the owner is part of our sub-hierarchy, cancel it. | - | ||||||||||||||||||||||||||||||
6464 | - | |||||||||||||||||||||||||||||||
6465 | QSet<QGesture *> canceledGestures; | - | ||||||||||||||||||||||||||||||
6466 | QHash<QGesture *, QGraphicsObject *>::Iterator iter = gestureTargets.begin(); | - | ||||||||||||||||||||||||||||||
6467 | while (iter != gestureTargets.end()) {
| 0 | ||||||||||||||||||||||||||||||
6468 | QGraphicsObject *item = iter.value(); | - | ||||||||||||||||||||||||||||||
6469 | // note that we don't touch the gestures for our originalItem | - | ||||||||||||||||||||||||||||||
6470 | if (item != originalItem && originalItem->isAncestorOf(item)) {
| 0 | ||||||||||||||||||||||||||||||
6471 | DEBUG() << " found a gesture to cancel" << iter.key(); dead code: QMessageLogger(__FILE__, 6471, __PRETTY_FUNCTION__).debug() << " found a gesture to cancel" << iter.key(); | - | ||||||||||||||||||||||||||||||
6472 | iter.key()->d_func()->state = Qt::GestureCanceled; | - | ||||||||||||||||||||||||||||||
6473 | canceledGestures << iter.key(); | - | ||||||||||||||||||||||||||||||
6474 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6475 | ++iter; | - | ||||||||||||||||||||||||||||||
6476 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6477 | - | |||||||||||||||||||||||||||||||
6478 | // sort them per target item by cherry picking from almostCanceledGestures and delivering | - | ||||||||||||||||||||||||||||||
6479 | QSet<QGesture *> almostCanceledGestures = canceledGestures; | - | ||||||||||||||||||||||||||||||
6480 | QSet<QGesture *>::Iterator setIter; | - | ||||||||||||||||||||||||||||||
6481 | while (!almostCanceledGestures.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
6482 | QGraphicsObject *target = 0; | - | ||||||||||||||||||||||||||||||
6483 | QSet<QGesture*> gestures; | - | ||||||||||||||||||||||||||||||
6484 | setIter = almostCanceledGestures.begin(); | - | ||||||||||||||||||||||||||||||
6485 | // sort per target item | - | ||||||||||||||||||||||||||||||
6486 | while (setIter != almostCanceledGestures.end()) {
| 0 | ||||||||||||||||||||||||||||||
6487 | QGraphicsObject *item = gestureTargets.value(*setIter); | - | ||||||||||||||||||||||||||||||
6488 | if (target == 0)
| 0 | ||||||||||||||||||||||||||||||
6489 | target = item; never executed: target = item; | 0 | ||||||||||||||||||||||||||||||
6490 | if (target == item) {
| 0 | ||||||||||||||||||||||||||||||
6491 | gestures << *setIter; | - | ||||||||||||||||||||||||||||||
6492 | setIter = almostCanceledGestures.erase(setIter); | - | ||||||||||||||||||||||||||||||
6493 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6494 | ++setIter; | - | ||||||||||||||||||||||||||||||
6495 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6496 | } | - | ||||||||||||||||||||||||||||||
6497 | Q_ASSERT(target); | - | ||||||||||||||||||||||||||||||
6498 | - | |||||||||||||||||||||||||||||||
6499 | QList<QGesture *> list = gestures.toList(); | - | ||||||||||||||||||||||||||||||
6500 | QGestureEvent ev(list); | - | ||||||||||||||||||||||||||||||
6501 | sendEvent(target, &ev); | - | ||||||||||||||||||||||||||||||
6502 | - | |||||||||||||||||||||||||||||||
6503 | foreach (QGesture *g, list) { | - | ||||||||||||||||||||||||||||||
6504 | if (ev.isAccepted() || ev.isAccepted(g))
| 0 | ||||||||||||||||||||||||||||||
6505 | gestures.remove(g); never executed: gestures.remove(g); | 0 | ||||||||||||||||||||||||||||||
6506 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6507 | - | |||||||||||||||||||||||||||||||
6508 | foreach (QGesture *g, gestures) { | - | ||||||||||||||||||||||||||||||
6509 | if (!g->hasHotSpot())
| 0 | ||||||||||||||||||||||||||||||
6510 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6511 | - | |||||||||||||||||||||||||||||||
6512 | QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, 0); | - | ||||||||||||||||||||||||||||||
6513 | for (int j = 0; j < items.size(); ++j) {
| 0 | ||||||||||||||||||||||||||||||
6514 | QGraphicsObject *item = items.at(j)->toGraphicsObject(); | - | ||||||||||||||||||||||||||||||
6515 | if (!item)
| 0 | ||||||||||||||||||||||||||||||
6516 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
6517 | QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); | - | ||||||||||||||||||||||||||||||
6518 | if (d->gestureContext.contains(g->gestureType())) {
| 0 | ||||||||||||||||||||||||||||||
6519 | QList<QGesture *> list; | - | ||||||||||||||||||||||||||||||
6520 | list << g; | - | ||||||||||||||||||||||||||||||
6521 | QGestureEvent ev(list); | - | ||||||||||||||||||||||||||||||
6522 | sendEvent(item, &ev); | - | ||||||||||||||||||||||||||||||
6523 | if (ev.isAccepted() || ev.isAccepted(g))
| 0 | ||||||||||||||||||||||||||||||
6524 | break; // successfully delivered never executed: break; | 0 | ||||||||||||||||||||||||||||||
6525 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6526 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6527 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6528 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6529 | - | |||||||||||||||||||||||||||||||
6530 | QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; | - | ||||||||||||||||||||||||||||||
6531 | Q_ASSERT(gestureManager); // it would be very odd if we got called without a manager. | - | ||||||||||||||||||||||||||||||
6532 | for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) {
| 0 | ||||||||||||||||||||||||||||||
6533 | gestureManager->recycle(*setIter); | - | ||||||||||||||||||||||||||||||
6534 | gestureTargets.remove(*setIter); | - | ||||||||||||||||||||||||||||||
6535 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6536 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6537 | - | |||||||||||||||||||||||||||||||
6538 | void QGraphicsScenePrivate::grabGesture(QGraphicsItem *, Qt::GestureType gesture) | - | ||||||||||||||||||||||||||||||
6539 | { | - | ||||||||||||||||||||||||||||||
6540 | (void)QGestureManager::instance(); // create a gesture manager | - | ||||||||||||||||||||||||||||||
6541 | if (!grabbedGestures[gesture]++) {
| 0 | ||||||||||||||||||||||||||||||
6542 | foreach (QGraphicsView *view, views) | - | ||||||||||||||||||||||||||||||
6543 | view->viewport()->grabGesture(gesture); never executed: view->viewport()->grabGesture(gesture); | 0 | ||||||||||||||||||||||||||||||
6544 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6545 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6546 | - | |||||||||||||||||||||||||||||||
6547 | void QGraphicsScenePrivate::ungrabGesture(QGraphicsItem *item, Qt::GestureType gesture) | - | ||||||||||||||||||||||||||||||
6548 | { | - | ||||||||||||||||||||||||||||||
6549 | // we know this can only be an object | - | ||||||||||||||||||||||||||||||
6550 | Q_ASSERT(item->d_ptr->isObject); | - | ||||||||||||||||||||||||||||||
6551 | QGraphicsObject *obj = static_cast<QGraphicsObject *>(item); | - | ||||||||||||||||||||||||||||||
6552 | QGestureManager::instance()->cleanupCachedGestures(obj, gesture); | - | ||||||||||||||||||||||||||||||
6553 | if (!--grabbedGestures[gesture]) {
| 0 | ||||||||||||||||||||||||||||||
6554 | foreach (QGraphicsView *view, views) | - | ||||||||||||||||||||||||||||||
6555 | view->viewport()->ungrabGesture(gesture); never executed: view->viewport()->ungrabGesture(gesture); | 0 | ||||||||||||||||||||||||||||||
6556 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6557 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
6558 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||||||||
6559 | - | |||||||||||||||||||||||||||||||
6560 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
6561 | - | |||||||||||||||||||||||||||||||
6562 | #include "moc_qgraphicsscene.cpp" | - | ||||||||||||||||||||||||||||||
6563 | - | |||||||||||||||||||||||||||||||
6564 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |