mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:57:26 +02:00
Merge pull request #9215 from hyperlogic/tablet-ui
TabletScriptingInterface and Help button now on tablet.
This commit is contained in:
commit
cbb88601d9
10 changed files with 357 additions and 62 deletions
|
@ -3,12 +3,34 @@ import QtGraphicalEffects 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: tablet
|
id: tablet
|
||||||
|
objectName: "tablet"
|
||||||
|
|
||||||
property double miclevel: 0.8
|
property double miclevel: 0.8
|
||||||
|
|
||||||
width: 480
|
width: 480
|
||||||
height: 720
|
height: 720
|
||||||
|
|
||||||
|
// called by C++ code when a button should be added to the tablet
|
||||||
|
function addButtonProxy(properties) {
|
||||||
|
var component = Qt.createComponent("TabletButton.qml");
|
||||||
|
var button = component.createObject(flowMain);
|
||||||
|
if (properties.icon) {
|
||||||
|
button.icon = properties.icon;
|
||||||
|
}
|
||||||
|
if (properties.color) {
|
||||||
|
button.color = properties.color;
|
||||||
|
}
|
||||||
|
if (properties.text) {
|
||||||
|
button.text = properties.text;
|
||||||
|
}
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// called by C++ code when a button should be removed from the tablet
|
||||||
|
function removeButtonProxy(properties) {
|
||||||
|
console.log("TABLET_UI_HACK: removeButtonProxy, NOT IMPLEMENTED!, properties = " + JSON.stringify(properties));
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: bgAudio
|
id: bgAudio
|
||||||
height: 90
|
height: 90
|
||||||
|
|
|
@ -9,6 +9,8 @@ Item {
|
||||||
width: 132
|
width: 132
|
||||||
height: 132
|
height: 132
|
||||||
|
|
||||||
|
signal clicked()
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: buttonBg
|
id: buttonBg
|
||||||
color: tabletButton.color
|
color: tabletButton.color
|
||||||
|
@ -62,6 +64,7 @@ Item {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
onClicked: tabletButton.clicked();
|
||||||
onEntered: {
|
onEntered: {
|
||||||
console.log("Tablet Button Hovered!");
|
console.log("Tablet Button Hovered!");
|
||||||
tabletButton.state = "hover state";
|
tabletButton.state = "hover state";
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
#include <ScriptCache.h>
|
#include <ScriptCache.h>
|
||||||
#include <SoundCache.h>
|
#include <SoundCache.h>
|
||||||
#include <steamworks-wrapper/SteamClient.h>
|
#include <steamworks-wrapper/SteamClient.h>
|
||||||
|
#include <TabletScriptingInterface.h>
|
||||||
#include <Tooltip.h>
|
#include <Tooltip.h>
|
||||||
#include <udt/PacketHeaders.h>
|
#include <udt/PacketHeaders.h>
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
|
@ -478,6 +479,7 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
DependencyManager::set<WindowScriptingInterface>();
|
DependencyManager::set<WindowScriptingInterface>();
|
||||||
DependencyManager::set<HMDScriptingInterface>();
|
DependencyManager::set<HMDScriptingInterface>();
|
||||||
DependencyManager::set<ResourceScriptingInterface>();
|
DependencyManager::set<ResourceScriptingInterface>();
|
||||||
|
DependencyManager::set<TabletScriptingInterface>();
|
||||||
DependencyManager::set<ToolbarScriptingInterface>();
|
DependencyManager::set<ToolbarScriptingInterface>();
|
||||||
DependencyManager::set<UserActivityLoggerScriptingInterface>();
|
DependencyManager::set<UserActivityLoggerScriptingInterface>();
|
||||||
|
|
||||||
|
|
63
interface/src/scripting/QmlWrapper.h
Normal file
63
interface/src/scripting/QmlWrapper.h
Normal file
|
@ -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 <QtCore/QObject>
|
||||||
|
#include <OffscreenUi.h>
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
|
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>();
|
||||||
|
offscreenUi->executeOnUiThread([=] {
|
||||||
|
_qmlObject->setProperty(propertyName.toStdString().c_str(), propertyValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE void writeProperties(QVariant propertyMap) {
|
||||||
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
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<OffscreenUi>();
|
||||||
|
return offscreenUi->returnFromUiThread([&]()->QVariant {
|
||||||
|
return _qmlObject->property(propertyName.toStdString().c_str());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE QVariant readProperties(const QVariant& propertyList) {
|
||||||
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
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
|
|
@ -8,58 +8,11 @@
|
||||||
|
|
||||||
#include "ToolbarScriptingInterface.h"
|
#include "ToolbarScriptingInterface.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
|
||||||
#include <OffscreenUi.h>
|
#include <OffscreenUi.h>
|
||||||
|
#include "QmlWrapper.h"
|
||||||
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>();
|
|
||||||
offscreenUi->executeOnUiThread([=] {
|
|
||||||
_qmlObject->setProperty(propertyName.toStdString().c_str(), propertyValue);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_INVOKABLE void writeProperties(QVariant propertyMap) {
|
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
|
||||||
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<OffscreenUi>();
|
|
||||||
return offscreenUi->returnFromUiThread([&]()->QVariant {
|
|
||||||
return _qmlObject->property(propertyName.toStdString().c_str());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_INVOKABLE QVariant readProperties(const QVariant& propertyList) {
|
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
|
||||||
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 };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ToolbarButtonProxy : public QmlWrapper {
|
class ToolbarButtonProxy : public QmlWrapper {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
#include <TextureCache.h>
|
#include <TextureCache.h>
|
||||||
#include <gpu/Context.h>
|
#include <gpu/Context.h>
|
||||||
|
#include <TabletScriptingInterface.h>
|
||||||
|
|
||||||
#include "EntityTreeRenderer.h"
|
#include "EntityTreeRenderer.h"
|
||||||
#include "EntitiesRendererLogging.h"
|
#include "EntitiesRendererLogging.h"
|
||||||
|
@ -255,7 +256,13 @@ void RenderableWebEntityItem::loadSourceURL() {
|
||||||
} else {
|
} else {
|
||||||
_contentType = qmlContent;
|
_contentType = qmlContent;
|
||||||
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath()));
|
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath()));
|
||||||
_webSurface->load(_sourceUrl, [&](QQmlContext* context, QObject* obj) { });
|
_webSurface->load(_sourceUrl, [&](QQmlContext* context, QObject* obj) {});
|
||||||
|
|
||||||
|
// TABLET_UI_HACK: move this to overlays as well!
|
||||||
|
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tablet") {
|
||||||
|
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||||
|
tabletScriptingInterface->setQmlTablet("com.highfidelity.interface.tablet.system", _webSurface->getRootItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include "WebSocketClass.h"
|
#include "WebSocketClass.h"
|
||||||
#include "RecordingScriptingInterface.h"
|
#include "RecordingScriptingInterface.h"
|
||||||
#include "ScriptEngines.h"
|
#include "ScriptEngines.h"
|
||||||
|
#include "TabletScriptingInterface.h"
|
||||||
|
|
||||||
#include "MIDIEvent.h"
|
#include "MIDIEvent.h"
|
||||||
|
|
||||||
|
@ -542,6 +543,8 @@ void ScriptEngine::init() {
|
||||||
auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
|
auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
|
||||||
registerGlobalObject("Recording", recordingInterface.data());
|
registerGlobalObject("Recording", recordingInterface.data());
|
||||||
|
|
||||||
|
registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
|
||||||
|
|
||||||
registerGlobalObject("Assets", &_assetScriptingInterface);
|
registerGlobalObject("Assets", &_assetScriptingInterface);
|
||||||
registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
|
registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
|
||||||
}
|
}
|
||||||
|
|
133
libraries/script-engine/src/TabletScriptingInterface.cpp
Normal file
133
libraries/script-engine/src/TabletScriptingInterface.cpp
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
//
|
||||||
|
// 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 <QtCore/QThread>
|
||||||
|
|
||||||
|
QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) {
|
||||||
|
TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));
|
||||||
|
if (tablet) {
|
||||||
|
tablet->setQmlTablet(qmlTablet);
|
||||||
|
} else {
|
||||||
|
qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// TabletProxy
|
||||||
|
//
|
||||||
|
|
||||||
|
TabletProxy::TabletProxy(QString name) : _name(name) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) {
|
||||||
|
QVariant resultVar;
|
||||||
|
Qt::ConnectionType connectionType = Qt::AutoConnection;
|
||||||
|
if (QThread::currentThread() != qmlTablet->thread()) {
|
||||||
|
connectionType = Qt::BlockingQueuedConnection;
|
||||||
|
}
|
||||||
|
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";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject* qmlButton = qvariant_cast<QObject *>(resultVar);
|
||||||
|
if (!qmlButton) {
|
||||||
|
qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) {
|
||||||
|
if (qmlTablet) {
|
||||||
|
_qmlTablet = qmlTablet;
|
||||||
|
std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
|
||||||
|
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||||
|
addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_qmlTablet = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (_qmlTablet) {
|
||||||
|
addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data());
|
||||||
|
}
|
||||||
|
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()) {
|
||||||
|
if (_qmlTablet) {
|
||||||
|
QMetaObject::invokeMethod(_qmlTablet, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
|
||||||
|
}
|
||||||
|
_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TABLET_UI_HACK remove
|
||||||
|
/*
|
||||||
|
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"
|
115
libraries/script-engine/src/TabletScriptingInterface.h
Normal file
115
libraries/script-engine/src/TabletScriptingInterface.h
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
//
|
||||||
|
// 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 <mutex>
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QScriptValue>
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
|
|
||||||
|
class TabletProxy;
|
||||||
|
class TabletButtonProxy;
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* @namespace Tablet
|
||||||
|
*/
|
||||||
|
class TabletScriptingInterface : public QObject, public Dependency {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
/**jsdoc
|
||||||
|
* Creates or retruns a new TabletProxy and returns it.
|
||||||
|
* @function Tablet.getTablet
|
||||||
|
* @param name {String} tablet name
|
||||||
|
* @return {TabletProxy} tablet instance
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QObject* getTablet(const QString& tabletId);
|
||||||
|
|
||||||
|
void setQmlTablet(QString tabletId, QQuickItem* qmlTablet);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
void setQmlTablet(QQuickItem* qmlTablet);
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* @function TabletProxy#addButton
|
||||||
|
* Creates a new button, adds it to this and returns it.
|
||||||
|
* @param properties {Object} button properties UI_TABLET_HACK: enumerate these when we figure out what they should be!
|
||||||
|
* @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;
|
||||||
|
QQuickItem* _qmlTablet { nullptr };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* @class TabletButtonProxy
|
||||||
|
* @property imageUrl {string}
|
||||||
|
*/
|
||||||
|
class TabletButtonProxy : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
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);
|
||||||
|
|
||||||
|
const QVariantMap& getProperties() const { return _properties; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void clickedSlot() { emit clicked(); }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**jsdoc
|
||||||
|
* Signaled when this button has been clicked on by the user.
|
||||||
|
* @function TabletButtonProxy#clicked
|
||||||
|
* @returns {Signal}
|
||||||
|
*/
|
||||||
|
void clicked();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mutable std::mutex _propertiesMutex;
|
||||||
|
QVariantMap _properties;
|
||||||
|
QScriptValue _initRequestHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_TabletScriptingInterface_h
|
|
@ -13,20 +13,14 @@
|
||||||
|
|
||||||
(function() { // BEGIN LOCAL_SCOPE
|
(function() { // BEGIN LOCAL_SCOPE
|
||||||
|
|
||||||
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
var buttonName = "help"; // matching location reserved in Desktop.qml
|
var button = tablet.addButton({
|
||||||
var button = toolBar.addButton({
|
//icon: "help.svg",
|
||||||
objectName: buttonName,
|
color: "#ff6f6f",
|
||||||
imageURL: Script.resolvePath("assets/images/tools/help.svg"),
|
text: "HELP"
|
||||||
visible: true,
|
|
||||||
hoverState: 2,
|
|
||||||
defaultState: 1,
|
|
||||||
buttonState: 1,
|
|
||||||
alpha: 0.9
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: make button state reflect whether the window is opened or closed (independently from us).
|
// TODO: make button state reflect whether the window is opened or closed (independently from us).
|
||||||
|
|
||||||
function onClicked(){
|
function onClicked(){
|
||||||
Menu.triggerOption('Help...')
|
Menu.triggerOption('Help...')
|
||||||
}
|
}
|
||||||
|
@ -34,7 +28,7 @@
|
||||||
button.clicked.connect(onClicked);
|
button.clicked.connect(onClicked);
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
toolBar.removeButton(buttonName);
|
tablet.removeButton(buttonName);
|
||||||
button.clicked.disconnect(onClicked);
|
button.clicked.disconnect(onClicked);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue