diff options
author | Liang Qi <liang.qi@digia.com> | 2013-04-12 11:52:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-23 12:53:48 +0200 |
commit | 7167ebd3012147b41a447a6b0bbecc64b6017bd4 (patch) | |
tree | c90308a2e5e3cf24c0750ce82e8bf8cac4ed433e /src/quick/items/qquickitem.cpp | |
parent | 5f7ba49e2501286670e19ee8ba7d48b169fa3330 (diff) |
Expose nextItemInFocusChain in QQuickItem
Convenient for other use cases related with tab focus chain.
Autotest is included.
Change-Id: I1ba6317e20edacc2b672bc5b78e3fcd29ac80bdc
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 59ab56dc66..7e606eb282 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -2044,6 +2044,18 @@ QQuickItem::~QQuickItem() */ bool QQuickItemPrivate::focusNextPrev(QQuickItem *item, bool forward) { + QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward); + + if (next == item) + return false; + + next->forceActiveFocus(forward ? Qt::TabFocusReason : Qt::BacktabFocusReason); + + return true; +} + +QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, bool forward) +{ Q_ASSERT(item); Q_ASSERT(item->activeFocusOnTab()); @@ -2111,12 +2123,7 @@ bool QQuickItemPrivate::focusNextPrev(QQuickItem *item, bool forward) from = last; } while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()); - if (current == item) - return false; - - current->forceActiveFocus(forward ? Qt::TabFocusReason : Qt::BacktabFocusReason); - - return true; + return current; } /*! @@ -3928,6 +3935,28 @@ void QQuickItem::forceActiveFocus(Qt::FocusReason reason) } /*! + \qmlmethod QtQuick2::Item::nextItemInFocusChain(bool forward) + + \since QtQuick 2.1 + + Returns the item in the focus chain which is next to this item. + If \a forward is \c true, or not supplied, it is the next item in + the forwards direction. If \a forward is \c false, it is the next + item in the backwards direction. +*/ +/*! + Returns the item in the focus chain which is next to this item. + If \a forward is \c true, or not supplied, it is the next item in + the forwards direction. If \a forward is \c false, it is the next + item in the backwards direction. +*/ + +QQuickItem *QQuickItem::nextItemInFocusChain(bool forward) +{ + return QQuickItemPrivate::nextPrevItemInTabFocusChain(this, forward); +} + +/*! \qmlmethod QtQuick2::Item::childAt(real x, real y) Returns the first visible child item found at point (\a x, \a y) within |