diff options
author | Antti Hölttä <AHoelttae@luxoft.com> | 2018-12-03 13:44:15 +0100 |
---|---|---|
committer | Antti Hölttä <AHoelttae@luxoft.com> | 2019-03-18 16:33:53 +0100 |
commit | a9445c3b9c8f51a229b62c25df1aeebe5c85c88d (patch) | |
tree | d431757016a1892135859fae565dfed759ccdeff | |
parent | 2d45defe15ca9a94f6eba992af3d544fcd5dfb32 (diff) |
Cursor now movable only to items that set the acceptsCursor value to true
-rw-r--r-- | DemoApplication/controls/CNButton.qml | 4 | ||||
-rw-r--r-- | DemoApplication/pages/Page1.qml | 8 | ||||
-rw-r--r-- | plugin/cursornavigation.cpp | 4 | ||||
-rw-r--r-- | plugin/cursornavigationattached.cpp | 59 |
4 files changed, 52 insertions, 23 deletions
diff --git a/DemoApplication/controls/CNButton.qml b/DemoApplication/controls/CNButton.qml index 33299d1..19dcb8e 100644 --- a/DemoApplication/controls/CNButton.qml +++ b/DemoApplication/controls/CNButton.qml @@ -8,7 +8,7 @@ Button { implicitHeight: 40 CursorNavigation.acceptsCursor: true - property bool hasCursor: CursorNavigation.hasCursor + //property bool hasCursor: CursorNavigation.hasCursor background: Rectangle { anchors.fill: parent @@ -31,7 +31,7 @@ Button { border.width: 2 border.color: "red" anchors.fill: parent - visible: root.hasCursor + visible: root.CursorNavigation.hasCursor color: "transparent" } } diff --git a/DemoApplication/pages/Page1.qml b/DemoApplication/pages/Page1.qml index a140c6e..84ef0a7 100644 --- a/DemoApplication/pages/Page1.qml +++ b/DemoApplication/pages/Page1.qml @@ -71,6 +71,14 @@ Item { y: 241 text: qsTr("Button") } + + CNButton { + id: button8 + x: 210 + y: 138 + text: qsTr("Button (cursor off)") + CursorNavigation.acceptsCursor: false + } } //this seems to be the way to force focus on a newly opened dialog? Component.onCompleted: { forceActiveFocus(); } diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp index e35a939..718a24b 100644 --- a/plugin/cursornavigation.cpp +++ b/plugin/cursornavigation.cpp @@ -176,7 +176,7 @@ void CursorNavigation::registerItem(CursorNavigationAttached* item) QQuickItem *parentItem = item->item()->parentItem(); CursorNavigationAttached *parentCNA=nullptr; while (parentItem) { - if ((parentCNA=CursorNavigation::cursorNavigationAttachment(parentItem))) + if ((parentCNA=CursorNavigation::cursorNavigationAttachment(parentItem)) && parentCNA->acceptsCursor()) break; parentItem = parentItem->parentItem(); } @@ -198,6 +198,8 @@ void CursorNavigation::unregisterItem(CursorNavigationAttached* item) if (item->m_parentNavigable) item->m_parentNavigable->m_children.removeOne(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) diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp index af34bfd..1c68ac9 100644 --- a/plugin/cursornavigationattached.cpp +++ b/plugin/cursornavigationattached.cpp @@ -37,6 +37,13 @@ void CursorNavigationAttached::setAcceptsCursor(bool acceptsCursor) { if (acceptsCursor != m_acceptsCursor) { m_acceptsCursor=acceptsCursor; + if (m_cursorNavigation) { + if (m_acceptsCursor) + m_cursorNavigation->registerItem(this); + else + m_cursorNavigation->unregisterItem(this); + } + emit acceptsCursorChanged(m_acceptsCursor); } } @@ -71,75 +78,89 @@ void CursorNavigationAttached::setEscapeTarget(QQuickItem *escapeTarget) void CursorNavigationAttached::move(qreal angle, qreal tolerance) { qWarning() << "move"; - m_cursorNavigation->move(angle, tolerance, false); + if (m_cursorNavigation) + m_cursorNavigation->move(angle, tolerance, false); } void CursorNavigationAttached::move(QVector2D vector, qreal tolerance) { qWarning() << "move"; - m_cursorNavigation->move(vector, tolerance, false); + if (m_cursorNavigation) + 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(); + if (m_cursorNavigation) { + 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(); + if (m_cursorNavigation) { + CursorNavigationAttached *item = m_cursorNavigation->find(vector, tolerance, false); + if (item) + return item->item(); + } return nullptr; } void CursorNavigationAttached::moveUp() { - m_cursorNavigation->move(-90, 0, true); + if (m_cursorNavigation) + m_cursorNavigation->move(-90, 0, true); } void CursorNavigationAttached::moveDown() { - m_cursorNavigation->move(90, 0, true); + if (m_cursorNavigation) + m_cursorNavigation->move(90, 0, true); } void CursorNavigationAttached::moveRight() { - m_cursorNavigation->move(0, 0, true); + if (m_cursorNavigation) + m_cursorNavigation->move(0, 0, true); } void CursorNavigationAttached::moveLeft() { - m_cursorNavigation->move(180, 0, true); + if (m_cursorNavigation) + m_cursorNavigation->move(180, 0, true); } void CursorNavigationAttached::activate() { - m_cursorNavigation->action(Activate); + if (m_cursorNavigation) + m_cursorNavigation->action(Activate); } void CursorNavigationAttached::forward() { - m_cursorNavigation->action(Forward); + if (m_cursorNavigation) + m_cursorNavigation->action(Forward); } void CursorNavigationAttached::back() { - m_cursorNavigation->action(Back); + if (m_cursorNavigation) + m_cursorNavigation->action(Back); } void CursorNavigationAttached::escape() { - m_cursorNavigation->action(Escape); + if (m_cursorNavigation) + m_cursorNavigation->action(Escape); } void CursorNavigationAttached::onWindowChanged(QQuickWindow *window) { qDebug() << "window changed, window = " << window; - if (m_cursorNavigation) + if (m_cursorNavigation && m_acceptsCursor) m_cursorNavigation->unregisterItem(this); if (window) { @@ -148,10 +169,8 @@ void CursorNavigationAttached::onWindowChanged(QQuickWindow *window) m_cursorNavigation = nullptr; } - if (m_cursorNavigation) + if (m_cursorNavigation && m_acceptsCursor) m_cursorNavigation->registerItem(this); - - //emit focusManagerChanged(); } QQuickItem *CursorNavigationAttached::item() const |