diff --git a/widgets/scrollwidget.cpp b/widgets/scrollwidget.cpp index 47a40139b..7f60209c4 100644 --- a/widgets/scrollwidget.cpp +++ b/widgets/scrollwidget.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -579,6 +580,51 @@ public: return widget.data()->y(); } + void handleKeyPressEvent(QKeyEvent *event) + { + if (!widget.data()) + return; + + QPointF start = q->scrollPosition(); + QPointF end = start; + + qreal step = 100; + + switch (event->key()) { + case Qt::Key_Left: + if (canXFlick()) { + end += QPointF(-step, 0); + } + break; + case Qt::Key_Right: + if (canXFlick()) { + end += QPointF(step, 0); + } + break; + case Qt::Key_Up: + if (canYFlick()) { + end += QPointF(0, -step); + } + break; + case Qt::Key_Down: + if (canYFlick()) { + end += QPointF(0, step); + } + break; + default: + break; + } + + fixupAnimation.groupX->stop(); + fixupAnimation.groupY->stop(); + fixupAnimation.snapX->stop(); + fixupAnimation.snapY->stop(); + directMoveAnimation->setStartValue(start); + directMoveAnimation->setEndValue(end); + directMoveAnimation->setDuration(200); + directMoveAnimation->start(); + } + void handleMousePressEvent(QGraphicsSceneMouseEvent *event) { lastPos = QPoint(); @@ -1257,6 +1303,11 @@ void ScrollWidget::resizeEvent(QGraphicsSceneResizeEvent *event) QGraphicsWidget::resizeEvent(event); } +void ScrollWidget::keyPressEvent(QKeyEvent *event) +{ + d->handleKeyPressEvent(event); +} + void ScrollWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (!d->widget) { diff --git a/widgets/scrollwidget.h b/widgets/scrollwidget.h index 20b701778..1738f4d53 100644 --- a/widgets/scrollwidget.h +++ b/widgets/scrollwidget.h @@ -255,6 +255,7 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void keyPressEvent(QKeyEvent *event); void wheelEvent(QGraphicsSceneWheelEvent *event); bool eventFilter(QObject *watched, QEvent *event); void focusInEvent(QFocusEvent *event);