diff --git a/interface/resources/qml/hifi/tablet/Tablet.qml b/interface/resources/qml/hifi/tablet/Tablet.qml index 63ea386452..c51bb1a598 100644 --- a/interface/resources/qml/hifi/tablet/Tablet.qml +++ b/interface/resources/qml/hifi/tablet/Tablet.qml @@ -1,15 +1,19 @@ import QtQuick 2.0 import QtGraphicalEffects 1.0 -Item { +FocusScope { id: tablet objectName: "tablet" - + focus: true + enabled: true property double micLevel: 0.8 - + property int index: 0 + property int count: flowMain.children.length width: parent.width height: parent.height + //property alias currentItem: flowMain.currentItem + // called by C++ code to keep audio bar updated function setMicLevel(newMicLevel) { tablet.micLevel = newMicLevel; @@ -42,7 +46,6 @@ Item { // pass a reference to the tabletRoot object to the button. button.tabletRoot = parent.parent; - return button; } @@ -179,6 +182,7 @@ Item { clip: true Flow { id: flowMain + focus: true spacing: 16 anchors.right: parent.right anchors.rightMargin: 30 @@ -188,6 +192,50 @@ Item { anchors.bottomMargin: 30 anchors.top: parent.top anchors.topMargin: 30 + + function setCurrentItemState(state) { + flowMain.children[index].state = state; + } + function nextItem() { + setCurrentItemState("base state"); + index = (index + count + 1) % count; + setCurrentItemState("hover state"); + console.log("next item at index: " + index); + } + + function previousItem() { + setCurrentItemState("base state"); + index = (index + count - 1 ) % count; + setCurrentItemState("hover state"); + console.log("previous item at index: " + index); + } + + function upItem() { + setCurrentItemState("base state"); + index = (index + count - 3) % count; + setCurrentItemState("hover state"); + console.log("up item at index: " + index); + } + + function downItem() { + setCurrentItemState("base state"); + index = (index + count + 3) % count; + setCurrentItemState("hover state"); + console.log("down item at index :" + index); + } + + function selectItem() { + flowMain.children[index].clicked(); + if(tabletRoot) { + tabletRoot.playButtonClickSound(); + } + } + + Keys.onRightPressed: nextItem(); + Keys.onLeftPressed: previousItem(); + Keys.onDownPressed: downItem(); + Keys.onUpPressed: upItem(); + Keys.onReturnPressed: selectItem(); } } } diff --git a/interface/resources/qml/hifi/tablet/TabletButton.qml b/interface/resources/qml/hifi/tablet/TabletButton.qml index f9c668a81f..6c2685f155 100644 --- a/interface/resources/qml/hifi/tablet/TabletButton.qml +++ b/interface/resources/qml/hifi/tablet/TabletButton.qml @@ -109,6 +109,7 @@ Item { MouseArea { anchors.fill: parent hoverEnabled: true + enabled: true onClicked: { console.log("Tablet Button Clicked!"); if (tabletButton.inDebugMode) { diff --git a/interface/resources/qml/hifi/tablet/TabletMenu.qml b/interface/resources/qml/hifi/tablet/TabletMenu.qml index 39f48f0334..a782192b4d 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenu.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenu.qml @@ -5,7 +5,7 @@ import QtQml 2.2 import "." import "../../styles-uit" -Item { +FocusScope { id: tabletMenu objectName: "tabletMenu" diff --git a/interface/resources/qml/hifi/tablet/TabletMenuView.qml b/interface/resources/qml/hifi/tablet/TabletMenuView.qml index b02c5b67ec..dedbfc80ab 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuView.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuView.qml @@ -111,12 +111,14 @@ FocusScope { function previousItem() { currentIndex = (currentIndex + count - 1) % count; } function nextItem() { currentIndex = (currentIndex + count + 1) % count; } function selectCurrentItem() { if (currentIndex != -1) root.selected(currentItem.source); } + function previousPage() {console.log("going to previous page"); } Keys.onUpPressed: previousItem(); Keys.onDownPressed: nextItem(); Keys.onSpacePressed: selectCurrentItem(); Keys.onRightPressed: selectCurrentItem(); Keys.onReturnPressed: selectCurrentItem(); + Keys.onLeftPressed: previousPage(); } } diff --git a/interface/resources/qml/hifi/tablet/TabletMouseHandler.qml b/interface/resources/qml/hifi/tablet/TabletMouseHandler.qml index 13d8cec505..1eb5f7cdd1 100644 --- a/interface/resources/qml/hifi/tablet/TabletMouseHandler.qml +++ b/interface/resources/qml/hifi/tablet/TabletMouseHandler.qml @@ -91,7 +91,7 @@ Item { breadcrumbText.text = "Menu"; topMenu = null; offscreenFlags.navigationFocused = false; - menuRoot.enabled = false; + //menuRoot.enabled = false; } } @@ -100,6 +100,7 @@ Item { topMenu = newMenu; topMenu.focus = true; offscreenFlags.navigationFocused = true; + console.log(offscreenWindow.activeFocusItem); } function clearMenus() { @@ -159,7 +160,7 @@ Item { function popup(parent, items) { d.clearMenus(); - menuRoot.enabled = true; + //menuRoot.enabled = true; d.buildMenu(items, point); } diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index 541119d4f0..66c22e2843 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -5,6 +5,7 @@ Item { id: tabletRoot objectName: "tabletRoot" property var eventBridge; + property bool desktopRoot: true function loadSource(url) { loader.source = url; @@ -24,6 +25,10 @@ Item { buttonClickSound.play(globalPosition); } + function forceFocus() { + loader.item.forceActiveFocus(); + } + Loader { id: loader objectName: "loader" @@ -44,8 +49,14 @@ Item { } }); } + //loader.item.parent = tablxetRoot; + loader.item.forceActiveFocus(); + offscreenFlags.navigationFocus = true; + console.log(loader.item.count); + console.log("Current focus item " + offscreenWindow.activeFocusItem); } } + Component.onDestruction: { offscreenFlags.navigationFocused = false; } width: 480 height: 720 diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index af9d27b08b..2626170bd6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1037,7 +1037,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo sendEvent(window, &event); lastKey = key; } - } else if (key != Qt::Key_unknown) { + } else if (key != Qt::Key_unknown && window) { if (state) { QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier); sendEvent(window, &event); diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index e91bf051df..f15f7da53e 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -51,6 +51,10 @@ QQuickWindow* TabletScriptingInterface::getTabletWindow() { TabletProxy* tablet = qobject_cast(getTablet("com.highfidelity.interface.tablet.system")); QObject* qmlSurface = tablet->getTabletSurface(); OffscreenQmlSurface* surface = dynamic_cast(qmlSurface); + + if (!surface) { + return nullptr; + } QQuickWindow* window = surface->getWindow(); return window; } @@ -212,6 +216,7 @@ void TabletProxy::addButtonsToHomeScreen() { } auto loader = _qmlTabletRoot->findChild("loader"); QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); + QMetaObject::invokeMethod(_qmlTabletRoot, "forceFocus"); } QObject* TabletProxy::getTabletSurface() {