Qt 4.8
qgraphicsscene_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
76 
78 class QGraphicsView;
79 class QGraphicsWidget;
80 
82 {
84 public:
86  void init();
87 
88  static QGraphicsScenePrivate *get(QGraphicsScene *q);
89 
93 
96 
98 
100 
116  quint32 sortCacheEnabled : 1; // for compatibility
119 
121 
122  void _q_emitUpdated();
124 
130 
132  void registerTopLevelItem(QGraphicsItem *item);
133  void unregisterTopLevelItem(QGraphicsItem *item);
134  void _q_updateLater();
135  void _q_polishItems();
136 
137  void _q_processDirtyItems();
138 
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 
149 
159  void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
160  void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
161 
163  void addPopup(QGraphicsWidget *widget);
164  void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
165 
168  void grabMouse(QGraphicsItem *item, bool implicit = false);
169  void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
170  void clearMouseGrabber();
171 
173  void grabKeyboard(QGraphicsItem *item);
174  void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
175  void clearKeyboardGrabber();
176 
183  void enableMouseTrackingOnViews();
187  QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
188  const QPointF &scenePos,
189  QWidget *widget) const;
190  void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
191 
193  void addView(QGraphicsView *view);
194  void removeView(QGraphicsView *view);
195 
197  void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
198  void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
199  bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
200  bool filterEvent(QGraphicsItem *item, QEvent *event);
201  bool sendEvent(QGraphicsItem *item, QEvent *event);
202 
203  bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
204  bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
205  void leaveScene(QWidget *viewport);
206 
207  void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
209  void sendDragDropEvent(QGraphicsItem *item,
210  QGraphicsSceneDragDropEvent *dragDropEvent);
211  void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
212  QGraphicsSceneHoverEvent *hoverEvent);
213  void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
214  void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
215  QGraphicsWidget *windowForItem(const QGraphicsItem *item) const;
216 
217  void drawItemHelper(QGraphicsItem *item, QPainter *painter,
218  const QStyleOptionGraphicsItem *option, QWidget *widget,
219  bool painterStateProtection);
220 
221  void drawItems(QPainter *painter, const QTransform *const viewTransform,
222  QRegion *exposedRegion, QWidget *widget);
223 
224  void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
225  QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
226  const QTransform *const effectTransform = 0);
227  void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
228  QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
229 
230  void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
231  bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false,
232  bool updateBoundingRect = false);
233  void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
234  qreal parentOpacity = qreal(1.0));
235 
236  inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
237  {
238  Q_ASSERT(item);
239  item->d_ptr->dirty = 0;
241  item->d_ptr->geometryChanged = 0;
242  if (!item->d_ptr->dirtyChildren)
243  recursive = false;
244  item->d_ptr->dirtyChildren = 0;
245  item->d_ptr->needsRepaint = QRectF();
246  item->d_ptr->allChildrenDirty = 0;
247  item->d_ptr->fullUpdatePending = 0;
248  item->d_ptr->ignoreVisible = 0;
249  item->d_ptr->ignoreOpacity = 0;
250 #ifndef QT_NO_GRAPHICSEFFECT
251  QGraphicsEffect::ChangeFlags flags;
252  if (item->d_ptr->notifyBoundingRectChanged) {
254  item->d_ptr->notifyBoundingRectChanged = 0;
255  }
256  if (item->d_ptr->notifyInvalidated) {
258  item->d_ptr->notifyInvalidated = 0;
259  }
260 #endif //QT_NO_GRAPHICSEFFECT
261  if (recursive) {
262  for (int i = 0; i < item->d_ptr->children.size(); ++i)
263  resetDirtyItem(item->d_ptr->children.at(i), recursive);
264  }
265 #ifndef QT_NO_GRAPHICSEFFECT
266  if (flags && item->d_ptr->graphicsEffect)
267  item->d_ptr->graphicsEffect->sourceChanged(flags);
268 #endif //QT_NO_GRAPHICSEFFECT
269  }
270 
272  {
273  if (needSortTopLevelItems) {
274  qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
275  topLevelSequentialOrdering = false;
276  needSortTopLevelItems = false;
277  }
278  }
279 
280  void ensureSequentialTopLevelSiblingIndexes();
281 
284  void setFont_helper(const QFont &font);
285  void resolveFont();
286  void updateFont(const QFont &font);
288  void setPalette_helper(const QPalette &palette);
289  void resolvePalette();
290  void updatePalette(const QPalette &palette);
291 
293 
296  static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
297  int findClosestTouchPointId(const QPointF &scenePos);
298  void touchEventHandler(QTouchEvent *touchEvent);
299  bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
300  void enableTouchEventsOnViews();
301 
303 #ifndef QT_NO_GESTURES
308  void gestureEventHandler(QGestureEvent *event);
309  void gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures,
310  Qt::GestureFlag flag,
311  QHash<QGraphicsObject *, QSet<QGesture *> > *targets,
312  QSet<QGraphicsObject *> *itemsSet = 0,
313  QSet<QGesture *> *normal = 0,
314  QSet<QGesture *> *conflicts = 0);
315  void cancelGesturesForChildren(QGesture *original);
316  void grabGesture(QGraphicsItem *, Qt::GestureType gesture);
317  void ungrabGesture(QGraphicsItem *, Qt::GestureType gesture);
318 #endif // QT_NO_GESTURES
319 
320  void updateInputMethodSensitivityInViews();
321 
323  void enterModal(QGraphicsItem *item,
325  void leaveModal(QGraphicsItem *item);
326 };
327 
328 // QRectF::intersects() returns false always if either the source or target
329 // rectangle's width or height are 0. This works around that problem.
330 static inline void _q_adjustRect(QRectF *rect)
331 {
332  Q_ASSERT(rect);
333  if (!rect->width())
334  rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
335  if (!rect->height())
336  rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
337 }
338 
340 {
341  Q_ASSERT(item);
344  return boundingRect;
345 }
346 
348 {
349  Q_ASSERT(item);
350  QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
351  _q_adjustRect(&boundingRect);
352  return boundingRect;
353 }
354 
356 
357 #endif // QT_NO_GRAPHICSVIEW
358 
359 #endif
The QMultiMap class is a convenience QMap subclass that provides multi-valued maps.
Definition: qcontainerfwd.h:59
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QMap< int, QGraphicsItem * > itemForTouchPointId
static QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
QMap< Qt::MouseButton, QPoint > mouseGrabberButtonDownScreenPos
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QList< QGraphicsItem * > keyboardGrabberItems
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
virtual void sourceChanged(ChangeFlags flags)
This virtual function is called by QGraphicsEffect to notify the effect that the source has changed...
static void _q_adjustRect(QRectF *rect)
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
QGraphicsItem * focusItem
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
QList< QGraphicsItem * > modalPanels
QList< QGraphicsItem * > cachedItemsUnderMouse
QVector< QGraphicsItem * > unpolishedItems
QGraphicsSceneIndex * index
QStyleOptionGraphicsItem styleOptionTmp
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QSet< QGraphicsItem * > scenePosItems
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownScenePos
QSet< QGraphicsItem * > selectedItems
QList< QGraphicsView * > views
QGraphicsItem * passiveFocusItem
static const QRectF boundingRect(const QPointF *points, int pointCount)
QGraphicsItem * dragDropItem
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QGraphicsWidget * enterWidget
The QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QList< QGraphicsItem * > mouseGrabberItems
static bool init
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
quint32 paintedViewBoundingRectsNeedRepaint
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsEffect * graphicsEffect
GestureFlag
Definition: qnamespace.h:1772
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
DropAction
Definition: qnamespace.h:1597
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
Qt::DropAction lastDropAction
QList< QGraphicsObject * > cachedTargetItems
QHash< Qt::GestureType, int > grabbedGestures
GestureType
Definition: qnamespace.h:1759
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownPos
QGraphicsItem * lastActivePanel
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QGraphicsWidget * tabFocusFirst
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QMap< QGraphicsItem *, QPointF > movingItemsInitialPositions
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
FocusReason
Definition: qnamespace.h:1521
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QList< QGraphicsItem * > topLevelItems
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:64
QHash< QGesture *, QGraphicsObject * > gestureTargets
void adjust(qreal x1, qreal y1, qreal x2, qreal y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:778
QList< QGraphicsItem * > hoverItems
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
quint32 scenePosDescendantsUpdatePending
QHash< QGraphicsObject *, QSet< QGesture * > > cachedItemGestures
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
ItemIndexMethod
This enum describes the indexing algorithms QGraphicsScene provides for managing positional informati...
QGraphicsItem * lastMouseGrabberItem
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
QMap< int, QTouchEvent::TouchPoint > sceneCurrentTouchPoints
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QList< QRectF > updatedRects
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
QTouchEventSequence touchEvent(QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget...
Definition: qtesttouch.h:141
QGraphicsItem * lastFocusItem
QList< QGraphicsItem * > children
PanelModality
This enum specifies the behavior of a modal panel.
The QGraphicsObject class provides a base class for all graphics items that require signals...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)
QGraphicsItem * activePanel
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters
#define enabled
QHash< QGraphicsObject *, QSet< QGesture * > > cachedAlreadyDeliveredGestures
QGraphicsScene::ItemIndexMethod indexMethod
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QList< QGraphicsWidget * > popupWidgets
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
quint32 lastMouseGrabberItemHasImplicitMouseGrab
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61