From d94da76b7260006eea22faed07e99d0c57077e81 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 13 Dec 2016 10:42:36 -0800 Subject: [PATCH] Added TabletScriptingInterface --- interface/src/scripting/QmlWrapper.h | 63 +++++++++++++++++++ .../scripting/TabletScriptingInterface.cpp | 33 ++++++++++ .../src/scripting/TabletScriptingInterface.h | 31 +++++++++ .../scripting/ToolbarScriptingInterface.cpp | 51 +-------------- 4 files changed, 129 insertions(+), 49 deletions(-) create mode 100644 interface/src/scripting/QmlWrapper.h create mode 100644 interface/src/scripting/TabletScriptingInterface.cpp create mode 100644 interface/src/scripting/TabletScriptingInterface.h diff --git a/interface/src/scripting/QmlWrapper.h b/interface/src/scripting/QmlWrapper.h new file mode 100644 index 0000000000..7dd319e445 --- /dev/null +++ b/interface/src/scripting/QmlWrapper.h @@ -0,0 +1,63 @@ +// +// Created by Anthony J. Thibault on 2016-12-12 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_QmlWrapper_h +#define hifi_QmlWrapper_h + +#include +#include +#include + +class QmlWrapper : public QObject { + Q_OBJECT +public: + QmlWrapper(QObject* qmlObject, QObject* parent = nullptr) + : QObject(parent), _qmlObject(qmlObject) { + } + + Q_INVOKABLE void writeProperty(QString propertyName, QVariant propertyValue) { + auto offscreenUi = DependencyManager::get(); + offscreenUi->executeOnUiThread([=] { + _qmlObject->setProperty(propertyName.toStdString().c_str(), propertyValue); + }); + } + + Q_INVOKABLE void writeProperties(QVariant propertyMap) { + auto offscreenUi = DependencyManager::get(); + offscreenUi->executeOnUiThread([=] { + QVariantMap map = propertyMap.toMap(); + for (const QString& key : map.keys()) { + _qmlObject->setProperty(key.toStdString().c_str(), map[key]); + } + }); + } + + Q_INVOKABLE QVariant readProperty(const QString& propertyName) { + auto offscreenUi = DependencyManager::get(); + return offscreenUi->returnFromUiThread([&]()->QVariant { + return _qmlObject->property(propertyName.toStdString().c_str()); + }); + } + + Q_INVOKABLE QVariant readProperties(const QVariant& propertyList) { + auto offscreenUi = DependencyManager::get(); + return offscreenUi->returnFromUiThread([&]()->QVariant { + QVariantMap result; + for (const QVariant& property : propertyList.toList()) { + QString propertyString = property.toString(); + result.insert(propertyString, _qmlObject->property(propertyString.toStdString().c_str())); + } + return result; + }); + } + +protected: + QObject* _qmlObject{ nullptr }; +}; + +#endif \ No newline at end of file diff --git a/interface/src/scripting/TabletScriptingInterface.cpp b/interface/src/scripting/TabletScriptingInterface.cpp new file mode 100644 index 0000000000..05b34cf675 --- /dev/null +++ b/interface/src/scripting/TabletScriptingInterface.cpp @@ -0,0 +1,33 @@ +// +// Created by Bradley Austin Davis on 2016-06-16 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "TabletScriptingInterface.h" + +#include + +#include +#include "QmlWrapper.h" + +class TabletButtonProxy : public QmlWrapper { + Q_OBJECT + +public: + TabletButtonProxy(QObject* qmlObject, QObject* parent = nullptr) : QmlWrapper(qmlObject, parent) { + connect(qmlObject, SIGNAL(clicked()), this, SIGNAL(clicked())); + } + +signals: + void clicked(); +}; + +QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { + // AJT TODO: how the fuck do I get access to the toolbar qml?!? from here? + return nullptr; +} + +#include "TabletScriptingInterface.moc" diff --git a/interface/src/scripting/TabletScriptingInterface.h b/interface/src/scripting/TabletScriptingInterface.h new file mode 100644 index 0000000000..8829894bbd --- /dev/null +++ b/interface/src/scripting/TabletScriptingInterface.h @@ -0,0 +1,31 @@ +// +// Created by Anthony J. Thibault on 2016-12-12 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_TabletScriptingInterface_h +#define hifi_TabletScriptingInterface_h + +#include + +#include + +/**jsdoc + * @namespace Tablet + */ +class TabletScriptingInterface : public QObject, public Dependency { + Q_OBJECT +public: + /**jsdoc + * Creates a new button on the tablet ui and returns it. + * @function Tablet.getTablet + * @param name {String} tablet name + * @return {QmlWrapper} tablet instance + */ + Q_INVOKABLE QObject* getTablet(const QString& tabletId); +}; + +#endif // hifi_TabletScriptingInterface_h diff --git a/interface/src/scripting/ToolbarScriptingInterface.cpp b/interface/src/scripting/ToolbarScriptingInterface.cpp index 0cb314615a..1f2228c6d9 100644 --- a/interface/src/scripting/ToolbarScriptingInterface.cpp +++ b/interface/src/scripting/ToolbarScriptingInterface.cpp @@ -8,58 +8,11 @@ #include "ToolbarScriptingInterface.h" + #include #include - -class QmlWrapper : public QObject { - Q_OBJECT -public: - QmlWrapper(QObject* qmlObject, QObject* parent = nullptr) - : QObject(parent), _qmlObject(qmlObject) { - } - - Q_INVOKABLE void writeProperty(QString propertyName, QVariant propertyValue) { - auto offscreenUi = DependencyManager::get(); - offscreenUi->executeOnUiThread([=] { - _qmlObject->setProperty(propertyName.toStdString().c_str(), propertyValue); - }); - } - - Q_INVOKABLE void writeProperties(QVariant propertyMap) { - auto offscreenUi = DependencyManager::get(); - offscreenUi->executeOnUiThread([=] { - QVariantMap map = propertyMap.toMap(); - for (const QString& key : map.keys()) { - _qmlObject->setProperty(key.toStdString().c_str(), map[key]); - } - }); - } - - Q_INVOKABLE QVariant readProperty(const QString& propertyName) { - auto offscreenUi = DependencyManager::get(); - return offscreenUi->returnFromUiThread([&]()->QVariant { - return _qmlObject->property(propertyName.toStdString().c_str()); - }); - } - - Q_INVOKABLE QVariant readProperties(const QVariant& propertyList) { - auto offscreenUi = DependencyManager::get(); - return offscreenUi->returnFromUiThread([&]()->QVariant { - QVariantMap result; - for (const QVariant& property : propertyList.toList()) { - QString propertyString = property.toString(); - result.insert(propertyString, _qmlObject->property(propertyString.toStdString().c_str())); - } - return result; - }); - } - - -protected: - QObject* _qmlObject{ nullptr }; -}; - +#include "QmlWrapper.h" class ToolbarButtonProxy : public QmlWrapper { Q_OBJECT