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 | 11 | #include <QtCore/QThread> |
| 12 | 12 | |
| 13 | 13 | #include <AccountManager.h> |
| 14 | +#include "DependencyManager.h" | |
| 14 | 15 | #include <PathUtils.h> |
| 16 | +#include <QmlWindowClass.h> | |
| 15 | 17 | #include <RegisteredMetaTypes.h> |
| 16 | 18 | #include "ScriptEngineLogging.h" |
| 17 | −#include "DependencyManager.h" | |
| 18 | 19 | #include <OffscreenUi.h> |
| 19 | 20 | #include <InfoView.h> |
| 20 | 21 | #include "SoundEffect.h" |
| @@ -159,6 +160,10 @@ static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; · 138 unmodified lines | ||
| 159 | 160 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; |
| 160 | 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 | 167 | TabletProxy::TabletProxy(QString name) : _name(name) { |
| 163 | 168 | |
| 164 | 169 | } |
| @@ -177,13 +182,16 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 12 unmodified lines | ||
| 177 | 182 | // create new desktop window |
| 178 | 183 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 179 | 184 | 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); | |
| 187 | 195 | }); |
| 188 | 196 | } else { |
| 189 | 197 | removeButtonsFromToolbar(); |
| @@ -271,7 +279,7 @@ void TabletProxy::gotoMenuScreen(const QString& submenu) { · 81 unmodified lines | ||
| 271 | 279 | if (!_toolbarMode && _qmlTabletRoot) { |
| 272 | 280 | root = _qmlTabletRoot; |
| 273 | 281 | } else if (_toolbarMode && _desktopWindow) { |
| 274 | − root = _desktopWindow; | |
| 282 | + root = _desktopWindow->asQuickItem(); | |
| 275 | 283 | } |
| 276 | 284 | |
| 277 | 285 | if (root) { |
| @@ -294,7 +302,7 @@ void TabletProxy::loadQMLSource(const QVariant& path) { · 16 unmodified lines | ||
| 294 | 302 | if (!_toolbarMode && _qmlTabletRoot) { |
| 295 | 303 | root = _qmlTabletRoot; |
| 296 | 304 | } else if (_toolbarMode && _desktopWindow) { |
| 297 | − root = _desktopWindow; | |
| 305 | + root = _desktopWindow->asQuickItem(); | |
| 298 | 306 | } |
| 299 | 307 | |
| 300 | 308 | if (root) { |
| @@ -317,8 +325,8 @@ void TabletProxy::gotoHomeScreen() { · 16 unmodified lines | ||
| 317 | 325 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 318 | 326 | } else if (_toolbarMode && _desktopWindow) { |
| 319 | 327 | // 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))); | |
| 322 | 330 | } |
| 323 | 331 | } |
| 324 | 332 | _state = State::Home; |
| @@ -336,33 +344,47 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS · 11 unmodified lines | ||
| 336 | 344 | if (!_toolbarMode && _qmlTabletRoot) { |
| 337 | 345 | root = _qmlTabletRoot; |
| 338 | 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 | 350 | if (root) { |
| 351 | + QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | |
| 350 | 352 | QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true))); |
| 351 | 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 | 359 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 356 | 360 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 357 | 361 | std::lock_guard<std::mutex> guard(_mutex); |
| 358 | 362 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 359 | − if (_qmlTabletRoot) { | |
| 363 | + if (!_toolbarMode && _qmlTabletRoot) { | |
| 360 | 364 | auto tablet = getQmlTablet(); |
| 361 | 365 | if (tablet) { |
| 362 | 366 | addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data()); |
| 363 | 367 | } else { |
| 364 | 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 | 389 | return tabletButtonProxy.data(); |
| 368 | 390 | } |
| @@ -381,11 +403,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 12 unmodified lines | ||
| 381 | 403 | |
| 382 | 404 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 383 | 405 | if (iter != _tabletButtonProxies.end()) { |
| 384 | − if (_qmlTabletRoot) { | |
| 406 | + if (!_toolbarMode && _qmlTabletRoot) { | |
| 385 | 407 | (*iter)->setQmlButton(nullptr); |
| 386 | 408 | if (tablet) { |
| 387 | 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 | 419 | _tabletButtonProxies.erase(iter); |
| 391 | 420 | } else { |
| @@ -412,14 +441,18 @@ void TabletProxy::updateAudioBar(const double micLevel) { · 20 unmodified lines | ||
| 412 | 441 | } |
| 413 | 442 | |
| 414 | 443 | void TabletProxy::emitScriptEvent(QVariant msg) { |
| 415 | − if (_qmlOffscreenSurface) { | |
| 444 | + if (!_toolbarMode && _qmlOffscreenSurface) { | |
| 416 | 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 | 451 | void TabletProxy::sendToQml(QVariant msg) { |
| 421 | − if (_qmlOffscreenSurface) { | |
| 452 | + if (!_toolbarMode && _qmlOffscreenSurface) { | |
| 422 | 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 | 479 | if (!_toolbarMode && _qmlTabletRoot) { |
| 447 | 480 | root = _qmlTabletRoot; |
| 448 | 481 | } else if (_toolbarMode && _desktopWindow) { |
| 449 | − root = _desktopWindow; | |
| 482 | + root = _desktopWindow->asQuickItem(); | |
| 450 | 483 | } |
| 451 | 484 | |
| 452 | 485 | if (!root) { |