Copies all tablet buttons between the tablet and the system toolbar. To test type this in the console: Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode = true;
Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -166,6 +166,8 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 165 unmodified lines | ||
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | + _toolbarMode = toolbarMode; | |
| 170 | + | |
| 169 | 171 | if (toolbarMode) { |
| 170 | 172 | removeButtonsFromHomeScreen(); |
| 171 | 173 | addButtonsToToolbar(); |
| @@ -173,7 +175,6 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 1 unmodified line | ||
| 173 | 175 | removeButtonsFromToolbar(); |
| 174 | 176 | addButtonsToHomeScreen(); |
| 175 | 177 | } |
| 176 | − _toolbarMode = toolbarMode; | |
| 177 | 178 | } |
| 178 | 179 | |
| 179 | 180 | static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) { |
| @@ -373,7 +374,7 @@ void TabletProxy::sendToQml(QVariant msg) { · 193 unmodified lines | ||
| 373 | 374 | |
| 374 | 375 | void TabletProxy::addButtonsToHomeScreen() { |
| 375 | 376 | auto tablet = getQmlTablet(); |
| 376 | − if (!tablet) { | |
| 377 | + if (!tablet || _toolbarMode) { | |
| 377 | 378 | return; |
| 378 | 379 | } |
| 379 | 380 | |
| @@ -410,7 +411,11 @@ void TabletProxy::addButtonsToMenuScreen() { · 30 unmodified lines | ||
| 410 | 411 | } |
| 411 | 412 | |
| 412 | 413 | void TabletProxy::removeButtonsFromHomeScreen() { |
| 414 | + auto tablet = getQmlTablet(); | |
| 413 | 415 | for (auto& buttonProxy : _tabletButtonProxies) { |
| 416 | + if (tablet) { | |
| 417 | + QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties())); | |
| 418 | + } | |
| 414 | 419 | buttonProxy->setQmlButton(nullptr); |
| 415 | 420 | } |
| 416 | 421 | } |
| @@ -418,12 +423,14 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 1 unmodified line | ||
| 418 | 423 | void TabletProxy::addButtonsToToolbar() { |
| 419 | 424 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 420 | 425 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); |
| 426 | + | |
| 427 | + Qt::ConnectionType connectionType = Qt::AutoConnection; | |
| 428 | + if (QThread::currentThread() != toolbarProxy->thread()) { | |
| 429 | + connectionType = Qt::BlockingQueuedConnection; | |
| 430 | + } | |
| 431 | + | |
| 421 | 432 | for (auto& buttonProxy : _tabletButtonProxies) { |
| 422 | 433 | // copy properties from tablet button proxy to toolbar button proxy. |
| 423 | − Qt::ConnectionType connectionType = Qt::AutoConnection; | |
| 424 | − if (QThread::currentThread() != toolbarProxy->thread()) { | |
| 425 | − connectionType = Qt::BlockingQueuedConnection; | |
| 426 | − } | |
| 427 | 434 | QObject* toolbarButtonProxy = nullptr; |
| 428 | 435 | bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties())); |
| 429 | 436 | if (hasResult) { |
| @@ -435,7 +442,13 @@ void TabletProxy::addButtonsToToolbar() { · 5 unmodified lines | ||
| 435 | 442 | } |
| 436 | 443 | |
| 437 | 444 | void TabletProxy::removeButtonsFromToolbar() { |
| 438 | − // | |
| 445 | + auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | |
| 446 | + QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | |
| 447 | + for (auto& buttonProxy : _tabletButtonProxies) { | |
| 448 | + // remove button from toolbarProxy | |
| 449 | + QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getUuid().toString())); | |
| 450 | + buttonProxy->setToolbarButtonProxy(nullptr); | |
| 451 | + } | |
| 439 | 452 | } |
| 440 | 453 | |
| 441 | 454 | QQuickItem* TabletProxy::getQmlTablet() const { |
| @@ -483,12 +496,14 @@ QQuickItem* TabletProxy::getQmlMenu() const { · 41 unmodified lines | ||
| 483 | 496 | // |
| 484 | 497 | |
| 485 | 498 | const QString UUID_KEY = "uuid"; |
| 499 | +const QString OBJECT_NAME_KEY = "objectName"; | |
| 486 | 500 | const QString STABLE_ORDER_KEY = "stableOrder"; |
| 487 | 501 | static int s_stableOrder = 1; |
| 488 | 502 | |
| 489 | 503 | TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) { |
| 490 | 504 | // this is used to uniquely identify this button. |
| 491 | 505 | _properties[UUID_KEY] = _uuid; |
| 506 | + _properties[OBJECT_NAME_KEY] = _uuid.toString(); | |
| 492 | 507 | _properties[STABLE_ORDER_KEY] = _stableOrder; |
| 493 | 508 | } |
| 494 | 509 | |