Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -11,10 +11,11 @@ · 10 unmodified lines | |||
| 11 | #include <QtCore/QThread> | 11 | #include <QtCore/QThread> |
| 12 | 12 | ||
| 13 | #include <AccountManager.h> | 13 | #include <AccountManager.h> |
| 14 | #include "DependencyManager.h" | ||
| 14 | #include <PathUtils.h> | 15 | #include <PathUtils.h> |
| 16 | #include <QmlWindowClass.h> | ||
| 15 | #include <RegisteredMetaTypes.h> | 17 | #include <RegisteredMetaTypes.h> |
| 16 | #include "ScriptEngineLogging.h" | 18 | #include "ScriptEngineLogging.h" |
| 17 | #include "DependencyManager.h" | ||
| 18 | #include <OffscreenUi.h> | 19 | #include <OffscreenUi.h> |
| 19 | #include <InfoView.h> | 20 | #include <InfoView.h> |
| 20 | #include "SoundEffect.h" | 21 | #include "SoundEffect.h" |
| @@ -159,6 +160,10 @@ static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; · 138 unmodified lines | |||
| 159 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; | 160 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; |
| 160 | static int s_windowNameCounter = 1; | 161 | static int s_windowNameCounter = 1; |
| 161 | 162 | ||
| 163 | class TabletRootWindow : public QmlWindowClass { | ||
| 164 | virtual QString qmlSource() const { return "hifi/tablet/WindowRoot.qml"; } | ||
| 165 | }; | ||
| 166 | |||
| 162 | TabletProxy::TabletProxy(QString name) : _name(name) { | 167 | TabletProxy::TabletProxy(QString name) : _name(name) { |
| 163 | 168 | ||
| 164 | } | 169 | } |
| @@ -177,13 +182,16 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 12 unmodified lines | |||
| 177 | // create new desktop window | 182 | // create new desktop window |
| 178 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | 183 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 179 | offscreenUi->executeOnUiThread([=, this] { | 184 | offscreenUi->executeOnUiThread([=, this] { |
| 180 | InfoView::registerType(); | 185 | auto tabletRootWindow = new TabletRootWindow(); |
| 181 | QString name = _name + QString("%1").arg(s_windowNameCounter++); | 186 | tabletRootWindow->initQml(QVariantMap()); |
| 182 | offscreenUi->show(QUrl("hifi/tablet/WindowRoot.qml"), name, [&](QQmlContext* context, QObject* newObject) { | 187 | auto quickItem = tabletRootWindow->asQuickItem(); |
| 183 | QQuickItem* item = dynamic_cast<QQuickItem*>(newObject); | 188 | _desktopWindow = tabletRootWindow; |
| 184 | _desktopWindow = item; | 189 | QMetaObject::invokeMethod(quickItem, "setShown", Q_ARG(const QVariant&, QVariant(false))); |
| 185 | QObject::connect(_desktopWindow, SIGNAL(windowClosed), this, SLOT(desktopWindowClosed())); | 190 | |
| 186 | }); | 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); | ||
| 187 | }); | 195 | }); |
| 188 | } else { | 196 | } else { |
| 189 | removeButtonsFromToolbar(); | 197 | removeButtonsFromToolbar(); |
| @@ -271,7 +279,7 @@ void TabletProxy::gotoMenuScreen(const QString& submenu) { · 81 unmodified lines | |||
| 271 | if (!_toolbarMode && _qmlTabletRoot) { | 279 | if (!_toolbarMode && _qmlTabletRoot) { |
| 272 | root = _qmlTabletRoot; | 280 | root = _qmlTabletRoot; |
| 273 | } else if (_toolbarMode && _desktopWindow) { | 281 | } else if (_toolbarMode && _desktopWindow) { |
| 274 | root = _desktopWindow; | 282 | root = _desktopWindow->asQuickItem(); |
| 275 | } | 283 | } |
| 276 | 284 | ||
| 277 | if (root) { | 285 | if (root) { |
| @@ -294,7 +302,7 @@ void TabletProxy::loadQMLSource(const QVariant& path) { · 16 unmodified lines | |||
| 294 | if (!_toolbarMode && _qmlTabletRoot) { | 302 | if (!_toolbarMode && _qmlTabletRoot) { |
| 295 | root = _qmlTabletRoot; | 303 | root = _qmlTabletRoot; |
| 296 | } else if (_toolbarMode && _desktopWindow) { | 304 | } else if (_toolbarMode && _desktopWindow) { |
| 297 | root = _desktopWindow; | 305 | root = _desktopWindow->asQuickItem(); |
| 298 | } | 306 | } |
| 299 | 307 | ||
| 300 | if (root) { | 308 | if (root) { |
| @@ -317,8 +325,8 @@ void TabletProxy::gotoHomeScreen() { · 16 unmodified lines | |||
| 317 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); | 325 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 318 | } else if (_toolbarMode && _desktopWindow) { | 326 | } else if (_toolbarMode && _desktopWindow) { |
| 319 | // close desktop window | 327 | // close desktop window |
| 320 | if (_desktopWindow) { | 328 | if (_desktopWindow->asQuickItem()) { |
| 321 | QMetaObject::invokeMethod(_desktopWindow, "setShown", Q_ARG(const QVariant&, QVariant(false))); | 329 | QMetaObject::invokeMethod(_desktopWindow->asQuickItem(), "setShown", Q_ARG(const QVariant&, QVariant(false))); |
| 322 | } | 330 | } |
| 323 | } | 331 | } |
| 324 | _state = State::Home; | 332 | _state = State::Home; |
| @@ -336,33 +344,47 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS · 11 unmodified lines | |||
| 336 | if (!_toolbarMode && _qmlTabletRoot) { | 344 | if (!_toolbarMode && _qmlTabletRoot) { |
| 337 | root = _qmlTabletRoot; | 345 | root = _qmlTabletRoot; |
| 338 | } else if (_toolbarMode && _desktopWindow) { | 346 | } else if (_toolbarMode && _desktopWindow) { |
| 339 | root = _desktopWindow; | 347 | root = _desktopWindow->asQuickItem(); |
| 340 | } | 348 | } |
| 341 | 349 | ||
| 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 | } | ||
| 349 | if (root) { | 350 | if (root) { |
| 351 | QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | ||
| 350 | QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true))); | 352 | QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true))); |
| 351 | QMetaObject::invokeMethod(root, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl))); | 353 | QMetaObject::invokeMethod(root, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl))); |
| 352 | } | 354 | } |
| 355 | _state = State::Web; | ||
| 356 | emit screenChanged(QVariant("Web"), QVariant(url)); | ||
| 353 | } | 357 | } |
| 354 | 358 | ||
| 355 | QObject* TabletProxy::addButton(const QVariant& properties) { | 359 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 356 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); | 360 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 357 | std::lock_guard<std::mutex> guard(_mutex); | 361 | std::lock_guard<std::mutex> guard(_mutex); |
| 358 | _tabletButtonProxies.push_back(tabletButtonProxy); | 362 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 359 | if (_qmlTabletRoot) { | 363 | if (!_toolbarMode && _qmlTabletRoot) { |
| 360 | auto tablet = getQmlTablet(); | 364 | auto tablet = getQmlTablet(); |
| 361 | if (tablet) { | 365 | if (tablet) { |
| 362 | addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data()); | 366 | addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data()); |
| 363 | } else { | 367 | } else { |
| 364 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; | 368 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; |
| 365 | } | 369 | } |
| 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 | } | ||
| 366 | } | 388 | } |
| 367 | return tabletButtonProxy.data(); | 389 | return tabletButtonProxy.data(); |
| 368 | } | 390 | } |
| @@ -381,11 +403,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 12 unmodified lines | |||
| 381 | 403 | ||
| 382 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | 404 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 383 | if (iter != _tabletButtonProxies.end()) { | 405 | if (iter != _tabletButtonProxies.end()) { |
| 384 | if (_qmlTabletRoot) { | 406 | if (!_toolbarMode && _qmlTabletRoot) { |
| 385 | (*iter)->setQmlButton(nullptr); | 407 | (*iter)->setQmlButton(nullptr); |
| 386 | if (tablet) { | 408 | if (tablet) { |
| 387 | QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | 409 | QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); |
| 388 | } | 410 | } |
| 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); | ||
| 389 | } | 418 | } |
| 390 | _tabletButtonProxies.erase(iter); | 419 | _tabletButtonProxies.erase(iter); |
| 391 | } else { | 420 | } else { |
| @@ -412,14 +441,18 @@ void TabletProxy::updateAudioBar(const double micLevel) { · 20 unmodified lines | |||
| 412 | } | 441 | } |
| 413 | 442 | ||
| 414 | void TabletProxy::emitScriptEvent(QVariant msg) { | 443 | void TabletProxy::emitScriptEvent(QVariant msg) { |
| 415 | if (_qmlOffscreenSurface) { | 444 | if (!_toolbarMode && _qmlOffscreenSurface) { |
| 416 | QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg)); | 445 | 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)); | ||
| 417 | } | 448 | } |
| 418 | } | 449 | } |
| 419 | 450 | ||
| 420 | void TabletProxy::sendToQml(QVariant msg) { | 451 | void TabletProxy::sendToQml(QVariant msg) { |
| 421 | if (_qmlOffscreenSurface) { | 452 | if (!_toolbarMode && _qmlOffscreenSurface) { |
| 422 | QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg)); | 453 | 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)); | ||
| 423 | } | 456 | } |
| 424 | } | 457 | } |
| 425 | 458 | ||
| @@ -446,7 +479,7 @@ void TabletProxy::addButtonsToMenuScreen() { · 20 unmodified lines | |||
| 446 | if (!_toolbarMode && _qmlTabletRoot) { | 479 | if (!_toolbarMode && _qmlTabletRoot) { |
| 447 | root = _qmlTabletRoot; | 480 | root = _qmlTabletRoot; |
| 448 | } else if (_toolbarMode && _desktopWindow) { | 481 | } else if (_toolbarMode && _desktopWindow) { |
| 449 | root = _desktopWindow; | 482 | root = _desktopWindow->asQuickItem(); |
| 450 | } | 483 | } |
| 451 | 484 | ||
| 452 | if (!root) { | 485 | if (!root) { |