diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2012-12-10 08:16:31 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-26 13:31:45 +0100 |
commit | c56f73cc1e8f4a0a2d55d713b152548efcc595aa (patch) | |
tree | 1648a6643c5c9e210a5297a0d344a7e1fb42aa7b /src/widgets/graphicsview | |
parent | 932c50c015fe416354b08cea50581fa5fdfee86e (diff) |
QGraphicsView - add function to get RubberBand rect
In many situations it is handy to know the rubberband rect.
There are many situations where we want to show something
related to the rubberband.
Regardless how that is done the rubberband area is needed.
(Not having this is a flaw that can force people to do make
a customized rubberband just to get this information)
Change-Id: Ia854db4c0022b6a97b150af2b4bb78fd5e974991
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 23 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.h | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 9c04a3c193..741d6658cc 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -1496,7 +1496,7 @@ void QGraphicsView::setDragMode(DragMode mode) The default value is Qt::IntersectsItemShape; all items whose shape intersects with or is contained by the rubber band are selected. - \sa dragMode, items() + \sa dragMode, items(), rubberBandRect() */ Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const { @@ -1508,6 +1508,27 @@ void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode) Q_D(QGraphicsView); d->rubberBandSelectionMode = mode; } + +/*! + \since 5.1 + This functions returns the current rubber band area (in viewport coordinates) if the user + is currently doing an itemselection with rubber band. When the user is not using the + rubber band this functions returns (a null) QRectF(). + + Notice that part of this QRect can be outise the visual viewport. It can e.g + contain negative values. + + \sa rubberBandSelectionMode +*/ + +QRect QGraphicsView::rubberBandRect() const +{ + Q_D(const QGraphicsView); + if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding) + return QRect(); + + return d->rubberBandRect; +} #endif /*! diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h index 565e89995f..a2981aec27 100644 --- a/src/widgets/graphicsview/qgraphicsview.h +++ b/src/widgets/graphicsview/qgraphicsview.h @@ -146,6 +146,7 @@ public: #ifndef QT_NO_RUBBERBAND Qt::ItemSelectionMode rubberBandSelectionMode() const; void setRubberBandSelectionMode(Qt::ItemSelectionMode mode); + QRect rubberBandRect() const; #endif CacheMode cacheMode() const; |