[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef QGRAPHICSVIEW_H
|
---|
| 43 | #define QGRAPHICSVIEW_H
|
---|
| 44 |
|
---|
| 45 | #include <QtCore/qmetatype.h>
|
---|
| 46 | #include <QtGui/qpainter.h>
|
---|
| 47 | #include <QtGui/qscrollarea.h>
|
---|
| 48 | #include <QtGui/qgraphicsscene.h>
|
---|
| 49 |
|
---|
| 50 | QT_BEGIN_HEADER
|
---|
| 51 |
|
---|
| 52 | QT_BEGIN_NAMESPACE
|
---|
| 53 |
|
---|
| 54 | QT_MODULE(Gui)
|
---|
| 55 |
|
---|
| 56 | #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
---|
| 57 |
|
---|
| 58 | class QGraphicsItem;
|
---|
| 59 | class QPainterPath;
|
---|
| 60 | class QPolygonF;
|
---|
| 61 | class QStyleOptionGraphicsItem;
|
---|
| 62 |
|
---|
| 63 | class QGraphicsViewPrivate;
|
---|
| 64 | class Q_GUI_EXPORT QGraphicsView : public QAbstractScrollArea
|
---|
| 65 | {
|
---|
| 66 | Q_OBJECT
|
---|
| 67 | Q_FLAGS(QPainter::RenderHints CacheMode OptimizationFlags)
|
---|
| 68 | Q_ENUMS(ViewportAnchor DragMode ViewportUpdateMode)
|
---|
| 69 | Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush)
|
---|
| 70 | Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush)
|
---|
| 71 | Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive)
|
---|
| 72 | Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect)
|
---|
| 73 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
|
---|
| 74 | Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
|
---|
| 75 | Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
|
---|
| 76 | Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode)
|
---|
| 77 | Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor WRITE setTransformationAnchor)
|
---|
| 78 | Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor)
|
---|
| 79 | Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode WRITE setViewportUpdateMode)
|
---|
| 80 | #ifndef QT_NO_RUBBERBAND
|
---|
| 81 | Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode WRITE setRubberBandSelectionMode)
|
---|
| 82 | #endif
|
---|
| 83 | Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags WRITE setOptimizationFlags)
|
---|
| 84 |
|
---|
| 85 | public:
|
---|
| 86 | enum ViewportAnchor {
|
---|
| 87 | NoAnchor,
|
---|
| 88 | AnchorViewCenter,
|
---|
| 89 | AnchorUnderMouse
|
---|
| 90 | };
|
---|
| 91 |
|
---|
| 92 | enum CacheModeFlag {
|
---|
| 93 | CacheNone = 0x0,
|
---|
| 94 | CacheBackground = 0x1
|
---|
| 95 | };
|
---|
| 96 | Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)
|
---|
| 97 |
|
---|
| 98 | enum DragMode {
|
---|
| 99 | NoDrag,
|
---|
| 100 | ScrollHandDrag,
|
---|
| 101 | RubberBandDrag
|
---|
| 102 | };
|
---|
| 103 |
|
---|
| 104 | enum ViewportUpdateMode {
|
---|
| 105 | FullViewportUpdate,
|
---|
| 106 | MinimalViewportUpdate,
|
---|
| 107 | SmartViewportUpdate,
|
---|
| 108 | NoViewportUpdate,
|
---|
| 109 | BoundingRectViewportUpdate
|
---|
| 110 | };
|
---|
| 111 |
|
---|
| 112 | enum OptimizationFlag {
|
---|
[561] | 113 | DontClipPainter = 0x1, // obsolete
|
---|
[2] | 114 | DontSavePainterState = 0x2,
|
---|
[561] | 115 | DontAdjustForAntialiasing = 0x4,
|
---|
| 116 | IndirectPainting = 0x8
|
---|
[2] | 117 | };
|
---|
| 118 | Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
|
---|
| 119 |
|
---|
| 120 | QGraphicsView(QWidget *parent = 0);
|
---|
| 121 | QGraphicsView(QGraphicsScene *scene, QWidget *parent = 0);
|
---|
| 122 | ~QGraphicsView();
|
---|
| 123 |
|
---|
| 124 | QSize sizeHint() const;
|
---|
| 125 |
|
---|
| 126 | QPainter::RenderHints renderHints() const;
|
---|
| 127 | void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
|
---|
| 128 | void setRenderHints(QPainter::RenderHints hints);
|
---|
| 129 |
|
---|
| 130 | Qt::Alignment alignment() const;
|
---|
| 131 | void setAlignment(Qt::Alignment alignment);
|
---|
| 132 |
|
---|
| 133 | ViewportAnchor transformationAnchor() const;
|
---|
| 134 | void setTransformationAnchor(ViewportAnchor anchor);
|
---|
| 135 |
|
---|
| 136 | ViewportAnchor resizeAnchor() const;
|
---|
| 137 | void setResizeAnchor(ViewportAnchor anchor);
|
---|
| 138 |
|
---|
| 139 | ViewportUpdateMode viewportUpdateMode() const;
|
---|
| 140 | void setViewportUpdateMode(ViewportUpdateMode mode);
|
---|
| 141 |
|
---|
| 142 | OptimizationFlags optimizationFlags() const;
|
---|
| 143 | void setOptimizationFlag(OptimizationFlag flag, bool enabled = true);
|
---|
| 144 | void setOptimizationFlags(OptimizationFlags flags);
|
---|
| 145 |
|
---|
| 146 | DragMode dragMode() const;
|
---|
| 147 | void setDragMode(DragMode mode);
|
---|
| 148 |
|
---|
| 149 | #ifndef QT_NO_RUBBERBAND
|
---|
| 150 | Qt::ItemSelectionMode rubberBandSelectionMode() const;
|
---|
| 151 | void setRubberBandSelectionMode(Qt::ItemSelectionMode mode);
|
---|
| 152 | #endif
|
---|
| 153 |
|
---|
| 154 | CacheMode cacheMode() const;
|
---|
| 155 | void setCacheMode(CacheMode mode);
|
---|
| 156 | void resetCachedContent();
|
---|
| 157 |
|
---|
| 158 | bool isInteractive() const;
|
---|
| 159 | void setInteractive(bool allowed);
|
---|
| 160 |
|
---|
| 161 | QGraphicsScene *scene() const;
|
---|
| 162 | void setScene(QGraphicsScene *scene);
|
---|
| 163 |
|
---|
| 164 | QRectF sceneRect() const;
|
---|
| 165 | void setSceneRect(const QRectF &rect);
|
---|
| 166 | inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
|
---|
| 167 |
|
---|
| 168 | QMatrix matrix() const;
|
---|
| 169 | void setMatrix(const QMatrix &matrix, bool combine = false);
|
---|
| 170 | void resetMatrix();
|
---|
| 171 | QTransform transform() const;
|
---|
| 172 | QTransform viewportTransform() const;
|
---|
[561] | 173 | bool isTransformed() const;
|
---|
[2] | 174 | void setTransform(const QTransform &matrix, bool combine = false);
|
---|
| 175 | void resetTransform();
|
---|
| 176 | void rotate(qreal angle);
|
---|
| 177 | void scale(qreal sx, qreal sy);
|
---|
| 178 | void shear(qreal sh, qreal sv);
|
---|
| 179 | void translate(qreal dx, qreal dy);
|
---|
| 180 |
|
---|
| 181 | void centerOn(const QPointF &pos);
|
---|
| 182 | inline void centerOn(qreal x, qreal y);
|
---|
| 183 | void centerOn(const QGraphicsItem *item);
|
---|
| 184 | void ensureVisible(const QRectF &rect, int xmargin = 50, int ymargin = 50);
|
---|
| 185 | inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
|
---|
| 186 | void ensureVisible(const QGraphicsItem *item, int xmargin = 50, int ymargin = 50);
|
---|
| 187 | void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
---|
| 188 | inline void fitInView(qreal x, qreal y, qreal w, qreal h,
|
---|
| 189 | Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
---|
| 190 | void fitInView(const QGraphicsItem *item,
|
---|
| 191 | Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
|
---|
| 192 |
|
---|
| 193 | void render(QPainter *painter, const QRectF &target = QRectF(), const QRect &source = QRect(),
|
---|
| 194 | Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
|
---|
| 195 |
|
---|
| 196 | QList<QGraphicsItem *> items() const;
|
---|
| 197 | QList<QGraphicsItem *> items(const QPoint &pos) const;
|
---|
| 198 | inline QList<QGraphicsItem *> items(int x, int y) const;
|
---|
| 199 | QList<QGraphicsItem *> items(const QRect &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
|
---|
| 200 | inline QList<QGraphicsItem *> items(int x, int y, int w, int h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
|
---|
| 201 | QList<QGraphicsItem *> items(const QPolygon &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
|
---|
| 202 | QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
|
---|
| 203 | QGraphicsItem *itemAt(const QPoint &pos) const;
|
---|
| 204 | inline QGraphicsItem *itemAt(int x, int y) const;
|
---|
| 205 |
|
---|
| 206 | QPointF mapToScene(const QPoint &point) const;
|
---|
| 207 | QPolygonF mapToScene(const QRect &rect) const;
|
---|
| 208 | QPolygonF mapToScene(const QPolygon &polygon) const;
|
---|
| 209 | QPainterPath mapToScene(const QPainterPath &path) const;
|
---|
| 210 | QPoint mapFromScene(const QPointF &point) const;
|
---|
| 211 | QPolygon mapFromScene(const QRectF &rect) const;
|
---|
| 212 | QPolygon mapFromScene(const QPolygonF &polygon) const;
|
---|
| 213 | QPainterPath mapFromScene(const QPainterPath &path) const;
|
---|
| 214 | inline QPointF mapToScene(int x, int y) const;
|
---|
| 215 | inline QPolygonF mapToScene(int x, int y, int w, int h) const;
|
---|
| 216 | inline QPoint mapFromScene(qreal x, qreal y) const;
|
---|
| 217 | inline QPolygon mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
|
---|
| 218 |
|
---|
| 219 | QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
|
---|
| 220 |
|
---|
| 221 | QBrush backgroundBrush() const;
|
---|
| 222 | void setBackgroundBrush(const QBrush &brush);
|
---|
| 223 |
|
---|
| 224 | QBrush foregroundBrush() const;
|
---|
| 225 | void setForegroundBrush(const QBrush &brush);
|
---|
| 226 |
|
---|
| 227 | public Q_SLOTS:
|
---|
| 228 | void updateScene(const QList<QRectF> &rects);
|
---|
| 229 | void invalidateScene(const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers);
|
---|
| 230 | void updateSceneRect(const QRectF &rect);
|
---|
| 231 |
|
---|
| 232 | protected Q_SLOTS:
|
---|
| 233 | void setupViewport(QWidget *widget);
|
---|
| 234 |
|
---|
| 235 | protected:
|
---|
| 236 | QGraphicsView(QGraphicsViewPrivate &, QWidget *parent = 0);
|
---|
| 237 | bool event(QEvent *event);
|
---|
| 238 | bool viewportEvent(QEvent *event);
|
---|
| 239 |
|
---|
| 240 | #ifndef QT_NO_CONTEXTMENU
|
---|
| 241 | void contextMenuEvent(QContextMenuEvent *event);
|
---|
| 242 | #endif
|
---|
| 243 | void dragEnterEvent(QDragEnterEvent *event);
|
---|
| 244 | void dragLeaveEvent(QDragLeaveEvent *event);
|
---|
| 245 | void dragMoveEvent(QDragMoveEvent *event);
|
---|
| 246 | void dropEvent(QDropEvent *event);
|
---|
| 247 | void focusInEvent(QFocusEvent *event);
|
---|
| 248 | bool focusNextPrevChild(bool next);
|
---|
| 249 | void focusOutEvent(QFocusEvent *event);
|
---|
| 250 | void keyPressEvent(QKeyEvent *event);
|
---|
| 251 | void keyReleaseEvent(QKeyEvent *event);
|
---|
| 252 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
| 253 | void mousePressEvent(QMouseEvent *event);
|
---|
| 254 | void mouseMoveEvent(QMouseEvent *event);
|
---|
| 255 | void mouseReleaseEvent(QMouseEvent *event);
|
---|
| 256 | #ifndef QT_NO_WHEELEVENT
|
---|
| 257 | void wheelEvent(QWheelEvent *event);
|
---|
| 258 | #endif
|
---|
| 259 | void paintEvent(QPaintEvent *event);
|
---|
| 260 | void resizeEvent(QResizeEvent *event);
|
---|
| 261 | void scrollContentsBy(int dx, int dy);
|
---|
| 262 | void showEvent(QShowEvent *event);
|
---|
| 263 | void inputMethodEvent(QInputMethodEvent *event);
|
---|
| 264 |
|
---|
| 265 | virtual void drawBackground(QPainter *painter, const QRectF &rect);
|
---|
| 266 | virtual void drawForeground(QPainter *painter, const QRectF &rect);
|
---|
| 267 | virtual void drawItems(QPainter *painter, int numItems,
|
---|
| 268 | QGraphicsItem *items[],
|
---|
| 269 | const QStyleOptionGraphicsItem options[]);
|
---|
| 270 |
|
---|
| 271 | private:
|
---|
| 272 | Q_DECLARE_PRIVATE(QGraphicsView)
|
---|
| 273 | Q_DISABLE_COPY(QGraphicsView)
|
---|
| 274 | #ifndef QT_NO_CURSOR
|
---|
| 275 | Q_PRIVATE_SLOT(d_func(), void _q_setViewportCursor(const QCursor &))
|
---|
| 276 | Q_PRIVATE_SLOT(d_func(), void _q_unsetViewportCursor())
|
---|
| 277 | #endif
|
---|
| 278 | friend class QGraphicsSceneWidget;
|
---|
| 279 | friend class QGraphicsScene;
|
---|
| 280 | friend class QGraphicsScenePrivate;
|
---|
[561] | 281 | friend class QGraphicsItemPrivate;
|
---|
[2] | 282 | };
|
---|
| 283 |
|
---|
| 284 | Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::CacheMode)
|
---|
| 285 | Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::OptimizationFlags)
|
---|
| 286 |
|
---|
| 287 | inline void QGraphicsView::setSceneRect(qreal ax, qreal ay, qreal aw, qreal ah)
|
---|
| 288 | { setSceneRect(QRectF(ax, ay, aw, ah)); }
|
---|
| 289 | inline void QGraphicsView::centerOn(qreal ax, qreal ay)
|
---|
| 290 | { centerOn(QPointF(ax, ay)); }
|
---|
| 291 | inline void QGraphicsView::ensureVisible(qreal ax, qreal ay, qreal aw, qreal ah, int xmargin, int ymargin)
|
---|
| 292 | { ensureVisible(QRectF(ax, ay, aw, ah), xmargin, ymargin); }
|
---|
| 293 | inline void QGraphicsView::fitInView(qreal ax, qreal ay, qreal w, qreal h, Qt::AspectRatioMode mode)
|
---|
| 294 | { fitInView(QRectF(ax, ay, w, h), mode); }
|
---|
| 295 | inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay) const
|
---|
| 296 | { return items(QPoint(ax, ay)); }
|
---|
| 297 | inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay, int w, int h, Qt::ItemSelectionMode mode) const
|
---|
| 298 | { return items(QRect(ax, ay, w, h), mode); }
|
---|
| 299 | inline QGraphicsItem *QGraphicsView::itemAt(int ax, int ay) const
|
---|
| 300 | { return itemAt(QPoint(ax, ay)); }
|
---|
| 301 | inline QPointF QGraphicsView::mapToScene(int ax, int ay) const
|
---|
| 302 | { return mapToScene(QPoint(ax, ay)); }
|
---|
| 303 | inline QPolygonF QGraphicsView::mapToScene(int ax, int ay, int w, int h) const
|
---|
| 304 | { return mapToScene(QRect(ax, ay, w, h)); }
|
---|
| 305 | inline QPoint QGraphicsView::mapFromScene(qreal ax, qreal ay) const
|
---|
| 306 | { return mapFromScene(QPointF(ax, ay)); }
|
---|
| 307 | inline QPolygon QGraphicsView::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const
|
---|
| 308 | { return mapFromScene(QRectF(ax, ay, w, h)); }
|
---|
| 309 |
|
---|
| 310 | #endif // QT_NO_GRAPHICSVIEW
|
---|
| 311 |
|
---|
| 312 | QT_END_NAMESPACE
|
---|
| 313 |
|
---|
| 314 | QT_END_HEADER
|
---|
| 315 |
|
---|
| 316 | #endif // QGRAPHICSVIEW_H
|
---|