mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-14 15:39:52 +02:00
Fleshing out TabletScriptingInterface.
Added TabletProxy and TabletButtonProxy
This commit is contained in:
parent
d94da76b72
commit
db0b2ba7d3
3 changed files with 145 additions and 19 deletions
|
@ -144,6 +144,7 @@
|
|||
#include "scripting/SettingsScriptingInterface.h"
|
||||
#include "scripting/WindowScriptingInterface.h"
|
||||
#include "scripting/ControllerScriptingInterface.h"
|
||||
#include "scripting/TabletScriptingInterface.h"
|
||||
#include "scripting/ToolbarScriptingInterface.h"
|
||||
#include "scripting/RatesScriptingInterface.h"
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||
|
@ -478,6 +479,7 @@ bool setupEssentials(int& argc, char** argv) {
|
|||
DependencyManager::set<WindowScriptingInterface>();
|
||||
DependencyManager::set<HMDScriptingInterface>();
|
||||
DependencyManager::set<ResourceScriptingInterface>();
|
||||
DependencyManager::set<TabletScriptingInterface>();
|
||||
DependencyManager::set<ToolbarScriptingInterface>();
|
||||
DependencyManager::set<UserActivityLoggerScriptingInterface>();
|
||||
|
||||
|
@ -5181,6 +5183,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
scriptEngine->registerGlobalObject("ScriptDiscoveryService", DependencyManager::get<ScriptEngines>().data());
|
||||
scriptEngine->registerGlobalObject("Reticle", getApplicationCompositor().getReticleInterface());
|
||||
|
||||
scriptEngine->registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data());
|
||||
scriptEngine->registerGlobalObject("Users", DependencyManager::get<UsersScriptingInterface>().data());
|
||||
|
||||
|
|
|
@ -10,24 +10,71 @@
|
|||
|
||||
#include <QtCore/QThread>
|
||||
|
||||
#include <OffscreenUi.h>
|
||||
#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;
|
||||
|
||||
std::lock_guard<std::mutex> guard(_tabletProxiesMutex);
|
||||
|
||||
// look up tabletId in the map.
|
||||
auto iter = _tabletProxies.find(tabletId);
|
||||
if (iter != _tabletProxies.end()) {
|
||||
// tablet already exists, just return it.
|
||||
return iter->second.data();
|
||||
} else {
|
||||
// allocate a new tablet, add it to the map then return it.
|
||||
auto tabletProxy = QSharedPointer<TabletProxy>(new TabletProxy(tabletId));
|
||||
_tabletProxies[tabletId] = tabletProxy;
|
||||
return tabletProxy.data();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TabletProxy
|
||||
//
|
||||
|
||||
TabletProxy::TabletProxy(QString name) : _name(name) {
|
||||
;
|
||||
}
|
||||
|
||||
QObject* TabletProxy::addButton(const QVariant& properties) {
|
||||
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
||||
std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
|
||||
_tabletButtonProxies.push_back(tabletButtonProxy);
|
||||
return tabletButtonProxy.data();
|
||||
}
|
||||
|
||||
void TabletProxy::removeButton(QObject* tabletButtonProxy) {
|
||||
std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
|
||||
auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
|
||||
if (iter != _tabletButtonProxies.end()) {
|
||||
_tabletButtonProxies.erase(iter);
|
||||
} else {
|
||||
qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TabletButtonProxy
|
||||
//
|
||||
|
||||
TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _properties(properties) {
|
||||
;
|
||||
}
|
||||
|
||||
void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) {
|
||||
_initRequestHandler = handler;
|
||||
}
|
||||
|
||||
static QString IMAGE_URL_KEY = "imageUrl";
|
||||
static QString IMAGE_URL_DEFAULT = "";
|
||||
|
||||
QString TabletButtonProxy::getImageUrl() const {
|
||||
std::lock_guard<std::mutex> guard(_propertiesMutex);
|
||||
return _properties.value(IMAGE_URL_KEY, IMAGE_URL_DEFAULT).toString();
|
||||
}
|
||||
|
||||
void TabletButtonProxy::setImageUrl(QString imageUrl) {
|
||||
std::lock_guard<std::mutex> guard(_propertiesMutex);
|
||||
_properties[IMAGE_URL_KEY] = imageUrl;
|
||||
}
|
||||
|
||||
#include "TabletScriptingInterface.moc"
|
||||
|
|
|
@ -9,10 +9,18 @@
|
|||
#ifndef hifi_TabletScriptingInterface_h
|
||||
#define hifi_TabletScriptingInterface_h
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QVariant>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
|
||||
class TabletProxy;
|
||||
class TabletButtonProxy;
|
||||
|
||||
/**jsdoc
|
||||
* @namespace Tablet
|
||||
*/
|
||||
|
@ -20,12 +28,79 @@ class TabletScriptingInterface : public QObject, public Dependency {
|
|||
Q_OBJECT
|
||||
public:
|
||||
/**jsdoc
|
||||
* Creates a new button on the tablet ui and returns it.
|
||||
* Creates or retruns a new TabletProxy and returns it.
|
||||
* @function Tablet.getTablet
|
||||
* @param name {String} tablet name
|
||||
* @return {QmlWrapper} tablet instance
|
||||
* @return {TabletProxy} tablet instance
|
||||
*/
|
||||
Q_INVOKABLE QObject* getTablet(const QString& tabletId);
|
||||
protected:
|
||||
std::mutex _tabletProxiesMutex;
|
||||
std::map<QString, QSharedPointer<TabletProxy>> _tabletProxies;
|
||||
};
|
||||
|
||||
/**jsdoc
|
||||
* @class TabletProxy
|
||||
* @property name {string} name of this tablet
|
||||
*/
|
||||
class TabletProxy : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ getName)
|
||||
public:
|
||||
TabletProxy(QString name);
|
||||
|
||||
/**jsdoc
|
||||
* @function TabletProxy#addButton
|
||||
* Creates a new button, adds it to this and returns it.
|
||||
* @param properties {Object} button properties AJT: TODO: enumerate these...
|
||||
* @returns {TabletButtonProxy}
|
||||
*/
|
||||
Q_INVOKABLE QObject* addButton(const QVariant& properties);
|
||||
|
||||
/**jsdoc
|
||||
* @function TabletProxy#removeButton
|
||||
* removes button from the tablet
|
||||
* @param tabletButtonProxy {TabletButtonProxy} button to be removed
|
||||
*/
|
||||
Q_INVOKABLE void removeButton(QObject* tabletButtonProxy);
|
||||
|
||||
QString getName() const { return _name; }
|
||||
protected:
|
||||
QString _name;
|
||||
std::mutex _tabletButtonProxiesMutex;
|
||||
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
|
||||
};
|
||||
|
||||
/**jsdoc
|
||||
* @class TabletButtonProxy
|
||||
* @property imageUrl {string}
|
||||
*/
|
||||
class TabletButtonProxy : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString imageUrl READ getImageUrl WRITE setImageUrl)
|
||||
public:
|
||||
TabletButtonProxy(const QVariantMap& properties);
|
||||
|
||||
/**jsdoc
|
||||
* @function TabletButtonProxy#setInitRequestHandler
|
||||
* @param handler {Function} A function used by the system to request the current button state from JavaScript.
|
||||
*/
|
||||
Q_INVOKABLE void setInitRequestHandler(const QScriptValue& handler);
|
||||
|
||||
QString getImageUrl() const;
|
||||
void setImageUrl(QString imageUrl);
|
||||
|
||||
signals:
|
||||
/**jsdoc
|
||||
* Signaled when this button has been clicked on by the user.
|
||||
* @function TabletButtonProxy#onClick
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void onClick();
|
||||
protected:
|
||||
mutable std::mutex _propertiesMutex;
|
||||
QVariantMap _properties;
|
||||
QScriptValue _initRequestHandler;
|
||||
};
|
||||
|
||||
#endif // hifi_TabletScriptingInterface_h
|
||||
|
|
Loading…
Reference in a new issue