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