aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DemoApplication/controls/CNButton.qml21
-rw-r--r--DemoApplication/controls/CNListView.qml73
-rw-r--r--DemoApplication/controls/qmldir1
-rw-r--r--DemoApplication/pages/Page2.qml64
-rw-r--r--DemoApplication/pages/Page3.qml5
-rw-r--r--DemoApplication/pages/Page4.qml4
-rw-r--r--DemoApplication/pages/Page5.qml47
-rw-r--r--plugin/cursornavigation.cpp113
-rw-r--r--plugin/cursornavigation.h12
-rw-r--r--plugin/cursornavigationattached.cpp102
-rw-r--r--plugin/cursornavigationattached.h21
-rw-r--r--plugin/inputadapter.cpp36
12 files changed, 276 insertions, 223 deletions
diff --git a/DemoApplication/controls/CNButton.qml b/DemoApplication/controls/CNButton.qml
index 19dcb8e..fb8e1b8 100644
--- a/DemoApplication/controls/CNButton.qml
+++ b/DemoApplication/controls/CNButton.qml
@@ -10,6 +10,27 @@ Button {
CursorNavigation.acceptsCursor: true
//property bool hasCursor: CursorNavigation.hasCursor
+ Rotation {
+ id: rot
+ origin.x: root.width/2
+ origin.y: root.height/2
+ }
+
+ transform: rot
+
+ CursorNavigation.onHasCursorChanged: {
+ if (!hasCursor)
+ rot.angle = 0
+ }
+
+ CursorNavigation.onMagnitudeChanged: {
+ rot.angle = magnitude*45.0;
+ var a = angle * Math.PI/180.0
+ rot.axis.x = -Math.sin(a)
+ rot.axis.y = Math.cos(a)
+ rot.axis.z = 0
+ }
+
background: Rectangle {
anchors.fill: parent
radius: 40
diff --git a/DemoApplication/controls/CNListView.qml b/DemoApplication/controls/CNListView.qml
new file mode 100644
index 0000000..3d67317
--- /dev/null
+++ b/DemoApplication/controls/CNListView.qml
@@ -0,0 +1,73 @@
+import QtQuick 2.11
+import QtQuick.Controls 2.4
+import CursorNavigation 1.0
+
+ListView {
+ id: listView
+ anchors.fill: parent
+ spacing: 4
+ focus: true
+ /* when list view scopes the cursor, the cursor is passed further to its
+ * currently focused child. this means, moving from outside to the list,
+ * will return the cursor to the item that was previously selected
+ * comment this out to make transition directly between individual list items and the rest of the ui
+ */
+ CursorNavigation.acceptsCursor: true
+
+ Rectangle {
+ anchors.fill: parent
+ border.width: 1
+ border.color: listView.activeFocus ? "red" : "black"
+ color: "transparent"
+ }
+
+ highlight: Rectangle {
+ width: listView.width
+ height: 40
+ color: "lightgrey"
+ opacity: 0.3
+ }
+
+ delegate: ItemDelegate {
+ id: deleg
+ width: listView.width
+ height: 40
+ CursorNavigation.acceptsCursor: true
+
+ //make sure the list's current index follows the cursor!
+ CursorNavigation.onHasCursorChanged: {
+ if (CursorNavigation.hasCursor)
+ listView.currentIndex = index
+ }
+
+ contentItem: Rectangle {
+ width: listView.width
+ height: 40
+ border.color: deleg.CursorNavigation.hasCursor ? "red" : "transparent"
+
+ Row {
+ width: (parent.width - x)
+ height: 35
+ x: 5
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 10
+ Rectangle {
+ width: parent.height
+ height: parent.height
+ radius: width/2
+ color: colorCode
+ }
+ Text {
+ height: parent.height
+ font.bold: true
+ verticalAlignment: Text.AlignVCenter
+ text: name
+ }
+ }
+ }
+ onClicked: {
+ listView.currentIndex = index;
+ }
+ }
+
+}
diff --git a/DemoApplication/controls/qmldir b/DemoApplication/controls/qmldir
index b1ec146..6def14f 100644
--- a/DemoApplication/controls/qmldir
+++ b/DemoApplication/controls/qmldir
@@ -4,3 +4,4 @@ CNToolButton 1.0 CNToolButton.qml
CNRadioButton 1.0 CNRadioButton.qml
CNSwitch 1.0 CNSwitch.qml
CNCheckBox 1.0 CNCheckBox.qml
+CNListView 1.0 CNListView.qml
diff --git a/DemoApplication/pages/Page2.qml b/DemoApplication/pages/Page2.qml
index 396f6ce..9d5a796 100644
--- a/DemoApplication/pages/Page2.qml
+++ b/DemoApplication/pages/Page2.qml
@@ -20,55 +20,11 @@ Item {
anchors.top: parent.top
anchors.topMargin: 20
- CursorNavigation.acceptsCursor: true
- ListView {
+
+ CNListView {
id: listView
anchors.fill: parent
spacing: 4
- focus: true
-
- Rectangle {
- anchors.fill: parent
- visible: listView.activeFocus
- border.width: 2
- border.color: "red"
- color: "transparent"
- }
-
- highlight: Rectangle {
- width: listView.width
- height: 40
- color: "lightgrey"
- opacity: 0.3
- }
-
- delegate: ItemDelegate {
- width: listView.width
- height: 40
-
- contentItem: Row {
- width: (parent.width - x)
- height: 35
- x: 5
- anchors.verticalCenter: parent.verticalCenter
- spacing: 10
- Rectangle {
- width: parent.height
- height: parent.height
- radius: width/2
- color: colorCode
- }
- Text {
- height: parent.height
- font.bold: true
- verticalAlignment: Text.AlignVCenter
- text: name
- }
- }
- onClicked: {
- listView.currentIndex = index;
- }
- }
model: ListModel {
ListElement {
@@ -90,6 +46,22 @@ Item {
name: "Green"
colorCode: "green"
}
+ ListElement {
+ name: "Cyan"
+ colorCode: "cyan"
+ }
+ ListElement {
+ name: "Magenta"
+ colorCode: "magenta"
+ }
+ ListElement {
+ name: "Yellow"
+ colorCode: "yellow"
+ }
+ ListElement {
+ name: "Black"
+ colorCode: "black"
+ }
}
}
}
diff --git a/DemoApplication/pages/Page3.qml b/DemoApplication/pages/Page3.qml
index 307dc50..d0ca1bb 100644
--- a/DemoApplication/pages/Page3.qml
+++ b/DemoApplication/pages/Page3.qml
@@ -17,6 +17,11 @@ Item {
width: 100
height: 100
text: "alone!"
+
+ CursorNavigation.onMovedUp: text = "moved up"
+ CursorNavigation.onMovedDown: text = "moved down"
+ CursorNavigation.onMovedRight: text = "moved right"
+ CursorNavigation.onMovedLeft: text = "moved left"
}
Grid {
diff --git a/DemoApplication/pages/Page4.qml b/DemoApplication/pages/Page4.qml
index a77ce7b..47828dd 100644
--- a/DemoApplication/pages/Page4.qml
+++ b/DemoApplication/pages/Page4.qml
@@ -30,7 +30,8 @@ Item {
parent.CursorNavigation.move(Qt.vector2d(axisLeftX, axisLeftY), 10)
cooldownTimer.start()
} else if (v.length() >= 0.1) {
- var item = parent.CursorNavigation.find(Qt.vector2d(axisLeftX, axisLeftY), 10)
+ parent.CursorNavigation.setMagnitude(v)
+ var item = parent.CursorNavigation.find(v, 10)
//cooldownTimer.start()
if (item != undefined) {
pointerRect.x = item.x
@@ -40,6 +41,7 @@ Item {
pointerRect.visible = true
}
} else {
+ parent.CursorNavigation.setMagnitude(0,0)
pointerRect.visible = false
}
}
diff --git a/DemoApplication/pages/Page5.qml b/DemoApplication/pages/Page5.qml
index 9ab75c6..79dda87 100644
--- a/DemoApplication/pages/Page5.qml
+++ b/DemoApplication/pages/Page5.qml
@@ -105,54 +105,11 @@ Item {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: -toolBar.height
- CursorNavigation.acceptsCursor: true
- ListView {
+
+ CNListView {
id: listView
anchors.fill: parent
spacing: 4
- focus: true
-
- Rectangle {
- anchors.fill: parent
- border.width: 1
- border.color: listView.activeFocus ? "red" : "black"
- color: "transparent"
- }
-
- highlight: Rectangle {
- width: listView.width
- height: 40
- color: "lightgrey"
- opacity: 0.3
- }
-
- delegate: ItemDelegate {
- width: listView.width
- height: 40
-
- contentItem: Row {
- width: (parent.width - x)
- height: 35
- x: 5
- anchors.verticalCenter: parent.verticalCenter
- spacing: 10
- Rectangle {
- width: parent.height
- height: parent.height
- radius: width/2
- color: colorCode
- }
- Text {
- height: parent.height
- font.bold: true
- verticalAlignment: Text.AlignVCenter
- text: name
- }
- }
- onClicked: {
- listView.currentIndex = index;
- }
- }
model: ListModel {
ListElement { name: "Joe"; colorCode: "grey" }
diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp
index 155a158..0a09ade 100644
--- a/plugin/cursornavigation.cpp
+++ b/plugin/cursornavigation.cpp
@@ -3,7 +3,6 @@
#include "spatialnavigation4dir.h"
#include <QQuickWindow>
#include <QQuickItem>
-#include <QtMath>
const char CursorNavigation::windowPropertyName[] = "cursor_navigation";
@@ -15,44 +14,60 @@ CursorNavigation::CursorNavigation(QQuickWindow *parent)
,m_rootItem(new CursorNavigationAttached(nullptr))
{
m_rootItem->setParent(m_window->contentItem());
-
- //m_algorithms.push_back(new SpatialNavigation4Dir());
+ m_rootItem->m_cursorNavigation = this;
connect(m_window, &QQuickWindow::activeFocusItemChanged, this, &CursorNavigation::onActiveFocusItemChanged);
onActiveFocusItemChanged();
}
-void CursorNavigation::move(qreal angle, qreal tolerance, bool discrete)
+bool CursorNavigation::move(qreal angle, qreal tolerance, bool discrete)
{
- qreal a = qDegreesToRadians(angle);
- qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
- _move(a, t, discrete);
-}
+ CursorNavigationAttached *nextItem = find(angle, tolerance, 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)));
- _move(a, t, discrete);
+ if (nextItem) {
+ setCursorOnItem(nextItem);
+ return true;
+ }
+ return false;
}
CursorNavigationAttached *CursorNavigation::find(qreal angle, qreal tolerance, bool discrete)
{
- qreal a = qDegreesToRadians(angle);
- qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
+ CursorNavigationAttached *nextItem = nullptr;
+ CursorNavigationAttached *parent = m_currentItem ?
+ m_currentItem->m_parentNavigable :
+ m_rootItem;
- return _find(a,t,discrete);
-}
+ if (!m_currentItem)
+ return defaultItem();
-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)));
+ qWarning() << "find next item, angle = " << angle << " tolerance = " << tolerance << " discrete = " << discrete;
+
+ QList<CursorNavigationAttached*> candidates;
+
+ do {
+ candidates.append(parent->m_children);
- return _find(a,t,discrete);
+ 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);
+ } else {
+ nextItem = m_navigation360.getNextCandidate(candidates, m_currentItem, cmd);
+ }
+
+ return nextItem;
}
-void CursorNavigation::action(Action action)
+bool CursorNavigation::action(Action action)
{
qWarning() << "handleActionCommand, action= " << action;
switch (action) {
@@ -70,12 +85,12 @@ void CursorNavigation::action(Action action)
* if we are already at the root item's children, nothing happens
*/
if (!m_currentItem)
- break;
+ return false;
QQuickItem *escapeTarget = m_currentItem->m_parentNavigable->escapeTarget();
if (!escapeTarget) {
if (m_currentItem->m_parentNavigable == m_rootItem) {
- break;
+ return false;
}
escapeTarget = m_currentItem->m_parentNavigable->m_parentNavigable->item();
}
@@ -84,12 +99,13 @@ void CursorNavigation::action(Action action)
escapeTarget->forceActiveFocus();
onActiveFocusItemChanged();
//escapeTarget->setFocus(true);
- break;
+ return true;
}
default:
break;
}
+ return false;
}
CursorNavigationAttached *CursorNavigation::qmlAttachedProperties(QObject *object)
@@ -202,51 +218,6 @@ void CursorNavigation::unregisterItem(CursorNavigationAttached* item)
//TODO if the item that is being unregistered has children, they should be reassigned to the item's parent
}
-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;
- 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 {
- 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);
- } else {
- nextItem = m_navigation360.getNextCandidate(candidates, m_currentItem, cmd);
- }
-
- return nextItem;
-}
-
CursorNavigationAttached *CursorNavigation::defaultItem()
{
if (m_rootItem->m_children.size())
diff --git a/plugin/cursornavigation.h b/plugin/cursornavigation.h
index f3a6f91..a32a357 100644
--- a/plugin/cursornavigation.h
+++ b/plugin/cursornavigation.h
@@ -20,13 +20,16 @@ class CursorNavigation : public QObject
public:
CursorNavigation(QQuickWindow *parent);
+ //pass input events forward to the current item
+ //void setMagnitude(qreal angle, qreal magnitude);
+ //void setMagnitude(const QVector2D& vector);
//move the cursor
- void move(qreal angle, qreal tolerance, bool discrete);
- void move(const QVector2D& vector, qreal tolerance, bool discrete);
+ bool move(qreal angle, qreal tolerance, bool discrete);
+ bool 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);
+ bool action(Action action);
static CursorNavigationAttached *qmlAttachedProperties(QObject *object);
@@ -40,8 +43,6 @@ private:
void registerItem(CursorNavigationAttached* item);
void unregisterItem(CursorNavigationAttached* item);
- void _move(qreal angle, qreal tolerance, bool discrete);
- CursorNavigationAttached *_find(qreal angle, qreal tolerance, bool discrete);
CursorNavigationAttached *defaultItem();
private:
@@ -55,6 +56,7 @@ private:
CursorNavigationAttached *m_rootItem;
friend class CursorNavigationAttached;
+ friend class InputAdapter;
};
QML_DECLARE_TYPEINFO(CursorNavigation, QML_HAS_ATTACHED_PROPERTIES)
diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp
index 2581920..ffa1b93 100644
--- a/plugin/cursornavigationattached.cpp
+++ b/plugin/cursornavigationattached.cpp
@@ -2,6 +2,7 @@
#include "cursornavigation.h"
#include <QQuickItem>
#include <QQuickWindow>
+#include <QtMath>
CursorNavigationAttached::CursorNavigationAttached(QQuickItem *parent)
:QObject(parent),
@@ -76,24 +77,49 @@ void CursorNavigationAttached::setEscapeTarget(QQuickItem *escapeTarget)
emit escapeTargetChanged(m_escapeTarget);
}
+void CursorNavigationAttached::setMagnitude(qreal angle, qreal magnitude)
+{
+ if (m_cursorNavigation && m_cursorNavigation->m_currentItem)
+ m_cursorNavigation->m_currentItem->magnitudeChanged(angle, magnitude);
+}
+
+void CursorNavigationAttached::setMagnitude(QVector2D vector)
+{
+ if (m_cursorNavigation && m_cursorNavigation->m_currentItem)
+ m_cursorNavigation->m_currentItem->magnitudeChanged(
+ qRadiansToDegrees(qAtan2(vector.y(), vector.x())), vector.length());
+}
+
void CursorNavigationAttached::move(qreal angle, qreal tolerance)
{
qWarning() << "move";
- if (m_cursorNavigation)
- m_cursorNavigation->move(angle, tolerance, false);
+ qreal a = qDegreesToRadians(angle);
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(a, t, false) && item)
+ item->moved(a,t);
+ }
}
void CursorNavigationAttached::move(QVector2D vector, qreal tolerance)
{
- qWarning() << "move";
- if (m_cursorNavigation)
- m_cursorNavigation->move(vector, tolerance, false);
+ qWarning() << "move (vector)";
+ qreal a = qAtan2(vector.y(), vector.x());
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(a, t, false) && item)
+ item->moved(a,t);
+ }
}
QQuickItem *CursorNavigationAttached::find(qreal angle, qreal tolerance)
{
+ qreal a = qDegreesToRadians(angle);
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
if (m_cursorNavigation) {
- CursorNavigationAttached *item = m_cursorNavigation->find(angle, tolerance, false);
+ CursorNavigationAttached *item = m_cursorNavigation->find(a, t, false);
if (item)
return item->item();
}
@@ -102,8 +128,10 @@ QQuickItem *CursorNavigationAttached::find(qreal angle, qreal tolerance)
QQuickItem *CursorNavigationAttached::find(QVector2D vector, qreal tolerance)
{
+ qreal a = qAtan2(vector.y(), vector.x());
+ qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180)));
if (m_cursorNavigation) {
- CursorNavigationAttached *item = m_cursorNavigation->find(vector, tolerance, false);
+ CursorNavigationAttached *item = m_cursorNavigation->find(a, t, false);
if (item)
return item->item();
}
@@ -112,50 +140,74 @@ QQuickItem *CursorNavigationAttached::find(QVector2D vector, qreal tolerance)
void CursorNavigationAttached::moveUp()
{
- if (m_cursorNavigation)
- m_cursorNavigation->move(-90, 0, true);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(qDegreesToRadians(-90.0f), 0, true) && item)
+ item->movedUp();
+ }
}
void CursorNavigationAttached::moveDown()
{
- if (m_cursorNavigation)
- m_cursorNavigation->move(90, 0, true);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(qDegreesToRadians(90.0f), 0, true) && item)
+ item->movedDown();
+ }
}
void CursorNavigationAttached::moveRight()
{
- if (m_cursorNavigation)
- m_cursorNavigation->move(0, 0, true);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(qDegreesToRadians(0.0f), 0, true) && item)
+ item->movedRight();
+ }
}
void CursorNavigationAttached::moveLeft()
{
- if (m_cursorNavigation)
- m_cursorNavigation->move(180, 0, true);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->move(qDegreesToRadians(180.0f), 0, true) && item)
+ item->movedLeft();
+ }
}
void CursorNavigationAttached::activate()
{
- if (m_cursorNavigation)
- m_cursorNavigation->action(Activate);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->action(Activate) && item)
+ item->activated();
+ }
}
-void CursorNavigationAttached::forward()
+void CursorNavigationAttached::moveForward()
{
- if (m_cursorNavigation)
- m_cursorNavigation->action(Forward);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->action(Forward) && item)
+ item->movedForward();
+ }
}
-void CursorNavigationAttached::back()
+void CursorNavigationAttached::moveBack()
{
- if (m_cursorNavigation)
- m_cursorNavigation->action(Back);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->action(Back) && item)
+ item->movedBack();
+ }
}
void CursorNavigationAttached::escape()
{
- if (m_cursorNavigation)
- m_cursorNavigation->action(Escape);
+ if (m_cursorNavigation) {
+ CursorNavigationAttached *item = m_cursorNavigation->m_currentItem;
+ if (m_cursorNavigation->action(Escape) && item)
+ item->escaped();
+ }
}
void CursorNavigationAttached::onWindowChanged(QQuickWindow *window)
diff --git a/plugin/cursornavigationattached.h b/plugin/cursornavigationattached.h
index 1409a93..f3c729d 100644
--- a/plugin/cursornavigationattached.h
+++ b/plugin/cursornavigationattached.h
@@ -45,6 +45,12 @@ public slots:
void setTrapsCursor(bool trapsCursor);
void setEscapeTarget(QQuickItem * escapeTarget);
+ /* just for passing movement changes forward. does not move the cursor.
+ * events are received by the item that currently has the cursor
+ */
+ void setMagnitude(qreal angle, qreal magnitude);
+ void setMagnitude(QVector2D vector);
+
void move(qreal angle, qreal tolerance = 0);
void move(QVector2D vector, qreal tolerance = 0);
@@ -57,8 +63,8 @@ public slots:
void moveRight();
void moveLeft();
void activate();
- void forward();
- void back();
+ void moveForward();
+ void moveBack();
void escape();
@@ -69,6 +75,17 @@ signals:
void escapeTargetChanged(QQuickItem * escapeTarget);
+ void magnitudeChanged(qreal angle, qreal magnitude);
+ void moved(qreal angle, qreal tolerance);
+ void movedUp();
+ void movedDown();
+ void movedRight();
+ void movedLeft();
+ void activated();
+ void movedForward();
+ void movedBack();
+ void escaped();
+
private slots:
void onWindowChanged(QQuickWindow *window);
diff --git a/plugin/inputadapter.cpp b/plugin/inputadapter.cpp
index feb1373..52eba34 100644
--- a/plugin/inputadapter.cpp
+++ b/plugin/inputadapter.cpp
@@ -21,47 +21,39 @@ bool InputAdapter::eventFilter(QObject *object, QEvent *event)
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
return handleKeyEvent(keyEvent);
- } else if (event->type() == QEvent::Wheel) {
- QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
- return handleWheelEvent(wheelEvent);
- } else if (event->type() == QEvent::MouseMove) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
- return handleMouseEvent(mouseEvent);
}
return false;
}
bool InputAdapter::handleKeyEvent(QKeyEvent *event)
{
- CursorNavigationCommand cmd;
- //detect arrow keys, tabs, enter and esc
switch (event->key())
{
case Qt::Key_Left:
- m_cursorNavigation->move(180, 0, true);
+ m_cursorNavigation->m_rootItem->moveLeft();
break;
case Qt::Key_Right:
- m_cursorNavigation->move(0, 0, true);
+ m_cursorNavigation->m_rootItem->moveRight();
break;
case Qt::Key_Up:
- m_cursorNavigation->move(-90, 0, true);
+ m_cursorNavigation->m_rootItem->moveUp();
break;
case Qt::Key_Down:
- m_cursorNavigation->move(90, 0, true);
+ m_cursorNavigation->m_rootItem->moveDown();
break;
case Qt::Key_Return:
case Qt::Key_Enter:
- m_cursorNavigation->action(Activate);
+ m_cursorNavigation->m_rootItem->activate();
break;
case Qt::BackButton:
case Qt::Key_Escape:
- m_cursorNavigation->action(Escape);
+ m_cursorNavigation->m_rootItem->escape();
break;
case Qt::Key_Tab:
- m_cursorNavigation->action(Forward);
+ m_cursorNavigation->m_rootItem->moveForward();
break;
case Qt::Key_Backtab:
- m_cursorNavigation->action(Back);
+ m_cursorNavigation->m_rootItem->moveBack();
break;
default:
return false;
@@ -69,15 +61,3 @@ bool InputAdapter::handleKeyEvent(QKeyEvent *event)
return true;
}
-
-bool InputAdapter::handleMouseEvent(QMouseEvent *event)
-{
- //interpret mouse movement as omnnidirectional joystick movements for testing purposes
- return false;
-}
-
-bool InputAdapter::handleWheelEvent(QWheelEvent *event)
-{
- //turn wheel events into tabs
- return false;
-}