History

Initial version of TabletProxy.toolbarMode boolean

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;

Anthony J. Thibault committed 9 years ago

Commit 45039231 parent 5e25d075 files · +185 −8Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+22−7
@@ -166,6 +166,8 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 165 unmodified lines
166 return;166 return;
167 }167 }
168 168
169 _toolbarMode = toolbarMode;
170
169 if (toolbarMode) {171 if (toolbarMode) {
170 removeButtonsFromHomeScreen();172 removeButtonsFromHomeScreen();
171 addButtonsToToolbar();173 addButtonsToToolbar();
@@ -173,7 +175,6 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 1 unmodified line
173 removeButtonsFromToolbar();175 removeButtonsFromToolbar();
174 addButtonsToHomeScreen();176 addButtonsToHomeScreen();
175 }177 }
176 _toolbarMode = toolbarMode;
177}178}
178 179
179static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) {180static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) {
@@ -373,7 +374,7 @@ void TabletProxy::sendToQml(QVariant msg) { · 193 unmodified lines
373 374
374void TabletProxy::addButtonsToHomeScreen() {375void TabletProxy::addButtonsToHomeScreen() {
375 auto tablet = getQmlTablet();376 auto tablet = getQmlTablet();
376 if (!tablet) {377 if (!tablet || _toolbarMode) {
377 return;378 return;
378 }379 }
379 380
@@ -410,7 +411,11 @@ void TabletProxy::addButtonsToMenuScreen() { · 30 unmodified lines
410}411}
411 412
412void TabletProxy::removeButtonsFromHomeScreen() {413void TabletProxy::removeButtonsFromHomeScreen() {
414 auto tablet = getQmlTablet();
413 for (auto& buttonProxy : _tabletButtonProxies) {415 for (auto& buttonProxy : _tabletButtonProxies) {
416 if (tablet) {
417 QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties()));
418 }
414 buttonProxy->setQmlButton(nullptr);419 buttonProxy->setQmlButton(nullptr);
415 }420 }
416}421}
@@ -418,12 +423,14 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 1 unmodified line
418void TabletProxy::addButtonsToToolbar() {423void TabletProxy::addButtonsToToolbar() {
419 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();424 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
420 QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();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 for (auto& buttonProxy : _tabletButtonProxies) {432 for (auto& buttonProxy : _tabletButtonProxies) {
422 // copy properties from tablet button proxy to toolbar button proxy.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 QObject* toolbarButtonProxy = nullptr;434 QObject* toolbarButtonProxy = nullptr;
428 bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties()));435 bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties()));
429 if (hasResult) {436 if (hasResult) {
@@ -435,7 +442,13 @@ void TabletProxy::addButtonsToToolbar() { · 5 unmodified lines
435}442}
436 443
437void TabletProxy::removeButtonsFromToolbar() {444void 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
441QQuickItem* TabletProxy::getQmlTablet() const {454QQuickItem* TabletProxy::getQmlTablet() const {
@@ -483,12 +496,14 @@ QQuickItem* TabletProxy::getQmlMenu() const { · 41 unmodified lines
483//496//
484 497
485const QString UUID_KEY = "uuid";498const QString UUID_KEY = "uuid";
499const QString OBJECT_NAME_KEY = "objectName";
486const QString STABLE_ORDER_KEY = "stableOrder";500const QString STABLE_ORDER_KEY = "stableOrder";
487static int s_stableOrder = 1;501static int s_stableOrder = 1;
488 502
489TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) {503TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) {
490 // this is used to uniquely identify this button.504 // this is used to uniquely identify this button.
491 _properties[UUID_KEY] = _uuid;505 _properties[UUID_KEY] = _uuid;
506 _properties[OBJECT_NAME_KEY] = _uuid.toString();
492 _properties[STABLE_ORDER_KEY] = _stableOrder;507 _properties[STABLE_ORDER_KEY] = _stableOrder;
493}508}
494 509