From 254ccf8f523c82ffad7f1e4fe0bf70cc39f2f4dd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 30 Mar 2016 11:51:09 +0300 Subject: [PATCH] Toggle ScrollHandDrag mode by clicking a middle mouse button. --HG-- branch : develop --- ChangeLog.txt | 1 + src/libs/vwidgets/vmaingraphicsscene.cpp | 8 --- src/libs/vwidgets/vmaingraphicsview.cpp | 64 +++++++++++++----------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a7586e318..9d35c42bb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- Toggle ScrollHandDrag mode by clicking a middle mouse button. - Added horizontal scrolling by pressiong Shift + mouse wheel. - [#366] Update 'Point from Distance and Angle' tool to read distance and angle between points. - [#395] Create Curve tool which uses point as control handle. diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index 59e0b0080..30e93f5ad 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -80,14 +80,6 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) } QGraphicsScene::mousePressEvent(event); -// if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) -// { -// QList items = selectedItems(); -// for (int i=0; i< items.size(); i++) -// { -// items[i]->setSelected(false); -// } -// } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index aea47ee32..10a61f9fa 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -382,43 +382,49 @@ void VMainGraphicsView::ZoomFitBest() */ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) { - if (mousePress->button() & Qt::LeftButton) + switch (mousePress->button()) { - switch (QGuiApplication::keyboardModifiers()) + case Qt::LeftButton: { - case Qt::ControlModifier: - QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); - break; - case Qt::NoModifier: - if (showToolOptions) + QGraphicsView::setDragMode(QGraphicsView::RubberBandDrag); + if (showToolOptions) + { + QList list = items(mousePress->pos()); + if (list.size() == 0) { - QList list = items(mousePress->pos()); - if (list.size() == 0) + emit itemClicked(nullptr); + break; + } + for (int i = 0; i < list.size(); ++i) + { + if (this->scene()->items().contains(list.at(i))) { - emit itemClicked(nullptr); - break; - } - for (int i = 0; i < list.size(); ++i) - { - if (this->scene()->items().contains(list.at(i))) + if (list.at(i)->type() <= VSimplePoint::Type && + list.at(i)->type() > QGraphicsItem::UserType) { - if (list.at(i)->type() <= VSimplePoint::Type && - list.at(i)->type() > QGraphicsItem::UserType) - { - emit itemClicked(list.at(i)); - break; - } - else - { - emit itemClicked(nullptr); - } + emit itemClicked(list.at(i)); + break; + } + else + { + emit itemClicked(nullptr); } } } - break; - default: - break; + } + break; } + case Qt::MiddleButton: + { + QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); + // create a new mouse event that simulates a click of the left button instead of the middle button + QMouseEvent mouseEvent (mousePress->type(), mousePress->pos(), Qt::LeftButton, Qt::LeftButton, + mousePress->modifiers()); + QGraphicsView::mousePressEvent(&mouseEvent); + return; + } + default: + break; } QGraphicsView::mousePressEvent(mousePress); } @@ -431,7 +437,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event) { QGraphicsView::mouseReleaseEvent ( event ); - QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag ); + QGraphicsView::setDragMode( QGraphicsView::NoDrag ); if (event->button() == Qt::LeftButton) { emit MouseRelease();