History

EventBridge support

Anthony J. Thibault committed 9 years ago

Commit ed11eda1 parent 912e8aa5 files · +65 −29Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+58−25
@@ -11,10 +11,11 @@ · 10 unmodified lines
1111 #include <QtCore/QThread>
1212
1313 #include <AccountManager.h>
14+#include "DependencyManager.h"
1415 #include <PathUtils.h>
16+#include <QmlWindowClass.h>
1517 #include <RegisteredMetaTypes.h>
1618 #include "ScriptEngineLogging.h"
17−#include "DependencyManager.h"
1819 #include <OffscreenUi.h>
1920 #include <InfoView.h>
2021 #include "SoundEffect.h"
@@ -159,6 +160,10 @@ static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; · 138 unmodified lines
159160 static const char* VRMENU_SOURCE_URL = "TabletMenu.qml";
160161 static int s_windowNameCounter = 1;
161162
163+class TabletRootWindow : public QmlWindowClass {
164+ virtual QString qmlSource() const { return "hifi/tablet/WindowRoot.qml"; }
165+};
166+
162167 TabletProxy::TabletProxy(QString name) : _name(name) {
163168
164169 }
@@ -177,13 +182,16 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 12 unmodified lines
177182 // create new desktop window
178183 auto offscreenUi = DependencyManager::get<OffscreenUi>();
179184 offscreenUi->executeOnUiThread([=, this] {
180− InfoView::registerType();
181− QString name = _name + QString("%1").arg(s_windowNameCounter++);
182− offscreenUi->show(QUrl("hifi/tablet/WindowRoot.qml"), name, [&](QQmlContext* context, QObject* newObject) {
183− QQuickItem* item = dynamic_cast<QQuickItem*>(newObject);
184− _desktopWindow = item;
185− QObject::connect(_desktopWindow, SIGNAL(windowClosed), this, SLOT(desktopWindowClosed()));
186− });
185+ auto tabletRootWindow = new TabletRootWindow();
186+ tabletRootWindow->initQml(QVariantMap());
187+ auto quickItem = tabletRootWindow->asQuickItem();
188+ _desktopWindow = tabletRootWindow;
189+ QMetaObject::invokeMethod(quickItem, "setShown", Q_ARG(const QVariant&, QVariant(false)));
190+
191+ QObject::connect(tabletRootWindow, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant)));
192+
193+ // forward qml surface events to interface js
194+ connect(tabletRootWindow, &QmlWindowClass::fromQml, this, &TabletProxy::fromQml);
187195 });
188196 } else {
189197 removeButtonsFromToolbar();
@@ -271,7 +279,7 @@ void TabletProxy::gotoMenuScreen(const QString& submenu) { · 81 unmodified lines
271279 if (!_toolbarMode && _qmlTabletRoot) {
272280 root = _qmlTabletRoot;
273281 } else if (_toolbarMode && _desktopWindow) {
274− root = _desktopWindow;
282+ root = _desktopWindow->asQuickItem();
275283 }
276284
277285 if (root) {
@@ -294,7 +302,7 @@ void TabletProxy::loadQMLSource(const QVariant& path) { · 16 unmodified lines
294302 if (!_toolbarMode && _qmlTabletRoot) {
295303 root = _qmlTabletRoot;
296304 } else if (_toolbarMode && _desktopWindow) {
297− root = _desktopWindow;
305+ root = _desktopWindow->asQuickItem();
298306 }
299307
300308 if (root) {
@@ -317,8 +325,8 @@ void TabletProxy::gotoHomeScreen() { · 16 unmodified lines
317325 QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
318326 } else if (_toolbarMode && _desktopWindow) {
319327 // close desktop window
320− if (_desktopWindow) {
321− QMetaObject::invokeMethod(_desktopWindow, "setShown", Q_ARG(const QVariant&, QVariant(false)));
328+ if (_desktopWindow->asQuickItem()) {
329+ QMetaObject::invokeMethod(_desktopWindow->asQuickItem(), "setShown", Q_ARG(const QVariant&, QVariant(false)));
322330 }
323331 }
324332 _state = State::Home;
@@ -336,33 +344,47 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS · 11 unmodified lines
336344 if (!_toolbarMode && _qmlTabletRoot) {
337345 root = _qmlTabletRoot;
338346 } else if (_toolbarMode && _desktopWindow) {
339− root = _desktopWindow;
347+ root = _desktopWindow->asQuickItem();
340348 }
341349
342− if (_state != State::Web) {
343− if (root) {
344− QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
345− }
346− _state = State::Web;
347− emit screenChanged(QVariant("Web"), QVariant(url));
348− }
349350 if (root) {
351+ QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
350352 QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
351353 QMetaObject::invokeMethod(root, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
352354 }
355+ _state = State::Web;
356+ emit screenChanged(QVariant("Web"), QVariant(url));
353357 }
354358
355359 QObject* TabletProxy::addButton(const QVariant& properties) {
356360 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
357361 std::lock_guard<std::mutex> guard(_mutex);
358362 _tabletButtonProxies.push_back(tabletButtonProxy);
359− if (_qmlTabletRoot) {
363+ if (!_toolbarMode && _qmlTabletRoot) {
360364 auto tablet = getQmlTablet();
361365 if (tablet) {
362366 addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data());
363367 } else {
364368 qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
365369 }
370+ } else if (_toolbarMode) {
371+
372+ auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
373+ QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
374+
375+ Qt::ConnectionType connectionType = Qt::AutoConnection;
376+ if (QThread::currentThread() != toolbarProxy->thread()) {
377+ connectionType = Qt::BlockingQueuedConnection;
378+ }
379+
380+ // copy properties from tablet button proxy to toolbar button proxy.
381+ QObject* toolbarButtonProxy = nullptr;
382+ bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, tabletButtonProxy->getProperties()));
383+ if (hasResult) {
384+ tabletButtonProxy->setToolbarButtonProxy(toolbarButtonProxy);
385+ } else {
386+ qCWarning(scriptengine) << "ToolbarProxy addButton has no result";
387+ }
366388 }
367389 return tabletButtonProxy.data();
368390 }
@@ -381,11 +403,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 12 unmodified lines
381403
382404 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
383405 if (iter != _tabletButtonProxies.end()) {
384− if (_qmlTabletRoot) {
406+ if (!_toolbarMode && _qmlTabletRoot) {
385407 (*iter)->setQmlButton(nullptr);
386408 if (tablet) {
387409 QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
388410 }
411+ } else if (_toolbarMode) {
412+ auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
413+ QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
414+
415+ // remove button from toolbarProxy
416+ QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getUuid().toString()));
417+ (*iter)->setToolbarButtonProxy(nullptr);
389418 }
390419 _tabletButtonProxies.erase(iter);
391420 } else {
@@ -412,14 +441,18 @@ void TabletProxy::updateAudioBar(const double micLevel) { · 20 unmodified lines
412441 }
413442
414443 void TabletProxy::emitScriptEvent(QVariant msg) {
415− if (_qmlOffscreenSurface) {
444+ if (!_toolbarMode && _qmlOffscreenSurface) {
416445 QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
446+ } else if (_toolbarMode && _desktopWindow) {
447+ QMetaObject::invokeMethod(_desktopWindow, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
417448 }
418449 }
419450
420451 void TabletProxy::sendToQml(QVariant msg) {
421− if (_qmlOffscreenSurface) {
452+ if (!_toolbarMode && _qmlOffscreenSurface) {
422453 QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
454+ } else if (_toolbarMode && _desktopWindow) {
455+ QMetaObject::invokeMethod(_desktopWindow, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
423456 }
424457 }
425458
@@ -446,7 +479,7 @@ void TabletProxy::addButtonsToMenuScreen() { · 20 unmodified lines
446479 if (!_toolbarMode && _qmlTabletRoot) {
447480 root = _qmlTabletRoot;
448481 } else if (_toolbarMode && _desktopWindow) {
449− root = _desktopWindow;
482+ root = _desktopWindow->asQuickItem();
450483 }
451484
452485 if (!root) {