Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -183,6 +183,18 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr · 182 unmodified lines | ||
| 183 | 183 | _qmlTabletRoot = qmlTabletRoot; |
| 184 | 184 | if (_qmlTabletRoot && _qmlOffscreenSurface) { |
| 185 | 185 | QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant))); |
| 186 | + | |
| 187 | + // forward qml surface events to interface js | |
| 188 | + connect(dynamic_cast<OffscreenQmlSurface*>(_qmlOffscreenSurface), &OffscreenQmlSurface::fromQml, [this](QVariant message) { | |
| 189 | + if (message.canConvert<QJSValue>()) { | |
| 190 | + emit fromQml(qvariant_cast<QJSValue>(message).toVariant()); | |
| 191 | + } else if (message.canConvert<QString>()) { | |
| 192 | + emit fromQml(message.toString()); | |
| 193 | + } else { | |
| 194 | + qWarning() << "fromQml: Unsupported message type " << message; | |
| 195 | + } | |
| 196 | + }); | |
| 197 | + | |
| 186 | 198 | gotoHomeScreen(); |
| 187 | 199 | |
| 188 | 200 | QMetaObject::invokeMethod(_qmlTabletRoot, "setUsername", Q_ARG(const QVariant&, QVariant(getUsername()))); |
| @@ -197,6 +209,7 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr · 8 unmodified lines | ||
| 197 | 209 | } else { |
| 198 | 210 | removeButtonsFromHomeScreen(); |
| 199 | 211 | _state = State::Uninitialized; |
| 212 | + emit screenChanged(QVariant("Closed"), QVariant("")); | |
| 200 | 213 | } |
| 201 | 214 | } |
| 202 | 215 | |
| @@ -208,6 +221,7 @@ void TabletProxy::gotoMenuScreen() { · 5 unmodified lines | ||
| 208 | 221 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToMenuScreen()), Qt::DirectConnection); |
| 209 | 222 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(VRMENU_SOURCE_URL))); |
| 210 | 223 | _state = State::Menu; |
| 224 | + emit screenChanged(QVariant("Menu"), QVariant(VRMENU_SOURCE_URL)); | |
| 211 | 225 | } |
| 212 | 226 | } |
| 213 | 227 | } |
| @@ -217,6 +231,7 @@ void TabletProxy::loadQMLSource(const QVariant& path) { · 3 unmodified lines | ||
| 217 | 231 | if (_state != State::QML) { |
| 218 | 232 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, path)); |
| 219 | 233 | _state = State::QML; |
| 234 | + emit screenChanged(QVariant("QML"), path); | |
| 220 | 235 | } |
| 221 | 236 | } |
| 222 | 237 | } |
| @@ -228,6 +243,7 @@ void TabletProxy::gotoHomeScreen() { · 5 unmodified lines | ||
| 228 | 243 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); |
| 229 | 244 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 230 | 245 | _state = State::Home; |
| 246 | + emit screenChanged(QVariant("Home"), QVariant(TABLET_SOURCE_URL)); | |
| 231 | 247 | } |
| 232 | 248 | } |
| 233 | 249 | } |
| @@ -244,6 +260,7 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS · 10 unmodified lines | ||
| 244 | 260 | if (_state != State::Web) { |
| 245 | 261 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); |
| 246 | 262 | _state = State::Web; |
| 263 | + emit screenChanged(QVariant("Web"), QVariant(url)); | |
| 247 | 264 | } |
| 248 | 265 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)), |
| 249 | 266 | Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl))); |
| @@ -306,6 +323,12 @@ void TabletProxy::emitScriptEvent(QVariant msg) { · 56 unmodified lines | ||
| 306 | 323 | } |
| 307 | 324 | } |
| 308 | 325 | |
| 326 | +void TabletProxy::sendToQml(QVariant msg) { | |
| 327 | + if (_qmlOffscreenSurface) { | |
| 328 | + QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg)); | |
| 329 | + } | |
| 330 | +} | |
| 331 | + | |
| 309 | 332 | void TabletProxy::addButtonsToHomeScreen() { |
| 310 | 333 | auto tablet = getQmlTablet(); |
| 311 | 334 | if (!tablet) { |