summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2018-12-04 15:39:53 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:33:53 +0100
commit1b7b25b06aaac3889be21aaa34654af9f5ac0262 (patch)
tree7469ae8ceb4d5f1bfbaf881bbd16623d488668ea /plugin
parentc58955328688a73bea53f65cd38dd3f07229b3e9 (diff)
Simplified the 4 way algorithm
Diffstat (limited to 'plugin')
-rw-r--r--plugin/spatialnavigation360.cpp2
-rw-r--r--plugin/spatialnavigation4dir.cpp74
2 files changed, 24 insertions, 52 deletions
diff --git a/plugin/spatialnavigation360.cpp b/plugin/spatialnavigation360.cpp
index 8dd0b20..bddcc5a 100644
--- a/plugin/spatialnavigation360.cpp
+++ b/plugin/spatialnavigation360.cpp
@@ -151,7 +151,7 @@ CursorNavigationAttached* SpatialNavigation360::getNextCandidate(
//item that overlaps the center of the selector beam
CursorNavigationAttached* directHitItem = nullptr;
qreal directHitDistance = -1;
- //item that overlaps selector beam does not overlap with the center
+ //item that overlaps selector beam, but does not overlap with the center
CursorNavigationAttached* withinToleranceItem = nullptr;
qreal withinToleranceDistance = -1;
diff --git a/plugin/spatialnavigation4dir.cpp b/plugin/spatialnavigation4dir.cpp
index ac72e4e..bc1d8f8 100644
--- a/plugin/spatialnavigation4dir.cpp
+++ b/plugin/spatialnavigation4dir.cpp
@@ -62,7 +62,6 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
if (CursorNavigationCommand::angleIsBetween(cmd.angle, right_start, right_end) ||
CursorNavigationCommand::angleIsBetween(cmd.angle, left_start, left_end) ) {
- //if (cmd == CursorNavigationCommand::Right || cmd == CursorNavigationCommand::Left) {
isInProjection = [&currentItemSceneRect](const QRectF &itemRect) {
return !( currentItemSceneRect.y() > itemRect.y()+itemRect.height() ||
@@ -81,7 +80,6 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
} else if (CursorNavigationCommand::angleIsBetween(cmd.angle, left_end, right_start) ||
CursorNavigationCommand::angleIsBetween(cmd.angle, right_end, left_start)) {
- //} else if (cmd == Command_Up || cmd == Command_Down) {
isInProjection = [&currentItemSceneRect](const QRectF &itemRect) {
return !( currentItemSceneRect.x() > itemRect.x()+itemRect.width() ||
currentItemSceneRect.x()+currentItemSceneRect.width() < itemRect.x() );
@@ -100,9 +98,12 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
return nullptr;
}
- std::pair<CursorNavigationAttached*,int> closest(nullptr,0);
-
- //qDebug() << "current: x=" << currentItemSceneRect.x() << " y=" << currentItemSceneRect.y();
+ //item that is closest within the projection
+ CursorNavigationAttached* inProjectionItem = nullptr;
+ qreal inProjectionItemDistance = -1;
+ //item that is closest in the general direction, but not within projection
+ CursorNavigationAttached* inDirectionItem = nullptr;
+ qreal inDirectionItemDistance = -1;
for (auto candidate : candidates)
{
@@ -117,57 +118,28 @@ CursorNavigationAttached* SpatialNavigation4Dir::getNextCandidate(
QRect( 0, 0,
candidateItem->width(), candidateItem->height() ));
- //qDebug() << "x=" << candidateSceneRect.x() << " y=" << candidateSceneRect.y();
-
- if (isInDirection(candidateSceneRect) && isInProjection(candidateSceneRect))
- {
- //qDebug() << " is in direction and projection...";
- int dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
- if (closest.second > dist || !closest.first)
- {
- closest.second = dist;
- closest.first = candidate;
- }
- }
- }
-
- if (closest.first)
- {
- qDebug() << "chosen one: " << closest.first->item()->mapRectToScene(
- QRect( 0, 0,
- closest.first->item()->width(), closest.first->item()->height() ));
- }
-
- if (!closest.first) {
- //qDebug() << Q_FUNC_INFO << " looking for a candidate in the general direction...";
-
- for (auto candidate : candidates)
- {
- QQuickItem *candidateItem = candidate->item();
- if (!candidateItem->isVisible() || !candidateItem->isEnabled()) {
- //qDebug() << "skipping a invisible/disabled item";
- continue;
- }
-
- //scene coords of the candidate
- QRectF candidateSceneRect = candidateItem->mapRectToScene(
- QRect( 0, 0,
- candidateItem->width(), candidateItem->height() ));
-
- if (isInDirection(candidateSceneRect))
- {
+ if (isInDirection(candidateSceneRect)) {
+ if (isInProjection(candidateSceneRect)) {
+ int dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
+ if (inProjectionItemDistance > dist || !inProjectionItem)
+ {
+ inProjectionItemDistance = dist;
+ inProjectionItem = candidate;
+ }
+ } else if (!inProjectionItem) {
int dist = distanceSquared(currentItemSceneRect,candidateSceneRect);
- if (closest.second > dist || !closest.first)
+ if (inDirectionItemDistance > dist || !inDirectionItem)
{
- closest.second = dist;
- closest.first = candidate;
+ inDirectionItemDistance = dist;
+ inDirectionItem = candidate;
}
}
}
}
- qDebug() << Q_FUNC_INFO << " selected candidate:" << closest.first;
-
- return closest.first;
-
+ if (inProjectionItem)
+ {
+ return inProjectionItem;
+ }
+ return inDirectionItem;
}