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

Last change on this file since 755 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 12.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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 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;
111 QVector<QGraphicsItem *> unpolishedItems;
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
125 QSet<QGraphicsItem *> scenePosItems;
126 bool scenePosDescendantsUpdatePending;
127 void setScenePosItemEnabled(QGraphicsItem *item, bool enabled);
128 void registerScenePosItem(QGraphicsItem *item);
129 void unregisterScenePosItem(QGraphicsItem *item);
130 void _q_updateScenePosDescendants();
131
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,
225 bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false);
226 void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
227 qreal parentOpacity = qreal(1.0));
228
229 inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
230 {
231 Q_ASSERT(item);
232 item->d_ptr->dirty = 0;
233 item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0;
234 item->d_ptr->geometryChanged = 0;
235 if (!item->d_ptr->dirtyChildren)
236 recursive = false;
237 item->d_ptr->dirtyChildren = 0;
238 item->d_ptr->needsRepaint = QRectF();
239 item->d_ptr->allChildrenDirty = 0;
240 item->d_ptr->fullUpdatePending = 0;
241 item->d_ptr->ignoreVisible = 0;
242 item->d_ptr->ignoreOpacity = 0;
243#ifndef QT_NO_GRAPHICSEFFECT
244 QGraphicsEffect::ChangeFlags flags;
245 if (item->d_ptr->notifyBoundingRectChanged) {
246 flags |= QGraphicsEffect::SourceBoundingRectChanged;
247 item->d_ptr->notifyBoundingRectChanged = 0;
248 }
249 if (item->d_ptr->notifyInvalidated) {
250 flags |= QGraphicsEffect::SourceInvalidated;
251 item->d_ptr->notifyInvalidated = 0;
252 }
253#endif //QT_NO_GRAPHICSEFFECT
254 if (recursive) {
255 for (int i = 0; i < item->d_ptr->children.size(); ++i)
256 resetDirtyItem(item->d_ptr->children.at(i), recursive);
257 }
258#ifndef QT_NO_GRAPHICSEFFECT
259 if (flags && item->d_ptr->graphicsEffect)
260 item->d_ptr->graphicsEffect->sourceChanged(flags);
261#endif //QT_NO_GRAPHICSEFFECT
262 }
263
264 inline void ensureSortedTopLevelItems()
265 {
266 if (needSortTopLevelItems) {
267 qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
268 topLevelSequentialOrdering = false;
269 needSortTopLevelItems = false;
270 }
271 }
272
273 void ensureSequentialTopLevelSiblingIndexes();
274
275 QStyle *style;
276 QFont font;
277 void setFont_helper(const QFont &font);
278 void resolveFont();
279 void updateFont(const QFont &font);
280 QPalette palette;
281 void setPalette_helper(const QPalette &palette);
282 void resolvePalette();
283 void updatePalette(const QPalette &palette);
284
285 QStyleOptionGraphicsItem styleOptionTmp;
286
287 QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
288 QMap<int, QGraphicsItem *> itemForTouchPointId;
289 static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
290 int findClosestTouchPointId(const QPointF &scenePos);
291 void touchEventHandler(QTouchEvent *touchEvent);
292 bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
293 bool allItemsIgnoreTouchEvents;
294 void enableTouchEventsOnViews();
295
296 QHash<QGesture *, QGraphicsObject *> gestureTargets;
297 void gestureEventHandler(QGestureEvent *event);
298 void getGestureTargets(const QSet<QGesture *> &gestures, QWidget *viewport,
299 QMap<Qt::GestureType, QGesture *> *conflictedGestures,
300 QList<QList<QGraphicsObject *> > *conflictedItems,
301 QHash<QGesture *, QGraphicsObject *> *normalGestures);
302 void cancelGesturesForChildren(QGesture *original, QWidget *viewport);
303
304 void updateInputMethodSensitivityInViews();
305
306 QList<QGraphicsItem *> modalPanels;
307 void enterModal(QGraphicsItem *item,
308 QGraphicsItem::PanelModality panelModality = QGraphicsItem::NonModal);
309 void leaveModal(QGraphicsItem *item);
310};
311
312// QRectF::intersects() returns false always if either the source or target
313// rectangle's width or height are 0. This works around that problem.
314static inline void _q_adjustRect(QRectF *rect)
315{
316 Q_ASSERT(rect);
317 if (!rect->width())
318 rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
319 if (!rect->height())
320 rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
321}
322
323static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
324{
325 Q_ASSERT(item);
326 QRectF boundingRect(item->boundingRect());
327 _q_adjustRect(&boundingRect);
328 return boundingRect;
329}
330
331static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
332{
333 Q_ASSERT(item);
334 QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
335 _q_adjustRect(&boundingRect);
336 return boundingRect;
337}
338
339QT_END_NAMESPACE
340
341#endif // QT_NO_GRAPHICSVIEW
342
343#endif
Note: See TracBrowser for help on using the repository browser.