Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -22,6 +22,22 @@ TabletScriptingInterface::TabletScriptingInterface() { · 21 unmodified lines | |||
| 22 | qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect"); | 22 | qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect"); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | QObject* TabletScriptingInterface::getSystemToolbarProxy() { | ||
| 26 | const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system"; | ||
| 27 | Qt::ConnectionType connectionType = Qt::AutoConnection; | ||
| 28 | if (QThread::currentThread() != _toolbarScriptingInterface->thread()) { | ||
| 29 | connectionType = Qt::BlockingQueuedConnection; | ||
| 30 | } | ||
| 31 | QObject* toolbarProxy = nullptr; | ||
| 32 | bool hasResult = QMetaObject::invokeMethod(_toolbarScriptingInterface, "getToolbar", connectionType, Q_RETURN_ARG(QObject*, toolbarProxy), Q_ARG(QString, SYSTEM_TOOLBAR)); | ||
| 33 | if (hasResult) { | ||
| 34 | return toolbarProxy; | ||
| 35 | } else { | ||
| 36 | qCWarning(scriptengine) << "ToolbarScriptingInterface getToolbar has no result"; | ||
| 37 | return nullptr; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 25 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { | 41 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { |
| 26 | 42 | ||
| 27 | std::lock_guard<std::mutex> guard(_mutex); | 43 | std::lock_guard<std::mutex> guard(_mutex); |
| @@ -145,6 +161,21 @@ TabletProxy::TabletProxy(QString name) : _name(name) { · 117 unmodified lines | |||
| 145 | ; | 161 | ; |
| 146 | } | 162 | } |
| 147 | 163 | ||
| 164 | void TabletProxy::setToolbarMode(bool toolbarMode) { | ||
| 165 | if (toolbarMode == _toolbarMode) { | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 169 | if (toolbarMode) { | ||
| 170 | removeButtonsFromHomeScreen(); | ||
| 171 | addButtonsToToolbar(); | ||
| 172 | } else { | ||
| 173 | removeButtonsFromToolbar(); | ||
| 174 | addButtonsToHomeScreen(); | ||
| 175 | } | ||
| 176 | _toolbarMode = toolbarMode; | ||
| 177 | } | ||
| 178 | |||
| 148 | static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) { | 179 | static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) { |
| 149 | QVariant resultVar; | 180 | QVariant resultVar; |
| 150 | Qt::ConnectionType connectionType = Qt::AutoConnection; | 181 | Qt::ConnectionType connectionType = Qt::AutoConnection; |
| @@ -379,12 +410,34 @@ void TabletProxy::addButtonsToMenuScreen() { · 228 unmodified lines | |||
| 379 | } | 410 | } |
| 380 | 411 | ||
| 381 | void TabletProxy::removeButtonsFromHomeScreen() { | 412 | void TabletProxy::removeButtonsFromHomeScreen() { |
| 382 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | ||
| 383 | for (auto& buttonProxy : _tabletButtonProxies) { | 413 | for (auto& buttonProxy : _tabletButtonProxies) { |
| 384 | buttonProxy->setQmlButton(nullptr); | 414 | buttonProxy->setQmlButton(nullptr); |
| 385 | } | 415 | } |
| 386 | } | 416 | } |
| 387 | 417 | ||
| 418 | void TabletProxy::addButtonsToToolbar() { | ||
| 419 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | ||
| 420 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | ||
| 421 | for (auto& buttonProxy : _tabletButtonProxies) { | ||
| 422 | // 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 | QObject* toolbarButtonProxy = nullptr; | ||
| 428 | bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties())); | ||
| 429 | if (hasResult) { | ||
| 430 | buttonProxy->setToolbarButtonProxy(toolbarButtonProxy); | ||
| 431 | } else { | ||
| 432 | qCWarning(scriptengine) << "ToolbarProxy addButton has no result"; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 437 | void TabletProxy::removeButtonsFromToolbar() { | ||
| 438 | // | ||
| 439 | } | ||
| 440 | |||
| 388 | QQuickItem* TabletProxy::getQmlTablet() const { | 441 | QQuickItem* TabletProxy::getQmlTablet() const { |
| 389 | if (!_qmlTabletRoot) { | 442 | if (!_qmlTabletRoot) { |
| 390 | return nullptr; | 443 | return nullptr; |
| @@ -444,6 +497,11 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) { · 53 unmodified lines | |||
| 444 | _qmlButton = qmlButton; | 497 | _qmlButton = qmlButton; |
| 445 | } | 498 | } |
| 446 | 499 | ||
| 500 | void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) { | ||
| 501 | std::lock_guard<std::mutex> guard(_mutex); | ||
| 502 | _toolbarButtonProxy = toolbarButtonProxy; | ||
| 503 | } | ||
| 504 | |||
| 447 | QVariantMap TabletButtonProxy::getProperties() const { | 505 | QVariantMap TabletButtonProxy::getProperties() const { |
| 448 | std::lock_guard<std::mutex> guard(_mutex); | 506 | std::lock_guard<std::mutex> guard(_mutex); |
| 449 | return _properties; | 507 | return _properties; |
| @@ -451,6 +509,7 @@ QVariantMap TabletButtonProxy::getProperties() const { · 1 unmodified line | |||
| 451 | 509 | ||
| 452 | void TabletButtonProxy::editProperties(QVariantMap properties) { | 510 | void TabletButtonProxy::editProperties(QVariantMap properties) { |
| 453 | std::lock_guard<std::mutex> guard(_mutex); | 511 | std::lock_guard<std::mutex> guard(_mutex); |
| 512 | |||
| 454 | QVariantMap::const_iterator iter = properties.constBegin(); | 513 | QVariantMap::const_iterator iter = properties.constBegin(); |
| 455 | while (iter != properties.constEnd()) { | 514 | while (iter != properties.constEnd()) { |
| 456 | _properties[iter.key()] = iter.value(); | 515 | _properties[iter.key()] = iter.value(); |
| @@ -459,6 +518,10 @@ void TabletButtonProxy::editProperties(QVariantMap properties) { · 2 unmodified lines | |||
| 459 | } | 518 | } |
| 460 | ++iter; | 519 | ++iter; |
| 461 | } | 520 | } |
| 521 | |||
| 522 | if (_toolbarButtonProxy) { | ||
| 523 | QMetaObject::invokeMethod(_toolbarButtonProxy, "editProperties", Qt::AutoConnection, Q_ARG(QVariant, properties)); | ||
| 524 | } | ||
| 462 | } | 525 | } |
| 463 | 526 | ||
| 464 | #include "TabletScriptingInterface.moc" | 527 | #include "TabletScriptingInterface.moc" |