diff options
-rw-r--r-- | DemoApplication/Page3Form.qml | 7 | ||||
-rw-r--r-- | plugin/cursornavigation.h | 4 | ||||
-rw-r--r-- | plugin/cursornavigationattached.cpp | 68 | ||||
-rw-r--r-- | plugin/cursornavigationattached.h | 11 | ||||
-rw-r--r-- | plugin/inputtypes.cpp | 4 | ||||
-rw-r--r-- | plugin/inputtypes.h | 2 |
6 files changed, 84 insertions, 12 deletions
diff --git a/DemoApplication/Page3Form.qml b/DemoApplication/Page3Form.qml index df06bee..f7d65e8 100644 --- a/DemoApplication/Page3Form.qml +++ b/DemoApplication/Page3Form.qml @@ -58,6 +58,13 @@ Item { anchors.fill: parent CursorNavigation.escapeTarget: defaultButton + //redefine the controls for this scope + //(default arrow keys will still work as well, unless reassigned here) + Keys.onDigit5Pressed: CursorNavigation.moveUp() + Keys.onDigit2Pressed: CursorNavigation.moveDown() + Keys.onDigit3Pressed: CursorNavigation.moveRight() + Keys.onDigit1Pressed: CursorNavigation.moveLeft() + Grid { spacing: 5 columns: 2 diff --git a/plugin/cursornavigation.h b/plugin/cursornavigation.h index 12468e4..96c5e67 100644 --- a/plugin/cursornavigation.h +++ b/plugin/cursornavigation.h @@ -20,8 +20,6 @@ public: CursorNavigation(QQuickWindow *parent); bool inputCommand(const CursorNavigationCommand &cmd); - void move(QVector2D moveVector); - void action(); static CursorNavigationAttached *qmlAttachedProperties(QObject *object); @@ -46,7 +44,7 @@ private: QList<CursorNavigationAlgorithm*> m_algorithms; //a root item that is not tied to any actual QQuickItem CursorNavigationAttached *m_rootItem; - QStack<CursorNavigationAttached*> m_scopeStack; + //QStack<CursorNavigationAttached*> m_scopeStack; friend class CursorNavigationAttached; }; diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp index 9a939ff..c015cd3 100644 --- a/plugin/cursornavigationattached.cpp +++ b/plugin/cursornavigationattached.cpp @@ -59,6 +59,65 @@ void CursorNavigationAttached::setTrapsCursor(bool trapsCursor) } } +void CursorNavigationAttached::setEscapeTarget(QQuickItem *escapeTarget) +{ + if (m_escapeTarget == escapeTarget) + return; + + m_escapeTarget = escapeTarget; + emit escapeTargetChanged(m_escapeTarget); +} + +void CursorNavigationAttached::move(int angle, float magnitude) +{ + CursorNavigationCommand cmd(magnitude, angle); + m_cursorNavigation->inputCommand(cmd); +} + +void CursorNavigationAttached::moveUp() +{ + m_cursorNavigation->inputCommand(CursorNavigationCommand::Up); +} + +void CursorNavigationAttached::moveDown() +{ + m_cursorNavigation->inputCommand(CursorNavigationCommand::Down); +} + +void CursorNavigationAttached::moveRight() +{ + m_cursorNavigation->inputCommand(CursorNavigationCommand::Right); +} + +void CursorNavigationAttached::moveLeft() +{ + m_cursorNavigation->inputCommand(CursorNavigationCommand::Left); +} + +void CursorNavigationAttached::activate() +{ + CursorNavigationCommand cmd(CursorNavigationCommand::Activate); + m_cursorNavigation->inputCommand(cmd); +} + +void CursorNavigationAttached::forward() +{ + CursorNavigationCommand cmd(CursorNavigationCommand::Forward); + m_cursorNavigation->inputCommand(cmd); +} + +void CursorNavigationAttached::back() +{ + CursorNavigationCommand cmd(CursorNavigationCommand::Back); + m_cursorNavigation->inputCommand(cmd); +} + +void CursorNavigationAttached::escape() +{ + CursorNavigationCommand cmd(CursorNavigationCommand::Escape); + m_cursorNavigation->inputCommand(cmd); +} + void CursorNavigationAttached::onWindowChanged(QQuickWindow *window) { qDebug() << "window changed, window = " << window; @@ -88,15 +147,6 @@ QQuickItem *CursorNavigationAttached::escapeTarget() const return m_escapeTarget; } -void CursorNavigationAttached::setEscapeTarget(QQuickItem *escapeTarget) -{ - if (m_escapeTarget == escapeTarget) - return; - - m_escapeTarget = escapeTarget; - emit escapeTargetChanged(m_escapeTarget); -} - void CursorNavigationAttached::setHasCursor(bool hasCursor) { if (hasCursor != m_hasCursor) { diff --git a/plugin/cursornavigationattached.h b/plugin/cursornavigationattached.h index 0f3f927..344b4fa 100644 --- a/plugin/cursornavigationattached.h +++ b/plugin/cursornavigationattached.h @@ -40,6 +40,17 @@ public slots: void setTrapsCursor(bool trapsCursor); void setEscapeTarget(QQuickItem * escapeTarget); + void move(int angle, float magnitude); + void moveUp(); + void moveDown(); + void moveRight(); + void moveLeft(); + void activate(); + void forward(); + void back(); + void escape(); + + signals: void acceptsCursorChanged(bool acceptsCursor); void hasCursorChanged(bool hasCursor); diff --git a/plugin/inputtypes.cpp b/plugin/inputtypes.cpp index 770b03d..344254b 100644 --- a/plugin/inputtypes.cpp +++ b/plugin/inputtypes.cpp @@ -13,6 +13,10 @@ CursorNavigationCommand::CursorNavigationCommand(float magnitude, int angle) :magnitude(magnitude), angle(angle), action(NoAction) {} +CursorNavigationCommand::CursorNavigationCommand(Action a) + :magnitude(-1), angle(-1), action(a) +{} + //test if this commands angle is between given angles. clockwise from begin to end bool CursorNavigationCommand::angleIsBetween(int begin, int end) const { diff --git a/plugin/inputtypes.h b/plugin/inputtypes.h index efe7f8a..c6cc532 100644 --- a/plugin/inputtypes.h +++ b/plugin/inputtypes.h @@ -19,6 +19,8 @@ struct CursorNavigationCommand CursorNavigationCommand(float magnitude, int angle); + CursorNavigationCommand(Action a); + //test if this commands angle is between given angles. clockwise from begin to end bool angleIsBetween(int begin, int end) const; |