From 6a484c615ae3f04873fe41a415277ef6c2c37573 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 17 Dec 2020 15:43:37 +0100 Subject: WIP --- tagview.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tagview.cpp') diff --git a/tagview.cpp b/tagview.cpp index 9a9c9a0..6bc3934 100644 --- a/tagview.cpp +++ b/tagview.cpp @@ -3,12 +3,13 @@ #include #include #include +#include TagView::TagView(QWidget *parent) : QGraphicsView(parent) , saveCenterTimer(this) { - setDragMode(QGraphicsView::ScrollHandDrag); + setDragMode(QGraphicsView::RubberBandDrag); setScene(&m_scene); connect(&m_scene, &TagScene::tagDoubleClicked, this, &TagView::tagDoubleClicked); connect(&m_scene, &TagScene::imageLoaded, this, &TagView::zoomToFit); @@ -86,6 +87,31 @@ void TagView::scrollContentsBy(int dx, int dy) saveCenterTimer.start(); } +void TagView::keyPressEvent(QKeyEvent *event) +{ + if (event->modifiers() & Qt::ControlModifier) + setDragMode(QGraphicsView::ScrollHandDrag); + else + setDragMode(QGraphicsView::RubberBandDrag); +} + +void TagView::keyReleaseEvent(QKeyEvent *event) +{ + if (event->modifiers() & Qt::ControlModifier) + setDragMode(QGraphicsView::ScrollHandDrag); + else + setDragMode(QGraphicsView::RubberBandDrag); +} + +void TagView::focusInEvent(QFocusEvent *event) +{ + Q_UNUSED(event); + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + setDragMode(QGraphicsView::ScrollHandDrag); + else + setDragMode(QGraphicsView::RubberBandDrag); +} + void TagView::saveCenter() { QPointF p = mapToScene(viewport()->rect().center()); -- cgit