Also, moved TabletScriptingInterface to script-engine library for easy access, baby.
Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -0,0 +1,85 @@ | |||
| 1 | // | ||
| 2 | // Created by Bradley Austin Davis on 2016-06-16 | ||
| 3 | // Copyright 2013-2016 High Fidelity, Inc. | ||
| 4 | // | ||
| 5 | // Distributed under the Apache License, Version 2.0. | ||
| 6 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 7 | // | ||
| 8 | |||
| 9 | #include "TabletScriptingInterface.h" | ||
| 10 | |||
| 11 | #include <QtCore/QThread> | ||
| 12 | |||
| 13 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { | ||
| 14 | |||
| 15 | std::lock_guard<std::mutex> guard(_tabletProxiesMutex); | ||
| 16 | |||
| 17 | // look up tabletId in the map. | ||
| 18 | auto iter = _tabletProxies.find(tabletId); | ||
| 19 | if (iter != _tabletProxies.end()) { | ||
| 20 | // tablet already exists, just return it. | ||
| 21 | return iter->second.data(); | ||
| 22 | } else { | ||
| 23 | // allocate a new tablet, add it to the map then return it. | ||
| 24 | auto tabletProxy = QSharedPointer<TabletProxy>(new TabletProxy(tabletId)); | ||
| 25 | _tabletProxies[tabletId] = tabletProxy; | ||
| 26 | return tabletProxy.data(); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | void TabletScriptingInterface::setupTablet(QString tabletId, QQuickItem* qmlTablet) { | ||
| 31 | // AJT: TODO | ||
| 32 | qDebug() << "AJT: setupTablet objname = " << qmlTablet->objectName(); | ||
| 33 | } | ||
| 34 | |||
| 35 | // | ||
| 36 | // TabletProxy | ||
| 37 | // | ||
| 38 | |||
| 39 | TabletProxy::TabletProxy(QString name) : _name(name) { | ||
| 40 | ; | ||
| 41 | } | ||
| 42 | |||
| 43 | QObject* TabletProxy::addButton(const QVariant& properties) { | ||
| 44 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); | ||
| 45 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | ||
| 46 | _tabletButtonProxies.push_back(tabletButtonProxy); | ||
| 47 | return tabletButtonProxy.data(); | ||
| 48 | } | ||
| 49 | |||
| 50 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { | ||
| 51 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | ||
| 52 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | ||
| 53 | if (iter != _tabletButtonProxies.end()) { | ||
| 54 | _tabletButtonProxies.erase(iter); | ||
| 55 | } else { | ||
| 56 | qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | // | ||
| 61 | // TabletButtonProxy | ||
| 62 | // | ||
| 63 | |||
| 64 | TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _properties(properties) { | ||
| 65 | ; | ||
| 66 | } | ||
| 67 | |||
| 68 | void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) { | ||
| 69 | _initRequestHandler = handler; | ||
| 70 | } | ||
| 71 | |||
| 72 | static QString IMAGE_URL_KEY = "imageUrl"; | ||
| 73 | static QString IMAGE_URL_DEFAULT = ""; | ||
| 74 | |||
| 75 | QString TabletButtonProxy::getImageUrl() const { | ||
| 76 | std::lock_guard<std::mutex> guard(_propertiesMutex); | ||
| 77 | return _properties.value(IMAGE_URL_KEY, IMAGE_URL_DEFAULT).toString(); | ||
| 78 | } | ||
| 79 | |||
| 80 | void TabletButtonProxy::setImageUrl(QString imageUrl) { | ||
| 81 | std::lock_guard<std::mutex> guard(_propertiesMutex); | ||
| 82 | _properties[IMAGE_URL_KEY] = imageUrl; | ||
| 83 | } | ||
| 84 | |||
| 85 | #include "TabletScriptingInterface.moc" | ||