diff options
-rw-r--r-- | DemoApplication/pages/Page3.qml | 8 | ||||
-rw-r--r-- | plugin/cursornavigation.cpp | 31 | ||||
-rw-r--r-- | plugin/cursornavigation.h | 1 | ||||
-rw-r--r-- | plugin/cursornavigationattached.cpp | 1 |
4 files changed, 36 insertions, 5 deletions
diff --git a/DemoApplication/pages/Page3.qml b/DemoApplication/pages/Page3.qml index e9c47e1..307dc50 100644 --- a/DemoApplication/pages/Page3.qml +++ b/DemoApplication/pages/Page3.qml @@ -54,6 +54,7 @@ Item { anchors.fill: parent CursorNavigation.acceptsCursor: true CursorNavigation.escapeTarget: defaultButton + CursorNavigation.trapsCursor: trapCheckBox.checked //redefine the controls for this scope //(default arrow keys will still work as well, unless reassigned here) @@ -65,7 +66,7 @@ Item { Grid { spacing: 5 columns: 2 - rows: 2 + rows: 3 CNButton { text: "sb1" @@ -83,6 +84,11 @@ Item { text: "sb4 (default focus)" focus: true } + + CNCheckBox { + id: trapCheckBox + text: "trap cursor" + } } } } diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp index 7cdd80a..155a158 100644 --- a/plugin/cursornavigation.cpp +++ b/plugin/cursornavigation.cpp @@ -214,13 +214,29 @@ void CursorNavigation::_move(qreal angle, qreal tolerance, bool discrete) CursorNavigationAttached *CursorNavigation::_find(qreal angle, qreal tolerance, bool discrete) { CursorNavigationAttached *nextItem = nullptr; + CursorNavigationAttached *parent = m_currentItem ? + m_currentItem->m_parentNavigable : + m_rootItem; + + if (!m_currentItem) + return defaultItem(); qWarning() << "find next item, angle = " << angle << " tolerance = " << tolerance << " discrete = " << discrete; - CursorNavigationCommand cmd(angle, tolerance); - QList<CursorNavigationAttached*> &candidates = m_currentItem ? - m_currentItem->m_parentNavigable->m_children : - m_rootItem->m_children; + QList<CursorNavigationAttached*> candidates; + + do { + candidates.append(parent->m_children); + + if (parent->trapsCursor()) + break; + parent = parent->m_parentNavigable; + } while (parent); + + if (candidates.isEmpty()) + return nullptr; + + CursorNavigationCommand cmd(angle, tolerance); if (discrete) { nextItem = m_navigation4Dir.getNextCandidate(candidates, m_currentItem, cmd); @@ -230,3 +246,10 @@ CursorNavigationAttached *CursorNavigation::_find(qreal angle, qreal tolerance, return nextItem; } + +CursorNavigationAttached *CursorNavigation::defaultItem() +{ + if (m_rootItem->m_children.size()) + return m_rootItem->m_children.first(); + return nullptr; +} diff --git a/plugin/cursornavigation.h b/plugin/cursornavigation.h index 34dd794..f3a6f91 100644 --- a/plugin/cursornavigation.h +++ b/plugin/cursornavigation.h @@ -42,6 +42,7 @@ private: void _move(qreal angle, qreal tolerance, bool discrete); CursorNavigationAttached *_find(qreal angle, qreal tolerance, bool discrete); + CursorNavigationAttached *defaultItem(); private: static const char windowPropertyName[]; diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp index 1c68ac9..6808922 100644 --- a/plugin/cursornavigationattached.cpp +++ b/plugin/cursornavigationattached.cpp @@ -9,6 +9,7 @@ m_cursorNavigation(nullptr), m_parentNavigable(nullptr), m_acceptsCursor(true), m_hasCursor(false), +m_trapsCursor(false), m_escapeTarget(nullptr) { if (parent) |