diff options
Diffstat (limited to 'tagview.cpp')
-rw-r--r-- | tagview.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tagview.cpp b/tagview.cpp index 9a9c9a0..6bc3934 100644 --- a/tagview.cpp +++ b/tagview.cpp @@ -3,12 +3,13 @@ #include <QWheelEvent> #include <QScrollBar> #include <cmath> +#include <QApplication> 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()); |