History

Hook up Help button to the new Tablet interface

Anthony J. Thibault committed 9 years ago

Commit d2c44171 parent d4f9d216 files · +95 −23Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+51−3
@@ -27,11 +27,16 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { · 26 unmodified lines
2727 }
2828 }
2929
30−void TabletScriptingInterface::setupTablet(QString tabletId, QQuickItem* qmlTablet) {
31− // AJT: TODO
32− qDebug() << "AJT: setupTablet objname = " << qmlTablet->objectName();
30+void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTablet) {
31+ TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId));
32+ if (tablet) {
33+ tablet->setQmlTablet(qmlTablet);
34+ } else {
35+ qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
36+ }
3337 }
3438
39+
3540 //
3641 // TabletProxy
3742 //
@@ -40,10 +45,47 @@ TabletProxy::TabletProxy(QString name) : _name(name) { · 2 unmodified lines
4045 ;
4146 }
4247
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+
4382 QObject* TabletProxy::addButton(const QVariant& properties) {
4483 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
4584 std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
4685 _tabletButtonProxies.push_back(tabletButtonProxy);
86+ if (_qmlTablet) {
87+ addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data());
88+ }
4789 return tabletButtonProxy.data();
4890 }
4991
@@ -51,6 +93,9 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 1 unmodified line
5193 std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
5294 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
5395 if (iter != _tabletButtonProxies.end()) {
96+ if (_qmlTablet) {
97+ QMetaObject::invokeMethod(_qmlTablet, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
98+ }
5499 _tabletButtonProxies.erase(iter);
55100 } else {
56101 qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
@@ -69,6 +114,8 @@ void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) { · 12 unmodified lines
69114 _initRequestHandler = handler;
70115 }
71116
117+// TABLET_UI_HACK remove
118+/*
72119 static QString IMAGE_URL_KEY = "imageUrl";
73120 static QString IMAGE_URL_DEFAULT = "";
74121
@@ -81,5 +128,6 @@ void TabletButtonProxy::setImageUrl(QString imageUrl) { · 6 unmodified lines
81128 std::lock_guard<std::mutex> guard(_propertiesMutex);
82129 _properties[IMAGE_URL_KEY] = imageUrl;
83130 }
131+*/
84132
85133 #include "TabletScriptingInterface.moc"