summaryrefslogtreecommitdiffstats
path: root/plugin/cursornavigation.cpp
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2019-02-19 15:36:39 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:42:31 +0100
commit8489f36322c585ec78199e6eb183000c74afae19 (patch)
tree8989b7cf6275b8b6cbffaa3b44467f5bd4ecdbf5 /plugin/cursornavigation.cpp
parenta5120f26d509a3464c79404de84e9428b8ddc690 (diff)
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.
Diffstat (limited to 'plugin/cursornavigation.cpp')
-rw-r--r--plugin/cursornavigation.cpp30
1 files changed, 21 insertions, 9 deletions
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 <QQuickWindow>
#include <QQuickItem>
+#include <QtMath>
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<CursorNavigationAttached*> 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)