diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-09-29 06:10:49 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-09-29 06:10:49 (GMT) |
commit | 1d65aff4f6c0339752c92f859ce78f1a59450a28 (patch) | |
tree | e5fe9fd8c8a9ada0977318bef9afd073e1ce3ba9 /src/declarative/fx | |
parent | 26afe9477e9b63d258631c96549de95556f0d97c (diff) | |
download | Qt-1d65aff4f6c0339752c92f859ce78f1a59450a28.zip Qt-1d65aff4f6c0339752c92f859ce78f1a59450a28.tar.gz Qt-1d65aff4f6c0339752c92f859ce78f1a59450a28.tar.bz2 |
Some fixes for ListView key handling.
Accept auto repeated keys in wrap mode even at the ends.
Allow Keys.onLeftPressed, etc. to override default key handling.
Diffstat (limited to 'src/declarative/fx')
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 35 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.h | 7 |
2 files changed, 34 insertions, 8 deletions
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 5de9bf3..3584892 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1339,13 +1339,19 @@ qreal QFxListView::maxXExtent() const void QFxListView::keyPressEvent(QKeyEvent *event) { Q_D(QFxListView); + QFxFlickable::keyPressEvent(event); + if (event->isAccepted()) + return; + if (d->model && d->model->count() && d->interactive) { if ((d->orient == Qt::Horizontal && event->key() == Qt::Key_Left) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Up)) { if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; - int index = currentIndex()-1; - d->updateCurrent(index >= 0 ? index : d->model->count()-1); + decrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { event->accept(); return; } @@ -1353,8 +1359,10 @@ void QFxListView::keyPressEvent(QKeyEvent *event) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Down)) { if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; - int index = currentIndex()+1; - d->updateCurrent(index < d->model->count() ? index : 0); + incrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { event->accept(); return; } @@ -1362,7 +1370,24 @@ void QFxListView::keyPressEvent(QKeyEvent *event) } d->moveReason = QFxListViewPrivate::Other; event->ignore(); - QFxFlickable::keyPressEvent(event); +} + +void QFxListView::incrementCurrentIndex() +{ + Q_D(QFxListView); + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex()+1; + d->updateCurrent(index < d->model->count() ? index : 0); + } +} + +void QFxListView::decrementCurrentIndex() +{ + Q_D(QFxListView); + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex()-1; + d->updateCurrent(index >= 0 ? index : d->model->count()-1); + } } void QFxListView::componentComplete() diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index cc3d910..fc15967 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -50,9 +50,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -//### incrementCurrentIndex(), decrementCurrentIndex() slots -//### default Keys.OnUp/DownPressed handler - class QFxVisualModel; class QFxListViewAttached; @@ -131,6 +128,10 @@ public: static QFxListViewAttached *qmlAttachedProperties(QObject *); +public Q_SLOTS: + void incrementCurrentIndex(); + void decrementCurrentIndex(); + Q_SIGNALS: void countChanged(); void spacingChanged(); |