handle keypresses (but don't steal them)

is the last thing that was missing from kineticscrolling

svn path=/trunk/KDE/kdelibs/; revision=1124609
This commit is contained in:
Marco Martin 2010-05-09 16:57:05 +00:00
parent 5ddac55dcc
commit 20d58299b2
2 changed files with 52 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include <QGraphicsGridLayout> #include <QGraphicsGridLayout>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QApplication> #include <QApplication>
#include <QKeyEvent>
#include <QWidget> #include <QWidget>
#include <QTimer> #include <QTimer>
#include <QTime> #include <QTime>
@ -579,6 +580,51 @@ public:
return widget.data()->y(); 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) void handleMousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
lastPos = QPoint(); lastPos = QPoint();
@ -1257,6 +1303,11 @@ void ScrollWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
QGraphicsWidget::resizeEvent(event); QGraphicsWidget::resizeEvent(event);
} }
void ScrollWidget::keyPressEvent(QKeyEvent *event)
{
d->handleKeyPressEvent(event);
}
void ScrollWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void ScrollWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!d->widget) { if (!d->widget) {

View File

@ -255,6 +255,7 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event); void wheelEvent(QGraphicsSceneWheelEvent *event);
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);
void focusInEvent(QFocusEvent *event); void focusInEvent(QFocusEvent *event);