WIP commit

This commit is contained in:
Anthony J. Thibault 2017-02-13 13:19:13 -08:00
parent f8055a027e
commit 5e25d073f3
3 changed files with 84 additions and 4 deletions

View file

@ -5462,6 +5462,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
scriptEngine->registerGlobalObject("Toolbars", DependencyManager::get<ToolbarScriptingInterface>().data());
DependencyManager::get<TabletScriptingInterface>().data()->setToolbarScriptingInterface(DependencyManager::get<ToolbarScriptingInterface>().data());
scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
qScriptRegisterMetaType(scriptEngine, CustomPromptResultToScriptValue, CustomPromptResultFromScriptValue);
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,

View file

@ -22,6 +22,22 @@ TabletScriptingInterface::TabletScriptingInterface() {
qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect");
}
QObject* TabletScriptingInterface::getSystemToolbarProxy() {
const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system";
Qt::ConnectionType connectionType = Qt::AutoConnection;
if (QThread::currentThread() != _toolbarScriptingInterface->thread()) {
connectionType = Qt::BlockingQueuedConnection;
}
QObject* toolbarProxy = nullptr;
bool hasResult = QMetaObject::invokeMethod(_toolbarScriptingInterface, "getToolbar", connectionType, Q_RETURN_ARG(QObject*, toolbarProxy), Q_ARG(QString, SYSTEM_TOOLBAR));
if (hasResult) {
return toolbarProxy;
} else {
qCWarning(scriptengine) << "ToolbarScriptingInterface getToolbar has no result";
return nullptr;
}
}
QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
std::lock_guard<std::mutex> guard(_mutex);
@ -145,6 +161,21 @@ TabletProxy::TabletProxy(QString name) : _name(name) {
;
}
void TabletProxy::setToolbarMode(bool toolbarMode) {
if (toolbarMode == _toolbarMode) {
return;
}
if (toolbarMode) {
removeButtonsFromHomeScreen();
addButtonsToToolbar();
} else {
removeButtonsFromToolbar();
addButtonsToHomeScreen();
}
_toolbarMode = toolbarMode;
}
static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) {
QVariant resultVar;
Qt::ConnectionType connectionType = Qt::AutoConnection;
@ -379,12 +410,34 @@ void TabletProxy::addButtonsToMenuScreen() {
}
void TabletProxy::removeButtonsFromHomeScreen() {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
for (auto& buttonProxy : _tabletButtonProxies) {
buttonProxy->setQmlButton(nullptr);
}
}
void TabletProxy::addButtonsToToolbar() {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
for (auto& buttonProxy : _tabletButtonProxies) {
// copy properties from tablet button proxy to toolbar button proxy.
Qt::ConnectionType connectionType = Qt::AutoConnection;
if (QThread::currentThread() != toolbarProxy->thread()) {
connectionType = Qt::BlockingQueuedConnection;
}
QObject* toolbarButtonProxy = nullptr;
bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties()));
if (hasResult) {
buttonProxy->setToolbarButtonProxy(toolbarButtonProxy);
} else {
qCWarning(scriptengine) << "ToolbarProxy addButton has no result";
}
}
}
void TabletProxy::removeButtonsFromToolbar() {
//
}
QQuickItem* TabletProxy::getQmlTablet() const {
if (!_qmlTabletRoot) {
return nullptr;
@ -444,6 +497,11 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
_qmlButton = qmlButton;
}
void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) {
std::lock_guard<std::mutex> guard(_mutex);
_toolbarButtonProxy = toolbarButtonProxy;
}
QVariantMap TabletButtonProxy::getProperties() const {
std::lock_guard<std::mutex> guard(_mutex);
return _properties;
@ -451,6 +509,7 @@ QVariantMap TabletButtonProxy::getProperties() const {
void TabletButtonProxy::editProperties(QVariantMap properties) {
std::lock_guard<std::mutex> guard(_mutex);
QVariantMap::const_iterator iter = properties.constBegin();
while (iter != properties.constEnd()) {
_properties[iter.key()] = iter.value();
@ -459,6 +518,10 @@ void TabletButtonProxy::editProperties(QVariantMap properties) {
}
++iter;
}
if (_toolbarButtonProxy) {
QMetaObject::invokeMethod(_toolbarButtonProxy, "editProperties", Qt::AutoConnection, Q_ARG(QVariant, properties));
}
}
#include "TabletScriptingInterface.moc"

View file

@ -35,6 +35,9 @@ class TabletScriptingInterface : public QObject, public Dependency {
public:
TabletScriptingInterface();
void setToolbarScriptingInterface(QObject* toolbarScriptingInterface) { _toolbarScriptingInterface = toolbarScriptingInterface; }
QObject* getSystemToolbarProxy();
/**jsdoc
* Creates or retruns a new TabletProxy and returns it.
* @function Tablet.getTablet
@ -58,15 +61,19 @@ private:
protected:
std::mutex _mutex;
std::map<QString, QSharedPointer<TabletProxy>> _tabletProxies;
QObject* _toolbarScriptingInterface { nullptr };
};
/**jsdoc
* @class TabletProxy
* @property name {string} READ_ONLY: name of this tablet
* @property toolbarMode {bool} - used to transition this tablet into and out of toolbar mode.
* When tablet is in toolbar mode, all its buttons will appear in a floating toolbar.
*/
class TabletProxy : public QObject {
Q_OBJECT
Q_PROPERTY(QString name READ getName)
Q_PROPERTY(bool toolbarMode READ getToolbarMode WRITE setToolbarMode)
public:
TabletProxy(QString name);
@ -74,6 +81,11 @@ public:
Q_INVOKABLE void gotoMenuScreen(const QString& submenu = "");
QString getName() const { return _name; }
bool getToolbarMode() const { return _toolbarMode; }
void setToolbarMode(bool toolbarMode);
/**jsdoc
* transition to the home screen
* @function TabletProxy#gotoHomeScreen
@ -120,8 +132,6 @@ public:
*/
Q_INVOKABLE void updateAudioBar(const double micLevel);
QString getName() const { return _name; }
/**jsdoc
* Used to send an event to the html/js embedded in the tablet
* @function TabletProxy#emitScriptEvent
@ -169,17 +179,20 @@ signals:
*/
void screenChanged(QVariant type, QVariant url);
private slots:
protected slots:
void addButtonsToHomeScreen();
void addButtonsToMenuScreen();
protected:
void removeButtonsFromHomeScreen();
void addButtonsToToolbar();
void removeButtonsFromToolbar();
QString _name;
std::mutex _mutex;
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
QQuickItem* _qmlTabletRoot { nullptr };
QObject* _qmlOffscreenSurface { nullptr };
bool _toolbarMode { false };
enum class State { Uninitialized, Home, Web, Menu, QML };
State _state { State::Uninitialized };
@ -196,6 +209,7 @@ public:
TabletButtonProxy(const QVariantMap& properties);
void setQmlButton(QQuickItem* qmlButton);
void setToolbarButtonProxy(QObject* toolbarButtonProxy);
QUuid getUuid() const { return _uuid; }
@ -229,6 +243,7 @@ protected:
int _stableOrder;
mutable std::mutex _mutex;
QQuickItem* _qmlButton { nullptr };
QObject* _toolbarButtonProxy { nullptr };
QVariantMap _properties;
};