Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -10,6 +10,8 @@ · 9 unmodified lines | |||
| 10 | 10 | ||
| 11 | #include <QtCore/QThread> | 11 | #include <QtCore/QThread> |
| 12 | 12 | ||
| 13 | #include "ScriptEngineLogging.h" | ||
| 14 | |||
| 13 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { | 15 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { |
| 14 | 16 | ||
| 15 | std::lock_guard<std::mutex> guard(_mutex); | 17 | std::lock_guard<std::mutex> guard(_mutex); |
| @@ -32,7 +34,7 @@ void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qm · 16 unmodified lines | |||
| 32 | if (tablet) { | 34 | if (tablet) { |
| 33 | tablet->setQmlTabletRoot(qmlTabletRoot); | 35 | tablet->setQmlTabletRoot(qmlTabletRoot); |
| 34 | } else { | 36 | } else { |
| 35 | qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object"; | 37 | qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object"; |
| 36 | } | 38 | } |
| 37 | } | 39 | } |
| 38 | 40 | ||
| @@ -57,13 +59,13 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 18 unmodified lines | |||
| 57 | bool hasResult = QMetaObject::invokeMethod(qmlTablet, "addButtonProxy", connectionType, | 59 | bool hasResult = QMetaObject::invokeMethod(qmlTablet, "addButtonProxy", connectionType, |
| 58 | Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, buttonProxy->getProperties())); | 60 | Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, buttonProxy->getProperties())); |
| 59 | if (!hasResult) { | 61 | if (!hasResult) { |
| 60 | qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet has no result"; | 62 | qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet has no result"; |
| 61 | return; | 63 | return; |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | QObject* qmlButton = qvariant_cast<QObject *>(resultVar); | 66 | QObject* qmlButton = qvariant_cast<QObject *>(resultVar); |
| 65 | if (!qmlButton) { | 67 | if (!qmlButton) { |
| 66 | qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject"; | 68 | qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject"; |
| 67 | return; | 69 | return; |
| 68 | } | 70 | } |
| 69 | QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot())); | 71 | QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot())); |
| @@ -107,36 +109,40 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 37 unmodified lines | |||
| 107 | std::lock_guard<std::mutex> guard(_mutex); | 109 | std::lock_guard<std::mutex> guard(_mutex); |
| 108 | _tabletButtonProxies.push_back(tabletButtonProxy); | 110 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 109 | if (_qmlTabletRoot) { | 111 | if (_qmlTabletRoot) { |
| 110 | addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data()); | 112 | auto tablet = getQmlTablet(); |
| 113 | if (tablet) { | ||
| 114 | addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data()); | ||
| 115 | } else { | ||
| 116 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; | ||
| 117 | } | ||
| 111 | } | 118 | } |
| 112 | return tabletButtonProxy.data(); | 119 | return tabletButtonProxy.data(); |
| 113 | } | 120 | } |
| 114 | 121 | ||
| 115 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { | 122 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { |
| 116 | std::lock_guard<std::mutex> guard(_mutex); | 123 | std::lock_guard<std::mutex> guard(_mutex); |
| 124 | |||
| 125 | auto tablet = getQmlTablet(); | ||
| 126 | if (!tablet) { | ||
| 127 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; | ||
| 128 | } | ||
| 129 | |||
| 117 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | 130 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 118 | if (iter != _tabletButtonProxies.end()) { | 131 | if (iter != _tabletButtonProxies.end()) { |
| 119 | if (_qmlTabletRoot) { | 132 | if (_qmlTabletRoot) { |
| 120 | (*iter)->setQmlButton(nullptr); | 133 | (*iter)->setQmlButton(nullptr); |
| 121 | QMetaObject::invokeMethod(_qmlTabletRoot, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | 134 | if (tablet) { |
| 135 | QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | ||
| 136 | } | ||
| 122 | } | 137 | } |
| 123 | _tabletButtonProxies.erase(iter); | 138 | _tabletButtonProxies.erase(iter); |
| 124 | } else { | 139 | } else { |
| 125 | qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | 140 | qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; |
| 126 | } | 141 | } |
| 127 | } | 142 | } |
| 128 | 143 | ||
| 129 | void TabletProxy::addButtonsToHomeScreen() { | 144 | void TabletProxy::addButtonsToHomeScreen() { |
| 130 | if (!_qmlTabletRoot) { | 145 | auto tablet = getQmlTablet(); |
| 131 | return; | ||
| 132 | } | ||
| 133 | |||
| 134 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | ||
| 135 | if (!loader) { | ||
| 136 | return; | ||
| 137 | } | ||
| 138 | |||
| 139 | auto tablet = loader->findChild<QQuickItem*>("tablet"); | ||
| 140 | if (!tablet) { | 146 | if (!tablet) { |
| 141 | return; | 147 | return; |
| 142 | } | 148 | } |
| @@ -154,6 +160,24 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 11 unmodified lines | |||
| 154 | } | 160 | } |
| 155 | } | 161 | } |
| 156 | 162 | ||
| 163 | QQuickItem* TabletProxy::getQmlTablet() const { | ||
| 164 | if (!_qmlTabletRoot) { | ||
| 165 | return nullptr; | ||
| 166 | } | ||
| 167 | |||
| 168 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | ||
| 169 | if (!loader) { | ||
| 170 | return nullptr; | ||
| 171 | } | ||
| 172 | |||
| 173 | auto tablet = loader->findChild<QQuickItem*>("tablet"); | ||
| 174 | if (!tablet) { | ||
| 175 | return nullptr; | ||
| 176 | } | ||
| 177 | |||
| 178 | return tablet; | ||
| 179 | } | ||
| 180 | |||
| 157 | // | 181 | // |
| 158 | // TabletButtonProxy | 182 | // TabletButtonProxy |
| 159 | // | 183 | // |