author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#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 other Qt classes. This header file may change from version to |
|
51 |
// 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 "qgraphicssceneevent.h" |
|
61 |
#include "qgraphicsview.h" |
|
62 |
#include "qgraphicsview_p.h" |
|
63 |
#include "qgraphicsitem_p.h" |
|
64 |
||
65 |
#include <private/qobject_p.h> |
|
66 |
#include <QtCore/qbitarray.h> |
|
67 |
#include <QtCore/qlist.h> |
|
68 |
#include <QtCore/qmap.h> |
|
69 |
#include <QtCore/qset.h> |
|
70 |
#include <QtGui/qfont.h> |
|
71 |
#include <QtGui/qpalette.h> |
|
72 |
#include <QtGui/qstyle.h> |
|
73 |
#include <QtGui/qstyleoption.h> |
|
74 |
||
75 |
QT_BEGIN_NAMESPACE |
|
76 |
||
77 |
class QGraphicsSceneIndex; |
|
78 |
class QGraphicsView; |
|
79 |
class QGraphicsWidget; |
|
80 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
class Q_AUTOTEST_EXPORT QGraphicsScenePrivate : public QObjectPrivate |
0 | 82 |
{ |
83 |
Q_DECLARE_PUBLIC(QGraphicsScene) |
|
84 |
public: |
|
85 |
QGraphicsScenePrivate(); |
|
86 |
void init(); |
|
87 |
||
88 |
static QGraphicsScenePrivate *get(QGraphicsScene *q); |
|
89 |
||
90 |
static int changedSignalIndex; |
|
91 |
||
92 |
QGraphicsScene::ItemIndexMethod indexMethod; |
|
93 |
QGraphicsSceneIndex *index; |
|
94 |
||
95 |
int lastItemCount; |
|
96 |
||
97 |
QRectF sceneRect; |
|
98 |
bool hasSceneRect; |
|
99 |
bool dirtyGrowingItemsBoundingRect; |
|
100 |
QRectF growingItemsBoundingRect; |
|
101 |
||
102 |
void _q_emitUpdated(); |
|
103 |
QList<QRectF> updatedRects; |
|
104 |
bool updateAll; |
|
105 |
bool calledEmitUpdated; |
|
106 |
bool processDirtyItemsEmitted; |
|
107 |
||
108 |
QPainterPath selectionArea; |
|
109 |
int selectionChanging; |
|
110 |
QSet<QGraphicsItem *> selectedItems; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
111 |
QVector<QGraphicsItem *> unpolishedItems; |
0 | 112 |
QList<QGraphicsItem *> topLevelItems; |
113 |
bool needSortTopLevelItems; |
|
114 |
bool holesInTopLevelSiblingIndex; |
|
115 |
bool topLevelSequentialOrdering; |
|
116 |
||
117 |
QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions; |
|
118 |
void registerTopLevelItem(QGraphicsItem *item); |
|
119 |
void unregisterTopLevelItem(QGraphicsItem *item); |
|
120 |
void _q_updateLater(); |
|
121 |
void _q_polishItems(); |
|
122 |
||
123 |
void _q_processDirtyItems(); |
|
124 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
QSet<QGraphicsItem *> scenePosItems; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
bool scenePosDescendantsUpdatePending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
void setScenePosItemEnabled(QGraphicsItem *item, bool enabled); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
void registerScenePosItem(QGraphicsItem *item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
void unregisterScenePosItem(QGraphicsItem *item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
void _q_updateScenePosDescendants(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
|
0 | 132 |
void removeItemHelper(QGraphicsItem *item); |
133 |
||
134 |
QBrush backgroundBrush; |
|
135 |
QBrush foregroundBrush; |
|
136 |
||
137 |
bool stickyFocus; |
|
138 |
bool hasFocus; |
|
139 |
QGraphicsItem *focusItem; |
|
140 |
QGraphicsItem *lastFocusItem; |
|
141 |
QGraphicsWidget *tabFocusFirst; |
|
142 |
QGraphicsItem *activePanel; |
|
143 |
QGraphicsItem *lastActivePanel; |
|
144 |
int activationRefCount; |
|
145 |
int childExplicitActivation; |
|
146 |
void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent); |
|
147 |
void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason); |
|
148 |
||
149 |
QList<QGraphicsWidget *> popupWidgets; |
|
150 |
void addPopup(QGraphicsWidget *widget); |
|
151 |
void removePopup(QGraphicsWidget *widget, bool itemIsDying = false); |
|
152 |
||
153 |
QGraphicsItem *lastMouseGrabberItem; |
|
154 |
bool lastMouseGrabberItemHasImplicitMouseGrab; |
|
155 |
QList<QGraphicsItem *> mouseGrabberItems; |
|
156 |
void grabMouse(QGraphicsItem *item, bool implicit = false); |
|
157 |
void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false); |
|
158 |
void clearMouseGrabber(); |
|
159 |
||
160 |
QList<QGraphicsItem *> keyboardGrabberItems; |
|
161 |
void grabKeyboard(QGraphicsItem *item); |
|
162 |
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false); |
|
163 |
void clearKeyboardGrabber(); |
|
164 |
||
165 |
QGraphicsItem *dragDropItem; |
|
166 |
QGraphicsWidget *enterWidget; |
|
167 |
Qt::DropAction lastDropAction; |
|
168 |
QList<QGraphicsItem *> cachedItemsUnderMouse; |
|
169 |
QList<QGraphicsItem *> hoverItems; |
|
170 |
QPointF lastSceneMousePos; |
|
171 |
bool allItemsIgnoreHoverEvents; |
|
172 |
bool allItemsUseDefaultCursor; |
|
173 |
void enableMouseTrackingOnViews(); |
|
174 |
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos; |
|
175 |
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos; |
|
176 |
QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos; |
|
177 |
QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos, |
|
178 |
const QPointF &scenePos, |
|
179 |
QWidget *widget) const; |
|
180 |
void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event); |
|
181 |
||
182 |
QList<QGraphicsView *> views; |
|
183 |
void addView(QGraphicsView *view); |
|
184 |
void removeView(QGraphicsView *view); |
|
185 |
||
186 |
bool painterStateProtection; |
|
187 |
||
188 |
QMultiMap<QGraphicsItem *, QGraphicsItem *> sceneEventFilters; |
|
189 |
void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter); |
|
190 |
void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter); |
|
191 |
bool filterDescendantEvent(QGraphicsItem *item, QEvent *event); |
|
192 |
bool filterEvent(QGraphicsItem *item, QEvent *event); |
|
193 |
bool sendEvent(QGraphicsItem *item, QEvent *event); |
|
194 |
||
195 |
bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent); |
|
196 |
bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const; |
|
197 |
void leaveScene(); |
|
198 |
||
199 |
void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest, |
|
200 |
QGraphicsSceneDragDropEvent *source); |
|
201 |
void sendDragDropEvent(QGraphicsItem *item, |
|
202 |
QGraphicsSceneDragDropEvent *dragDropEvent); |
|
203 |
void sendHoverEvent(QEvent::Type type, QGraphicsItem *item, |
|
204 |
QGraphicsSceneHoverEvent *hoverEvent); |
|
205 |
void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent); |
|
206 |
void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent); |
|
207 |
QGraphicsWidget *windowForItem(const QGraphicsItem *item) const; |
|
208 |
||
209 |
bool sortCacheEnabled; // for compatibility |
|
210 |
||
211 |
void drawItemHelper(QGraphicsItem *item, QPainter *painter, |
|
212 |
const QStyleOptionGraphicsItem *option, QWidget *widget, |
|
213 |
bool painterStateProtection); |
|
214 |
||
215 |
void drawItems(QPainter *painter, const QTransform *const viewTransform, |
|
216 |
QRegion *exposedRegion, QWidget *widget); |
|
217 |
||
218 |
void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const, |
|
219 |
QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0), |
|
220 |
const QTransform *const effectTransform = 0); |
|
221 |
void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const, |
|
222 |
QRegion *, QWidget *, qreal, const QTransform *const, bool, bool); |
|
223 |
||
224 |
void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false, |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
225 |
bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false, |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
226 |
bool updateBoundingRect = false); |
0 | 227 |
void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false, |
228 |
qreal parentOpacity = qreal(1.0)); |
|
229 |
||
230 |
inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false) |
|
231 |
{ |
|
232 |
Q_ASSERT(item); |
|
233 |
item->d_ptr->dirty = 0; |
|
234 |
item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0; |
|
235 |
item->d_ptr->geometryChanged = 0; |
|
236 |
if (!item->d_ptr->dirtyChildren) |
|
237 |
recursive = false; |
|
238 |
item->d_ptr->dirtyChildren = 0; |
|
239 |
item->d_ptr->needsRepaint = QRectF(); |
|
240 |
item->d_ptr->allChildrenDirty = 0; |
|
241 |
item->d_ptr->fullUpdatePending = 0; |
|
242 |
item->d_ptr->ignoreVisible = 0; |
|
243 |
item->d_ptr->ignoreOpacity = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 245 |
QGraphicsEffect::ChangeFlags flags; |
246 |
if (item->d_ptr->notifyBoundingRectChanged) { |
|
247 |
flags |= QGraphicsEffect::SourceBoundingRectChanged; |
|
248 |
item->d_ptr->notifyBoundingRectChanged = 0; |
|
249 |
} |
|
250 |
if (item->d_ptr->notifyInvalidated) { |
|
251 |
flags |= QGraphicsEffect::SourceInvalidated; |
|
252 |
item->d_ptr->notifyInvalidated = 0; |
|
253 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 255 |
if (recursive) { |
256 |
for (int i = 0; i < item->d_ptr->children.size(); ++i) |
|
257 |
resetDirtyItem(item->d_ptr->children.at(i), recursive); |
|
258 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
#ifndef QT_NO_GRAPHICSEFFECT |
0 | 260 |
if (flags && item->d_ptr->graphicsEffect) |
261 |
item->d_ptr->graphicsEffect->sourceChanged(flags); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
#endif //QT_NO_GRAPHICSEFFECT |
0 | 263 |
} |
264 |
||
265 |
inline void ensureSortedTopLevelItems() |
|
266 |
{ |
|
267 |
if (needSortTopLevelItems) { |
|
268 |
qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
topLevelSequentialOrdering = false; |
0 | 270 |
needSortTopLevelItems = false; |
271 |
} |
|
272 |
} |
|
273 |
||
274 |
void ensureSequentialTopLevelSiblingIndexes(); |
|
275 |
||
276 |
QStyle *style; |
|
277 |
QFont font; |
|
278 |
void setFont_helper(const QFont &font); |
|
279 |
void resolveFont(); |
|
280 |
void updateFont(const QFont &font); |
|
281 |
QPalette palette; |
|
282 |
void setPalette_helper(const QPalette &palette); |
|
283 |
void resolvePalette(); |
|
284 |
void updatePalette(const QPalette &palette); |
|
285 |
||
286 |
QStyleOptionGraphicsItem styleOptionTmp; |
|
287 |
||
288 |
QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints; |
|
289 |
QMap<int, QGraphicsItem *> itemForTouchPointId; |
|
290 |
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent); |
|
291 |
int findClosestTouchPointId(const QPointF &scenePos); |
|
292 |
void touchEventHandler(QTouchEvent *touchEvent); |
|
293 |
bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent); |
|
294 |
bool allItemsIgnoreTouchEvents; |
|
295 |
void enableTouchEventsOnViews(); |
|
296 |
||
297 |
QHash<QGesture *, QGraphicsObject *> gestureTargets; |
|
298 |
void gestureEventHandler(QGestureEvent *event); |
|
299 |
void getGestureTargets(const QSet<QGesture *> &gestures, QWidget *viewport, |
|
300 |
QMap<Qt::GestureType, QGesture *> *conflictedGestures, |
|
301 |
QList<QList<QGraphicsObject *> > *conflictedItems, |
|
302 |
QHash<QGesture *, QGraphicsObject *> *normalGestures); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
void cancelGesturesForChildren(QGesture *original, QWidget *viewport); |
0 | 304 |
|
305 |
void updateInputMethodSensitivityInViews(); |
|
306 |
||
307 |
QList<QGraphicsItem *> modalPanels; |
|
308 |
void enterModal(QGraphicsItem *item, |
|
309 |
QGraphicsItem::PanelModality panelModality = QGraphicsItem::NonModal); |
|
310 |
void leaveModal(QGraphicsItem *item); |
|
311 |
}; |
|
312 |
||
313 |
// QRectF::intersects() returns false always if either the source or target |
|
314 |
// rectangle's width or height are 0. This works around that problem. |
|
315 |
static inline void _q_adjustRect(QRectF *rect) |
|
316 |
{ |
|
317 |
Q_ASSERT(rect); |
|
318 |
if (!rect->width()) |
|
319 |
rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0); |
|
320 |
if (!rect->height()) |
|
321 |
rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001)); |
|
322 |
} |
|
323 |
||
324 |
static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item) |
|
325 |
{ |
|
326 |
Q_ASSERT(item); |
|
327 |
QRectF boundingRect(item->boundingRect()); |
|
328 |
_q_adjustRect(&boundingRect); |
|
329 |
return boundingRect; |
|
330 |
} |
|
331 |
||
332 |
static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item) |
|
333 |
{ |
|
334 |
Q_ASSERT(item); |
|
335 |
QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect()); |
|
336 |
_q_adjustRect(&boundingRect); |
|
337 |
return boundingRect; |
|
338 |
} |
|
339 |
||
340 |
QT_END_NAMESPACE |
|
341 |
||
342 |
#endif // QT_NO_GRAPHICSVIEW |
|
343 |
||
344 |
#endif |