1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
| #ifndef QGRAPHICSVIEW_H #define QGRAPHICSVIEW_H
#include <QtWidgets/qtwidgetsglobal.h> #include <QtCore/qmetatype.h> #include <QtGui/qpainter.h> #include <QtWidgets/qscrollarea.h> #include <QtWidgets/qgraphicsscene.h>
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
class QGraphicsItem; class QPainterPath; class QPolygonF; class QStyleOptionGraphicsItem;
class QGraphicsViewPrivate; class Q_WIDGETS_EXPORT QGraphicsView : public QAbstractScrollArea { Q_OBJECT Q_FLAGS(QPainter::RenderHints CacheMode OptimizationFlags) Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush) Q_PROPERTY(QBrush foregroundBrush READ foregroundBrush WRITE setForegroundBrush) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) Q_PROPERTY(QRectF sceneRect READ sceneRect WRITE setSceneRect) Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints) Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode) Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode) Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor WRITE setTransformationAnchor) Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor) Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode WRITE setViewportUpdateMode) #if QT_CONFIG(rubberband) Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode WRITE setRubberBandSelectionMode) #endif Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags WRITE setOptimizationFlags)
public: enum ViewportAnchor { NoAnchor, AnchorViewCenter, AnchorUnderMouse }; Q_ENUM(ViewportAnchor)
enum CacheModeFlag { CacheNone = 0x0, CacheBackground = 0x1 }; Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)
enum DragMode { NoDrag, ScrollHandDrag, RubberBandDrag }; Q_ENUM(DragMode)
enum ViewportUpdateMode { FullViewportUpdate, MinimalViewportUpdate, SmartViewportUpdate, NoViewportUpdate, BoundingRectViewportUpdate }; Q_ENUM(ViewportUpdateMode)
enum OptimizationFlag { #if QT_DEPRECATED_SINCE(5, 14) DontClipPainter Q_DECL_ENUMERATOR_DEPRECATED_X("This flag is unused") = 0x1, #endif DontSavePainterState = 0x2, DontAdjustForAntialiasing = 0x4, IndirectPainting = 0x8 }; Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
QGraphicsView(QWidget *parent = nullptr); QGraphicsView(QGraphicsScene *scene, QWidget *parent = nullptr); ~QGraphicsView();
QSize sizeHint() const override;
QPainter::RenderHints renderHints() const; void setRenderHint(QPainter::RenderHint hint, bool enabled = true); void setRenderHints(QPainter::RenderHints hints);
Qt::Alignment alignment() const; void setAlignment(Qt::Alignment alignment);
ViewportAnchor transformationAnchor() const; void setTransformationAnchor(ViewportAnchor anchor);
ViewportAnchor resizeAnchor() const; void setResizeAnchor(ViewportAnchor anchor);
ViewportUpdateMode viewportUpdateMode() const; void setViewportUpdateMode(ViewportUpdateMode mode);
OptimizationFlags optimizationFlags() const; void setOptimizationFlag(OptimizationFlag flag, bool enabled = true); void setOptimizationFlags(OptimizationFlags flags);
DragMode dragMode() const; void setDragMode(DragMode mode);
#if QT_CONFIG(rubberband) Qt::ItemSelectionMode rubberBandSelectionMode() const; void setRubberBandSelectionMode(Qt::ItemSelectionMode mode); QRect rubberBandRect() const; #endif
CacheMode cacheMode() const; void setCacheMode(CacheMode mode); void resetCachedContent();
bool isInteractive() const; void setInteractive(bool allowed);
QGraphicsScene *scene() const; void setScene(QGraphicsScene *scene);
QRectF sceneRect() const; void setSceneRect(const QRectF &rect); inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
#if QT_DEPRECATED_SINCE(5, 15) QT_DEPRECATED_X("Use transform()") QMatrix matrix() const; QT_DEPRECATED_X("Use setTransform()") void setMatrix(const QMatrix &matrix, bool combine = false); QT_DEPRECATED_X("Use resetTransform()") void resetMatrix(); #endif QTransform transform() const; QTransform viewportTransform() const; bool isTransformed() const; void setTransform(const QTransform &matrix, bool combine = false); void resetTransform(); void rotate(qreal angle); void scale(qreal sx, qreal sy); void shear(qreal sh, qreal sv); void translate(qreal dx, qreal dy);
void centerOn(const QPointF &pos); inline void centerOn(qreal x, qreal y); void centerOn(const QGraphicsItem *item); void ensureVisible(const QRectF &rect, int xmargin = 50, int ymargin = 50); inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50); void ensureVisible(const QGraphicsItem *item, int xmargin = 50, int ymargin = 50); void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio); inline void fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio); void fitInView(const QGraphicsItem *item, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
void render(QPainter *painter, const QRectF &target = QRectF(), const QRect &source = QRect(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
QList<QGraphicsItem *> items() const; QList<QGraphicsItem *> items(const QPoint &pos) const; inline QList<QGraphicsItem *> items(int x, int y) const; QList<QGraphicsItem *> items(const QRect &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; inline QList<QGraphicsItem *> items(int x, int y, int w, int h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; QList<QGraphicsItem *> items(const QPolygon &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; QGraphicsItem *itemAt(const QPoint &pos) const; inline QGraphicsItem *itemAt(int x, int y) const;
QPointF mapToScene(const QPoint &point) const; QPolygonF mapToScene(const QRect &rect) const; QPolygonF mapToScene(const QPolygon &polygon) const; QPainterPath mapToScene(const QPainterPath &path) const; QPoint mapFromScene(const QPointF &point) const; QPolygon mapFromScene(const QRectF &rect) const; QPolygon mapFromScene(const QPolygonF &polygon) const; QPainterPath mapFromScene(const QPainterPath &path) const; inline QPointF mapToScene(int x, int y) const; inline QPolygonF mapToScene(int x, int y, int w, int h) const; inline QPoint mapFromScene(qreal x, qreal y) const; inline QPolygon mapFromScene(qreal x, qreal y, qreal w, qreal h) const;
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
QBrush backgroundBrush() const; void setBackgroundBrush(const QBrush &brush);
QBrush foregroundBrush() const; void setForegroundBrush(const QBrush &brush);
public Q_SLOTS: void updateScene(const QList<QRectF> &rects); void invalidateScene(const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers); void updateSceneRect(const QRectF &rect);
#if QT_CONFIG(rubberband) Q_SIGNALS: void rubberBandChanged(QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint); #endif
protected Q_SLOTS: void setupViewport(QWidget *widget) override;
protected: QGraphicsView(QGraphicsViewPrivate &, QWidget *parent = nullptr); bool event(QEvent *event) override; bool viewportEvent(QEvent *event) override;
#ifndef QT_NO_CONTEXTMENU void contextMenuEvent(QContextMenuEvent *event) override; #endif #if QT_CONFIG(draganddrop) void dragEnterEvent(QDragEnterEvent *event) override; void dragLeaveEvent(QDragLeaveEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; void dropEvent(QDropEvent *event) override; #endif void focusInEvent(QFocusEvent *event) override; bool focusNextPrevChild(bool next) override; void focusOutEvent(QFocusEvent *event) override; void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; #if QT_CONFIG(wheelevent) void wheelEvent(QWheelEvent *event) override; #endif void paintEvent(QPaintEvent *event) override; void resizeEvent(QResizeEvent *event) override; void scrollContentsBy(int dx, int dy) override; void showEvent(QShowEvent *event) override; void inputMethodEvent(QInputMethodEvent *event) override;
virtual void drawBackground(QPainter *painter, const QRectF &rect); virtual void drawForeground(QPainter *painter, const QRectF &rect); virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]);
private: Q_DECLARE_PRIVATE(QGraphicsView) Q_DISABLE_COPY(QGraphicsView) #ifndef QT_NO_CURSOR Q_PRIVATE_SLOT(d_func(), void _q_setViewportCursor(const QCursor &)) Q_PRIVATE_SLOT(d_func(), void _q_unsetViewportCursor()) #endif friend class QGraphicsSceneWidget; friend class QGraphicsScene; friend class QGraphicsScenePrivate; friend class QGraphicsItemPrivate; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::CacheMode) Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsView::OptimizationFlags)
inline void QGraphicsView::setSceneRect(qreal ax, qreal ay, qreal aw, qreal ah) { setSceneRect(QRectF(ax, ay, aw, ah)); } inline void QGraphicsView::centerOn(qreal ax, qreal ay) { centerOn(QPointF(ax, ay)); } inline void QGraphicsView::ensureVisible(qreal ax, qreal ay, qreal aw, qreal ah, int xmargin, int ymargin) { ensureVisible(QRectF(ax, ay, aw, ah), xmargin, ymargin); } inline void QGraphicsView::fitInView(qreal ax, qreal ay, qreal w, qreal h, Qt::AspectRatioMode mode) { fitInView(QRectF(ax, ay, w, h), mode); } inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay) const { return items(QPoint(ax, ay)); } inline QList<QGraphicsItem *> QGraphicsView::items(int ax, int ay, int w, int h, Qt::ItemSelectionMode mode) const { return items(QRect(ax, ay, w, h), mode); } inline QGraphicsItem *QGraphicsView::itemAt(int ax, int ay) const { return itemAt(QPoint(ax, ay)); } inline QPointF QGraphicsView::mapToScene(int ax, int ay) const { return mapToScene(QPoint(ax, ay)); } inline QPolygonF QGraphicsView::mapToScene(int ax, int ay, int w, int h) const { return mapToScene(QRect(ax, ay, w, h)); } inline QPoint QGraphicsView::mapFromScene(qreal ax, qreal ay) const { return mapFromScene(QPointF(ax, ay)); } inline QPolygon QGraphicsView::mapFromScene(qreal ax, qreal ay, qreal w, qreal h) const { return mapFromScene(QRectF(ax, ay, w, h)); }
QT_END_NAMESPACE
#endif
|