Switching between tablet and toolbar is not as dynamic as I'd like but it's a start.
Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -15,7 +15,8 @@ · 14 unmodified lines | |||
| 15 | #include <RegisteredMetaTypes.h> | 15 | #include <RegisteredMetaTypes.h> |
| 16 | #include "ScriptEngineLogging.h" | 16 | #include "ScriptEngineLogging.h" |
| 17 | #include "DependencyManager.h" | 17 | #include "DependencyManager.h" |
| 18 | #include "OffscreenUi.h" | 18 | #include <OffscreenUi.h> |
| 19 | #include <InfoView.h> | ||
| 19 | #include "SoundEffect.h" | 20 | #include "SoundEffect.h" |
| 20 | 21 | ||
| 21 | TabletScriptingInterface::TabletScriptingInterface() { | 22 | TabletScriptingInterface::TabletScriptingInterface() { |
| @@ -156,9 +157,10 @@ QObject* TabletScriptingInterface::getFlags() · 134 unmodified lines | |||
| 156 | static const char* TABLET_SOURCE_URL = "Tablet.qml"; | 157 | static const char* TABLET_SOURCE_URL = "Tablet.qml"; |
| 157 | static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; | 158 | static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; |
| 158 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; | 159 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; |
| 160 | static int s_windowNameCounter = 1; | ||
| 159 | 161 | ||
| 160 | TabletProxy::TabletProxy(QString name) : _name(name) { | 162 | TabletProxy::TabletProxy(QString name) : _name(name) { |
| 161 | ; | 163 | |
| 162 | } | 164 | } |
| 163 | 165 | ||
| 164 | void TabletProxy::setToolbarMode(bool toolbarMode) { | 166 | void TabletProxy::setToolbarMode(bool toolbarMode) { |
| @@ -171,9 +173,27 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 6 unmodified lines | |||
| 171 | if (toolbarMode) { | 173 | if (toolbarMode) { |
| 172 | removeButtonsFromHomeScreen(); | 174 | removeButtonsFromHomeScreen(); |
| 173 | addButtonsToToolbar(); | 175 | addButtonsToToolbar(); |
| 176 | |||
| 177 | // create new desktop window | ||
| 178 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); | ||
| 179 | 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 | }); | ||
| 187 | }); | ||
| 174 | } else { | 188 | } else { |
| 175 | removeButtonsFromToolbar(); | 189 | removeButtonsFromToolbar(); |
| 176 | addButtonsToHomeScreen(); | 190 | addButtonsToHomeScreen(); |
| 191 | |||
| 192 | // destroy desktop window | ||
| 193 | if (_desktopWindow) { | ||
| 194 | _desktopWindow->deleteLater(); | ||
| 195 | _desktopWindow = nullptr; | ||
| 196 | } | ||
| 177 | } | 197 | } |
| 178 | } | 198 | } |
| 179 | 199 | ||
| @@ -246,39 +266,63 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr · 66 unmodified lines | |||
| 246 | } | 266 | } |
| 247 | 267 | ||
| 248 | void TabletProxy::gotoMenuScreen(const QString& submenu) { | 268 | void TabletProxy::gotoMenuScreen(const QString& submenu) { |
| 249 | if (_qmlTabletRoot) { | 269 | |
| 270 | QObject* root = nullptr; | ||
| 271 | if (!_toolbarMode && _qmlTabletRoot) { | ||
| 272 | root = _qmlTabletRoot; | ||
| 273 | } else if (_toolbarMode && _desktopWindow) { | ||
| 274 | root = _desktopWindow; | ||
| 275 | } | ||
| 276 | |||
| 277 | if (root) { | ||
| 250 | if (_state != State::Menu) { | 278 | if (_state != State::Menu) { |
| 251 | removeButtonsFromHomeScreen(); | 279 | removeButtonsFromHomeScreen(); |
| 252 | QMetaObject::invokeMethod(_qmlTabletRoot, "setOption", Q_ARG(const QVariant&, QVariant(submenu))); | 280 | QMetaObject::invokeMethod(root, "setOption", Q_ARG(const QVariant&, QVariant(submenu))); |
| 253 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | 281 | auto loader = root->findChild<QQuickItem*>("loader"); |
| 254 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToMenuScreen()), Qt::DirectConnection); | 282 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToMenuScreen()), Qt::DirectConnection); |
| 255 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(VRMENU_SOURCE_URL))); | 283 | QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(VRMENU_SOURCE_URL))); |
| 256 | _state = State::Menu; | 284 | _state = State::Menu; |
| 257 | emit screenChanged(QVariant("Menu"), QVariant(VRMENU_SOURCE_URL)); | 285 | emit screenChanged(QVariant("Menu"), QVariant(VRMENU_SOURCE_URL)); |
| 286 | QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true))); | ||
| 258 | } | 287 | } |
| 259 | } | 288 | } |
| 260 | } | 289 | } |
| 261 | 290 | ||
| 262 | void TabletProxy::loadQMLSource(const QVariant& path) { | 291 | void TabletProxy::loadQMLSource(const QVariant& path) { |
| 263 | if (_qmlTabletRoot) { | 292 | |
| 293 | QObject* root = nullptr; | ||
| 294 | if (!_toolbarMode && _qmlTabletRoot) { | ||
| 295 | root = _qmlTabletRoot; | ||
| 296 | } else if (_toolbarMode && _desktopWindow) { | ||
| 297 | root = _desktopWindow; | ||
| 298 | } | ||
| 299 | |||
| 300 | if (root) { | ||
| 264 | if (_state != State::QML) { | 301 | if (_state != State::QML) { |
| 265 | removeButtonsFromHomeScreen(); | 302 | removeButtonsFromHomeScreen(); |
| 266 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, path)); | 303 | QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, path)); |
| 267 | _state = State::QML; | 304 | _state = State::QML; |
| 268 | emit screenChanged(QVariant("QML"), path); | 305 | emit screenChanged(QVariant("QML"), path); |
| 306 | QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true))); | ||
| 269 | } | 307 | } |
| 270 | } | 308 | } |
| 271 | } | 309 | } |
| 310 | |||
| 272 | void TabletProxy::gotoHomeScreen() { | 311 | void TabletProxy::gotoHomeScreen() { |
| 273 | if (_qmlTabletRoot) { | 312 | if (_state != State::Home) { |
| 274 | if (_state != State::Home) { | 313 | if (!_toolbarMode && _qmlTabletRoot) { |
| 275 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | 314 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); |
| 276 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()), Qt::DirectConnection); | 315 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()), Qt::DirectConnection); |
| 277 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); | 316 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); |
| 278 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); | 317 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 279 | _state = State::Home; | 318 | } else if (_toolbarMode && _desktopWindow) { |
| 280 | emit screenChanged(QVariant("Home"), QVariant(TABLET_SOURCE_URL)); | 319 | // close desktop window |
| 320 | if (_desktopWindow) { | ||
| 321 | QMetaObject::invokeMethod(_desktopWindow, "setShown", Q_ARG(const QVariant&, QVariant(false))); | ||
| 322 | } | ||
| 281 | } | 323 | } |
| 324 | _state = State::Home; | ||
| 325 | emit screenChanged(QVariant("Home"), QVariant(TABLET_SOURCE_URL)); | ||
| 282 | } | 326 | } |
| 283 | } | 327 | } |
| 284 | 328 | ||
| @@ -287,17 +331,24 @@ void TabletProxy::gotoWebScreen(const QString& url) { · 2 unmodified lines | |||
| 287 | } | 331 | } |
| 288 | 332 | ||
| 289 | void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl) { | 333 | void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl) { |
| 290 | if (_qmlTabletRoot) { | 334 | |
| 291 | if (_state == State::Home) { | 335 | QObject* root = nullptr; |
| 292 | removeButtonsFromHomeScreen(); | 336 | if (!_toolbarMode && _qmlTabletRoot) { |
| 293 | } | 337 | root = _qmlTabletRoot; |
| 294 | if (_state != State::Web) { | 338 | } else if (_toolbarMode && _desktopWindow) { |
| 295 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | 339 | root = _desktopWindow; |
| 296 | _state = State::Web; | 340 | } |
| 297 | emit screenChanged(QVariant("Web"), QVariant(url)); | 341 | |
| 342 | if (_state != State::Web) { | ||
| 343 | if (root) { | ||
| 344 | QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | ||
| 298 | } | 345 | } |
| 299 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), | 346 | _state = State::Web; |
| 300 | Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl))); | 347 | emit screenChanged(QVariant("Web"), QVariant(url)); |
| 348 | } | ||
| 349 | if (root) { | ||
| 350 | 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))); | ||
| 301 | } | 352 | } |
| 302 | } | 353 | } |
| 303 | 354 | ||
| @@ -391,11 +442,18 @@ QObject* TabletProxy::getTabletSurface() { · 87 unmodified lines | |||
| 391 | } | 442 | } |
| 392 | 443 | ||
| 393 | void TabletProxy::addButtonsToMenuScreen() { | 444 | void TabletProxy::addButtonsToMenuScreen() { |
| 394 | if (!_qmlTabletRoot) { | 445 | QObject* root = nullptr; |
| 446 | if (!_toolbarMode && _qmlTabletRoot) { | ||
| 447 | root = _qmlTabletRoot; | ||
| 448 | } else if (_toolbarMode && _desktopWindow) { | ||
| 449 | root = _desktopWindow; | ||
| 450 | } | ||
| 451 | |||
| 452 | if (!root) { | ||
| 395 | return; | 453 | return; |
| 396 | } | 454 | } |
| 397 | 455 | ||
| 398 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | 456 | auto loader = root->findChild<QQuickItem*>("loader"); |
| 399 | if (!loader) { | 457 | if (!loader) { |
| 400 | return; | 458 | return; |
| 401 | } | 459 | } |
| @@ -420,6 +478,10 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 18 unmodified lines | |||
| 420 | } | 478 | } |
| 421 | } | 479 | } |
| 422 | 480 | ||
| 481 | void TabletProxy::desktopWindowClosed() { | ||
| 482 | gotoHomeScreen(); | ||
| 483 | } | ||
| 484 | |||
| 423 | void TabletProxy::addButtonsToToolbar() { | 485 | void TabletProxy::addButtonsToToolbar() { |
| 424 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | 486 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 425 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | 487 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); |
| @@ -515,6 +577,9 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) { · 89 unmodified lines | |||
| 515 | void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) { | 577 | void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) { |
| 516 | std::lock_guard<std::mutex> guard(_mutex); | 578 | std::lock_guard<std::mutex> guard(_mutex); |
| 517 | _toolbarButtonProxy = toolbarButtonProxy; | 579 | _toolbarButtonProxy = toolbarButtonProxy; |
| 580 | if (_toolbarButtonProxy) { | ||
| 581 | QObject::connect(_toolbarButtonProxy, SIGNAL(clicked()), this, SLOT(clickedSlot())); | ||
| 582 | } | ||
| 518 | } | 583 | } |
| 519 | 584 | ||
| 520 | QVariantMap TabletButtonProxy::getProperties() const { | 585 | QVariantMap TabletButtonProxy::getProperties() const { |