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
28QT_REQUIRE_CONFIG(graphicsview);
29
30QT_BEGIN_NAMESPACE
31
32class Q_WIDGETS_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
33{
34 Q_DECLARE_PUBLIC(QGraphicsView)
35public:
36 QGraphicsViewPrivate();
37 ~QGraphicsViewPrivate();
38
39 void recalculateContentSize();
40 void centerView(QGraphicsView::ViewportAnchor anchor);
41
42 QPainter::RenderHints renderHints;
43
44 QGraphicsView::DragMode dragMode;
45
46 quint32 sceneInteractionAllowed : 1;
47 quint32 hasSceneRect : 1;
48 quint32 connectedToScene : 1;
49 quint32 useLastMouseEvent : 1;
50 quint32 identityMatrix : 1;
51 quint32 dirtyScroll : 1;
52 quint32 accelerateScrolling : 1;
53 quint32 keepLastCenterPoint : 1;
54 quint32 transforming : 1;
55 quint32 handScrolling : 1;
56 quint32 mustAllocateStyleOptions : 1;
57 quint32 mustResizeBackgroundPixmap : 1;
58 quint32 fullUpdatePending : 1;
59 quint32 hasUpdateClip : 1;
60 quint32 padding : 18;
61
62 QRectF sceneRect;
63 void updateLastCenterPoint();
64
65 qint64 horizontalScroll() const;
66 qint64 verticalScroll() const;
67
68 QRectF mapRectToScene(const QRect &rect) const;
69 QRectF mapRectFromScene(const QRectF &rect) const;
70
71 QRect updateClip;
72 QPointF mousePressItemPoint;
73 QPointF mousePressScenePoint;
74 QPoint mousePressViewPoint;
75 QPoint mousePressScreenPoint;
76 QPointF lastMouseMoveScenePoint;
77 QPointF lastRubberbandScenePoint;
78 QPoint lastMouseMoveScreenPoint;
79 QPoint dirtyScrollOffset;
80 Qt::MouseButton mousePressButton;
81 QTransform matrix;
82 qint64 scrollX, scrollY;
83 void updateScroll();
84 bool canStartScrollingAt(const QPoint &startPos) const override;
85
86 qreal leftIndent;
87 qreal topIndent;
88
89 // Replaying mouse events
90 QMutableSinglePointEvent lastMouseEvent;
91 void replayLastMouseEvent();
92 void storeMouseEvent(QMouseEvent *event);
93 void mouseMoveEventHandler(QMouseEvent *event);
94
95 QPointF lastCenterPoint;
96 Qt::Alignment alignment;
97
98 QGraphicsView::ViewportAnchor transformationAnchor;
99 QGraphicsView::ViewportAnchor resizeAnchor;
100 QGraphicsView::ViewportUpdateMode viewportUpdateMode;
101 QGraphicsView::OptimizationFlags optimizationFlags;
102
103 bool stereoEnabled = false; // Set in setupViewport()
104
105 QPointer<QGraphicsScene> scene;
106#if QT_CONFIG(rubberband)
107 QRect rubberBandRect;
108 QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const;
109 void updateRubberBand(const QMouseEvent *event);
110 void clearRubberBand();
111 bool rubberBanding;
112 Qt::ItemSelectionMode rubberBandSelectionMode;
113 Qt::ItemSelectionOperation rubberBandSelectionOperation;
114#endif
115 int handScrollMotions;
116
117 QGraphicsView::CacheMode cacheMode;
118
119 QList<QStyleOptionGraphicsItem> styleOptions;
120 QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
121 void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
122
123 QBrush backgroundBrush;
124 QBrush foregroundBrush;
125 QPixmap backgroundPixmap;
126 QRegion backgroundPixmapExposed;
127
128#ifndef QT_NO_CURSOR
129 QCursor originalCursor;
130 bool hasStoredOriginalCursor;
131 void _q_setViewportCursor(const QCursor &cursor);
132 void _q_unsetViewportCursor();
133#endif
134
135 QGraphicsSceneDragDropEvent *lastDragDropEvent;
136 void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event);
137 void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
138 QDropEvent *source);
139
140 QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
141 QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
142 QRegion dirtyRegion;
143 QRect dirtyBoundingRect;
144 void processPendingUpdates();
145 inline void updateAll()
146 {
147 viewport->update();
148 fullUpdatePending = true;
149 dirtyBoundingRect = QRect();
150 dirtyRegion = QRegion();
151 }
152
153 inline void dispatchPendingUpdateRequests()
154 {
155 if (qt_widget_private(widget: viewport)->shouldPaintOnScreen())
156 QCoreApplication::sendPostedEvents(receiver: viewport, event_type: QEvent::UpdateRequest);
157 else
158 QCoreApplication::sendPostedEvents(receiver: viewport->window(), event_type: QEvent::UpdateRequest);
159 }
160
161 void setUpdateClip(QGraphicsItem *);
162
163 inline bool updateRectF(const QRectF &rect)
164 {
165 if (rect.isEmpty())
166 return false;
167 if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
168 return updateRect(rect: rect.toAlignedRect().adjusted(xp1: -1, yp1: -1, xp2: 1, yp2: 1));
169 return updateRect(rect: rect.toAlignedRect().adjusted(xp1: -2, yp1: -2, xp2: 2, yp2: 2));
170 }
171
172 bool updateRect(const QRect &rect);
173 bool updateRegion(const QRectF &rect, const QTransform &xform);
174 bool updateSceneSlotReimplementedChecked;
175 QRegion exposedRegion;
176
177 QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems,
178 const QTransform &viewTransform) const;
179
180 QPointF mapToScene(const QPointF &point) const;
181 QRectF mapToScene(const QRectF &rect) const;
182 static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent);
183 void updateInputMethodSensitivity();
184};
185
186QT_END_NAMESPACE
187
188#endif
189

source code of qtbase/src/widgets/graphicsview/qgraphicsview_p.h