aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/cursornavigation.cpp50
-rw-r--r--plugin/cursornavigation.h7
-rw-r--r--plugin/cursornavigationattached.cpp16
-rw-r--r--plugin/cursornavigationattached.h5
-rw-r--r--plugin/inputadapter.cpp2
-rw-r--r--plugin/spatialnavigation4dir.cpp2
6 files changed, 60 insertions, 22 deletions
diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp
index 1a81f76..e35a939 100644
--- a/plugin/cursornavigation.cpp
+++ b/plugin/cursornavigation.cpp
@@ -26,14 +26,30 @@ void CursorNavigation::move(qreal angle, qreal tolerance, bool discrete)
{
qreal a = qDegreesToRadians(angle);
qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
- handleMove(a, t, discrete);
+ _move(a, t, discrete);
}
void CursorNavigation::move(const QVector2D& vector, qreal tolerance, bool discrete)
{
qreal a = qAtan2(vector.y(), vector.x());
qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
- handleMove(a, t, discrete);
+ _move(a, t, discrete);
+}
+
+CursorNavigationAttached *CursorNavigation::find(qreal angle, qreal tolerance, bool discrete)
+{
+ qreal a = qDegreesToRadians(angle);
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
+
+ return _find(a,t,discrete);
+}
+
+CursorNavigationAttached *CursorNavigation::find(const QVector2D& vector, qreal tolerance, bool discrete)
+{
+ qreal a = qAtan2(vector.y(), vector.x());
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
+
+ return _find(a,t,discrete);
}
void CursorNavigation::action(Action action)
@@ -47,7 +63,7 @@ void CursorNavigation::action(Action action)
case Activate:
break;
case Escape: {
- /* if item has escapeTrgate defined, set focus to that. otherwise leave
+ /* if item has escapeTarget defined, set focus to that. otherwise leave
* scope, ie. go back to parent's parent in the hierarchy and set focus
* (back) to it (setting the focus further to one of its children
* depends on the focus mechanism).
@@ -184,11 +200,20 @@ void CursorNavigation::unregisterItem(CursorNavigationAttached* item)
item->m_parentNavigable->m_children.removeOne(item);
}
-bool CursorNavigation::handleMove(qreal angle, qreal tolerance, bool discrete)
+void CursorNavigation::_move(qreal angle, qreal tolerance, bool discrete)
+{
+ CursorNavigationAttached *nextItem = _find(angle, tolerance, discrete);
+
+ if (nextItem) {
+ setCursorOnItem(nextItem);
+ }
+}
+
+CursorNavigationAttached *CursorNavigation::_find(qreal angle, qreal tolerance, bool discrete)
{
CursorNavigationAttached *nextItem = nullptr;
- qWarning() << "handleMove, angle = " << angle << " tolerance = " << tolerance << " discrete = " << discrete;
+ qWarning() << "find next item, angle = " << angle << " tolerance = " << tolerance << " discrete = " << discrete;
CursorNavigationCommand cmd(angle, tolerance);
QList<CursorNavigationAttached*> &candidates = m_currentItem ?
@@ -201,18 +226,5 @@ bool CursorNavigation::handleMove(qreal angle, qreal tolerance, bool discrete)
nextItem = m_navigation360.getNextCandidate(candidates, m_currentItem, cmd);
}
- if (nextItem) {
- setCursorOnItem(nextItem);
- }
-
-/* for (auto alg : m_algorithms) {
- nextItem = alg->getNextCandidate(candidates, m_currentItem, cmd);
- if (nextItem) {
- setCursorOnItem(nextItem);
- break;
- }
- }*/
-
- return true;
+ return nextItem;
}
-
diff --git a/plugin/cursornavigation.h b/plugin/cursornavigation.h
index 5c7d7f8..34dd794 100644
--- a/plugin/cursornavigation.h
+++ b/plugin/cursornavigation.h
@@ -20,8 +20,12 @@ class CursorNavigation : public QObject
public:
CursorNavigation(QQuickWindow *parent);
+ //move the cursor
void move(qreal angle, qreal tolerance, bool discrete);
void move(const QVector2D& vector, qreal tolerance, bool discrete);
+ //find the next item without moving the cursor
+ CursorNavigationAttached *find(qreal angle, qreal tolerance, bool discrete);
+ CursorNavigationAttached *find(const QVector2D& vector, qreal tolerance, bool discrete);
void action(Action action);
static CursorNavigationAttached *qmlAttachedProperties(QObject *object);
@@ -36,7 +40,8 @@ private:
void registerItem(CursorNavigationAttached* item);
void unregisterItem(CursorNavigationAttached* item);
- bool handleMove(qreal angle, qreal tolerance, bool discrete);
+ void _move(qreal angle, qreal tolerance, bool discrete);
+ CursorNavigationAttached *_find(qreal angle, qreal tolerance, bool discrete);
private:
static const char windowPropertyName[];
diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp
index 0f7afdc..af34bfd 100644
--- a/plugin/cursornavigationattached.cpp
+++ b/plugin/cursornavigationattached.cpp
@@ -80,6 +80,22 @@ void CursorNavigationAttached::move(QVector2D vector, qreal tolerance)
m_cursorNavigation->move(vector, tolerance, false);
}
+QQuickItem *CursorNavigationAttached::find(qreal angle, qreal tolerance)
+{
+ CursorNavigationAttached *item = m_cursorNavigation->find(angle, tolerance, false);
+ if (item)
+ return item->item();
+ return nullptr;
+}
+
+QQuickItem *CursorNavigationAttached::find(QVector2D vector, qreal tolerance)
+{
+ CursorNavigationAttached *item = m_cursorNavigation->find(vector, tolerance, false);
+ if (item)
+ return item->item();
+ return nullptr;
+}
+
void CursorNavigationAttached::moveUp()
{
m_cursorNavigation->move(-90, 0, true);
diff --git a/plugin/cursornavigationattached.h b/plugin/cursornavigationattached.h
index ee32f76..1ae2119 100644
--- a/plugin/cursornavigationattached.h
+++ b/plugin/cursornavigationattached.h
@@ -42,6 +42,11 @@ public slots:
void move(qreal angle, qreal tolerance = 0);
void move(QVector2D vector, qreal tolerance = 0);
+
+ //find the next item with this move, without moving
+ QQuickItem *find(qreal angle, qreal tolerance = 0);
+ QQuickItem *find(QVector2D vector, qreal tolerance = 0);
+
void moveUp();
void moveDown();
void moveRight();
diff --git a/plugin/inputadapter.cpp b/plugin/inputadapter.cpp
index 89fa1a8..feb1373 100644
--- a/plugin/inputadapter.cpp
+++ b/plugin/inputadapter.cpp
@@ -44,7 +44,7 @@ bool InputAdapter::handleKeyEvent(QKeyEvent *event)
m_cursorNavigation->move(0, 0, true);
break;
case Qt::Key_Up:
- m_cursorNavigation->move(270, 0, true);
+ m_cursorNavigation->move(-90, 0, true);
break;
case Qt::Key_Down:
m_cursorNavigation->move(90, 0, true);
diff --git a/plugin/spatialnavigation4dir.cpp b/plugin/spatialnavigation4dir.cpp
index 0ccf041..ac72e4e 100644
--- a/plugin/spatialnavigation4dir.cpp
+++ b/plugin/spatialnavigation4dir.cpp
@@ -30,7 +30,7 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
if (candidates.isEmpty())
return nullptr;
- qDebug() << "spatial chooser called, no of candidates=" << candidates.count();
+ qDebug() << "4-way algortihm called, no of candidates=" << candidates.count();
if (!currentItem && candidates.size()) {
qDebug() << "the spatial chooser falling back to first child" << candidates.first();