Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -27,11 +27,16 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { · 26 unmodified lines | |||
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | void TabletScriptingInterface::setupTablet(QString tabletId, QQuickItem* qmlTablet) { | 30 | void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) { |
| 31 | // AJT: TODO | 31 | TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId)); |
| 32 | qDebug() << "AJT: setupTablet objname = " << qmlTablet->objectName(); | 32 | if (tablet) { |
| 33 | tablet->setQmlTablet(qmlTablet); | ||
| 34 | } else { | ||
| 35 | qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object"; | ||
| 36 | } | ||
| 33 | } | 37 | } |
| 34 | 38 | ||
| 39 | |||
| 35 | // | 40 | // |
| 36 | // TabletProxy | 41 | // TabletProxy |
| 37 | // | 42 | // |
| @@ -40,10 +45,47 @@ TabletProxy::TabletProxy(QString name) : _name(name) { · 2 unmodified lines | |||
| 40 | ; | 45 | ; |
| 41 | } | 46 | } |
| 42 | 47 | ||
| 48 | static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* buttonProxy) { | ||
| 49 | QVariant resultVar; | ||
| 50 | Qt::ConnectionType connectionType = Qt::AutoConnection; | ||
| 51 | if (QThread::currentThread() != qmlTablet->thread()) { | ||
| 52 | connectionType = Qt::BlockingQueuedConnection; | ||
| 53 | } | ||
| 54 | bool hasResult = QMetaObject::invokeMethod(qmlTablet, "addButtonProxy", connectionType, | ||
| 55 | Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, buttonProxy->getProperties())); | ||
| 56 | if (!hasResult) { | ||
| 57 | qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet has no result"; | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | QObject* qmlButton = qvariant_cast<QObject *>(resultVar); | ||
| 62 | if (!qmlButton) { | ||
| 63 | qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject"; | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot())); | ||
| 67 | } | ||
| 68 | |||
| 69 | void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) { | ||
| 70 | if (qmlTablet) { | ||
| 71 | _qmlTablet = qmlTablet; | ||
| 72 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | ||
| 73 | for (auto& buttonProxy : _tabletButtonProxies) { | ||
| 74 | addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data()); | ||
| 75 | } | ||
| 76 | } else { | ||
| 77 | _qmlTablet = nullptr; | ||
| 78 | } | ||
| 79 | |||
| 80 | } | ||
| 81 | |||
| 43 | QObject* TabletProxy::addButton(const QVariant& properties) { | 82 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 44 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); | 83 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 45 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | 84 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); |
| 46 | _tabletButtonProxies.push_back(tabletButtonProxy); | 85 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 86 | if (_qmlTablet) { | ||
| 87 | addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data()); | ||
| 88 | } | ||
| 47 | return tabletButtonProxy.data(); | 89 | return tabletButtonProxy.data(); |
| 48 | } | 90 | } |
| 49 | 91 | ||
| @@ -51,6 +93,9 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 1 unmodified line | |||
| 51 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); | 93 | std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex); |
| 52 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | 94 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 53 | if (iter != _tabletButtonProxies.end()) { | 95 | if (iter != _tabletButtonProxies.end()) { |
| 96 | if (_qmlTablet) { | ||
| 97 | QMetaObject::invokeMethod(_qmlTablet, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | ||
| 98 | } | ||
| 54 | _tabletButtonProxies.erase(iter); | 99 | _tabletButtonProxies.erase(iter); |
| 55 | } else { | 100 | } else { |
| 56 | qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | 101 | qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; |
| @@ -69,6 +114,8 @@ void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) { · 12 unmodified lines | |||
| 69 | _initRequestHandler = handler; | 114 | _initRequestHandler = handler; |
| 70 | } | 115 | } |
| 71 | 116 | ||
| 117 | // TABLET_UI_HACK remove | ||
| 118 | /* | ||
| 72 | static QString IMAGE_URL_KEY = "imageUrl"; | 119 | static QString IMAGE_URL_KEY = "imageUrl"; |
| 73 | static QString IMAGE_URL_DEFAULT = ""; | 120 | static QString IMAGE_URL_DEFAULT = ""; |
| 74 | 121 | ||
| @@ -81,5 +128,6 @@ void TabletButtonProxy::setImageUrl(QString imageUrl) { · 6 unmodified lines | |||
| 81 | std::lock_guard<std::mutex> guard(_propertiesMutex); | 128 | std::lock_guard<std::mutex> guard(_propertiesMutex); |
| 82 | _properties[IMAGE_URL_KEY] = imageUrl; | 129 | _properties[IMAGE_URL_KEY] = imageUrl; |
| 83 | } | 130 | } |
| 131 | */ | ||
| 84 | 132 | ||
| 85 | #include "TabletScriptingInterface.moc" | 133 | #include "TabletScriptingInterface.moc" |