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
27 }27 }
28}28}
29 29
30void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) {30void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot) {
31 TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));31 TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));
32 if (tablet) {32 if (tablet) {
33 tablet->setQmlTablet(qmlTablet);33 tablet->setQmlTabletRoot(qmlTabletRoot);
34 } else {34 } else {
35 qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";35 qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
36 }36 }
@@ -40,6 +40,10 @@ void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTab · 3 unmodified lines
40// TabletProxy40// TabletProxy
41//41//
42 42
43static const char* TABLET_SOURCE_URL = "Tablet.qml";
44static const char* WEB_VIEW_SOURCE_URL = "TabletWebView.qml";
45static const char* LOADER_SOURCE_PROPERTY_NAME = "loaderSource";
46
43TabletProxy::TabletProxy(QString name) : _name(name) {47TabletProxy::TabletProxy(QString name) : _name(name) {
44 ;48 ;
45}49}
@@ -66,18 +70,35 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 20 unmodified lines
66 buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));70 buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));
67}71}
68 72
69void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) {73void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot) {
70 std::lock_guard<std::mutex> guard(_mutex);74 std::lock_guard<std::mutex> guard(_mutex);
71 if (qmlTablet) {75 _qmlTabletRoot = qmlTabletRoot;
72 _qmlTablet = qmlTablet;76 if (_qmlTabletRoot) {
73 for (auto& buttonProxy : _tabletButtonProxies) {77 gotoHomeScreen();
74 addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data());
75 }
76 } else {78 } else {
77 for (auto& buttonProxy : _tabletButtonProxies) {79 removeButtonsFromHomeScreen();
78 buttonProxy->setQmlButton(nullptr);80 }
81}
82
83void 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
93void 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 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));106 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
86 std::lock_guard<std::mutex> guard(_mutex);107 std::lock_guard<std::mutex> guard(_mutex);
87 _tabletButtonProxies.push_back(tabletButtonProxy);108 _tabletButtonProxies.push_back(tabletButtonProxy);
88 if (_qmlTablet) {109 if (_qmlTabletRoot) {
89 addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data());110 addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data());
90 }111 }
91 return tabletButtonProxy.data();112 return tabletButtonProxy.data();
92}113}
@@ -95,9 +116,9 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 2 unmodified lines
95 std::lock_guard<std::mutex> guard(_mutex);116 std::lock_guard<std::mutex> guard(_mutex);
96 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);117 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
97 if (iter != _tabletButtonProxies.end()) {118 if (iter != _tabletButtonProxies.end()) {
98 if (_qmlTablet) {119 if (_qmlTabletRoot) {
99 (*iter)->setQmlButton(nullptr);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 _tabletButtonProxies.erase(iter);123 _tabletButtonProxies.erase(iter);
103 } else {124 } else {
@@ -105,6 +126,34 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 1 unmodified line
105 }126 }
106}127}
107 128
129void 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
150void TabletProxy::removeButtonsFromHomeScreen() {
151 auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
152 for (auto& buttonProxy : _tabletButtonProxies) {
153 buttonProxy->setQmlButton(nullptr);
154 }
155}
156
108//157//
109// TabletButtonProxy158// TabletButtonProxy
110//159//