source: trunk/src/gui/graphicsview/qgraphicsscene_p.h@ 858

Last change on this file since 858 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 13.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia 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 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
75QT_BEGIN_NAMESPACE
76
77class QGraphicsSceneIndex;
78class QGraphicsView;
79class QGraphicsWidget;
80
81class Q_AUTOTEST_EXPORT QGraphicsScenePrivate : public QObjectPrivate
82{
83 Q_DECLARE_PUBLIC(QGraphicsScene)
84public:
85 QGraphicsScenePrivate();
86 void init();
87
88 static QGraphicsScenePrivate *get(QGraphicsScene *q);
89
90 int changedSignalIndex;
91 int processDirtyItemsIndex;
92 int polishItemsIndex;
93
94 QGraphicsScene::ItemIndexMethod indexMethod;
95 QGraphicsSceneIndex *index;
96
97 int lastItemCount;
98
99 QRectF sceneRect;
100
101 quint32 hasSceneRect : 1;
102 quint32 dirtyGrowingItemsBoundingRect : 1;
103 quint32 updateAll : 1;
104 quint32 calledEmitUpdated : 1;
105 quint32 processDirtyItemsEmitted : 1;
106 quint32 needSortTopLevelItems : 1;
107 quint32 holesInTopLevelSiblingIndex : 1;
108 quint32 topLevelSequentialOrdering : 1;
109 quint32 scenePosDescendantsUpdatePending : 1;
110 quint32 stickyFocus : 1;
111 quint32 hasFocus : 1;
112 quint32 lastMouseGrabberItemHasImplicitMouseGrab : 1;
113 quint32 allItemsIgnoreHoverEvents : 1;
114 quint32 allItemsUseDefaultCursor : 1;
115 quint32 painterStateProtection : 1;
116 quint32 sortCacheEnabled : 1; // for compatibility
117 quint32 allItemsIgnoreTouchEvents : 1;
118 quint32 padding : 15;
119
120 QRectF growingItemsBoundingRect;
121
122 void _q_emitUpdated();
123 QList<QRectF> updatedRects;
124
125 QPainterPath selectionArea;
126 int selectionChanging;
127 QSet<QGraphicsItem *> selectedItems;
128 QVector<QGraphicsItem *> unpolishedItems;
129 QList<QGraphicsItem *> topLevelItems;
130
131 QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions;
132 void registerTopLevelItem(QGraphicsItem *item);
133 void unregisterTopLevelItem(QGraphicsItem *item);
134 void _q_updateLater();
135 void _q_polishItems();
136
137 void _q_processDirtyItems();
138
139 QSet<QGraphicsItem *> scenePosItems;
140 void setScenePosItemEnabled(QGraphicsItem *item, bool enabled);
141 void registerScenePosItem(QGraphicsItem *item);
142 void unregisterScenePosItem(QGraphicsItem *item);
143 void _q_updateScenePosDescendants();
144
145 void removeItemHelper(QGraphicsItem *item);
146
147 QBrush backgroundBrush;
148 QBrush foregroundBrush;
149
150 quint32 rectAdjust;
151 QGraphicsItem *focusItem;
152 QGraphicsItem *lastFocusItem;
153 QGraphicsWidget *tabFocusFirst;
154 QGraphicsItem *activePanel;
155 QGraphicsItem *lastActivePanel;
156 int activationRefCount;
157 int childExplicitActivation;
158 void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
159 void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
160
161 QList<QGraphicsWidget *> popupWidgets;
162 void addPopup(QGraphicsWidget *widget);
163 void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
164
165 QGraphicsItem *lastMouseGrabberItem;
166 QList<QGraphicsItem *> mouseGrabberItems;
167 void grabMouse(QGraphicsItem *item, bool implicit = false);
168 void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
169 void clearMouseGrabber();
170
171 QList<QGraphicsItem *> keyboardGrabberItems;
172 void grabKeyboard(QGraphicsItem *item);
173 void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
174 void clearKeyboardGrabber();
175
176 QGraphicsItem *dragDropItem;
177 QGraphicsWidget *enterWidget;
178 Qt::DropAction lastDropAction;
179 QList<QGraphicsItem *> cachedItemsUnderMouse;
180 QList<QGraphicsItem *> hoverItems;
181 QPointF lastSceneMousePos;
182 void enableMouseTrackingOnViews();
183 QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
184 QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
185 QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos;
186 QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
187 const QPointF &scenePos,
188 QWidget *widget) const;
189 void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
190
191 QList<QGraphicsView *> views;
192 void addView(QGraphicsView *view);
193 void removeView(QGraphicsView *view);
194
195 QMultiMap<QGraphicsItem *, QGraphicsItem *> sceneEventFilters;
196 void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
197 void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
198 bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
199 bool filterEvent(QGraphicsItem *item, QEvent *event);
200 bool sendEvent(QGraphicsItem *item, QEvent *event);
201
202 bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
203 bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
204 void leaveScene();
205
206 void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
207 QGraphicsSceneDragDropEvent *source);
208 void sendDragDropEvent(QGraphicsItem *item,
209 QGraphicsSceneDragDropEvent *dragDropEvent);
210 void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
211 QGraphicsSceneHoverEvent *hoverEvent);
212 void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
213 void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
214 QGraphicsWidget *windowForItem(const QGraphicsItem *item) const;
215
216 void drawItemHelper(QGraphicsItem *item, QPainter *painter,
217 const QStyleOptionGraphicsItem *option, QWidget *widget,
218 bool painterStateProtection);
219
220 void drawItems(QPainter *painter, const QTransform *const viewTransform,
221 QRegion *exposedRegion, QWidget *widget);
222
223 void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
224 QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
225 const QTransform *const effectTransform = 0);
226 void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
227 QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
228
229 void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
230 bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false,
231 bool updateBoundingRect = false);
232 void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
233 qreal parentOpacity = qreal(1.0));
234
235 inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
236 {
237 Q_ASSERT(item);
238 item->d_ptr->dirty = 0;
239 item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0;
240 item->d_ptr->geometryChanged = 0;
241 if (!item->d_ptr->dirtyChildren)
242 recursive = false;
243 item->d_ptr->dirtyChildren = 0;
244 item->d_ptr->needsRepaint = QRectF();
245 item->d_ptr->allChildrenDirty = 0;
246 item->d_ptr->fullUpdatePending = 0;
247 item->d_ptr->ignoreVisible = 0;
248 item->d_ptr->ignoreOpacity = 0;
249#ifndef QT_NO_GRAPHICSEFFECT
250 QGraphicsEffect::ChangeFlags flags;
251 if (item->d_ptr->notifyBoundingRectChanged) {
252 flags |= QGraphicsEffect::SourceBoundingRectChanged;
253 item->d_ptr->notifyBoundingRectChanged = 0;
254 }
255 if (item->d_ptr->notifyInvalidated) {
256 flags |= QGraphicsEffect::SourceInvalidated;
257 item->d_ptr->notifyInvalidated = 0;
258 }
259#endif //QT_NO_GRAPHICSEFFECT
260 if (recursive) {
261 for (int i = 0; i < item->d_ptr->children.size(); ++i)
262 resetDirtyItem(item->d_ptr->children.at(i), recursive);
263 }
264#ifndef QT_NO_GRAPHICSEFFECT
265 if (flags && item->d_ptr->graphicsEffect)
266 item->d_ptr->graphicsEffect->sourceChanged(flags);
267#endif //QT_NO_GRAPHICSEFFECT
268 }
269
270 inline void ensureSortedTopLevelItems()
271 {
272 if (needSortTopLevelItems) {
273 qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
274 topLevelSequentialOrdering = false;
275 needSortTopLevelItems = false;
276 }
277 }
278
279 void ensureSequentialTopLevelSiblingIndexes();
280
281 QStyle *style;
282 QFont font;
283 void setFont_helper(const QFont &font);
284 void resolveFont();
285 void updateFont(const QFont &font);
286 QPalette palette;
287 void setPalette_helper(const QPalette &palette);
288 void resolvePalette();
289 void updatePalette(const QPalette &palette);
290
291 QStyleOptionGraphicsItem styleOptionTmp;
292
293 QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
294 QMap<int, QGraphicsItem *> itemForTouchPointId;
295 static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
296 int findClosestTouchPointId(const QPointF &scenePos);
297 void touchEventHandler(QTouchEvent *touchEvent);
298 bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
299 void enableTouchEventsOnViews();
300
301 QList<QGraphicsObject *> cachedTargetItems;
302#ifndef QT_NO_GESTURES
303 QHash<QGraphicsObject *, QSet<QGesture *> > cachedItemGestures;
304 QHash<QGraphicsObject *, QSet<QGesture *> > cachedAlreadyDeliveredGestures;
305 QHash<QGesture *, QGraphicsObject *> gestureTargets;
306 QHash<Qt::GestureType, int> grabbedGestures;
307 void gestureEventHandler(QGestureEvent *event);
308 void gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures,
309 Qt::GestureFlag flag,
310 QHash<QGraphicsObject *, QSet<QGesture *> > *targets,
311 QSet<QGraphicsObject *> *itemsSet = 0,
312 QSet<QGesture *> *normal = 0,
313 QSet<QGesture *> *conflicts = 0);
314 void cancelGesturesForChildren(QGesture *original);
315 void grabGesture(QGraphicsItem *, Qt::GestureType gesture);
316 void ungrabGesture(QGraphicsItem *, Qt::GestureType gesture);
317#endif // QT_NO_GESTURES
318
319 void updateInputMethodSensitivityInViews();
320
321 QList<QGraphicsItem *> modalPanels;
322 void enterModal(QGraphicsItem *item,
323 QGraphicsItem::PanelModality panelModality = QGraphicsItem::NonModal);
324 void leaveModal(QGraphicsItem *item);
325};
326
327// QRectF::intersects() returns false always if either the source or target
328// rectangle's width or height are 0. This works around that problem.
329static inline void _q_adjustRect(QRectF *rect)
330{
331 Q_ASSERT(rect);
332 if (!rect->width())
333 rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
334 if (!rect->height())
335 rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
336}
337
338static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
339{
340 Q_ASSERT(item);
341 QRectF boundingRect(item->boundingRect());
342 _q_adjustRect(&boundingRect);
343 return boundingRect;
344}
345
346static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
347{
348 Q_ASSERT(item);
349 QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
350 _q_adjustRect(&boundingRect);
351 return boundingRect;
352}
353
354QT_END_NAMESPACE
355
356#endif // QT_NO_GRAPHICSVIEW
357
358#endif
Note: See TracBrowser for help on using the repository browser.