diff options
author | Andy Maloney <asmaloney@gmail.com> | 2015-01-04 13:41:25 -0500 |
---|---|---|
committer | Andy Maloney <asmaloney@gmail.com> | 2015-01-13 13:04:40 +0100 |
commit | 75f2a0b4ef721b135c42d8e08d70bbdd0ed04c4c (patch) | |
tree | a6dca5a8babb7fedc2ac89609bc59c8a3fd89235 /src/widgets/graphicsview/qgraphicsview.cpp | |
parent | f0f5beb0e5db5538b38f07e6ecab89cc292ef609 (diff) |
Extend selections in QGraphicsView when selection extension key down
If the user has some objects selected and holds down the "extend selection"
key (Control on Windows, Command on Mac OS X), clicking and dragging a
rubber band selection deselects the current selection. This is
counter-intuitive and confusing for users.
This commit fixes the behavior so users can extend selections using the
rubber band when the proper key is held down.
Task-number: QTBUG-6523
Change-Id: Ieda4aaa50adb351c0405f5cb8aae23332eec58a9
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsview.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 5484ecb96e..b92655013e 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -350,6 +350,7 @@ QGraphicsViewPrivate::QGraphicsViewPrivate() #ifndef QT_NO_RUBBERBAND rubberBanding(false), rubberBandSelectionMode(Qt::IntersectsItemShape), + rubberBandSelectionOperation(Qt::ReplaceSelection), #endif handScrollMotions(0), cacheMode(0), #ifndef QT_NO_CURSOR @@ -735,6 +736,7 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) // if we didn't get the release events). if (!event->buttons()) { rubberBanding = false; + rubberBandSelectionOperation = Qt::ReplaceSelection; if (!rubberBandRect.isNull()) { rubberBandRect = QRect(); emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF()); @@ -768,7 +770,7 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) selectionArea.addPolygon(q->mapToScene(rubberBandRect)); selectionArea.closeSubpath(); if (scene) - scene->setSelectionArea(selectionArea, rubberBandSelectionMode, q->viewportTransform()); + scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform()); } #endif @@ -3289,8 +3291,14 @@ void QGraphicsView::mousePressEvent(QMouseEvent *event) d->rubberBanding = true; d->rubberBandRect = QRect(); if (d->scene) { - // Initiating a rubber band always clears the selection. - d->scene->clearSelection(); + bool extendSelection = (event->modifiers() & Qt::ControlModifier) != 0; + + if (extendSelection) { + d->rubberBandSelectionOperation = Qt::AddToSelection; + } else { + d->rubberBandSelectionOperation = Qt::ReplaceSelection; + d->scene->clearSelection(); + } } } } else @@ -3347,6 +3355,7 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event) d->updateAll(); } d->rubberBanding = false; + d->rubberBandSelectionOperation = Qt::ReplaceSelection; if (!d->rubberBandRect.isNull()) { d->rubberBandRect = QRect(); emit rubberBandChanged(d->rubberBandRect, QPointF(), QPointF()); |