From ae3e542f9fe76819c8e97cbb348d3c50bcad1ea3 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sun, 22 Oct 2023 17:59:09 +0200 Subject: [PATCH] CelView: Add dragging for mouse This patch adds dragging for mouse, so by pressing shift dragging mode is being changed to scroll hand drag, basically it allows to navigate on the image without pressing scroll bars. --- source/celview.cpp | 25 +++++++++++++++++++++++++ source/celview.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/source/celview.cpp b/source/celview.cpp index 4564469da..9bc115673 100644 --- a/source/celview.cpp +++ b/source/celview.cpp @@ -20,8 +20,23 @@ CelScene::CelScene(QWidget *v) { } +void CelScene::keyPressEvent(QKeyEvent *keyEvent) +{ + if (keyEvent->modifiers() & Qt::ShiftModifier) + static_cast(view)->setDragMode(QGraphicsView::ScrollHandDrag); +} + +void CelScene::keyReleaseEvent(QKeyEvent *keyEvent) +{ + static_cast(view)->setDragMode(QGraphicsView::NoDrag); +} + void CelScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { + // bail out if dragging mode on mouse is enabled + if (static_cast(view)->dragMode() == QGraphicsView::ScrollHandDrag) + return; + if (event->button() != Qt::LeftButton) { return; } @@ -520,3 +535,13 @@ void CelView::dropEvent(QDropEvent *event) // try to insert as frames ((MainWindow *)this->window())->openImageFiles(IMAGE_FILE_MODE::AUTO, filePaths, false); } + +void CelView::setDragMode(enum QGraphicsView::DragMode dragMode) +{ + this->ui->celGraphicsView->setDragMode(dragMode); +} + +QGraphicsView::DragMode CelView::dragMode() +{ + return this->ui->celGraphicsView->dragMode(); +} diff --git a/source/celview.h b/source/celview.h index abf5864ea..4422b1b54 100644 --- a/source/celview.h +++ b/source/celview.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,8 @@ class CelScene : public QGraphicsScene { CelScene(QWidget *view); private slots: + void keyPressEvent(QKeyEvent *keyEvent); + void keyReleaseEvent(QKeyEvent *keyEvent); void mousePressEvent(QGraphicsSceneMouseEvent *event); void dragEnterEvent(QGraphicsSceneDragDropEvent *event); void dragMoveEvent(QGraphicsSceneDragDropEvent *event); @@ -56,6 +59,8 @@ class CelView : public QWidget { void replaceCurrentFrame(const QString &imagefilePath); void removeCurrentFrame(); void regroupFrames(int numGroups); + void setDragMode(enum QGraphicsView::DragMode dragMode); + QGraphicsView::DragMode dragMode(); void displayFrame();