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
166166 return;
167167 }
168168
169+ _toolbarMode = toolbarMode;
170+
169171 if (toolbarMode) {
170172 removeButtonsFromHomeScreen();
171173 addButtonsToToolbar();
@@ -173,7 +175,6 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { · 1 unmodified line
173175 removeButtonsFromToolbar();
174176 addButtonsToHomeScreen();
175177 }
176− _toolbarMode = toolbarMode;
177178 }
178179
179180 static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) {
@@ -373,7 +374,7 @@ void TabletProxy::sendToQml(QVariant msg) { · 193 unmodified lines
373374
374375 void TabletProxy::addButtonsToHomeScreen() {
375376 auto tablet = getQmlTablet();
376− if (!tablet) {
377+ if (!tablet || _toolbarMode) {
377378 return;
378379 }
379380
@@ -410,7 +411,11 @@ void TabletProxy::addButtonsToMenuScreen() { · 30 unmodified lines
410411 }
411412
412413 void TabletProxy::removeButtonsFromHomeScreen() {
414+ auto tablet = getQmlTablet();
413415 for (auto& buttonProxy : _tabletButtonProxies) {
416+ if (tablet) {
417+ QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties()));
418+ }
414419 buttonProxy->setQmlButton(nullptr);
415420 }
416421 }
@@ -418,12 +423,14 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 1 unmodified line
418423 void TabletProxy::addButtonsToToolbar() {
419424 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
420425 QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
426+
427+ Qt::ConnectionType connectionType = Qt::AutoConnection;
428+ if (QThread::currentThread() != toolbarProxy->thread()) {
429+ connectionType = Qt::BlockingQueuedConnection;
430+ }
431+
421432 for (auto& buttonProxy : _tabletButtonProxies) {
422433 // 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− }
427434 QObject* toolbarButtonProxy = nullptr;
428435 bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties()));
429436 if (hasResult) {
@@ -435,7 +442,13 @@ void TabletProxy::addButtonsToToolbar() { · 5 unmodified lines
435442 }
436443
437444 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+ }
439452 }
440453
441454 QQuickItem* TabletProxy::getQmlTablet() const {
@@ -483,12 +496,14 @@ QQuickItem* TabletProxy::getQmlMenu() const { · 41 unmodified lines
483496 //
484497
485498 const QString UUID_KEY = "uuid";
499+const QString OBJECT_NAME_KEY = "objectName";
486500 const QString STABLE_ORDER_KEY = "stableOrder";
487501 static int s_stableOrder = 1;
488502
489503 TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) {
490504 // this is used to uniquely identify this button.
491505 _properties[UUID_KEY] = _uuid;
506+ _properties[OBJECT_NAME_KEY] = _uuid.toString();
492507 _properties[STABLE_ORDER_KEY] = _stableOrder;
493508 }
494509