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
64QT_REQUIRE_CONFIG(graphicsview);
65
66QT_BEGIN_NAMESPACE
67
68class Q_WIDGETS_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
69{
70 Q_DECLARE_PUBLIC(QGraphicsView)
71public:
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 bool rubberBanding;
144 Qt::ItemSelectionMode rubberBandSelectionMode;
145 Qt::ItemSelectionOperation rubberBandSelectionOperation;
146#endif
147 int handScrollMotions;
148
149 QGraphicsView::CacheMode cacheMode;
150
151 QVector<QStyleOptionGraphicsItem> styleOptions;
152 QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
153 void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
154
155 QBrush backgroundBrush;
156 QBrush foregroundBrush;
157 QPixmap backgroundPixmap;
158 QRegion backgroundPixmapExposed;
159
160#ifndef QT_NO_CURSOR
161 QCursor originalCursor;
162 bool hasStoredOriginalCursor;
163 void _q_setViewportCursor(const QCursor &cursor);
164 void _q_unsetViewportCursor();
165#endif
166
167 QGraphicsSceneDragDropEvent *lastDragDropEvent;
168 void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event);
169 void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
170 QDropEvent *source);
171
172 QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
173 QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
174 QRegion dirtyRegion;
175 QRect dirtyBoundingRect;
176 void processPendingUpdates();
177 inline void updateAll()
178 {
179 viewport->update();
180 fullUpdatePending = true;
181 dirtyBoundingRect = QRect();
182 dirtyRegion = QRegion();
183 }
184
185 inline void dispatchPendingUpdateRequests()
186 {
187#if 0 // Used to be included in Qt4 for Q_WS_MAC
188 // QWidget::update() works slightly different on the Mac without the raster engine;
189 // it's not part of our backing store so it needs special threatment.
190 if (QApplicationPrivate::graphics_system_name != QLatin1String("raster")) {
191 // At this point either HIViewSetNeedsDisplay (Carbon) or setNeedsDisplay: YES (Cocoa)
192 // is called, which means there's a pending update request. We want to dispatch it
193 // now because otherwise graphics view updates would require two
194 // round-trips in the event loop before the item is painted.
195 extern void qt_mac_dispatchPendingUpdateRequests(QWidget *);
196 qt_mac_dispatchPendingUpdateRequests(viewport->window());
197 } else
198#endif
199 {
200 if (qt_widget_private(viewport)->paintOnScreen())
201 QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest);
202 else
203 QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest);
204 }
205 }
206
207 void setUpdateClip(QGraphicsItem *);
208
209 inline bool updateRectF(const QRectF &rect)
210 {
211 if (rect.isEmpty())
212 return false;
213 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
214 return updateRect(rect.toAlignedRect().adjusted(-1, -1, 1, 1));
215 return updateRect(rect.toAlignedRect().adjusted(-2, -2, 2, 2));
216 }
217
218 bool updateRect(const QRect &rect);
219 bool updateRegion(const QRectF &rect, const QTransform &xform);
220 bool updateSceneSlotReimplementedChecked;
221 QRegion exposedRegion;
222
223 QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems,
224 const QTransform &viewTransform) const;
225
226 QPointF mapToScene(const QPointF &point) const;
227 QRectF mapToScene(const QRectF &rect) const;
228 static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent);
229 void updateInputMethodSensitivity();
230};
231
232QT_END_NAMESPACE
233
234#endif
235