Skip to content

Commit 7179877

Browse files
committed
adaptions for app image
1 parent 2867746 commit 7179877

File tree

4 files changed

+84
-17
lines changed

4 files changed

+84
-17
lines changed

src/test/ui_test_cmd.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ void RTCommandUIGet::assignVariables_impl(const VariablesMap& variables)
191191
*************************************************************************/
192192

193193
/**
194+
* Inject UI events into UI objects, e.g.
195+
* uiinject mouse(left,click,50,40) => inject a mouse click at (50,40)
196+
* mouse(right,click,-1,-1) => inject a mouse click at the middle of the widget
197+
* mouse(left,click,50%,50%) => inject a mouse click at the middle of the widget
198+
* mouse(left,rect,0,0,100,100) => press the mouse at (0,0), move to (100,100) and release the mouse
194199
*/
195200
bool RTCommandUIInject::run_impl()
196201
{

src/test/ui_test_event_injections.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool injectKeyCmdEvent(QWidget* root,
166166

167167
auto injectionMsg = [ & ] (const std::string& obj_type)
168168
{
169-
loginf << "Injecting command";
169+
loginf << "Injecting key into " << obj_type;
170170
};
171171

172172
if (obj.second->isWidgetType())
@@ -183,6 +183,46 @@ bool injectKeyCmdEvent(QWidget* root,
183183
return true;
184184
}
185185

186+
/**
187+
*/
188+
bool injectKeySequenceEvent(QWidget* root,
189+
const QString& obj_name,
190+
const QKeySequence& keys,
191+
int delay)
192+
{
193+
auto obj = findObject(root, obj_name);
194+
if (obj.first != rtcommand::FindObjectErrCode::NoError)
195+
{
196+
logObjectError("injectKeySequenceEvent", obj_name, obj.first);
197+
return false;
198+
}
199+
if (!obj.second->isWidgetType() && !obj.second->isWindowType())
200+
{
201+
logObjectError("injectKeySequenceEvent", obj_name, rtcommand::FindObjectErrCode::WrongType);
202+
return false;
203+
}
204+
205+
auto injectionMsg = [ & ] (const std::string& obj_type)
206+
{
207+
loginf << "Injecting key sequence into " << obj_type;
208+
};
209+
210+
if (obj.second->isWidgetType())
211+
{
212+
injectionMsg("widget");
213+
//@TODO: keySequence not available in appimage qt
214+
//QTest::keySequence(dynamic_cast<QWidget*>(obj.second), keys);
215+
}
216+
else //window
217+
{
218+
injectionMsg("window");
219+
//@TODO: keySequence not available in appimage qt
220+
//QTest::keySequence(dynamic_cast<QWindow*>(obj.second), keys);
221+
}
222+
223+
return true;
224+
}
225+
186226
/**
187227
* Injects mouse clicks into widgets or windows.
188228
*/

src/test/ui_test_event_injections.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ namespace ui_test
5656
const Qt::Key& key,
5757
Qt::KeyboardModifiers modifier,
5858
int delay = -1);
59+
bool injectKeySequenceEvent(QWidget* root,
60+
const QString& obj_name,
61+
const QKeySequence& keys,
62+
int delay = -1);
5963
bool injectClickEvent(QWidget* root,
6064
const QString& obj_name,
6165
int x = -1,

src/test/ui_test_inject.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ bool injectUIEvent(QWidget* parent,
3737
if (w.first != rtcommand::FindObjectErrCode::NoError)
3838
return false;
3939

40+
auto splitEvent = [ & ] (QString& evt_type, QStringList& params, const QString& str)
41+
{
42+
int idx = str.indexOf("(", 0);
43+
if (idx < 1)
44+
return false;
45+
46+
evt_type = str.mid(0, idx);
47+
48+
auto param_str = str.mid(idx);
49+
if (!param_str.startsWith("(") || !param_str.endsWith(")"))
50+
return false;
51+
52+
param_str = param_str.mid(1, param_str.count() - 2);
53+
54+
params = param_str.split(",");
55+
56+
return true;
57+
};
58+
4059
auto mouseButtonFromString = [ & ] (const QString& str)
4160
{
4261
if (str == "left")
@@ -78,13 +97,12 @@ bool injectUIEvent(QWidget* parent,
7897
if (s.endsWith("%"))
7998
{
8099
percent = true;
81-
s = s.chopped(1);
100+
s.chop(1);
82101
}
83102

84103
if (s.isEmpty())
85104
return c;
86105

87-
88106
bool ok;
89107
double v = s.toDouble(&ok);
90108

@@ -97,23 +115,21 @@ bool injectUIEvent(QWidget* parent,
97115
return c;
98116
};
99117

100-
if (event.startsWith("mouse"))
101-
{
102-
auto param_str = QString(event).remove("mouse");
103-
104-
if (!param_str.startsWith("(") || !param_str.endsWith(")"))
105-
return false;
106-
107-
param_str = param_str.mid(1, param_str.count() - 2);
118+
QString evt_type;
119+
QStringList params;
120+
if (!splitEvent(evt_type, params, event))
121+
return false;
108122

109-
auto params = param_str.split(",");
123+
if (evt_type == "mouse")
124+
{
110125
if (params.size() < 2)
111126
return false;
112127

113128
auto button = mouseButtonFromString(params[ 0 ]);
114129
auto action = mouseActionFromString(params[ 1 ]);
115130

116-
if (button == Qt::NoButton || action == MouseAction::NoAction)
131+
if (button == Qt::NoButton ||
132+
action == MouseAction::NoAction)
117133
return false;
118134

119135
if (action == MouseAction::Click)
@@ -144,15 +160,17 @@ bool injectUIEvent(QWidget* parent,
144160
return false;
145161
}
146162
}
147-
else if (event.endsWith("wheel"))
163+
else if (evt_type == "wheel")
148164
{
149165
//@TODO
150166
return false;
151167
}
152-
else if (event.endsWith("keys"))
168+
else if (evt_type == "keys")
153169
{
154-
//@TODO
155-
return false;
170+
if (params.size() != 1)
171+
return false;
172+
173+
return injectKeySequenceEvent(w.second, "", QKeySequence(params[ 0 ]));
156174
}
157175

158176
//unknown event

0 commit comments

Comments
 (0)