-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrolpanelconnector.cpp
More file actions
108 lines (102 loc) · 4.26 KB
/
Copy pathcontrolpanelconnector.cpp
File metadata and controls
108 lines (102 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "controlpanelconnector.h"
ControlPanelUiConnector::ControlPanelUiConnector(QObject *parent, QObject *root) : QObject(parent), m_rootItem(root) {
if (!root) {
qDebug() << "Err: root item is null";
return;
}
QObject *item = root->findChild<QObject *>("btn_select");
QObject *item2 = root->findChild<QObject *>("btn_translate");
QObject *item3 = root->findChild<QObject *>("item_instance");
if (!item3) {
qDebug() << "item3 is not valid";
} else {
const QMetaObject *metaObj = item3->metaObject();
for (int i = 0; i < metaObj->methodCount(); ++i) {
QMetaMethod method = metaObj->method(i);
qDebug() << method.methodSignature();
}
}
QObject::connect(item, SIGNAL(qmlSignal(QString)), this, SLOT(cppSlot(QString)));
QObject::connect(item2, SIGNAL(qmlSignal(int)), this, SLOT(cppSlot(int)));
QObject::connect(item3, SIGNAL(qmlSignal3(QVariant)), this, SLOT(cppSlot3(QVariant)));
}
void ControlPanelUiConnector::cppSlot(const QString &msg) { qDebug() << "cpp received signal from qml: " << msg; }
void ControlPanelUiConnector::cppSlot(const int msg) { qDebug() << "cpp received signal from qml: " << msg; }
void ControlPanelUiConnector::cppSlot3(QVariant vitem) {
// QQuickItem *item = qvariant_cast<QQuickItem *>(vitem.value(Qt::UserRole));
// QQuickItem item = (QQuickItem)vitem;
qDebug() << "Called the C++ slot with item:" << vitem;
// qDebug() << "Item dimensions:" << item->width() << item->height();
}
void ControlPanelUiConnector::key_ev_slot(const QString &key_stcode, const QString &key_infos) {
QStringList list2 = key_infos.split(QLatin1Char(':'), Qt::SkipEmptyParts);
qDebug() << "code:" << key_stcode << ", infos:" << key_infos << ",splits:" << list2;
if (list2.length() < 3 || list2[1].length() < 1 || list2[2].length() < 4) {
return;
}
QString key_text = list2[1];
QString key_action = list2[2];
int try_num = 5;
while (try_num > 0) {
QString key_objectName;
switch (try_num--) {
case 5: {
key_objectName = key_text.toLower();
break;
}
case 4: {
key_objectName = key_text.toUpper();
break;
}
case 3: {
if (key_text.length() < 2)
return;
key_objectName = key_text.at(0).toUpper() + key_text.right(key_text.length() - 1).toLower();
break;
}
case 2: {
if (key_text.length() < 3)
return;
key_objectName = key_text.at(0).toLower() + key_text.mid(1, 1).toUpper() +
key_text.right(key_text.length() - 2).toLower();
break;
}
case 1: {
key_objectName = key_text;
break;
}
default:
return;
}
if (key_objectName.length() < 1) {
return;
}
QList<QQuickItem *> all_objs = m_rootItem->findChildren<QQuickItem *>(key_objectName);
for (int i = 0; i < all_objs.length(); i++) {
qDebug() << "qml-obj-" << i << all_objs[i];
QQuickItem *cp_btn = all_objs[i];
QVariant property_value(true);
if (QString("press") == key_action.toLower()) {
if (property_value == cp_btn->property("highlighted")) {
cp_btn->setProperty("highlighted", false);
} else {
cp_btn->setProperty("highlighted", true);
}
} else if (QString("left") == key_action.toLower()) {
qDebug() << "property: " << cp_btn->property("testing_left_show");
if (property_value == cp_btn->property("testing_left_show")) {
cp_btn->setProperty("testing_left_show", false);
} else {
cp_btn->setProperty("testing_left_show", true);
}
} else if (QString("right") == key_action.toLower()) {
if (property_value == cp_btn->property("testing_right_show")) {
cp_btn->setProperty("testing_right_show", false);
} else {
cp_btn->setProperty("testing_right_show", true);
}
}
return;
}
}
}