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 | 15 | #include <RegisteredMetaTypes.h> |
| 16 | 16 | #include "ScriptEngineLogging.h" |
| 17 | 17 | #include "DependencyManager.h" |
| 18 | −#include "OffscreenUi.h" | |
| 18 | +#include <OffscreenUi.h> | |
| 19 | +#include <InfoView.h> | |
| 19 | 20 | #include "SoundEffect.h" |
| 20 | 21 | |
| 21 | 22 | TabletScriptingInterface::TabletScriptingInterface() { |
| @@ -156,9 +157,10 @@ QObject* TabletScriptingInterface::getFlags() · 134 unmodified lines | ||
| 156 | 157 | static const char* TABLET_SOURCE_URL = "Tablet.qml"; |
| 157 | 158 | static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; |
| 158 | 159 | static const char* VRMENU_SOURCE_URL = "TabletMenu.qml"; |
| 160 | +static int s_windowNameCounter = 1; | |
| 159 | 161 | |
| 160 | 162 | TabletProxy::TabletProxy(QString name) : _name(name) { |
| 161 | − ; | |
| 163 | + | |
| 162 | 164 | } |
| 163 | 165 | |
| 164 | 166 | void TabletProxy::setToolbarMode(bool toolbarMode) { |
| @@ -171,9 +173,27 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 6 unmodified lines | ||
| 171 | 173 | if (toolbarMode) { |
| 172 | 174 | removeButtonsFromHomeScreen(); |
| 173 | 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 | 188 | } else { |
| 175 | 189 | removeButtonsFromToolbar(); |
| 176 | 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 | 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 | 278 | if (_state != State::Menu) { |
| 251 | 279 | removeButtonsFromHomeScreen(); |
| 252 | − QMetaObject::invokeMethod(_qmlTabletRoot, "setOption", Q_ARG(const QVariant&, QVariant(submenu))); | |
| 253 | − auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | |
| 280 | + QMetaObject::invokeMethod(root, "setOption", Q_ARG(const QVariant&, QVariant(submenu))); | |
| 281 | + auto loader = root->findChild<QQuickItem*>("loader"); | |
| 254 | 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 | 284 | _state = State::Menu; |
| 257 | 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 | 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 | 301 | if (_state != State::QML) { |
| 265 | 302 | removeButtonsFromHomeScreen(); |
| 266 | − QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, path)); | |
| 303 | + QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, path)); | |
| 267 | 304 | _state = State::QML; |
| 268 | 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 | 311 | void TabletProxy::gotoHomeScreen() { |
| 273 | − if (_qmlTabletRoot) { | |
| 274 | − if (_state != State::Home) { | |
| 312 | + if (_state != State::Home) { | |
| 313 | + if (!_toolbarMode && _qmlTabletRoot) { | |
| 275 | 314 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); |
| 276 | 315 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()), Qt::DirectConnection); |
| 277 | 316 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); |
| 278 | 317 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 279 | − _state = State::Home; | |
| 280 | − emit screenChanged(QVariant("Home"), QVariant(TABLET_SOURCE_URL)); | |
| 318 | + } else if (_toolbarMode && _desktopWindow) { | |
| 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 | 333 | void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl) { |
| 290 | − if (_qmlTabletRoot) { | |
| 291 | − if (_state == State::Home) { | |
| 292 | − removeButtonsFromHomeScreen(); | |
| 293 | − } | |
| 294 | − if (_state != State::Web) { | |
| 295 | − QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | |
| 296 | − _state = State::Web; | |
| 297 | − emit screenChanged(QVariant("Web"), QVariant(url)); | |
| 334 | + | |
| 335 | + QObject* root = nullptr; | |
| 336 | + if (!_toolbarMode && _qmlTabletRoot) { | |
| 337 | + root = _qmlTabletRoot; | |
| 338 | + } else if (_toolbarMode && _desktopWindow) { | |
| 339 | + root = _desktopWindow; | |
| 340 | + } | |
| 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)), | |
| 300 | − Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl))); | |
| 346 | + _state = State::Web; | |
| 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 | 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 | 453 | return; |
| 396 | 454 | } |
| 397 | 455 | |
| 398 | − auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | |
| 456 | + auto loader = root->findChild<QQuickItem*>("loader"); | |
| 399 | 457 | if (!loader) { |
| 400 | 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 | 485 | void TabletProxy::addButtonsToToolbar() { |
| 424 | 486 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 425 | 487 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); |
| @@ -515,6 +577,9 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) { · 89 unmodified lines | ||
| 515 | 577 | void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) { |
| 516 | 578 | std::lock_guard<std::mutex> guard(_mutex); |
| 517 | 579 | _toolbarButtonProxy = toolbarButtonProxy; |
| 580 | + if (_toolbarButtonProxy) { | |
| 581 | + QObject::connect(_toolbarButtonProxy, SIGNAL(clicked()), this, SLOT(clickedSlot())); | |
| 582 | + } | |
| 518 | 583 | } |
| 519 | 584 | |
| 520 | 585 | QVariantMap TabletButtonProxy::getProperties() const { |