Help button has been updated to switch to the help.html. It doesn't look good because the content was authored expecting landscape window, not portrait. The API is by no means final. But it exposes two methods to JS. * Tablet.gotoHomeScreen() - Used to forcefully go back to the home tablet "springboard", eventually this will hooked up to the tablet button. * Tablet.gotoWebScreen(url) - Causes the tablet to switch from the home "springboard" and load a web url. tabletTest.js and help.js have been updated to use this functionality.
Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 7 files). Show all
Unified · Split
| @@ -27,10 +27,10 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { · 26 unmodified lines | ||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | −void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) { | |
| 30 | +void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot) { | |
| 31 | 31 | TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId)); |
| 32 | 32 | if (tablet) { |
| 33 | − tablet->setQmlTablet(qmlTablet); | |
| 33 | + tablet->setQmlTabletRoot(qmlTabletRoot); | |
| 34 | 34 | } else { |
| 35 | 35 | qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object"; |
| 36 | 36 | } |
| @@ -40,6 +40,10 @@ void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTab · 3 unmodified lines | ||
| 40 | 40 | // TabletProxy |
| 41 | 41 | // |
| 42 | 42 | |
| 43 | +static const char* TABLET_SOURCE_URL = "Tablet.qml"; | |
| 44 | +static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml"; | |
| 45 | +static const char* LOADER_SOURCE_PROPERTY_NAME = "loaderSource"; | |
| 46 | + | |
| 43 | 47 | TabletProxy::TabletProxy(QString name) : _name(name) { |
| 44 | 48 | ; |
| 45 | 49 | } |
| @@ -66,18 +70,35 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 20 unmodified lines | ||
| 66 | 70 | buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton)); |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | −void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) { | |
| 73 | +void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot) { | |
| 70 | 74 | std::lock_guard<std::mutex> guard(_mutex); |
| 71 | − if (qmlTablet) { | |
| 72 | − _qmlTablet = qmlTablet; | |
| 73 | − for (auto& buttonProxy : _tabletButtonProxies) { | |
| 74 | − addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data()); | |
| 75 | − } | |
| 75 | + _qmlTabletRoot = qmlTabletRoot; | |
| 76 | + if (_qmlTabletRoot) { | |
| 77 | + gotoHomeScreen(); | |
| 76 | 78 | } else { |
| 77 | − for (auto& buttonProxy : _tabletButtonProxies) { | |
| 78 | − buttonProxy->setQmlButton(nullptr); | |
| 79 | + removeButtonsFromHomeScreen(); | |
| 80 | + } | |
| 81 | +} | |
| 82 | + | |
| 83 | +void TabletProxy::gotoHomeScreen() { | |
| 84 | + if (_qmlTabletRoot) { | |
| 85 | + QString tabletSource = _qmlTabletRoot->property(LOADER_SOURCE_PROPERTY_NAME).toString(); | |
| 86 | + if (tabletSource != TABLET_SOURCE_URL) { | |
| 87 | + QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); | |
| 88 | + addButtonsToHomeScreen(); | |
| 89 | + } | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | +void TabletProxy::gotoWebScreen(const QString& url) { | |
| 94 | + if (_qmlTabletRoot) { | |
| 95 | + removeButtonsFromHomeScreen(); | |
| 96 | + QString tabletSource = _qmlTabletRoot->property(LOADER_SOURCE_PROPERTY_NAME).toString(); | |
| 97 | + if (tabletSource != WEB_VIEW_SOURCE_URL) { | |
| 98 | + QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); | |
| 99 | + // TABLET_UI_HACK: TODO: addEventBridge to tablet.... | |
| 79 | 100 | } |
| 80 | − _qmlTablet = nullptr; | |
| 101 | + QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url))); | |
| 81 | 102 | } |
| 82 | 103 | } |
| 83 | 104 | |
| @@ -85,8 +106,8 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 1 unmodified line | ||
| 85 | 106 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 86 | 107 | std::lock_guard<std::mutex> guard(_mutex); |
| 87 | 108 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 88 | − if (_qmlTablet) { | |
| 89 | − addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data()); | |
| 109 | + if (_qmlTabletRoot) { | |
| 110 | + addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data()); | |
| 90 | 111 | } |
| 91 | 112 | return tabletButtonProxy.data(); |
| 92 | 113 | } |
| @@ -95,9 +116,9 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 2 unmodified lines | ||
| 95 | 116 | std::lock_guard<std::mutex> guard(_mutex); |
| 96 | 117 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 97 | 118 | if (iter != _tabletButtonProxies.end()) { |
| 98 | − if (_qmlTablet) { | |
| 119 | + if (_qmlTabletRoot) { | |
| 99 | 120 | (*iter)->setQmlButton(nullptr); |
| 100 | − QMetaObject::invokeMethod(_qmlTablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | |
| 121 | + QMetaObject::invokeMethod(_qmlTabletRoot, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | |
| 101 | 122 | } |
| 102 | 123 | _tabletButtonProxies.erase(iter); |
| 103 | 124 | } else { |
| @@ -105,6 +126,34 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 1 unmodified line | ||
| 105 | 126 | } |
| 106 | 127 | } |
| 107 | 128 | |
| 129 | +void TabletProxy::addButtonsToHomeScreen() { | |
| 130 | + if (!_qmlTabletRoot) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + | |
| 134 | + auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | |
| 135 | + if (!loader) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + | |
| 139 | + auto tablet = loader->findChild<QQuickItem*>("tablet"); | |
| 140 | + if (!tablet) { | |
| 141 | + return; | |
| 142 | + } | |
| 143 | + | |
| 144 | + auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | |
| 145 | + for (auto& buttonProxy : _tabletButtonProxies) { | |
| 146 | + addButtonProxyToQmlTablet(tablet, buttonProxy.data()); | |
| 147 | + } | |
| 148 | +} | |
| 149 | + | |
| 150 | +void TabletProxy::removeButtonsFromHomeScreen() { | |
| 151 | + auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | |
| 152 | + for (auto& buttonProxy : _tabletButtonProxies) { | |
| 153 | + buttonProxy->setQmlButton(nullptr); | |
| 154 | + } | |
| 155 | +} | |
| 156 | + | |
| 108 | 157 | // |
| 109 | 158 | // TabletButtonProxy |
| 110 | 159 | // |