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 bool canStartScrollingAt(const QPoint &startPos) const override;
121
122 qreal leftIndent;
123 qreal topIndent;
124
125 // Replaying mouse events
126 QMouseEvent lastMouseEvent;
127 void replayLastMouseEvent();
128 void storeMouseEvent(QMouseEvent *event);
129 void mouseMoveEventHandler(QMouseEvent *event);
130
131 QPointF lastCenterPoint;
132 Qt::Alignment alignment;
133
134 QGraphicsView::ViewportAnchor transformationAnchor;
135 QGraphicsView::ViewportAnchor resizeAnchor;
136 QGraphicsView::ViewportUpdateMode viewportUpdateMode;
137 QGraphicsView::OptimizationFlags optimizationFlags;
138
139 QPointer<QGraphicsScene> scene;
140#if QT_CONFIG(rubberband)
141 QRect rubberBandRect;
142 QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const;
143 void updateRubberBand(const QMouseEvent *event);
144 void clearRubberBand();
145 bool rubberBanding;
146 Qt::ItemSelectionMode rubberBandSelectionMode;
147 Qt::ItemSelectionOperation rubberBandSelectionOperation;
148#endif
149 int handScrollMotions;
150
151 QGraphicsView::CacheMode cacheMode;
152
153 QList<QStyleOptionGraphicsItem> styleOptions;
154 QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
155 void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
156
157 QBrush backgroundBrush;
158 QBrush foregroundBrush;
159 QPixmap backgroundPixmap;
160 QRegion backgroundPixmapExposed;
161
162#ifndef QT_NO_CURSOR
163 QCursor originalCursor;
164 bool hasStoredOriginalCursor;
165 void _q_setViewportCursor(const QCursor &cursor);
166 void _q_unsetViewportCursor();
167#endif
168
169 QGraphicsSceneDragDropEvent *lastDragDropEvent;
170 void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event);
171 void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
172 QDropEvent *source);
173
174 QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
175 QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
176 QRegion dirtyRegion;
177 QRect dirtyBoundingRect;
178 void processPendingUpdates();
179 inline void updateAll()
180 {
181 viewport->update();
182 fullUpdatePending = true;
183 dirtyBoundingRect = QRect();
184 dirtyRegion = QRegion();
185 }
186
187 inline void dispatchPendingUpdateRequests()
188 {
189 if (qt_widget_private(viewport)->shouldPaintOnScreen())
190 QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest);
191 else
192 QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest);
193 }
194
195 void setUpdateClip(QGraphicsItem *);
196
197 inline bool updateRectF(const QRectF &rect)
198 {
199 if (rect.isEmpty())
200 return false;
201 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
202 return updateRect(rect.toAlignedRect().adjusted(-1, -1, 1, 1));
203 return updateRect(rect.toAlignedRect().adjusted(-2, -2, 2, 2));
204 }
205
206 bool updateRect(const QRect &rect);
207 bool updateRegion(const QRectF &rect, const QTransform &xform);
208 bool updateSceneSlotReimplementedChecked;
209 QRegion exposedRegion;
210
211 QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems,
212 const QTransform &viewTransform) const;
213
214 QPointF mapToScene(const QPointF &point) const;
215 QRectF mapToScene(const QRectF &rect) const;
216 static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent);
217 void updateInputMethodSensitivity();
218};
219
220QT_END_NAMESPACE
221
222#endif
223