1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGRAPHICSVIEW_P_H
41 #define QGRAPHICSVIEW_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists for the convenience
48 // of other Qt classes.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtWidgets/private/qtwidgetsglobal_p.h>
55 #include "qgraphicsview.h"
56 
57 #include <QtGui/qevent.h>
58 #include <QtCore/qcoreapplication.h>
59 #include "qgraphicssceneevent.h"
60 #include <QtWidgets/qstyleoption.h>
61 #include <private/qabstractscrollarea_p.h>
62 #include <private/qapplication_p.h>
63 
64 QT_REQUIRE_CONFIG(graphicsview);
65 
66 QT_BEGIN_NAMESPACE
67 
68 class Q_WIDGETS_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
69 {
70     Q_DECLARE_PUBLIC(QGraphicsView)
71 public:
72     QGraphicsViewPrivate();
73     ~QGraphicsViewPrivate();
74 
75     void recalculateContentSize();
76     void centerView(QGraphicsView::ViewportAnchor anchor);
77 
78     QPainter::RenderHints renderHints;
79 
80     QGraphicsView::DragMode dragMode;
81 
82     quint32 sceneInteractionAllowed : 1;
83     quint32 hasSceneRect : 1;
84     quint32 connectedToScene : 1;
85     quint32 useLastMouseEvent : 1;
86     quint32 identityMatrix : 1;
87     quint32 dirtyScroll : 1;
88     quint32 accelerateScrolling : 1;
89     quint32 keepLastCenterPoint : 1;
90     quint32 transforming : 1;
91     quint32 handScrolling : 1;
92     quint32 mustAllocateStyleOptions : 1;
93     quint32 mustResizeBackgroundPixmap : 1;
94     quint32 fullUpdatePending : 1;
95     quint32 hasUpdateClip : 1;
96     quint32 padding : 18;
97 
98     QRectF sceneRect;
99     void updateLastCenterPoint();
100 
101     qint64 horizontalScroll() const;
102     qint64 verticalScroll() const;
103 
104     QRectF mapRectToScene(const QRect &rect) const;
105     QRectF mapRectFromScene(const QRectF &rect) const;
106 
107     QRect updateClip;
108     QPointF mousePressItemPoint;
109     QPointF mousePressScenePoint;
110     QPoint mousePressViewPoint;
111     QPoint mousePressScreenPoint;
112     QPointF lastMouseMoveScenePoint;
113     QPointF lastRubberbandScenePoint;
114     QPoint lastMouseMoveScreenPoint;
115     QPoint dirtyScrollOffset;
116     Qt::MouseButton mousePressButton;
117     QTransform matrix;
118     qint64 scrollX, scrollY;
119     void updateScroll();
120 
121     qreal leftIndent;
122     qreal topIndent;
123 
124     // Replaying mouse events
125     QMouseEvent lastMouseEvent;
126     void replayLastMouseEvent();
127     void storeMouseEvent(QMouseEvent *event);
128     void mouseMoveEventHandler(QMouseEvent *event);
129 
130     QPointF lastCenterPoint;
131     Qt::Alignment alignment;
132 
133     QGraphicsView::ViewportAnchor transformationAnchor;
134     QGraphicsView::ViewportAnchor resizeAnchor;
135     QGraphicsView::ViewportUpdateMode viewportUpdateMode;
136     QGraphicsView::OptimizationFlags optimizationFlags;
137 
138     QPointer<QGraphicsScene> scene;
139 #if QT_CONFIG(rubberband)
140     QRect rubberBandRect;
141     QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const;
142     void updateRubberBand(const QMouseEvent *event);
143     void clearRubberBand();
144     bool rubberBanding;
145     Qt::ItemSelectionMode rubberBandSelectionMode;
146     Qt::ItemSelectionOperation rubberBandSelectionOperation;
147 #endif
148     int handScrollMotions;
149 
150     QGraphicsView::CacheMode cacheMode;
151 
152     QVector<QStyleOptionGraphicsItem> styleOptions;
153     QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
154     void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
155 
156     QBrush backgroundBrush;
157     QBrush foregroundBrush;
158     QPixmap backgroundPixmap;
159     QRegion backgroundPixmapExposed;
160 
161 #ifndef QT_NO_CURSOR
162     QCursor originalCursor;
163     bool hasStoredOriginalCursor;
164     void _q_setViewportCursor(const QCursor &cursor);
165     void _q_unsetViewportCursor();
166 #endif
167 
168     QGraphicsSceneDragDropEvent *lastDragDropEvent;
169     void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event);
170     void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
171                                     QDropEvent *source);
172 
173     QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
174     QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
175     QRegion dirtyRegion;
176     QRect dirtyBoundingRect;
177     void processPendingUpdates();
updateAll()178     inline void updateAll()
179     {
180         viewport->update();
181         fullUpdatePending = true;
182         dirtyBoundingRect = QRect();
183         dirtyRegion = QRegion();
184     }
185 
dispatchPendingUpdateRequests()186     inline void dispatchPendingUpdateRequests()
187     {
188         if (qt_widget_private(viewport)->shouldPaintOnScreen())
189             QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest);
190         else
191             QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest);
192     }
193 
194     void setUpdateClip(QGraphicsItem *);
195 
updateRectF(const QRectF & rect)196     inline bool updateRectF(const QRectF &rect)
197     {
198         if (rect.isEmpty())
199             return false;
200         if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
201             return updateRect(rect.toAlignedRect().adjusted(-1, -1, 1, 1));
202         return updateRect(rect.toAlignedRect().adjusted(-2, -2, 2, 2));
203     }
204 
205     bool updateRect(const QRect &rect);
206     bool updateRegion(const QRectF &rect, const QTransform &xform);
207     bool updateSceneSlotReimplementedChecked;
208     QRegion exposedRegion;
209 
210     QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems,
211                                      const QTransform &viewTransform) const;
212 
213     QPointF mapToScene(const QPointF &point) const;
214     QRectF mapToScene(const QRectF &rect) const;
215     static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent);
216     void updateInputMethodSensitivity();
217 };
218 
219 QT_END_NAMESPACE
220 
221 #endif
222