From 8489f36322c585ec78199e6eb183000c74afae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20H=C3=B6ltt=C3=A4?= Date: Tue, 19 Feb 2019 15:36:39 +0100 Subject: Add redirect feature for manually fine tuning the cursor's movement Cursornavigation now has a property redirects, that allows defining exceptions to the navigation behaviour. A redirect allows defining a starting and an ending angle and a target object. If the move command's direction falls between the limits, the algorithm is bypassed and cursor is moved to the target object. --- plugin/cursornavigation.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'plugin/cursornavigation.cpp') diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp index bf2d390..e069efc 100644 --- a/plugin/cursornavigation.cpp +++ b/plugin/cursornavigation.cpp @@ -3,6 +3,7 @@ #include "spatialnavigation4dir.h" #include #include +#include const char CursorNavigation::windowPropertyName[] = "cursor_navigation"; @@ -22,27 +23,38 @@ CursorNavigation::CursorNavigation(QQuickWindow *parent) bool CursorNavigation::move(qreal angle, qreal tolerance, bool discrete) { - CursorNavigationAttached *nextItem = find(angle, tolerance, discrete); + QQuickItem *foundItem = find(angle, tolerance, discrete); + CursorNavigationAttached *nextItem = cursorNavigationAttachment(foundItem); if (nextItem) { setCursorOnItem(nextItem); return true; + } else if (foundItem) { + foundItem->forceActiveFocus(); + return true; } return false; } -CursorNavigationAttached *CursorNavigation::find(qreal angle, qreal tolerance, bool discrete) +QQuickItem *CursorNavigation::find(qreal angle, qreal tolerance, bool discrete) { + if (!m_currentItem) + return defaultItem()->item(); + + if (m_currentItem->m_redirects.size()) { + for (auto redirect : m_currentItem->m_redirects) { + if (redirect->angleIsIncluded(angle)) { + if (!redirect->target()) + qWarning() << "Redirect target is null"; + return redirect->target(); + } + } + } + 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; - QList candidates; do { @@ -64,7 +76,7 @@ CursorNavigationAttached *CursorNavigation::find(qreal angle, qreal tolerance, b nextItem = m_navigation360.getNextCandidate(candidates, m_currentItem, cmd); } - return nextItem; + return nextItem ? nextItem->item() : nullptr; } bool CursorNavigation::action(Action action) -- cgit v1.2.3