summaryrefslogtreecommitdiffstats
path: root/plugin/cursornavigation.cpp
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2018-11-06 15:39:36 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:31:43 +0100
commitfbe75056a6ca179504b33c74d741c540f5b22dcd (patch)
treec535cd55d285b8e2e6b9a450a88a8e316e5ba12f /plugin/cursornavigation.cpp
parent00fa5d9215d32124292fe3e45372acebac7b9d31 (diff)
More on scopes, works to some extent in the test program
Scope may be entered and escaped. Navigable items may have escape targets defined
Diffstat (limited to 'plugin/cursornavigation.cpp')
-rw-r--r--plugin/cursornavigation.cpp92
1 files changed, 73 insertions, 19 deletions
diff --git a/plugin/cursornavigation.cpp b/plugin/cursornavigation.cpp
index 7e4ba81..0011cb2 100644
--- a/plugin/cursornavigation.cpp
+++ b/plugin/cursornavigation.cpp
@@ -9,33 +9,26 @@ const char CursorNavigation::windowPropertyName[] = "cursor_navigation";
CursorNavigation::CursorNavigation(QQuickWindow *parent)
:QObject(parent)
,m_window(parent)
-,m_inputAdapter(parent, this)
+,m_inputAdapter(m_window->contentItem(), this)
,m_currentItem(nullptr)
-,m_rootItem(nullptr)
+,m_rootItem(new CursorNavigationAttached(nullptr))
{
+ m_rootItem->setParent(m_window->contentItem());
+
m_algorithms.push_back(new SpatialNavigation4Dir());
connect(m_window, &QQuickWindow::activeFocusItemChanged, this, &CursorNavigation::onActiveFocusItemChanged);
onActiveFocusItemChanged();
}
-bool CursorNavigation::inputCommand(CursorNavigationCommand cmd)
+bool CursorNavigation::inputCommand(const CursorNavigationCommand &cmd)
{
- CursorNavigationAttached *nextItem = nullptr;
-
- QList<CursorNavigationAttached*> &candidates = m_currentItem ?
- m_currentItem->m_parentNavigable->m_children :
- m_rootItem.m_children;
- for (auto alg : m_algorithms) {
- nextItem = alg->getNextCandidate(candidates, m_currentItem, cmd);
- if (nextItem) {
- setCursorOnItem(nextItem);
- break;
- }
+ if (cmd.action == CursorNavigationCommand::NoAction) {
+ return handleDirectionCommand(cmd);
+ } else {
+ return handleActionCommand(cmd);
}
-
- return true;
}
CursorNavigationAttached *CursorNavigation::qmlAttachedProperties(QObject *object)
@@ -96,7 +89,8 @@ void CursorNavigation::setCursorOnItem(CursorNavigationAttached *item)
if (item) {
item->setHasCursor(true);
m_currentItem = item;
- m_currentItem->item()->setFocus(true);
+ m_currentItem->item()->forceActiveFocus();
+ //m_currentItem->item()->setFocus(true);
qWarning() << "Set cursor to " << item->item();
} else {
qWarning() << "Set cursor to NULL";
@@ -130,8 +124,8 @@ void CursorNavigation::registerItem(CursorNavigationAttached* item)
item->m_parentNavigable=parentCNA;
parentCNA->m_children.append(item);
} else {
- m_rootItem.m_children.append(item);
- item->m_parentNavigable=&m_rootItem;
+ m_rootItem->m_children.append(item);
+ item->m_parentNavigable=m_rootItem;
}
}
@@ -145,3 +139,63 @@ void CursorNavigation::unregisterItem(CursorNavigationAttached* item)
item->m_parentNavigable->m_children.removeOne(item);
}
+bool CursorNavigation::handleDirectionCommand(const CursorNavigationCommand &cmd)
+{
+ qWarning() << "handleDirectionCommand";
+ CursorNavigationAttached *nextItem = nullptr;
+
+ QList<CursorNavigationAttached*> &candidates = m_currentItem ?
+ m_currentItem->m_parentNavigable->m_children :
+ m_rootItem->m_children;
+
+ for (auto alg : m_algorithms) {
+ nextItem = alg->getNextCandidate(candidates, m_currentItem, cmd);
+ if (nextItem) {
+ setCursorOnItem(nextItem);
+ break;
+ }
+ }
+
+ return true;
+}
+
+bool CursorNavigation::handleActionCommand(const CursorNavigationCommand &cmd)
+{
+ qWarning() << "handleActionCommand, cmd.action= " << cmd.action;
+ switch (cmd.action) {
+ case CursorNavigationCommand::Forward:
+ break;
+ case CursorNavigationCommand::Back:
+ break;
+ case CursorNavigationCommand::Activate:
+ break;
+ case CursorNavigationCommand::Escape: {
+ /* if item has escapeTrgate defined, set focus to that. otherwise leave
+ * scope, ie. go back to parent's parent in the hierarchy and set focus
+ * (back) to it (setting the focus further to one of its children
+ * depends on the focus mechanism).
+ * if we are already at the root item's children, nothing happens
+ */
+ if (!m_currentItem)
+ break;
+
+ QQuickItem *escapeTarget = m_currentItem->m_parentNavigable->escapeTarget();
+ if (!escapeTarget) {
+ if (m_currentItem->m_parentNavigable == m_rootItem) {
+ break;
+ }
+ escapeTarget = m_currentItem->m_parentNavigable->m_parentNavigable->item();
+ }
+ qWarning() << "escaping, target = " << escapeTarget;
+ setCursorOnItem(nullptr);
+ escapeTarget->forceActiveFocus();
+ onActiveFocusItemChanged();
+ //escapeTarget->setFocus(true);
+ break;
+ }
+
+ default:
+ break;
+ }
+}
+