diff --git a/source/celview.cpp b/source/celview.cpp index 4564469da..c20a36114 100644 --- a/source/celview.cpp +++ b/source/celview.cpp @@ -22,16 +22,43 @@ CelScene::CelScene(QWidget *v) void CelScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() != Qt::LeftButton) { - return; - } + switch (event->button()) { + case Qt::LeftButton: { + // return if currently set drag mode is scroll hand drag + if (views()[0]->dragMode() == QGraphicsView::ScrollHandDrag) + return; - int x = event->scenePos().x(); - int y = event->scenePos().y(); + int x = event->scenePos().x(); + int y = event->scenePos().y(); - qDebug() << "Clicked: " << x << "," << y; + qDebug() << "Clicked: " << x << "," << y; - emit this->framePixelClicked(x, y); + emit this->framePixelClicked(x, y); + break; + } + case Qt::MiddleButton: { + views()[0]->setDragMode(QGraphicsView::ScrollHandDrag); + + // after middle button has been pressed - send the mouse press event to QGraphicsView that holds this scene, since + // it will toggle on dragging on ScrollHandDrag + QMouseEvent eventGraphicsView(QEvent::MouseButtonPress, event->scenePos(), event->scenePos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QApplication::sendEvent(views()[0]->viewport(), &eventGraphicsView); + break; + } + } +} + +void CelScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + switch (event->button()) { + case Qt::LeftButton: { + break; + } + case Qt::MiddleButton: { + views()[0]->setDragMode(QGraphicsView::NoDrag); + break; + } + } } void CelScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) diff --git a/source/celview.h b/source/celview.h index abf5864ea..d5154892f 100644 --- a/source/celview.h +++ b/source/celview.h @@ -28,6 +28,7 @@ class CelScene : public QGraphicsScene { CelScene(QWidget *view); private slots: + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void dragEnterEvent(QGraphicsSceneDragDropEvent *event); void dragMoveEvent(QGraphicsSceneDragDropEvent *event);