This commit is contained in:
jaseg 2020-12-17 15:43:37 +01:00
parent c6713d0876
commit 6a484c615a
17 changed files with 175 additions and 7 deletions

View file

@ -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());