1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QGRAPHICSSCENE_P_H
|
---|
43 | #define QGRAPHICSSCENE_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
|
---|
51 | // file may change from version to version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "qgraphicsscene.h"
|
---|
57 |
|
---|
58 | #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
---|
59 |
|
---|
60 | #include "qgraphicsscene_bsp_p.h"
|
---|
61 | #include "qgraphicsitem_p.h"
|
---|
62 |
|
---|
63 | #include <private/qobject_p.h>
|
---|
64 | #include <QtCore/qbitarray.h>
|
---|
65 | #include <QtCore/qlist.h>
|
---|
66 | #include <QtCore/qmap.h>
|
---|
67 | #include <QtCore/qset.h>
|
---|
68 | #include <QtGui/qfont.h>
|
---|
69 | #include <QtGui/qpalette.h>
|
---|
70 | #include <QtGui/qstyle.h>
|
---|
71 |
|
---|
72 | QT_BEGIN_NAMESPACE
|
---|
73 |
|
---|
74 | class QGraphicsView;
|
---|
75 | class QGraphicsWidget;
|
---|
76 |
|
---|
77 | class QGraphicsScenePrivate : public QObjectPrivate
|
---|
78 | {
|
---|
79 | Q_DECLARE_PUBLIC(QGraphicsScene)
|
---|
80 | public:
|
---|
81 | QGraphicsScenePrivate();
|
---|
82 | void init();
|
---|
83 |
|
---|
84 | quint32 changedSignalMask;
|
---|
85 |
|
---|
86 | QGraphicsScene::ItemIndexMethod indexMethod;
|
---|
87 | int bspTreeDepth;
|
---|
88 |
|
---|
89 | QList<QGraphicsItem *> estimateItemsInRect(const QRectF &rect) const;
|
---|
90 | void addToIndex(QGraphicsItem *item);
|
---|
91 | void removeFromIndex(QGraphicsItem *item);
|
---|
92 | void resetIndex();
|
---|
93 |
|
---|
94 | QGraphicsSceneBspTree bspTree;
|
---|
95 | void _q_updateIndex();
|
---|
96 | int lastItemCount;
|
---|
97 |
|
---|
98 | QRectF sceneRect;
|
---|
99 | bool hasSceneRect;
|
---|
100 | QRectF growingItemsBoundingRect;
|
---|
101 | QRectF largestUntransformableItem;
|
---|
102 |
|
---|
103 | void _q_emitUpdated();
|
---|
104 | QList<QRectF> updatedRects;
|
---|
105 | bool updateAll;
|
---|
106 | bool calledEmitUpdated;
|
---|
107 |
|
---|
108 | QPainterPath selectionArea;
|
---|
109 | int selectionChanging;
|
---|
110 | QSet<QGraphicsItem *> selectedItems;
|
---|
111 | QList<QGraphicsItem *> unindexedItems;
|
---|
112 | QList<QGraphicsItem *> indexedItems;
|
---|
113 | QList<QGraphicsItem *> dirtyItems;
|
---|
114 | QList<QGraphicsItem *> pendingUpdateItems;
|
---|
115 | QList<QGraphicsItem *> unpolishedItems;
|
---|
116 | QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions;
|
---|
117 | void _q_updateLater();
|
---|
118 | void _q_polishItems();
|
---|
119 |
|
---|
120 | void _q_resetDirtyItems();
|
---|
121 | void resetDirtyItemsLater();
|
---|
122 | bool dirtyItemResetPending;
|
---|
123 |
|
---|
124 | QList<int> freeItemIndexes;
|
---|
125 | bool regenerateIndex;
|
---|
126 |
|
---|
127 | bool purgePending;
|
---|
128 | void _q_removeItemLater(QGraphicsItem *item);
|
---|
129 | QSet<QGraphicsItem *> removedItems;
|
---|
130 | void purgeRemovedItems();
|
---|
131 |
|
---|
132 | QBrush backgroundBrush;
|
---|
133 | QBrush foregroundBrush;
|
---|
134 |
|
---|
135 | int indexTimerId;
|
---|
136 | bool restartIndexTimer;
|
---|
137 | void startIndexTimer();
|
---|
138 |
|
---|
139 | bool stickyFocus;
|
---|
140 | bool hasFocus;
|
---|
141 | QGraphicsItem *focusItem;
|
---|
142 | QGraphicsItem *lastFocusItem;
|
---|
143 | QGraphicsWidget *tabFocusFirst;
|
---|
144 | QGraphicsWidget *activeWindow;
|
---|
145 | int activationRefCount;
|
---|
146 |
|
---|
147 | QList<QGraphicsWidget *> popupWidgets;
|
---|
148 | void addPopup(QGraphicsWidget *widget);
|
---|
149 | void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
|
---|
150 |
|
---|
151 | QGraphicsItem *lastMouseGrabberItem;
|
---|
152 | bool lastMouseGrabberItemHasImplicitMouseGrab;
|
---|
153 | QList<QGraphicsItem *> mouseGrabberItems;
|
---|
154 | void grabMouse(QGraphicsItem *item, bool implicit = false);
|
---|
155 | void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
|
---|
156 | void clearMouseGrabber();
|
---|
157 |
|
---|
158 | QList<QGraphicsItem *> keyboardGrabberItems;
|
---|
159 | void grabKeyboard(QGraphicsItem *item);
|
---|
160 | void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
|
---|
161 | void clearKeyboardGrabber();
|
---|
162 |
|
---|
163 | QGraphicsItem *dragDropItem;
|
---|
164 | QGraphicsWidget *enterWidget;
|
---|
165 | Qt::DropAction lastDropAction;
|
---|
166 | QList<QGraphicsItem *> cachedItemsUnderMouse;
|
---|
167 | QList<QGraphicsItem *> hoverItems;
|
---|
168 | QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
|
---|
169 | QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
|
---|
170 | QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos;
|
---|
171 | QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
|
---|
172 | const QPointF &scenePos,
|
---|
173 | QWidget *widget) const;
|
---|
174 | static bool itemCollidesWithPath(QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode);
|
---|
175 | void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
|
---|
176 |
|
---|
177 | QList<QGraphicsView *> views;
|
---|
178 | bool painterStateProtection;
|
---|
179 |
|
---|
180 | QMultiMap<QGraphicsItem *, QGraphicsItem *> sceneEventFilters;
|
---|
181 | void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
|
---|
182 | void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
|
---|
183 | bool filterEvent(QGraphicsItem *item, QEvent *event);
|
---|
184 | bool sendEvent(QGraphicsItem *item, QEvent *event);
|
---|
185 |
|
---|
186 | bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
|
---|
187 | bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
|
---|
188 | void leaveScene();
|
---|
189 |
|
---|
190 | void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
|
---|
191 | QGraphicsSceneDragDropEvent *source);
|
---|
192 | void sendDragDropEvent(QGraphicsItem *item,
|
---|
193 | QGraphicsSceneDragDropEvent *dragDropEvent);
|
---|
194 | void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
|
---|
195 | QGraphicsSceneHoverEvent *hoverEvent);
|
---|
196 | void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
---|
197 | void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
|
---|
198 | QGraphicsWidget *windowForItem(const QGraphicsItem *item) const;
|
---|
199 |
|
---|
200 | QList<QGraphicsItem *> items_helper(const QPointF &pos) const;
|
---|
201 | QList<QGraphicsItem *> items_helper(const QRectF &rect,
|
---|
202 | Qt::ItemSelectionMode mode,
|
---|
203 | Qt::SortOrder order) const;
|
---|
204 | QList<QGraphicsItem *> items_helper(const QPolygonF &rect,
|
---|
205 | Qt::ItemSelectionMode mode,
|
---|
206 | Qt::SortOrder order) const;
|
---|
207 | QList<QGraphicsItem *> items_helper(const QPainterPath &rect,
|
---|
208 | Qt::ItemSelectionMode mode,
|
---|
209 | Qt::SortOrder order) const;
|
---|
210 | void childItems_helper(QList<QGraphicsItem *> *items,
|
---|
211 | const QGraphicsItem *parent,
|
---|
212 | const QPointF &pos) const;
|
---|
213 | void childItems_helper(QList<QGraphicsItem *> *items,
|
---|
214 | const QGraphicsItem *parent,
|
---|
215 | const QRectF &rect,
|
---|
216 | Qt::ItemSelectionMode mode) const;
|
---|
217 | void childItems_helper(QList<QGraphicsItem *> *items,
|
---|
218 | const QGraphicsItem *parent,
|
---|
219 | const QPolygonF &polygon,
|
---|
220 | Qt::ItemSelectionMode mode) const;
|
---|
221 | void childItems_helper(QList<QGraphicsItem *> *items,
|
---|
222 | const QGraphicsItem *parent,
|
---|
223 | const QPainterPath &path,
|
---|
224 | Qt::ItemSelectionMode mode) const;
|
---|
225 |
|
---|
226 | bool sortCacheEnabled;
|
---|
227 | bool updatingSortCache;
|
---|
228 | void invalidateSortCache();
|
---|
229 | static void climbTree(QGraphicsItem *item, int *stackingOrder);
|
---|
230 | void _q_updateSortCache();
|
---|
231 |
|
---|
232 | static bool closestItemFirst_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
|
---|
233 | static bool closestItemLast_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
|
---|
234 |
|
---|
235 | static inline bool closestItemFirst_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
|
---|
236 | {
|
---|
237 | return item1->d_ptr->globalStackingOrder < item2->d_ptr->globalStackingOrder;
|
---|
238 | }
|
---|
239 | static inline bool closestItemLast_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
|
---|
240 | {
|
---|
241 | return item1->d_ptr->globalStackingOrder >= item2->d_ptr->globalStackingOrder;
|
---|
242 | }
|
---|
243 |
|
---|
244 | static void sortItems(QList<QGraphicsItem *> *itemList, Qt::SortOrder order, bool cached);
|
---|
245 |
|
---|
246 | void drawItemHelper(QGraphicsItem *item, QPainter *painter,
|
---|
247 | const QStyleOptionGraphicsItem *option, QWidget *widget,
|
---|
248 | bool painterStateProtection);
|
---|
249 |
|
---|
250 | QStyle *style;
|
---|
251 | QFont font;
|
---|
252 | void setFont_helper(const QFont &font);
|
---|
253 | void resolveFont();
|
---|
254 | void updateFont(const QFont &font);
|
---|
255 | QPalette palette;
|
---|
256 | void setPalette_helper(const QPalette &palette);
|
---|
257 | void resolvePalette();
|
---|
258 | void updatePalette(const QPalette &palette);
|
---|
259 |
|
---|
260 | mutable QVector<QTransform> sceneTransformCache;
|
---|
261 | mutable QBitArray validTransforms;
|
---|
262 | mutable QVector<int> freeSceneTransformSlots;
|
---|
263 | };
|
---|
264 |
|
---|
265 | QT_END_NAMESPACE
|
---|
266 |
|
---|
267 | #endif // QT_NO_GRAPHICSVIEW
|
---|
268 |
|
---|
269 | #endif
|
---|