mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:16:56 +02:00
controller with menus finally work
This commit is contained in:
parent
9a61b6030b
commit
baff07b0f9
7 changed files with 117 additions and 22 deletions
|
@ -1,9 +1,8 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import QtGraphicalEffects 1.0
|
import QtGraphicalEffects 1.0
|
||||||
|
|
||||||
FocusScope {
|
Item {
|
||||||
id: tablet
|
id: tablet
|
||||||
focus: true
|
|
||||||
objectName: "tablet"
|
objectName: "tablet"
|
||||||
property double micLevel: 0.8
|
property double micLevel: 0.8
|
||||||
property int rowIndex: 0
|
property int rowIndex: 0
|
||||||
|
@ -214,6 +213,9 @@ FocusScope {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.log("On Complete tab: " + activeFocus ); }
|
||||||
|
|
||||||
function setCurrentItemState(state) {
|
function setCurrentItemState(state) {
|
||||||
var index = rowIndex + columnIndex;
|
var index = rowIndex + columnIndex;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ FocusScope {
|
||||||
id: root
|
id: root
|
||||||
implicitHeight: background.height
|
implicitHeight: background.height
|
||||||
implicitWidth: background.width
|
implicitWidth: background.width
|
||||||
|
objectName: "root"
|
||||||
property alias currentItem: listView.currentItem
|
property alias currentItem: listView.currentItem
|
||||||
property alias model: listView.model
|
property alias model: listView.model
|
||||||
property bool isSubMenu: false
|
property bool isSubMenu: false
|
||||||
|
@ -45,6 +45,7 @@ FocusScope {
|
||||||
height: 720
|
height: 720
|
||||||
contentWidth: 480
|
contentWidth: 480
|
||||||
contentHeight: 720
|
contentHeight: 720
|
||||||
|
objectName: "menuList"
|
||||||
|
|
||||||
topMargin: hifi.dimensions.menuPadding.y
|
topMargin: hifi.dimensions.menuPadding.y
|
||||||
bottomMargin: hifi.dimensions.menuPadding.y
|
bottomMargin: hifi.dimensions.menuPadding.y
|
||||||
|
|
|
@ -81,6 +81,7 @@ Item {
|
||||||
if (menuStack.length) {
|
if (menuStack.length) {
|
||||||
topMenu = menuStack[menuStack.length - 1];
|
topMenu = menuStack[menuStack.length - 1];
|
||||||
topMenu.focus = true;
|
topMenu.focus = true;
|
||||||
|
topMenu.forceActiveFocus();
|
||||||
// show current menu level on nav bar
|
// show current menu level on nav bar
|
||||||
if (topMenu.objectName === "") {
|
if (topMenu.objectName === "") {
|
||||||
breadcrumbText.text = "Menu";
|
breadcrumbText.text = "Menu";
|
||||||
|
@ -98,6 +99,7 @@ Item {
|
||||||
menuStack.push(newMenu);
|
menuStack.push(newMenu);
|
||||||
topMenu = newMenu;
|
topMenu = newMenu;
|
||||||
topMenu.focus = true;
|
topMenu.focus = true;
|
||||||
|
topMenu.forceActiveFocus();
|
||||||
offscreenFlags.navigationFocused = true;
|
offscreenFlags.navigationFocused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import Hifi 1.0
|
import Hifi 1.0
|
||||||
|
import "../../desktop"
|
||||||
FocusScope {
|
FocusScope {
|
||||||
id: tabletRoot
|
id: tabletRoot
|
||||||
objectName: "tabletRoot"
|
objectName: "tabletRoot"
|
||||||
property var eventBridge;
|
property var eventBridge;
|
||||||
property bool desktopRoot: true
|
property bool desktopRoot: true
|
||||||
|
|
||||||
|
signal showDesktop();
|
||||||
|
|
||||||
function loadSource(url) {
|
function loadSource(url) {
|
||||||
loader.source = url;
|
loader.source = url;
|
||||||
}
|
}
|
||||||
|
@ -24,15 +26,7 @@ FocusScope {
|
||||||
function playButtonClickSound() {
|
function playButtonClickSound() {
|
||||||
buttonClickSound.play(globalPosition);
|
buttonClickSound.play(globalPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
function forceFocus() {
|
|
||||||
console.log(loader.item.objectName);
|
|
||||||
offscreenWindow.requestActivate();
|
|
||||||
loader.item.forceActiveFocus();
|
|
||||||
console.log("----------> adding focus");
|
|
||||||
console.log("------>Current foucs itrm: " + offscreenWindow.activeFocusItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: loader
|
id: loader
|
||||||
objectName: "loader"
|
objectName: "loader"
|
||||||
|
@ -42,7 +36,6 @@ FocusScope {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
onLoaded: {
|
onLoaded: {
|
||||||
// propogate eventBridge to WebEngineView
|
|
||||||
if (loader.item.hasOwnProperty("eventBridge")) {
|
if (loader.item.hasOwnProperty("eventBridge")) {
|
||||||
loader.item.eventBridge = eventBridge;
|
loader.item.eventBridge = eventBridge;
|
||||||
|
|
||||||
|
@ -53,13 +46,14 @@ FocusScope {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//loader.item.parent = tablxetRoot;
|
|
||||||
loader.item.forceActiveFocus();
|
loader.item.forceActiveFocus();
|
||||||
offscreenFlags.navigationFocus = true;
|
offscreenFlags.navigationFocused = true;
|
||||||
console.log(loader.item.count);
|
|
||||||
console.log("Current focus item " + offscreenWindow.activeFocusItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
offscreenWindow.requestActivate();
|
||||||
|
offscreenWindow.forceActiveFocus();
|
||||||
|
}
|
||||||
Component.onDestruction: { offscreenFlags.navigationFocused = false; }
|
Component.onDestruction: { offscreenFlags.navigationFocused = false; }
|
||||||
|
|
||||||
width: 480
|
width: 480
|
||||||
|
|
|
@ -1033,12 +1033,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
if (key != Qt::Key_unknown) {
|
if (key != Qt::Key_unknown) {
|
||||||
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
||||||
sendEvent(window, &event);
|
sendEvent(window, &event);
|
||||||
|
tabletScriptingInterface->processEvent(&event);
|
||||||
lastKey = key;
|
lastKey = key;
|
||||||
}
|
}
|
||||||
} else if (key != Qt::Key_unknown && window) {
|
} else if (key != Qt::Key_unknown && window) {
|
||||||
if (state) {
|
if (state) {
|
||||||
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
||||||
sendEvent(window, &event);
|
sendEvent(window, &event);
|
||||||
|
tabletScriptingInterface->processEvent(&event);
|
||||||
} else {
|
} else {
|
||||||
QKeyEvent event(QEvent::KeyRelease, key, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyRelease, key, Qt::NoModifier);
|
||||||
sendEvent(window, &event);
|
sendEvent(window, &event);
|
||||||
|
|
|
@ -59,6 +59,71 @@ QQuickWindow* TabletScriptingInterface::getTabletWindow() {
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabletScriptingInterface::processMenuEvents(QObject* object, const QKeyEvent* event) {
|
||||||
|
switch (event->key()) {
|
||||||
|
case Qt::Key_Down:
|
||||||
|
QMetaObject::invokeMethod(object, "nextItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Up:
|
||||||
|
QMetaObject::invokeMethod(object, "previousItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Left:
|
||||||
|
QMetaObject::invokeMethod(object, "previousPage");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Right:
|
||||||
|
QMetaObject::invokeMethod(object, "selectCurrentItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Return:
|
||||||
|
QMetaObject::invokeMethod(object, "selectCurrentItem");
|
||||||
|
break;
|
||||||
|
defualt:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabletScriptingInterface::processTabletEvents(QObject* object, const QKeyEvent* event) {
|
||||||
|
switch (event->key()) {
|
||||||
|
case Qt::Key_Down:
|
||||||
|
QMetaObject::invokeMethod(object, "downItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Up:
|
||||||
|
QMetaObject::invokeMethod(object, "upItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Left:
|
||||||
|
QMetaObject::invokeMethod(object, "previousItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Right:
|
||||||
|
QMetaObject::invokeMethod(object, "nextItem");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Qt::Key_Return:
|
||||||
|
QMetaObject::invokeMethod(object, "selectItem");
|
||||||
|
break;
|
||||||
|
defualt:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TabletScriptingInterface::processEvent(const QKeyEvent* event) {
|
||||||
|
TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet("com.highfidelity.interface.tablet.system"));
|
||||||
|
QObject* qmlTablet = tablet->getQmlTablet();
|
||||||
|
QObject* qmlMenu = tablet->getQmlMenu();
|
||||||
|
|
||||||
|
if (qmlTablet) {
|
||||||
|
processTabletEvents(qmlTablet, event);
|
||||||
|
} else if (qmlMenu) {
|
||||||
|
processMenuEvents(qmlMenu, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QObject* TabletScriptingInterface::getFlags()
|
QObject* TabletScriptingInterface::getFlags()
|
||||||
{
|
{
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
@ -215,8 +280,6 @@ void TabletProxy::addButtonsToHomeScreen() {
|
||||||
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
||||||
}
|
}
|
||||||
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
||||||
QMetaObject::invokeMethod(_qmlTabletRoot, "forceFocus");
|
|
||||||
qDebug() << "----> INVOKEMETHOD";
|
|
||||||
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
|
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +299,6 @@ void TabletProxy::addButtonsToMenuScreen() {
|
||||||
|
|
||||||
QQuickItem* VrMenu = loader->findChild<QQuickItem*>("tabletMenu");
|
QQuickItem* VrMenu = loader->findChild<QQuickItem*>("tabletMenu");
|
||||||
if (!VrMenu) {
|
if (!VrMenu) {
|
||||||
qDebug() << "----------> could not find vr menu";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +332,29 @@ QQuickItem* TabletProxy::getQmlTablet() const {
|
||||||
return tablet;
|
return tablet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QQuickItem* TabletProxy::getQmlMenu() const {
|
||||||
|
if (!_qmlTabletRoot) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
||||||
|
if (!loader) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem* VrMenu = loader->findChild<QQuickItem*>("tabletMenu");
|
||||||
|
if (!VrMenu) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem* menuList = VrMenu->findChild<QQuickItem*>("menuList");
|
||||||
|
if (!menuList) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
qDebug() << "---------->found menuList";
|
||||||
|
return menuList;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TabletButtonProxy
|
// TabletButtonProxy
|
||||||
//
|
//
|
||||||
|
|
|
@ -47,10 +47,16 @@ public:
|
||||||
|
|
||||||
void setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface);
|
void setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface);
|
||||||
|
|
||||||
|
void processEvent(const QKeyEvent* event);
|
||||||
|
|
||||||
QQuickWindow* getTabletWindow();
|
QQuickWindow* getTabletWindow();
|
||||||
|
|
||||||
QObject* getFlags();
|
QObject* getFlags();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void processMenuEvents(QObject* object, const QKeyEvent* event);
|
||||||
|
void processTabletEvents(QObject* object, const QKeyEvent* event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
std::map<QString, QSharedPointer<TabletProxy>> _tabletProxies;
|
std::map<QString, QSharedPointer<TabletProxy>> _tabletProxies;
|
||||||
|
@ -119,6 +125,10 @@ public:
|
||||||
|
|
||||||
QObject* getTabletSurface();
|
QObject* getTabletSurface();
|
||||||
|
|
||||||
|
QQuickItem* getQmlTablet() const;
|
||||||
|
|
||||||
|
QQuickItem* getQmlMenu() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Signaled when this tablet receives an event from the html/js embedded in the tablet
|
* Signaled when this tablet receives an event from the html/js embedded in the tablet
|
||||||
|
@ -133,7 +143,6 @@ private slots:
|
||||||
void addButtonsToMenuScreen();
|
void addButtonsToMenuScreen();
|
||||||
protected:
|
protected:
|
||||||
void removeButtonsFromHomeScreen();
|
void removeButtonsFromHomeScreen();
|
||||||
QQuickItem* getQmlTablet() const;
|
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
|
|
Loading…
Reference in a new issue