0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
|
|
81 |
class QGraphicsScenePrivate : public QObjectPrivate
|
|
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;
|
|
111 |
QSet<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 |
void removeItemHelper(QGraphicsItem *item);
|
|
126 |
|
|
127 |
QBrush backgroundBrush;
|
|
128 |
QBrush foregroundBrush;
|
|
129 |
|
|
130 |
bool stickyFocus;
|
|
131 |
bool hasFocus;
|
|
132 |
QGraphicsItem *focusItem;
|
|
133 |
QGraphicsItem *lastFocusItem;
|
|
134 |
QGraphicsWidget *tabFocusFirst;
|
|
135 |
QGraphicsItem *activePanel;
|
|
136 |
QGraphicsItem *lastActivePanel;
|
|
137 |
int activationRefCount;
|
|
138 |
int childExplicitActivation;
|
|
139 |
void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
|
|
140 |
void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
|
|
141 |
|
|
142 |
QList<QGraphicsWidget *> popupWidgets;
|
|
143 |
void addPopup(QGraphicsWidget *widget);
|
|
144 |
void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
|
|
145 |
|
|
146 |
QGraphicsItem *lastMouseGrabberItem;
|
|
147 |
bool lastMouseGrabberItemHasImplicitMouseGrab;
|
|
148 |
QList<QGraphicsItem *> mouseGrabberItems;
|
|
149 |
void grabMouse(QGraphicsItem *item, bool implicit = false);
|
|
150 |
void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
|
|
151 |
void clearMouseGrabber();
|
|
152 |
|
|
153 |
QList<QGraphicsItem *> keyboardGrabberItems;
|
|
154 |
void grabKeyboard(QGraphicsItem *item);
|
|
155 |
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
|
|
156 |
void clearKeyboardGrabber();
|
|
157 |
|
|
158 |
QGraphicsItem *dragDropItem;
|
|
159 |
QGraphicsWidget *enterWidget;
|
|
160 |
Qt::DropAction lastDropAction;
|
|
161 |
QList<QGraphicsItem *> cachedItemsUnderMouse;
|
|
162 |
QList<QGraphicsItem *> hoverItems;
|
|
163 |
QPointF lastSceneMousePos;
|
|
164 |
bool allItemsIgnoreHoverEvents;
|
|
165 |
bool allItemsUseDefaultCursor;
|
|
166 |
void enableMouseTrackingOnViews();
|
|
167 |
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
|
|
168 |
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
|
|
169 |
QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos;
|
|
170 |
QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
|
|
171 |
const QPointF &scenePos,
|
|
172 |
QWidget *widget) const;
|
|
173 |
void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
|
|
174 |
|
|
175 |
QList<QGraphicsView *> views;
|
|
176 |
void addView(QGraphicsView *view);
|
|
177 |
void removeView(QGraphicsView *view);
|
|
178 |
|
|
179 |
bool painterStateProtection;
|
|
180 |
|
|
181 |
QMultiMap<QGraphicsItem *, QGraphicsItem *> sceneEventFilters;
|
|
182 |
void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
|
|
183 |
void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
|
|
184 |
bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
|
|
185 |
bool filterEvent(QGraphicsItem *item, QEvent *event);
|
|
186 |
bool sendEvent(QGraphicsItem *item, QEvent *event);
|
|
187 |
|
|
188 |
bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
|
|
189 |
bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
|
|
190 |
void leaveScene();
|
|
191 |
|
|
192 |
void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
|
|
193 |
QGraphicsSceneDragDropEvent *source);
|
|
194 |
void sendDragDropEvent(QGraphicsItem *item,
|
|
195 |
QGraphicsSceneDragDropEvent *dragDropEvent);
|
|
196 |
void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
|
|
197 |
QGraphicsSceneHoverEvent *hoverEvent);
|
|
198 |
void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
|
199 |
void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
|
|
200 |
QGraphicsWidget *windowForItem(const QGraphicsItem *item) const;
|
|
201 |
|
|
202 |
bool sortCacheEnabled; // for compatibility
|
|
203 |
|
|
204 |
void drawItemHelper(QGraphicsItem *item, QPainter *painter,
|
|
205 |
const QStyleOptionGraphicsItem *option, QWidget *widget,
|
|
206 |
bool painterStateProtection);
|
|
207 |
|
|
208 |
void drawItems(QPainter *painter, const QTransform *const viewTransform,
|
|
209 |
QRegion *exposedRegion, QWidget *widget);
|
|
210 |
|
|
211 |
void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
|
|
212 |
QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
|
|
213 |
const QTransform *const effectTransform = 0);
|
|
214 |
void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
|
|
215 |
QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
|
|
216 |
|
|
217 |
void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
|
|
218 |
bool maybeDirtyClipPath = false, bool force = false, bool ignoreOpacity = false,
|
|
219 |
bool removingItemFromScene = false);
|
|
220 |
void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
|
|
221 |
qreal parentOpacity = qreal(1.0));
|
|
222 |
|
|
223 |
inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
|
|
224 |
{
|
|
225 |
Q_ASSERT(item);
|
|
226 |
item->d_ptr->dirty = 0;
|
|
227 |
item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0;
|
|
228 |
item->d_ptr->geometryChanged = 0;
|
|
229 |
if (!item->d_ptr->dirtyChildren)
|
|
230 |
recursive = false;
|
|
231 |
item->d_ptr->dirtyChildren = 0;
|
|
232 |
item->d_ptr->needsRepaint = QRectF();
|
|
233 |
item->d_ptr->allChildrenDirty = 0;
|
|
234 |
item->d_ptr->fullUpdatePending = 0;
|
|
235 |
item->d_ptr->ignoreVisible = 0;
|
|
236 |
item->d_ptr->ignoreOpacity = 0;
|
|
237 |
QGraphicsEffect::ChangeFlags flags;
|
|
238 |
if (item->d_ptr->notifyBoundingRectChanged) {
|
|
239 |
flags |= QGraphicsEffect::SourceBoundingRectChanged;
|
|
240 |
item->d_ptr->notifyBoundingRectChanged = 0;
|
|
241 |
}
|
|
242 |
if (item->d_ptr->notifyInvalidated) {
|
|
243 |
flags |= QGraphicsEffect::SourceInvalidated;
|
|
244 |
item->d_ptr->notifyInvalidated = 0;
|
|
245 |
}
|
|
246 |
if (recursive) {
|
|
247 |
for (int i = 0; i < item->d_ptr->children.size(); ++i)
|
|
248 |
resetDirtyItem(item->d_ptr->children.at(i), recursive);
|
|
249 |
}
|
|
250 |
if (flags && item->d_ptr->graphicsEffect)
|
|
251 |
item->d_ptr->graphicsEffect->sourceChanged(flags);
|
|
252 |
}
|
|
253 |
|
|
254 |
inline void ensureSortedTopLevelItems()
|
|
255 |
{
|
|
256 |
if (needSortTopLevelItems) {
|
|
257 |
qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
|
|
258 |
needSortTopLevelItems = false;
|
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
void ensureSequentialTopLevelSiblingIndexes();
|
|
263 |
|
|
264 |
QStyle *style;
|
|
265 |
QFont font;
|
|
266 |
void setFont_helper(const QFont &font);
|
|
267 |
void resolveFont();
|
|
268 |
void updateFont(const QFont &font);
|
|
269 |
QPalette palette;
|
|
270 |
void setPalette_helper(const QPalette &palette);
|
|
271 |
void resolvePalette();
|
|
272 |
void updatePalette(const QPalette &palette);
|
|
273 |
|
|
274 |
QStyleOptionGraphicsItem styleOptionTmp;
|
|
275 |
|
|
276 |
QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
|
|
277 |
QMap<int, QGraphicsItem *> itemForTouchPointId;
|
|
278 |
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
|
|
279 |
int findClosestTouchPointId(const QPointF &scenePos);
|
|
280 |
void touchEventHandler(QTouchEvent *touchEvent);
|
|
281 |
bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
|
|
282 |
bool allItemsIgnoreTouchEvents;
|
|
283 |
void enableTouchEventsOnViews();
|
|
284 |
|
|
285 |
QHash<QGesture *, QGraphicsObject *> gestureTargets;
|
|
286 |
void gestureEventHandler(QGestureEvent *event);
|
|
287 |
void getGestureTargets(const QSet<QGesture *> &gestures, QWidget *viewport,
|
|
288 |
QMap<Qt::GestureType, QGesture *> *conflictedGestures,
|
|
289 |
QList<QList<QGraphicsObject *> > *conflictedItems,
|
|
290 |
QHash<QGesture *, QGraphicsObject *> *normalGestures);
|
|
291 |
|
|
292 |
void updateInputMethodSensitivityInViews();
|
|
293 |
|
|
294 |
QList<QGraphicsItem *> modalPanels;
|
|
295 |
void enterModal(QGraphicsItem *item,
|
|
296 |
QGraphicsItem::PanelModality panelModality = QGraphicsItem::NonModal);
|
|
297 |
void leaveModal(QGraphicsItem *item);
|
|
298 |
};
|
|
299 |
|
|
300 |
// QRectF::intersects() returns false always if either the source or target
|
|
301 |
// rectangle's width or height are 0. This works around that problem.
|
|
302 |
static inline void _q_adjustRect(QRectF *rect)
|
|
303 |
{
|
|
304 |
Q_ASSERT(rect);
|
|
305 |
if (!rect->width())
|
|
306 |
rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
|
|
307 |
if (!rect->height())
|
|
308 |
rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
|
|
309 |
}
|
|
310 |
|
|
311 |
static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
|
|
312 |
{
|
|
313 |
Q_ASSERT(item);
|
|
314 |
QRectF boundingRect(item->boundingRect());
|
|
315 |
_q_adjustRect(&boundingRect);
|
|
316 |
return boundingRect;
|
|
317 |
}
|
|
318 |
|
|
319 |
static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
|
|
320 |
{
|
|
321 |
Q_ASSERT(item);
|
|
322 |
QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
|
|
323 |
_q_adjustRect(&boundingRect);
|
|
324 |
return boundingRect;
|
|
325 |
}
|
|
326 |
|
|
327 |
QT_END_NAMESPACE
|
|
328 |
|
|
329 |
#endif // QT_NO_GRAPHICSVIEW
|
|
330 |
|
|
331 |
#endif
|