diff options
author | Antti Hölttä <AHoelttae@luxoft.com> | 2019-02-19 15:36:39 +0100 |
---|---|---|
committer | Antti Hölttä <AHoelttae@luxoft.com> | 2019-03-18 16:42:31 +0100 |
commit | 8489f36322c585ec78199e6eb183000c74afae19 (patch) | |
tree | 8989b7cf6275b8b6cbffaa3b44467f5bd4ecdbf5 /plugin/cursornavigationattached.cpp | |
parent | a5120f26d509a3464c79404de84e9428b8ddc690 (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/cursornavigationattached.cpp')
-rw-r--r-- | plugin/cursornavigationattached.cpp | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp index a897327..133890e 100644 --- a/plugin/cursornavigationattached.cpp +++ b/plugin/cursornavigationattached.cpp @@ -92,10 +92,10 @@ void CursorNavigationAttached::setMagnitude(QVector2D vector) void CursorNavigationAttached::move(qreal angle, qreal tolerance) { - qWarning() << "move"; - qreal a = qDegreesToRadians(angle); - qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); if (m_cursorNavigation) { + qWarning() << "move"; + 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) item->moved(a,t); @@ -104,10 +104,10 @@ void CursorNavigationAttached::move(qreal angle, qreal tolerance) void CursorNavigationAttached::move(QVector2D vector, qreal tolerance) { - qWarning() << "move (vector)"; - qreal a = qAtan2(vector.y(), vector.x()); - qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); if (m_cursorNavigation) { + qWarning() << "move (vector)"; + 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) item->moved(a,t); @@ -116,24 +116,20 @@ void CursorNavigationAttached::move(QVector2D vector, qreal tolerance) 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(a, t, false); - if (item) - return item->item(); + qreal a = qDegreesToRadians(angle); + qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); + return m_cursorNavigation->find(a, t, false); } return nullptr; } 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(a, t, false); - if (item) - return item->item(); + qreal a = qAtan2(vector.y(), vector.x()); + qreal t = qDegreesToRadians(qFabs(std::fmod(tolerance, 180))); + return m_cursorNavigation->find(a, t, false); } return nullptr; } @@ -234,6 +230,15 @@ QQuickItem *CursorNavigationAttached::escapeTarget() const return m_escapeTarget; } +QQmlListProperty<Redirect> CursorNavigationAttached::redirects() +{ + return QQmlListProperty<Redirect>(this, this, + &CursorNavigationAttached::appendRedirect, + &CursorNavigationAttached::redirectCount, + &CursorNavigationAttached::redirect, + &CursorNavigationAttached::clearRedirects); +} + bool CursorNavigationAttached::available() const { if (m_acceptsCursor && item()->isVisible() && item()->isEnabled()) { @@ -252,3 +257,27 @@ void CursorNavigationAttached::setHasCursor(bool hasCursor) } } +void CursorNavigationAttached::appendRedirect(QQmlListProperty<Redirect> *property, Redirect *redirect) +{ + CursorNavigationAttached *cna = static_cast<CursorNavigationAttached*>(property->object); + cna->m_redirects.append(redirect); +} + +int CursorNavigationAttached::redirectCount(QQmlListProperty<Redirect> *property) +{ + CursorNavigationAttached *cna = static_cast<CursorNavigationAttached*>(property->object); + return cna->m_redirects.count(); +} + +Redirect *CursorNavigationAttached::redirect(QQmlListProperty<Redirect> *property, int index) +{ + CursorNavigationAttached *cna = static_cast<CursorNavigationAttached*>(property->object); + return cna->m_redirects.at(index); +} + +void CursorNavigationAttached::clearRedirects(QQmlListProperty<Redirect> *property) +{ + CursorNavigationAttached *cna = static_cast<CursorNavigationAttached*>(property->object); + cna->m_redirects.clear(); +} + |