Skip to content

Commit

Permalink
CelView: Add dragging for mouse
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tetektoza committed Oct 22, 2023
1 parent 2e62c58 commit ae3e542
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions source/celview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ CelScene::CelScene(QWidget *v)
{
}

void CelScene::keyPressEvent(QKeyEvent *keyEvent)
{
if (keyEvent->modifiers() & Qt::ShiftModifier)
static_cast<CelView *>(view)->setDragMode(QGraphicsView::ScrollHandDrag);
}

void CelScene::keyReleaseEvent(QKeyEvent *keyEvent)
{
static_cast<CelView *>(view)->setDragMode(QGraphicsView::NoDrag);
}

void CelScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// bail out if dragging mode on mouse is enabled
if (static_cast<CelView *>(view)->dragMode() == QGraphicsView::ScrollHandDrag)
return;

if (event->button() != Qt::LeftButton) {
return;
}
Expand Down Expand Up @@ -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();
}
5 changes: 5 additions & 0 deletions source/celview.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneDragDropEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QPoint>
#include <QStringList>
#include <QTimer>
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ae3e542

Please sign in to comment.