summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraavit <eirik.aavitsland@digia.com>2014-10-20 14:09:58 +0200
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2014-10-24 21:59:47 +0200
commit9911550fa7fa58cfef66a33ccd8b1d0c531f848e (patch)
treec8af4de74ac0d730e3d5a0ce78e6d4bb75143713
parent74a51d590f4acd189f8d0594a5a706cbf97c805b (diff)
Fix rubberband selection in rotated GraphicsView
Selection rectangle was incorrectly mapped to scene space when the view was rotated. It became a rotated rectangle instead of the correct polygon (rhombus). Task-number: QTBUG-42008 Change-Id: Ib7b366bec7e1f83109e03c434268ad6897138f30 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp43
2 files changed, 44 insertions, 1 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 88d5e52204..5484ecb96e 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -765,7 +765,7 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
}
// Set the new selection area
QPainterPath selectionArea;
- selectionArea.addPolygon(mapToScene(rubberBandRect));
+ selectionArea.addPolygon(q->mapToScene(rubberBandRect));
selectionArea.closeSubpath();
if (scene)
scene->setSelectionArea(selectionArea, rubberBandSelectionMode, q->viewportTransform());
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index d38bb86487..afd8be71e8 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -160,6 +160,7 @@ private slots:
void dragMode_scrollHand();
void dragMode_rubberBand();
void rubberBandSelectionMode();
+ void rotated_rubberBand();
void backgroundBrush();
void foregroundBrush();
void matrix();
@@ -935,6 +936,48 @@ void tst_QGraphicsView::rubberBandSelectionMode()
QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << rect);
}
+void tst_QGraphicsView::rotated_rubberBand()
+{
+ QWidget toplevel;
+ setFrameless(&toplevel);
+
+ QGraphicsScene scene;
+ const int dim = 3;
+ for (int i = 0; i < dim; i++) {
+ for (int j = 0; j < dim; j ++) {
+ QGraphicsRectItem *rect = new QGraphicsRectItem(i * 20, j * 20, 10, 10);
+ rect->setFlag(QGraphicsItem::ItemIsSelectable);
+ rect->setData(0, (i == j));
+ scene.addItem(rect);
+ }
+ }
+
+ QGraphicsView view(&scene, &toplevel);
+ QCOMPARE(view.rubberBandSelectionMode(), Qt::IntersectsItemShape);
+ view.setDragMode(QGraphicsView::RubberBandDrag);
+ view.resize(120, 120);
+ view.rotate(45);
+ toplevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
+
+ // Disable mouse tracking to prevent the window system from sending mouse
+ // move events to the viewport while we are synthesizing events. If
+ // QGraphicsView gets a mouse move event with no buttons down, it'll
+ // terminate the rubber band.
+ view.viewport()->setMouseTracking(false);
+
+ QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>());
+ int midWidth = view.viewport()->width() / 2;
+ sendMousePress(view.viewport(), QPoint(midWidth - 2, 0), Qt::LeftButton);
+ sendMouseMove(view.viewport(), QPoint(midWidth + 2, view.viewport()->height()),
+ Qt::LeftButton, Qt::LeftButton);
+ QCOMPARE(scene.selectedItems().count(), dim);
+ foreach (const QGraphicsItem *item, scene.items()) {
+ QCOMPARE(item->isSelected(), item->data(0).toBool());
+ }
+ sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton);
+}
+
void tst_QGraphicsView::backgroundBrush()
{
QGraphicsScene scene;