| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QGRAPHICSVIEW_P_H
|
|---|
| 43 | #define QGRAPHICSVIEW_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 50 | // of other Qt classes. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include "qgraphicsview.h"
|
|---|
| 57 |
|
|---|
| 58 | #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
|---|
| 59 |
|
|---|
| 60 | #include <QtGui/qevent.h>
|
|---|
| 61 | #include <QtCore/qcoreapplication.h>
|
|---|
| 62 | #include "qgraphicssceneevent.h"
|
|---|
| 63 | #include <QtGui/qstyleoption.h>
|
|---|
| 64 | #include <private/qabstractscrollarea_p.h>
|
|---|
| 65 |
|
|---|
| 66 | QT_BEGIN_NAMESPACE
|
|---|
| 67 |
|
|---|
| 68 | class Q_GUI_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
|
|---|
| 69 | {
|
|---|
| 70 | Q_DECLARE_PUBLIC(QGraphicsView)
|
|---|
| 71 | public:
|
|---|
| 72 | QGraphicsViewPrivate();
|
|---|
| 73 |
|
|---|
| 74 | void recalculateContentSize();
|
|---|
| 75 | void centerView(QGraphicsView::ViewportAnchor anchor);
|
|---|
| 76 |
|
|---|
| 77 | QPainter::RenderHints renderHints;
|
|---|
| 78 |
|
|---|
| 79 | QGraphicsView::DragMode dragMode;
|
|---|
| 80 |
|
|---|
| 81 | quint32 sceneInteractionAllowed : 1;
|
|---|
| 82 | quint32 hasSceneRect : 1;
|
|---|
| 83 | quint32 connectedToScene : 1;
|
|---|
| 84 | quint32 useLastMouseEvent : 1;
|
|---|
| 85 | quint32 identityMatrix : 1;
|
|---|
| 86 | quint32 dirtyScroll : 1;
|
|---|
| 87 | quint32 accelerateScrolling : 1;
|
|---|
| 88 | quint32 keepLastCenterPoint : 1;
|
|---|
| 89 | quint32 transforming : 1;
|
|---|
| 90 | quint32 handScrolling : 1;
|
|---|
| 91 | quint32 mustAllocateStyleOptions : 1;
|
|---|
| 92 | quint32 mustResizeBackgroundPixmap : 1;
|
|---|
| 93 | quint32 fullUpdatePending : 1;
|
|---|
| 94 | quint32 hasUpdateClip : 1;
|
|---|
| 95 | quint32 padding : 18;
|
|---|
| 96 |
|
|---|
| 97 | QRectF sceneRect;
|
|---|
| 98 | void updateLastCenterPoint();
|
|---|
| 99 |
|
|---|
| 100 | qint64 horizontalScroll() const;
|
|---|
| 101 | qint64 verticalScroll() const;
|
|---|
| 102 |
|
|---|
| 103 | QRectF mapRectToScene(const QRect &rect) const;
|
|---|
| 104 | QRectF mapRectFromScene(const QRectF &rect) const;
|
|---|
| 105 |
|
|---|
| 106 | QRect updateClip;
|
|---|
| 107 | QPointF mousePressItemPoint;
|
|---|
| 108 | QPointF mousePressScenePoint;
|
|---|
| 109 | QPoint mousePressViewPoint;
|
|---|
| 110 | QPoint mousePressScreenPoint;
|
|---|
| 111 | QPointF lastMouseMoveScenePoint;
|
|---|
| 112 | QPoint lastMouseMoveScreenPoint;
|
|---|
| 113 | QPoint dirtyScrollOffset;
|
|---|
| 114 | Qt::MouseButton mousePressButton;
|
|---|
| 115 | QTransform matrix;
|
|---|
| 116 | qint64 scrollX, scrollY;
|
|---|
| 117 | void updateScroll();
|
|---|
| 118 |
|
|---|
| 119 | qreal leftIndent;
|
|---|
| 120 | qreal topIndent;
|
|---|
| 121 |
|
|---|
| 122 | // Replaying mouse events
|
|---|
| 123 | QMouseEvent lastMouseEvent;
|
|---|
| 124 | void replayLastMouseEvent();
|
|---|
| 125 | void storeMouseEvent(QMouseEvent *event);
|
|---|
| 126 | void mouseMoveEventHandler(QMouseEvent *event);
|
|---|
| 127 |
|
|---|
| 128 | QPointF lastCenterPoint;
|
|---|
| 129 | Qt::Alignment alignment;
|
|---|
| 130 |
|
|---|
| 131 | QGraphicsView::ViewportAnchor transformationAnchor;
|
|---|
| 132 | QGraphicsView::ViewportAnchor resizeAnchor;
|
|---|
| 133 | QGraphicsView::ViewportUpdateMode viewportUpdateMode;
|
|---|
| 134 | QGraphicsView::OptimizationFlags optimizationFlags;
|
|---|
| 135 |
|
|---|
| 136 | QPointer<QGraphicsScene> scene;
|
|---|
| 137 | #ifndef QT_NO_RUBBERBAND
|
|---|
| 138 | QRect rubberBandRect;
|
|---|
| 139 | QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const;
|
|---|
| 140 | bool rubberBanding;
|
|---|
| 141 | Qt::ItemSelectionMode rubberBandSelectionMode;
|
|---|
| 142 | #endif
|
|---|
| 143 | int handScrollMotions;
|
|---|
| 144 |
|
|---|
| 145 | QGraphicsView::CacheMode cacheMode;
|
|---|
| 146 |
|
|---|
| 147 | QVector<QStyleOptionGraphicsItem> styleOptions;
|
|---|
| 148 | QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
|
|---|
| 149 | void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
|
|---|
| 150 |
|
|---|
| 151 | QBrush backgroundBrush;
|
|---|
| 152 | QBrush foregroundBrush;
|
|---|
| 153 | QPixmap backgroundPixmap;
|
|---|
| 154 | QRegion backgroundPixmapExposed;
|
|---|
| 155 |
|
|---|
| 156 | #ifndef QT_NO_CURSOR
|
|---|
| 157 | QCursor originalCursor;
|
|---|
| 158 | bool hasStoredOriginalCursor;
|
|---|
| 159 | void _q_setViewportCursor(const QCursor &cursor);
|
|---|
| 160 | void _q_unsetViewportCursor();
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | QGraphicsSceneDragDropEvent *lastDragDropEvent;
|
|---|
| 164 | void storeDragDropEvent(const QGraphicsSceneDragDropEvent *event);
|
|---|
| 165 | void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
|
|---|
| 166 | QDropEvent *source);
|
|---|
| 167 |
|
|---|
| 168 | QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
|
|---|
| 169 | QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
|
|---|
| 170 | QRegion dirtyRegion;
|
|---|
| 171 | QRect dirtyBoundingRect;
|
|---|
| 172 | void processPendingUpdates();
|
|---|
| 173 | inline void updateAll()
|
|---|
| 174 | {
|
|---|
| 175 | viewport->update();
|
|---|
| 176 | fullUpdatePending = true;
|
|---|
| 177 | dirtyBoundingRect = QRect();
|
|---|
| 178 | dirtyRegion = QRegion();
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | inline void dispatchPendingUpdateRequests()
|
|---|
| 182 | {
|
|---|
| 183 | #ifndef Q_WS_MAC
|
|---|
| 184 | // QWidget::update() works slightly different on the Mac; it's not part of
|
|---|
| 185 | // our backing store so it needs special threatment.
|
|---|
| 186 | if (qt_widget_private(viewport)->paintOnScreen())
|
|---|
| 187 | QCoreApplication::sendPostedEvents(viewport, QEvent::UpdateRequest);
|
|---|
| 188 | else
|
|---|
| 189 | QCoreApplication::sendPostedEvents(viewport->window(), QEvent::UpdateRequest);
|
|---|
| 190 | #else
|
|---|
| 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 | #endif
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | void setUpdateClip(QGraphicsItem *);
|
|---|
| 201 |
|
|---|
| 202 | inline bool updateRectF(const QRectF &rect)
|
|---|
| 203 | {
|
|---|
| 204 | if (rect.isEmpty())
|
|---|
| 205 | return false;
|
|---|
| 206 | if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
|
|---|
| 207 | return updateRect(rect.toAlignedRect().adjusted(-1, -1, 1, 1));
|
|---|
| 208 | return updateRect(rect.toAlignedRect().adjusted(-2, -2, 2, 2));
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | bool updateRect(const QRect &rect);
|
|---|
| 212 | bool updateRegion(const QRectF &rect, const QTransform &xform);
|
|---|
| 213 | bool updateSceneSlotReimplementedChecked;
|
|---|
| 214 | QRegion exposedRegion;
|
|---|
| 215 |
|
|---|
| 216 | QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems,
|
|---|
| 217 | const QTransform &viewTransform) const;
|
|---|
| 218 |
|
|---|
| 219 | QPointF mapToScene(const QPointF &point) const;
|
|---|
| 220 | QRectF mapToScene(const QRectF &rect) const;
|
|---|
| 221 | static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent);
|
|---|
| 222 | void updateInputMethodSensitivity();
|
|---|
| 223 | };
|
|---|
| 224 |
|
|---|
| 225 | QT_END_NAMESPACE
|
|---|
| 226 |
|
|---|
| 227 | #endif // QT_NO_GRAPHICSVIEW
|
|---|
| 228 |
|
|---|
| 229 | #endif
|
|---|