Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -12,7 +12,7 @@ · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { | 13 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { |
| 14 | 14 | ||
| 15 | std::lock_guard<std::mutex> guard(_tabletProxiesMutex); | 15 | std::lock_guard<std::mutex> guard(_mutex); |
| 16 | 16 | ||
| 17 | // look up tabletId in the map. | 17 | // look up tabletId in the map. |
| 18 | auto iter = _tabletProxies.find(tabletId); | 18 | auto iter = _tabletProxies.find(tabletId); |
| @@ -36,7 +36,6 @@ void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTab · 17 unmodified lines | |||
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | |||
| 40 | // | 39 | // |
| 41 | // TabletProxy | 40 | // TabletProxy |
| 42 | // | 41 | // |
| @@ -64,24 +63,27 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 21 unmodified lines | |||
| 64 | return; | 63 | return; |
| 65 | } | 64 | } |
| 66 | QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot())); | 65 | QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot())); |
| 66 | buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton)); | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) { | 69 | void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) { |
| 70 | std::lock_guard<std::mutex> guard(_mutex); | ||
| 70 | if (qmlTablet) { | 71 | if (qmlTablet) { |
| 71 | _qmlTablet = qmlTablet; | 72 | _qmlTablet = qmlTablet; |
| 72 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | ||
| 73 | for (auto& buttonProxy : _tabletButtonProxies) { | 73 | for (auto& buttonProxy : _tabletButtonProxies) { |
| 74 | addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data()); | 74 | addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data()); |
| 75 | } | 75 | } |
| 76 | } else { | 76 | } else { |
| 77 | for (auto& buttonProxy : _tabletButtonProxies) { | ||
| 78 | buttonProxy->setQmlButton(nullptr); | ||
| 79 | } | ||
| 77 | _qmlTablet = nullptr; | 80 | _qmlTablet = nullptr; |
| 78 | } | 81 | } |
| 79 | |||
| 80 | } | 82 | } |
| 81 | 83 | ||
| 82 | QObject* TabletProxy::addButton(const QVariant& properties) { | 84 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 83 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); | 85 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 84 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | 86 | std::lock_guard<std::mutex> guard(_mutex); |
| 85 | _tabletButtonProxies.push_back(tabletButtonProxy); | 87 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 86 | if (_qmlTablet) { | 88 | if (_qmlTablet) { |
| 87 | addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data()); | 89 | addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data()); |
| @@ -90,11 +92,12 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 2 unmodified lines | |||
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { | 94 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { |
| 93 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | 95 | std::lock_guard<std::mutex> guard(_mutex); |
| 94 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | 96 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 95 | if (iter != _tabletButtonProxies.end()) { | 97 | if (iter != _tabletButtonProxies.end()) { |
| 96 | if (_qmlTablet) { | 98 | if (_qmlTablet) { |
| 97 | QMetaObject::invokeMethod(_qmlTablet, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | 99 | (*iter)->setQmlButton(nullptr); |
| 100 | QMetaObject::invokeMethod(_qmlTablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | ||
| 98 | } | 101 | } |
| 99 | _tabletButtonProxies.erase(iter); | 102 | _tabletButtonProxies.erase(iter); |
| 100 | } else { | 103 | } else { |
| @@ -106,28 +109,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 5 unmodified lines | |||
| 106 | // TabletButtonProxy | 109 | // TabletButtonProxy |
| 107 | // | 110 | // |
| 108 | 111 | ||
| 109 | TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _properties(properties) { | 112 | const QString UUID_KEY = "uuid"; |
| 110 | ; | ||
| 111 | } | ||
| 112 | 113 | ||
| 113 | void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) { | 114 | TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _properties(properties) { |
| 114 | _initRequestHandler = handler; | 115 | // this is used to uniquely identify this button. |
| 116 | _properties[UUID_KEY] = _uuid; | ||
| 115 | } | 117 | } |
| 116 | 118 | ||
| 117 | // TABLET_UI_HACK remove | 119 | void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) { |
| 118 | /* | 120 | std::lock_guard<std::mutex> guard(_mutex); |
| 119 | static QString IMAGE_URL_KEY = "imageUrl"; | 121 | _qmlButton = qmlButton; |
| 120 | static QString IMAGE_URL_DEFAULT = ""; | ||
| 121 | |||
| 122 | QString TabletButtonProxy::getImageUrl() const { | ||
| 123 | std::lock_guard<std::mutex> guard(_propertiesMutex); | ||
| 124 | return _properties.value(IMAGE_URL_KEY, IMAGE_URL_DEFAULT).toString(); | ||
| 125 | } | 122 | } |
| 126 | 123 | ||
| 127 | void TabletButtonProxy::setImageUrl(QString imageUrl) { | 124 | // TABLET_UI_HACK TODO: add property accessors, and forward property changes to the _qmlButton if present. |
| 128 | std::lock_guard<std::mutex> guard(_propertiesMutex); | ||
| 129 | _properties[IMAGE_URL_KEY] = imageUrl; | ||
| 130 | } | ||
| 131 | */ | ||
| 132 | 125 | ||
| 133 | #include "TabletScriptingInterface.moc" | 126 | #include "TabletScriptingInterface.moc" |