1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QGRAPHICSVIEW_P_H |
5 | #define QGRAPHICSVIEW_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include "qgraphicsview.h" |
20 | |
21 | #include <QtGui/private/qevent_p.h> |
22 | #include <QtCore/qcoreapplication.h> |
23 | #include "qgraphicssceneevent.h" |
24 | #include <QtWidgets/qstyleoption.h> |
25 | #include <private/qabstractscrollarea_p.h> |
26 | #include <private/qapplication_p.h> |
27 | |
28 | #include <QtCore/qpointer.h> |
29 | |
30 | QT_REQUIRE_CONFIG(graphicsview); |
31 | |
32 | QT_BEGIN_NAMESPACE |
33 | |
34 | class Q_WIDGETS_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate |
35 | { |
36 | Q_DECLARE_PUBLIC(QGraphicsView) |
37 | public: |
38 | QGraphicsViewPrivate(); |
39 | ~QGraphicsViewPrivate(); |
40 | |
41 | void recalculateContentSize(); |
42 | void centerView(QGraphicsView::ViewportAnchor anchor); |
43 | |
44 | QPainter::RenderHints renderHints; |
45 | |
46 | QGraphicsView::DragMode dragMode; |
47 | |
48 | quint32 sceneInteractionAllowed : 1; |
49 | quint32 hasSceneRect : 1; |
50 | quint32 connectedToScene : 1; |
51 | quint32 useLastMouseEvent : 1; |
52 | quint32 identityMatrix : 1; |
53 | quint32 dirtyScroll : 1; |
54 | quint32 accelerateScrolling : 1; |
55 | quint32 keepLastCenterPoint : 1; |
56 | quint32 transforming : 1; |
57 | quint32 handScrolling : 1; |
58 | quint32 mustAllocateStyleOptions : 1; |
59 | quint32 mustResizeBackgroundPixmap : 1; |
60 | quint32 fullUpdatePending : 1; |
61 | quint32 hasUpdateClip : 1; |
62 | quint32 padding : 18; |
63 | |
64 | QRectF sceneRect; |
65 | void updateLastCenterPoint(); |
66 | |
67 | qint64 horizontalScroll() const; |
68 | qint64 verticalScroll() const; |
69 | |
70 | QRectF mapRectToScene(const QRect &rect) const; |
71 | QRectF mapRectFromScene(const QRectF &rect) const; |
72 | |
73 | QRect updateClip; |
74 | QPointF mousePressItemPoint; |
75 | QPointF mousePressScenePoint; |
76 | QPoint mousePressViewPoint; |
77 | QPoint mousePressScreenPoint; |
78 | QPointF lastMouseMoveScenePoint; |
79 | QPointF lastRubberbandScenePoint; |
80 | QPoint lastMouseMoveScreenPoint; |
81 | QPoint dirtyScrollOffset; |
82 | Qt::MouseButton mousePressButton; |
83 | QTransform matrix; |
84 | qint64 scrollX, scrollY; |
85 | void updateScroll(); |
86 | bool canStartScrollingAt(const QPoint &startPos) const override; |
87 | |
88 | qreal leftIndent; |
89 | qreal topIndent; |
90 | |
91 | // Replaying mouse events |
92 | QMutableSinglePointEvent lastMouseEvent; |
93 | void replayLastMouseEvent(); |
94 | void storeMouseEvent(QMouseEvent *event); |
95 | void mouseMoveEventHandler(QMouseEvent *event); |
96 | |
97 | QPointF lastCenterPoint; |
98 | Qt::Alignment alignment; |
99 | |
100 | QGraphicsView::ViewportAnchor transformationAnchor; |
101 | QGraphicsView::ViewportAnchor resizeAnchor; |
102 | QGraphicsView::ViewportUpdateMode viewportUpdateMode; |
103 | QGraphicsView::OptimizationFlags optimizationFlags; |
104 | |
105 | bool stereoEnabled = false; // Set in setupViewport() |
106 | |
107 | QPointer<QGraphicsScene> scene; |
108 | #if QT_CONFIG(rubberband) |
109 | QRect rubberBandRect; |
110 | QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const; |
111 | void updateRubberBand(const QMouseEvent *event); |
112 | void clearRubberBand(); |
113 | bool rubberBanding; |
114 | Qt::ItemSelectionMode rubberBandSelectionMode; |
115 | Qt::ItemSelectionOperation rubberBandSelectionOperation; |
116 | #endif |
117 | int handScrollMotions; |
118 | |
119 | QGraphicsView::CacheMode cacheMode; |
120 | |
121 | QList<QStyleOptionGraphicsItem> styleOptions; |
122 | QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems); |
123 | void freeStyleOptionsArray(QStyleOptionGraphicsItem *array); |
124 | |
125 | QBrush backgroundBrush; |
126 | QBrush foregroundBrush; |
127 | QPixmap backgroundPixmap; |
128 | QRegion backgroundPixmapExposed; |
129 | |
130 | #ifndef QT_NO_CURSOR |
131 | QCursor originalCursor; |
132 | bool hasStoredOriginalCursor; |
133 | void _q_setViewportCursor(const QCursor &cursor); |
134 | void _q_unsetViewportCursor(); |
135 | #endif |
136 | |
137 | QGraphicsSceneDragDropEvent *lastDragDropEvent; |
138 | void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event); |
139 | void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest, |
140 | QDropEvent *source); |
141 | |
142 | QTransform mapToViewTransform(const QGraphicsItem *item) const; |
143 | QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const; |
144 | QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const; |
145 | QRegion dirtyRegion; |
146 | QRect dirtyBoundingRect; |
147 | void processPendingUpdates(); |
148 | inline void updateAll() |
149 | { |
150 | viewport->update(); |
151 | fullUpdatePending = true; |
152 | dirtyBoundingRect = QRect(); |
153 | dirtyRegion = QRegion(); |
154 | } |
155 | |
156 | inline void dispatchPendingUpdateRequests() |
157 | { |
158 | if (qt_widget_private(widget: viewport)->shouldPaintOnScreen()) |
159 | QCoreApplication::sendPostedEvents(receiver: viewport, event_type: QEvent::UpdateRequest); |
160 | else |
161 | QCoreApplication::sendPostedEvents(receiver: viewport->window(), event_type: QEvent::UpdateRequest); |
162 | } |
163 | |
164 | void setUpdateClip(QGraphicsItem *); |
165 | |
166 | inline bool updateRectF(const QRectF &rect) |
167 | { |
168 | if (rect.isEmpty()) |
169 | return false; |
170 | if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing) |
171 | return updateRect(rect: rect.toAlignedRect().adjusted(xp1: -1, yp1: -1, xp2: 1, yp2: 1)); |
172 | return updateRect(rect: rect.toAlignedRect().adjusted(xp1: -2, yp1: -2, xp2: 2, yp2: 2)); |
173 | } |
174 | |
175 | bool updateRect(const QRect &rect); |
176 | bool updateRegion(const QRectF &rect, const QTransform &xform); |
177 | bool updateSceneSlotReimplementedChecked; |
178 | QRegion exposedRegion; |
179 | |
180 | QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems, |
181 | const QTransform &viewTransform) const; |
182 | |
183 | QPointF mapToScene(const QPointF &point) const; |
184 | QRectF mapToScene(const QRectF &rect) const; |
185 | static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent); |
186 | void updateInputMethodSensitivity(); |
187 | }; |
188 | |
189 | QT_END_NAMESPACE |
190 | |
191 | #endif |
192 | |