some what working d-pad

This commit is contained in:
Dante Ruiz 2017-01-16 22:37:08 +00:00
parent 865a78a8c8
commit d3fa7651c9
8 changed files with 76 additions and 8 deletions

View file

@ -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();
}
}
}

View file

@ -109,6 +109,7 @@ Item {
MouseArea {
anchors.fill: parent
hoverEnabled: true
enabled: true
onClicked: {
console.log("Tablet Button Clicked!");
if (tabletButton.inDebugMode) {

View file

@ -5,7 +5,7 @@ import QtQml 2.2
import "."
import "../../styles-uit"
Item {
FocusScope {
id: tabletMenu
objectName: "tabletMenu"

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -51,6 +51,10 @@ QQuickWindow* TabletScriptingInterface::getTabletWindow() {
TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet("com.highfidelity.interface.tablet.system"));
QObject* qmlSurface = tablet->getTabletSurface();
OffscreenQmlSurface* surface = dynamic_cast<OffscreenQmlSurface*>(qmlSurface);
if (!surface) {
return nullptr;
}
QQuickWindow* window = surface->getWindow();
return window;
}
@ -212,6 +216,7 @@ void TabletProxy::addButtonsToHomeScreen() {
}
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
QMetaObject::invokeMethod(_qmlTabletRoot, "forceFocus");
}
QObject* TabletProxy::getTabletSurface() {