History

Tablet can switch to a web url.

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.

Anthony J. Thibault committed 9 years ago

Commit a791ddc1 parent 856791c7 files · +144 −28Browse files

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

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+64−15
@@ -27,10 +27,10 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { · 26 unmodified lines
2727 }
2828 }
2929
30−void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) {
30+void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot) {
3131 TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));
3232 if (tablet) {
33− tablet->setQmlTablet(qmlTablet);
33+ tablet->setQmlTabletRoot(qmlTabletRoot);
3434 } else {
3535 qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
3636 }
@@ -40,6 +40,10 @@ void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTab · 3 unmodified lines
4040 // TabletProxy
4141 //
4242
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+
4347 TabletProxy::TabletProxy(QString name) : _name(name) {
4448 ;
4549 }
@@ -66,18 +70,35 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 20 unmodified lines
6670 buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));
6771 }
6872
69−void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) {
73+void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot) {
7074 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();
7678 } 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....
79100 }
80− _qmlTablet = nullptr;
101+ QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)));
81102 }
82103 }
83104
@@ -85,8 +106,8 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 1 unmodified line
85106 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
86107 std::lock_guard<std::mutex> guard(_mutex);
87108 _tabletButtonProxies.push_back(tabletButtonProxy);
88− if (_qmlTablet) {
89− addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data());
109+ if (_qmlTabletRoot) {
110+ addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data());
90111 }
91112 return tabletButtonProxy.data();
92113 }
@@ -95,9 +116,9 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 2 unmodified lines
95116 std::lock_guard<std::mutex> guard(_mutex);
96117 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
97118 if (iter != _tabletButtonProxies.end()) {
98− if (_qmlTablet) {
119+ if (_qmlTabletRoot) {
99120 (*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()));
101122 }
102123 _tabletButtonProxies.erase(iter);
103124 } else {
@@ -105,6 +126,34 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 1 unmodified line
105126 }
106127 }
107128
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+
108157 //
109158 // TabletButtonProxy
110159 //