mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:29:01 +02:00
EventBridge support
This commit is contained in:
parent
912e8aa04a
commit
ed11edad56
5 changed files with 65 additions and 29 deletions
|
@ -15,6 +15,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSource(url) {
|
function loadSource(url) {
|
||||||
|
loader.source = ""; // HACK: make sure we load the qml fresh each time.
|
||||||
loader.source = url;
|
loader.source = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ Windows.ScrollingWindow {
|
||||||
signal showDesktop();
|
signal showDesktop();
|
||||||
|
|
||||||
function loadSource(url) {
|
function loadSource(url) {
|
||||||
|
loader.source = ""; // HACK: make sure we load the qml fresh each time.
|
||||||
loader.source = url;
|
loader.source = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
|
#include "DependencyManager.h"
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
|
#include <QmlWindowClass.h>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
#include "ScriptEngineLogging.h"
|
#include "ScriptEngineLogging.h"
|
||||||
#include "DependencyManager.h"
|
|
||||||
#include <OffscreenUi.h>
|
#include <OffscreenUi.h>
|
||||||
#include <InfoView.h>
|
#include <InfoView.h>
|
||||||
#include "SoundEffect.h"
|
#include "SoundEffect.h"
|
||||||
|
@ -159,6 +160,10 @@ static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml";
|
||||||
static const char* VRMENU_SOURCE_URL = "TabletMenu.qml";
|
static const char* VRMENU_SOURCE_URL = "TabletMenu.qml";
|
||||||
static int s_windowNameCounter = 1;
|
static int s_windowNameCounter = 1;
|
||||||
|
|
||||||
|
class TabletRootWindow : public QmlWindowClass {
|
||||||
|
virtual QString qmlSource() const { return "hifi/tablet/WindowRoot.qml"; }
|
||||||
|
};
|
||||||
|
|
||||||
TabletProxy::TabletProxy(QString name) : _name(name) {
|
TabletProxy::TabletProxy(QString name) : _name(name) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -177,13 +182,16 @@ void TabletProxy::setToolbarMode(bool toolbarMode) {
|
||||||
// create new desktop window
|
// create new desktop window
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
offscreenUi->executeOnUiThread([=, this] {
|
offscreenUi->executeOnUiThread([=, this] {
|
||||||
InfoView::registerType();
|
auto tabletRootWindow = new TabletRootWindow();
|
||||||
QString name = _name + QString("%1").arg(s_windowNameCounter++);
|
tabletRootWindow->initQml(QVariantMap());
|
||||||
offscreenUi->show(QUrl("hifi/tablet/WindowRoot.qml"), name, [&](QQmlContext* context, QObject* newObject) {
|
auto quickItem = tabletRootWindow->asQuickItem();
|
||||||
QQuickItem* item = dynamic_cast<QQuickItem*>(newObject);
|
_desktopWindow = tabletRootWindow;
|
||||||
_desktopWindow = item;
|
QMetaObject::invokeMethod(quickItem, "setShown", Q_ARG(const QVariant&, QVariant(false)));
|
||||||
QObject::connect(_desktopWindow, SIGNAL(windowClosed), this, SLOT(desktopWindowClosed()));
|
|
||||||
});
|
QObject::connect(tabletRootWindow, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant)));
|
||||||
|
|
||||||
|
// forward qml surface events to interface js
|
||||||
|
connect(tabletRootWindow, &QmlWindowClass::fromQml, this, &TabletProxy::fromQml);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
removeButtonsFromToolbar();
|
removeButtonsFromToolbar();
|
||||||
|
@ -271,7 +279,7 @@ void TabletProxy::gotoMenuScreen(const QString& submenu) {
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
} else if (_toolbarMode && _desktopWindow) {
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
root = _desktopWindow;
|
root = _desktopWindow->asQuickItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
@ -294,7 +302,7 @@ void TabletProxy::loadQMLSource(const QVariant& path) {
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
} else if (_toolbarMode && _desktopWindow) {
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
root = _desktopWindow;
|
root = _desktopWindow->asQuickItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
@ -317,8 +325,8 @@ void TabletProxy::gotoHomeScreen() {
|
||||||
QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
|
QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
|
||||||
} else if (_toolbarMode && _desktopWindow) {
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
// close desktop window
|
// close desktop window
|
||||||
if (_desktopWindow) {
|
if (_desktopWindow->asQuickItem()) {
|
||||||
QMetaObject::invokeMethod(_desktopWindow, "setShown", Q_ARG(const QVariant&, QVariant(false)));
|
QMetaObject::invokeMethod(_desktopWindow->asQuickItem(), "setShown", Q_ARG(const QVariant&, QVariant(false)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_state = State::Home;
|
_state = State::Home;
|
||||||
|
@ -336,33 +344,47 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
} else if (_toolbarMode && _desktopWindow) {
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
root = _desktopWindow;
|
root = _desktopWindow->asQuickItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_state != State::Web) {
|
|
||||||
if (root) {
|
|
||||||
QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
|
|
||||||
}
|
|
||||||
_state = State::Web;
|
|
||||||
emit screenChanged(QVariant("Web"), QVariant(url));
|
|
||||||
}
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
|
||||||
QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
|
QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
|
||||||
QMetaObject::invokeMethod(root, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
|
QMetaObject::invokeMethod(root, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
|
||||||
}
|
}
|
||||||
|
_state = State::Web;
|
||||||
|
emit screenChanged(QVariant("Web"), QVariant(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* TabletProxy::addButton(const QVariant& properties) {
|
QObject* TabletProxy::addButton(const QVariant& properties) {
|
||||||
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
||||||
std::lock_guard<std::mutex> guard(_mutex);
|
std::lock_guard<std::mutex> guard(_mutex);
|
||||||
_tabletButtonProxies.push_back(tabletButtonProxy);
|
_tabletButtonProxies.push_back(tabletButtonProxy);
|
||||||
if (_qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
auto tablet = getQmlTablet();
|
auto tablet = getQmlTablet();
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data());
|
addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data());
|
||||||
} else {
|
} else {
|
||||||
qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
|
qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
|
||||||
}
|
}
|
||||||
|
} else if (_toolbarMode) {
|
||||||
|
|
||||||
|
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||||
|
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
|
||||||
|
|
||||||
|
Qt::ConnectionType connectionType = Qt::AutoConnection;
|
||||||
|
if (QThread::currentThread() != toolbarProxy->thread()) {
|
||||||
|
connectionType = Qt::BlockingQueuedConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy properties from tablet button proxy to toolbar button proxy.
|
||||||
|
QObject* toolbarButtonProxy = nullptr;
|
||||||
|
bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, tabletButtonProxy->getProperties()));
|
||||||
|
if (hasResult) {
|
||||||
|
tabletButtonProxy->setToolbarButtonProxy(toolbarButtonProxy);
|
||||||
|
} else {
|
||||||
|
qCWarning(scriptengine) << "ToolbarProxy addButton has no result";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return tabletButtonProxy.data();
|
return tabletButtonProxy.data();
|
||||||
}
|
}
|
||||||
|
@ -381,11 +403,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) {
|
||||||
|
|
||||||
auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
|
auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
|
||||||
if (iter != _tabletButtonProxies.end()) {
|
if (iter != _tabletButtonProxies.end()) {
|
||||||
if (_qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
(*iter)->setQmlButton(nullptr);
|
(*iter)->setQmlButton(nullptr);
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
|
QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
|
||||||
}
|
}
|
||||||
|
} else if (_toolbarMode) {
|
||||||
|
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||||
|
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
|
||||||
|
|
||||||
|
// remove button from toolbarProxy
|
||||||
|
QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getUuid().toString()));
|
||||||
|
(*iter)->setToolbarButtonProxy(nullptr);
|
||||||
}
|
}
|
||||||
_tabletButtonProxies.erase(iter);
|
_tabletButtonProxies.erase(iter);
|
||||||
} else {
|
} else {
|
||||||
|
@ -412,14 +441,18 @@ void TabletProxy::updateAudioBar(const double micLevel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletProxy::emitScriptEvent(QVariant msg) {
|
void TabletProxy::emitScriptEvent(QVariant msg) {
|
||||||
if (_qmlOffscreenSurface) {
|
if (!_toolbarMode && _qmlOffscreenSurface) {
|
||||||
QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
||||||
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
|
QMetaObject::invokeMethod(_desktopWindow, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletProxy::sendToQml(QVariant msg) {
|
void TabletProxy::sendToQml(QVariant msg) {
|
||||||
if (_qmlOffscreenSurface) {
|
if (!_toolbarMode && _qmlOffscreenSurface) {
|
||||||
QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
||||||
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
|
QMetaObject::invokeMethod(_desktopWindow, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,7 +479,7 @@ void TabletProxy::addButtonsToMenuScreen() {
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
} else if (_toolbarMode && _desktopWindow) {
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
root = _desktopWindow;
|
root = _desktopWindow->asQuickItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
class TabletProxy;
|
class TabletProxy;
|
||||||
class TabletButtonProxy;
|
class TabletButtonProxy;
|
||||||
|
class QmlWindowClass;
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @namespace Tablet
|
* @namespace Tablet
|
||||||
|
@ -193,7 +194,7 @@ protected:
|
||||||
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
|
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
|
||||||
QQuickItem* _qmlTabletRoot { nullptr };
|
QQuickItem* _qmlTabletRoot { nullptr };
|
||||||
QObject* _qmlOffscreenSurface { nullptr };
|
QObject* _qmlOffscreenSurface { nullptr };
|
||||||
QQuickItem* _desktopWindow { nullptr };
|
QmlWindowClass* _desktopWindow { nullptr };
|
||||||
bool _toolbarMode { false };
|
bool _toolbarMode { false };
|
||||||
|
|
||||||
enum class State { Uninitialized, Home, Web, Menu, QML };
|
enum class State { Uninitialized, Home, Web, Menu, QML };
|
||||||
|
|
|
@ -31,6 +31,9 @@ public:
|
||||||
QmlWindowClass();
|
QmlWindowClass();
|
||||||
~QmlWindowClass();
|
~QmlWindowClass();
|
||||||
|
|
||||||
|
virtual void initQml(QVariantMap properties);
|
||||||
|
QQuickItem* asQuickItem() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
|
@ -81,9 +84,6 @@ protected:
|
||||||
|
|
||||||
virtual QString qmlSource() const { return "QmlWindow.qml"; }
|
virtual QString qmlSource() const { return "QmlWindow.qml"; }
|
||||||
|
|
||||||
virtual void initQml(QVariantMap properties);
|
|
||||||
QQuickItem* asQuickItem() const;
|
|
||||||
|
|
||||||
// FIXME needs to be initialized in the ctor once we have support
|
// FIXME needs to be initialized in the ctor once we have support
|
||||||
// for tool window panes in QML
|
// for tool window panes in QML
|
||||||
bool _toolWindow { false };
|
bool _toolWindow { false };
|
||||||
|
|
Loading…
Reference in a new issue