aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickmenu.cpp36
-rw-r--r--src/quicktemplates2/qquickmenu_p_p.h3
2 files changed, 30 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp
index 9e8fabe0..c40c49e1 100644
--- a/src/quicktemplates2/qquickmenu.cpp
+++ b/src/quicktemplates2/qquickmenu.cpp
@@ -254,6 +254,31 @@ void QQuickMenuPrivate::setCurrentIndex(int index)
contentItem->setProperty("currentIndex", index);
}
+void QQuickMenuPrivate::activateNextItem()
+{
+ int index = currentIndex();
+ int count = contentModel->count();
+ while (++index < count) {
+ QQuickItem *item = itemAt(index);
+ if (!item || !item->activeFocusOnTab())
+ continue;
+ item->forceActiveFocus(Qt::TabFocusReason);
+ break;
+ }
+}
+
+void QQuickMenuPrivate::activatePreviousItem()
+{
+ int index = currentIndex();
+ while (--index >= 0) {
+ QQuickItem *item = itemAt(index);
+ if (!item || !item->activeFocusOnTab())
+ continue;
+ item->forceActiveFocus(Qt::BacktabFocusReason);
+ break;
+ }
+}
+
void QQuickMenuPrivate::contentData_append(QQmlListProperty<QObject> *prop, QObject *obj)
{
QQuickMenuPrivate *p = static_cast<QQuickMenuPrivate *>(prop->data);
@@ -511,23 +536,16 @@ void QQuickMenu::keyReleaseEvent(QKeyEvent *event)
// shown at once.
switch (event->key()) {
case Qt::Key_Up:
- if (d->contentItem->metaObject()->indexOfMethod("decrementCurrentIndex()") != -1)
- QMetaObject::invokeMethod(d->contentItem, "decrementCurrentIndex");
+ d->activatePreviousItem();
break;
case Qt::Key_Down:
- if (d->contentItem->metaObject()->indexOfMethod("incrementCurrentIndex()") != -1)
- QMetaObject::invokeMethod(d->contentItem, "incrementCurrentIndex");
+ d->activateNextItem();
break;
default:
break;
}
-
- int index = d->currentIndex();
- QQuickItem *item = itemAt(index);
- if (item)
- item->forceActiveFocus();
}
QFont QQuickMenu::defaultFont() const
diff --git a/src/quicktemplates2/qquickmenu_p_p.h b/src/quicktemplates2/qquickmenu_p_p.h
index 504bc74d..583bb41d 100644
--- a/src/quicktemplates2/qquickmenu_p_p.h
+++ b/src/quicktemplates2/qquickmenu_p_p.h
@@ -84,6 +84,9 @@ public:
int currentIndex() const;
void setCurrentIndex(int index);
+ void activateNextItem();
+ void activatePreviousItem();
+
static void contentData_append(QQmlListProperty<QObject> *prop, QObject *obj);
static int contentData_count(QQmlListProperty<QObject> *prop);
static QObject *contentData_at(QQmlListProperty<QObject> *prop, int index);