diff --git a/CMakeLists.txt b/CMakeLists.txt index 518dcad6f..ec1d49ea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +include_directories(source/) set(PROJECT_SOURCES source/celview.cpp source/celview.h @@ -49,6 +51,8 @@ set(PROJECT_SOURCES source/exportdialog.cpp source/exportdialog.h source/exportdialog.ui + source/view.cpp + source/view.h source/levelcelview.cpp source/levelcelview.h source/levelcelview.ui diff --git a/source/celview.cpp b/source/celview.cpp index 4564469da..ef9d05e89 100644 --- a/source/celview.cpp +++ b/source/celview.cpp @@ -22,6 +22,10 @@ CelScene::CelScene(QWidget *v) void CelScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { + // return if currently set drag mode is scroll hand drag + if (views()[0]->dragMode() == QGraphicsView::ScrollHandDrag) + return; + if (event->button() != Qt::LeftButton) { return; } diff --git a/source/view.cpp b/source/view.cpp new file mode 100644 index 000000000..4c036b03c --- /dev/null +++ b/source/view.cpp @@ -0,0 +1,45 @@ +#include "view.h" + +View::View(QWidget *parent) + : QGraphicsView(parent) +{ +} + +void View::mousePressEvent(QMouseEvent *event) +{ + switch (event->button()) { + case Qt::LeftButton: { + QGraphicsView::mousePressEvent(event); + break; + } + case Qt::MiddleButton: { + this->setDragMode(QGraphicsView::ScrollHandDrag); + + // after middle button has been pressed - send the mouse press event to base + // class that holds this scene, since it will toggle on dragging on ScrollHandDrag + QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, + event->pos(), event->globalPosition(), Qt::MouseButton::LeftButton, + Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier); + + QGraphicsView::mousePressEvent(pressEvent); + break; + } + default: { + QGraphicsView::mousePressEvent(event); + break; + } + } +} + +void View::mouseReleaseEvent(QMouseEvent *event) +{ + switch (event->button()) { + case Qt::LeftButton: { + break; + } + case Qt::MiddleButton: { + this->setDragMode(QGraphicsView::NoDrag); + break; + } + } +} diff --git a/source/view.h b/source/view.h new file mode 100644 index 000000000..62de97ddf --- /dev/null +++ b/source/view.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +class View : public QGraphicsView { + Q_OBJECT + +public: + View(QWidget *parent = nullptr); + +private slots: + void mouseReleaseEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); +};