Updated Web3dOverlay.cpp to work with TabletRoot.qml

This commit is contained in:
Anthony J. Thibault 2016-12-20 14:40:29 -08:00
parent ec38c4e319
commit 01a96347a5
4 changed files with 45 additions and 24 deletions

View file

@ -59,10 +59,9 @@ Web3DOverlay::~Web3DOverlay() {
if (_webSurface) {
QQuickItem* rootItem = _webSurface->getRootItem();
// TABLET_UI_HACK: TODO: update this with rootTablet
if (rootItem && rootItem->objectName() == "tablet") {
if (rootItem && rootItem->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", nullptr);
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr);
}
// Fix for crash in QtWebEngineCore when rapidly switching domains
@ -137,10 +136,9 @@ void Web3DOverlay::loadSourceURL() {
_webSurface->load(_url, [&](QQmlContext* context, QObject* obj) {});
_webSurface->resume();
// TABLET_UI_HACK: TODO: update this to use rootTablet.
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tablet") {
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
}
}
}

View file

@ -258,7 +258,6 @@ void RenderableWebEntityItem::loadSourceURL() {
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath()));
_webSurface->load(_sourceUrl, [&](QQmlContext* context, QObject* obj) {});
// TABLET_UI_HACK: move this to overlays as well!
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
@ -360,7 +359,6 @@ void RenderableWebEntityItem::destroyWebSurface() {
QQuickItem* rootItem = _webSurface->getRootItem();
// TABLET_UI_HACK: move this to overlays as well!
if (rootItem && rootItem->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", nullptr);

View file

@ -10,6 +10,8 @@
#include <QtCore/QThread>
#include "ScriptEngineLogging.h"
QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
std::lock_guard<std::mutex> guard(_mutex);
@ -32,7 +34,7 @@ void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qm
if (tablet) {
tablet->setQmlTabletRoot(qmlTabletRoot);
} else {
qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object";
}
}
@ -57,13 +59,13 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy*
bool hasResult = QMetaObject::invokeMethod(qmlTablet, "addButtonProxy", connectionType,
Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, buttonProxy->getProperties()));
if (!hasResult) {
qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet has no result";
qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet has no result";
return;
}
QObject* qmlButton = qvariant_cast<QObject *>(resultVar);
if (!qmlButton) {
qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject";
qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject";
return;
}
QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot()));
@ -107,36 +109,40 @@ QObject* TabletProxy::addButton(const QVariant& properties) {
std::lock_guard<std::mutex> guard(_mutex);
_tabletButtonProxies.push_back(tabletButtonProxy);
if (_qmlTabletRoot) {
addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data());
auto tablet = getQmlTablet();
if (tablet) {
addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data());
} else {
qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
}
}
return tabletButtonProxy.data();
}
void TabletProxy::removeButton(QObject* tabletButtonProxy) {
std::lock_guard<std::mutex> guard(_mutex);
auto tablet = getQmlTablet();
if (!tablet) {
qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
}
auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
if (iter != _tabletButtonProxies.end()) {
if (_qmlTabletRoot) {
(*iter)->setQmlButton(nullptr);
QMetaObject::invokeMethod(_qmlTabletRoot, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
if (tablet) {
QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
}
}
_tabletButtonProxies.erase(iter);
} else {
qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
}
}
void TabletProxy::addButtonsToHomeScreen() {
if (!_qmlTabletRoot) {
return;
}
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
if (!loader) {
return;
}
auto tablet = loader->findChild<QQuickItem*>("tablet");
auto tablet = getQmlTablet();
if (!tablet) {
return;
}
@ -154,6 +160,24 @@ void TabletProxy::removeButtonsFromHomeScreen() {
}
}
QQuickItem* TabletProxy::getQmlTablet() const {
if (!_qmlTabletRoot) {
return nullptr;
}
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
if (!loader) {
return nullptr;
}
auto tablet = loader->findChild<QQuickItem*>("tablet");
if (!tablet) {
return nullptr;
}
return tablet;
}
//
// TabletButtonProxy
//

View file

@ -89,6 +89,7 @@ protected:
void addButtonsToHomeScreen();
void removeButtonsFromHomeScreen();
QQuickItem* getQmlTablet() const;
QString _name;
std::mutex _mutex;