aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DemoApplication/main.qml48
-rw-r--r--plugin/cursornavigationattached.cpp10
-rw-r--r--plugin/cursornavigationattached.h7
-rw-r--r--plugin/spatialnavigation360.cpp6
-rw-r--r--plugin/spatialnavigation4dir.cpp14
5 files changed, 52 insertions, 33 deletions
diff --git a/DemoApplication/main.qml b/DemoApplication/main.qml
index 58f1af5..bfb7840 100644
--- a/DemoApplication/main.qml
+++ b/DemoApplication/main.qml
@@ -13,28 +13,34 @@ ApplicationWindow {
visible: true
title: qsTr("Cursor Navigation Demo Application")
- header: TabBar {
- id: tabBar
- width: parent.width
- CNTabButton {
- text: qsTr("Page 1")
- }
- CNTabButton {
- text: qsTr("Page 2")
- }
- CNTabButton {
- text: qsTr("Page 3")
- }
- CNTabButton {
- text: qsTr("Page 4")
- }
- CNTabButton {
- text: qsTr("Page 5")
- }
- CNTabButton {
- text: qsTr("Map")
+ header:
+
+ TabBar {
+ id: tabBar
+ width: window.width
+
+ CursorNavigation.acceptsCursor: true
+
+ CNTabButton {
+ text: qsTr("Page 1")
+ focus: true
+ }
+ CNTabButton {
+ text: qsTr("Page 2")
+ }
+ CNTabButton {
+ text: qsTr("Page 3")
+ }
+ CNTabButton {
+ text: qsTr("Page 4")
+ }
+ CNTabButton {
+ text: qsTr("Page 5")
+ }
+ CNTabButton {
+ text: qsTr("Map")
+ }
}
- }
contentData: StackLayout {
anchors.fill: parent
diff --git a/plugin/cursornavigationattached.cpp b/plugin/cursornavigationattached.cpp
index 6808922..2581920 100644
--- a/plugin/cursornavigationattached.cpp
+++ b/plugin/cursornavigationattached.cpp
@@ -185,6 +185,16 @@ QQuickItem *CursorNavigationAttached::escapeTarget() const
return m_escapeTarget;
}
+bool CursorNavigationAttached::available() const
+{
+ if (m_acceptsCursor && item()->isVisible() && item()->isEnabled()) {
+ QRectF parentRect(0,0,m_parentNavigable->item()->width(), m_parentNavigable->item()->height());
+ QRectF thisRect = item()->mapRectToItem(m_parentNavigable->item(), QRectF(0,0,item()->width(), item()->height()));
+ return parentRect.intersects(thisRect);
+ }
+ return false;
+}
+
void CursorNavigationAttached::setHasCursor(bool hasCursor)
{
if (hasCursor != m_hasCursor) {
diff --git a/plugin/cursornavigationattached.h b/plugin/cursornavigationattached.h
index 1ae2119..1409a93 100644
--- a/plugin/cursornavigationattached.h
+++ b/plugin/cursornavigationattached.h
@@ -12,7 +12,7 @@ class QQuickWindow;
class CursorNavigationAttached : public QObject
{
Q_OBJECT
- //is available for cursor navigation
+ //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
Q_PROPERTY(bool hasCursor READ hasCursor NOTIFY hasCursorChanged)
@@ -32,6 +32,11 @@ public:
bool hasCursor() const;
bool trapsCursor() const;
QQuickItem *escapeTarget() const;
+ /* indicates if the item is currently available for the navigation.
+ * item might not be availble if it is disabled, invisible, outside of its
+ * parent's geometry or simply not accepting cursor
+ */
+ bool available() const;
QQuickItem *item() const;
diff --git a/plugin/spatialnavigation360.cpp b/plugin/spatialnavigation360.cpp
index f7d1e62..0e6d19b 100644
--- a/plugin/spatialnavigation360.cpp
+++ b/plugin/spatialnavigation360.cpp
@@ -153,12 +153,12 @@ CursorNavigationAttached* SpatialNavigation360::getNextCandidate(
for (auto iter: candidates)
{
+ if (!iter->available() || iter == currentItem)
+ continue;
+
const QRectF itemSceneRect = iter->item()->mapRectToScene(
QRectF( 0, 0, iter->item()->width(), iter->item()->height() ));
- if (iter == currentItem || !iter->item()->isVisible() || !iter->item()->isEnabled())
- continue;
-
if (isRectIncluded(quadrants, itemSceneRect, origin)) {
std::pair<qreal,qreal> sector = getSector(itemSceneRect, origin);
diff --git a/plugin/spatialnavigation4dir.cpp b/plugin/spatialnavigation4dir.cpp
index bc1d8f8..8bccd7c 100644
--- a/plugin/spatialnavigation4dir.cpp
+++ b/plugin/spatialnavigation4dir.cpp
@@ -100,34 +100,32 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
//item that is closest within the projection
CursorNavigationAttached* inProjectionItem = nullptr;
- qreal inProjectionItemDistance = -1;
+ float inProjectionItemDistance = -1;
//item that is closest in the general direction, but not within projection
CursorNavigationAttached* inDirectionItem = nullptr;
- qreal inDirectionItemDistance = -1;
+ float inDirectionItemDistance = -1;
for (auto candidate : candidates)
{
QQuickItem *candidateItem = candidate->item();
- if (!candidateItem->isVisible() || !candidateItem->isEnabled()) {
- //qDebug() << "skipping a invisible/disabled item";
+ if (!candidate->available() || candidate == currentItem)
continue;
- }
//scene coords of the candidate
QRectF candidateSceneRect = candidateItem->mapRectToScene(
- QRect( 0, 0,
+ QRectF( 0, 0,
candidateItem->width(), candidateItem->height() ));
if (isInDirection(candidateSceneRect)) {
if (isInProjection(candidateSceneRect)) {
- int dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
+ float dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
if (inProjectionItemDistance > dist || !inProjectionItem)
{
inProjectionItemDistance = dist;
inProjectionItem = candidate;
}
} else if (!inProjectionItem) {
- int dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
+ float dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
if (inDirectionItemDistance > dist || !inDirectionItem)
{
inDirectionItemDistance = dist;