Hooked up EventBridge to TabletScriptingInterface.

This commit is contained in:
Anthony J. Thibault 2017-01-03 15:43:21 -08:00
parent 850db0b6b3
commit 3c2f9acd39
6 changed files with 55 additions and 17 deletions

View file

@ -3,6 +3,7 @@ import QtQuick 2.0
Item {
id: tabletRoot
objectName: "tabletRoot"
property var eventBridge;
function loadSource(url) {
loader.source = url;
@ -19,6 +20,13 @@ Item {
width: parent.width
height: parent.height
onLoaded: {
// propogate eventBridge to WebEngineView
if (loader.item.hasOwnProperty("eventBridge")) {
loader.item.eventBridge = eventBridge;
}
}
}
width: 480

View file

@ -1,9 +1,10 @@
import QtQuick 2.0
import QtWebEngine 1.2
WebEngineView {
id: webEngineView
height: parent.height
width: parent.width
import "../../controls" as Controls
Controls.WebView {
}

View file

@ -61,7 +61,7 @@ Web3DOverlay::~Web3DOverlay() {
if (rootItem && rootItem->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr);
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr, nullptr);
}
// Fix for crash in QtWebEngineCore when rapidly switching domains
@ -138,7 +138,7 @@ void Web3DOverlay::loadSourceURL() {
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
}
}
}

View file

@ -268,7 +268,7 @@ void RenderableWebEntityItem::loadSourceURL() {
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
}
}
}
@ -372,7 +372,7 @@ void RenderableWebEntityItem::destroyWebSurface() {
if (rootItem && rootItem->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr);
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr, nullptr);
}
// Fix for crash in QtWebEngineCore when rapidly switching domains

View file

@ -29,10 +29,10 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
}
}
void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot) {
void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) {
TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));
if (tablet) {
tablet->setQmlTabletRoot(qmlTabletRoot);
if (tablet && qmlOffscreenSurface) {
tablet->setQmlTabletRoot(qmlTabletRoot, qmlOffscreenSurface);
} else {
qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object";
}
@ -72,10 +72,12 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy*
buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));
}
void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot) {
void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) {
std::lock_guard<std::mutex> guard(_mutex);
_qmlOffscreenSurface = qmlOffscreenSurface;
_qmlTabletRoot = qmlTabletRoot;
if (_qmlTabletRoot) {
if (_qmlTabletRoot && _qmlOffscreenSurface) {
QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant)));
gotoHomeScreen();
} else {
removeButtonsFromHomeScreen();
@ -141,6 +143,12 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) {
}
}
void TabletProxy::emitScriptEvent(QVariant msg) {
if (_qmlOffscreenSurface) {
QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
}
}
void TabletProxy::addButtonsToHomeScreen() {
auto tablet = getQmlTablet();
if (!tablet) {

View file

@ -37,7 +37,7 @@ public:
*/
Q_INVOKABLE QObject* getTablet(const QString& tabletId);
void setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot);
void setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface);
protected:
std::mutex _mutex;
@ -46,7 +46,7 @@ protected:
/**jsdoc
* @class TabletProxy
* @property name {string} name of this tablet
* @property name {string} READ_ONLY: name of this tablet
*/
class TabletProxy : public QObject {
Q_OBJECT
@ -54,7 +54,7 @@ class TabletProxy : public QObject {
public:
TabletProxy(QString name);
void setQmlTabletRoot(QQuickItem* qmlTabletRoot);
void setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface);
/**jsdoc
* transition to the home screen
@ -85,6 +85,23 @@ public:
Q_INVOKABLE void removeButton(QObject* tabletButtonProxy);
QString getName() const { return _name; }
/**jsdoc
* Used to send an event to the html/js embedded in the tablet
* @function TabletProxy#emitScriptEvent
* @param msg {object|string}
*/
Q_INVOKABLE void emitScriptEvent(QVariant msg);
signals:
/**jsdoc
* Signaled when this tablet receives an event from the html/js embedded in the tablet
* @function TabletProxy#webEventReceived
* @param msg {object|string}
* @returns {Signal}
*/
void webEventReceived(QVariant msg);
protected:
void addButtonsToHomeScreen();
@ -95,19 +112,23 @@ protected:
std::mutex _mutex;
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
QQuickItem* _qmlTabletRoot { nullptr };
QObject* _qmlOffscreenSurface { nullptr };
};
/**jsdoc
* @class TabletButtonProxy
* @property imageUrl {string}
* @property uuid {QUuid} READ_ONLY: uniquely identifies this button
*/
class TabletButtonProxy : public QObject {
Q_OBJECT
Q_PROPERTY(QUuid uuid READ getUuid)
public:
TabletButtonProxy(const QVariantMap& properties);
void setQmlButton(QQuickItem* qmlButton);
QUuid getUuid() const { return _uuid; }
/**jsdoc
* Returns the current value of this button's properties
* @function TabletButtonProxy#getProperties