diff options
-rw-r--r-- | plugin/cursornavigation.cpp | 4 | ||||
-rw-r--r-- | plugin/cursornavigation.h | 2 | ||||
-rw-r--r-- | plugin/cursornavigationattached.cpp | 32 | ||||
-rw-r--r-- | plugin/cursornavigationattached.h | 6 |
4 files changed, 35 insertions, 9 deletions
diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp index 022bc16..e52d028 100644 --- a/plugin/cursornavigation.cpp +++ b/plugin/cursornavigation.cpp @@ -60,9 +60,9 @@ CursorNavigation::CursorNavigation(QQuickWindow *parent) onActiveFocusItemChanged(); } -bool CursorNavigation::move(qreal angle, qreal tolerance, bool discrete) +bool CursorNavigation::move(qreal angle, qreal offset, qreal tolerance, bool discrete) { - QQuickItem *foundItem = find(angle, tolerance, discrete); + QQuickItem *foundItem = find(angle + offset, tolerance, discrete); CursorNavigationAttached *nextItem = cursorNavigationAttachment(foundItem); if (nextItem) { diff --git a/plugin/cursornavigation.h b/plugin/cursornavigation.h index 5829ff9..86f9b58 100644 --- a/plugin/cursornavigation.h +++ b/plugin/cursornavigation.h @@ -65,7 +65,7 @@ public: //void setMagnitude(qreal angle, qreal magnitude); //void setMagnitude(const QVector2D& vector); //move the cursor - bool move(qreal angle, qreal tolerance, bool discrete); + bool move(qreal angle, qreal offset, qreal tolerance, bool discrete); //find the next item without moving the cursor QQuickItem *find(qreal angle, qreal tolerance, bool discrete); bool action(Action action); diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp index 162f80c..cabab73 100644 --- a/plugin/cursornavigationattached.cpp +++ b/plugin/cursornavigationattached.cpp @@ -48,6 +48,7 @@ CursorNavigationAttached::CursorNavigationAttached(QQuickItem *parent) :QObject(parent), m_cursorNavigation(nullptr), m_parentNavigable(nullptr), +m_angleOffset(0.0), m_acceptsCursor(false), m_hasCursor(false), m_trapsCursor(false), @@ -70,6 +71,19 @@ CursorNavigationAttached::~CursorNavigationAttached() m_cursorNavigation->unregisterItem(this); } +double CursorNavigationAttached::angleOffset() const +{ + return m_angleOffset; +} + +void CursorNavigationAttached::setAngleOffset(double angleOffset) +{ + if (angleOffset != m_angleOffset) { + m_angleOffset = angleOffset; + emit angleOffsetChanged(m_angleOffset); + qWarning() << "rotation changed " << m_angleOffset; + } +} bool CursorNavigationAttached::acceptsCursor() const { return m_acceptsCursor; @@ -137,7 +151,8 @@ void CursorNavigationAttached::move(qreal angle, qreal tolerance) qreal a = qDegreesToRadians(angle); qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(a, t, false) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(a, offset, t, false) && item) item->moved(a,t); } } @@ -149,7 +164,8 @@ void CursorNavigationAttached::move(const QVector2D &vector, qreal tolerance) qreal a = qAtan2(vector.y(), vector.x()); qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(a, t, false) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(a, offset, t, false) && item) item->moved(a,t); } } @@ -178,7 +194,8 @@ void CursorNavigationAttached::moveUp() { if (m_cursorNavigation) { CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(qDegreesToRadians(-90.0f), 0, true) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(qDegreesToRadians(-90.0f), offset, 0, true) && item) item->movedUp(); } } @@ -187,7 +204,8 @@ void CursorNavigationAttached::moveDown() { if (m_cursorNavigation) { CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(qDegreesToRadians(90.0f), 0, true) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(qDegreesToRadians(90.0f), offset, 0, true) && item) item->movedDown(); } } @@ -196,7 +214,8 @@ void CursorNavigationAttached::moveRight() { if (m_cursorNavigation) { CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(qDegreesToRadians(0.0f), 0, true) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(qDegreesToRadians(0.0f), offset, 0, true) && item) item->movedRight(); } } @@ -205,7 +224,8 @@ void CursorNavigationAttached::moveLeft() { if (m_cursorNavigation) { CursorNavigationAttached *item = m_cursorNavigation->m_currentItem; - if (m_cursorNavigation->move(qDegreesToRadians(180.0f), 0, true) && item) + double offset = item ? item->angleOffset() : 0.0; + if (m_cursorNavigation->move(qDegreesToRadians(180.0f), offset, 0, true) && item) item->movedLeft(); } } diff --git a/plugin/cursornavigationattached.h b/plugin/cursornavigationattached.h index e6f5621..25a6769 100644 --- a/plugin/cursornavigationattached.h +++ b/plugin/cursornavigationattached.h @@ -54,6 +54,8 @@ class QVector2D; class CursorNavigationAttached : public QObject { Q_OBJECT + //is used to add offsets to any directional movement of the cursor navigation + Q_PROPERTY(double angleOffset READ angleOffset WRITE setAngleOffset NOTIFY angleOffsetChanged) //is included for cursor navigation Q_PROPERTY(bool acceptsCursor READ acceptsCursor WRITE setAcceptsCursor NOTIFY acceptsCursorChanged) //indicates if item is currently selected, indicated also by activeFocus property @@ -68,6 +70,7 @@ public: CursorNavigationAttached(QQuickItem *parent); ~CursorNavigationAttached(); + double angleOffset() const; bool acceptsCursor() const; bool hasCursor() const; bool trapsCursor() const; @@ -83,6 +86,7 @@ public: QQuickItem *item() const; public slots: + void setAngleOffset(double angleOffset); void setAcceptsCursor(bool acceptsCursor); void setTrapsCursor(bool trapsCursor); void setEscapeTarget(QQuickItem * escapeTarget); @@ -113,6 +117,7 @@ public slots: QQuickItem *currentItem(); signals: + void angleOffsetChanged(double angleOffset); void acceptsCursorChanged(bool acceptsCursor); void hasCursorChanged(bool hasCursor); void trapsCursorChanged(bool trapsCursor); @@ -145,6 +150,7 @@ private: CursorNavigationAttached *m_parentNavigable; QList<CursorNavigationAttached*> m_children; + double m_angleOffset; bool m_acceptsCursor; bool m_hasCursor; bool m_trapsCursor; |