summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2018-12-07 10:52:06 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:33:53 +0100
commit6fd358d2fd82cd06dbe25a019e7de19817ba3017 (patch)
tree4098c93b7a6728b6b2c3c1d2765fac0a85e42876 /plugin
parent65b3492325672bc24400edbdeb0aa91b46cb8c8e (diff)
Add available-function for a cursor navigable
Availability means that the item first of all accepting cursor, visible, enabled, and within its parent's geometry. This value is meant for the algorithms to define if item is navigable.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/cursornavigationattached.cpp10
-rw-r--r--plugin/cursornavigationattached.h7
-rw-r--r--plugin/spatialnavigation360.cpp6
-rw-r--r--plugin/spatialnavigation4dir.cpp14
4 files changed, 25 insertions, 12 deletions
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;