kineticscroll accepts keyboard events too, scrollwidget scrollbars don't

accept focus

svn path=/trunk/KDE/kdelibs/; revision=1048165
This commit is contained in:
Marco Martin 2009-11-12 20:44:02 +00:00
parent 1d656bb418
commit 377e6bf9c1
3 changed files with 33 additions and 0 deletions

View File

@ -228,6 +228,30 @@ void KineticScrolling::wheelReleaseEvent(QGraphicsSceneWheelEvent *event)
}
void KineticScrolling::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Left:
d->kinMovement.setX(kinMovement().x() - 30);
startAnimationTimer(30);
break;
case Qt::Key_Right:
d->kinMovement.setX(kinMovement().x() + 30);
startAnimationTimer(30);
break;
case Qt::Key_Up:
d->kinMovement.setY(kinMovement().y() - 30);
startAnimationTimer(30);
break;
case Qt::Key_Down:
d->kinMovement.setY(kinMovement().y() + 30);
startAnimationTimer(30);
break;
default:
break;
}
}
void KineticScrolling::startAnimationTimer(int interval)
{
if (d->timerID) {
@ -396,6 +420,11 @@ bool KineticScrolling::eventFilter(QObject *watched, QEvent *event)
case QEvent::GraphicsSceneWheel:
wheelReleaseEvent(we);
break;
case QEvent::KeyPress: {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
keyPressEvent(ke);
break;
}
default:
break;
}

View File

@ -47,6 +47,7 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void wheelReleaseEvent(QGraphicsSceneWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
private:
KineticScrollingPrivate *d;

View File

@ -244,6 +244,7 @@ ScrollWidget::ScrollWidget(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new ScrollWidgetPrivate(this))
{
setFocusPolicy(Qt::StrongFocus);
d->layout = new QGraphicsGridLayout(this);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->layout->setContentsMargins(1, 1, 1, 1);
@ -254,6 +255,7 @@ ScrollWidget::ScrollWidget(QGraphicsWidget *parent)
d->verticalScrollBarPolicy = Qt::ScrollBarAsNeeded;
d->verticalScrollBar = new Plasma::ScrollBar(this);
d->verticalScrollBar->setFocusPolicy(Qt::NoFocus);
d->layout->addItem(d->verticalScrollBar, 0, 1);
d->verticalScrollBar->nativeWidget()->setMinimum(0);
d->verticalScrollBar->nativeWidget()->setMaximum(100);
@ -261,6 +263,7 @@ ScrollWidget::ScrollWidget(QGraphicsWidget *parent)
d->horizontalScrollBarPolicy = Qt::ScrollBarAsNeeded;
d->horizontalScrollBar = new Plasma::ScrollBar(this);
d->verticalScrollBar->setFocusPolicy(Qt::NoFocus);
d->horizontalScrollBar->setOrientation(Qt::Horizontal);
d->layout->addItem(d->horizontalScrollBar, 1, 0);
d->horizontalScrollBar->nativeWidget()->setMinimum(0);