-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.cpp
43 lines (40 loc) · 1.42 KB
/
main.cpp
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
#include <QApplication>
#include <QDesktopWidget>
#include <QtScript/QScriptEngine>
#include "agent.hpp"
#include "mainwin.hpp"
#include "my_custom_button.hpp"
#include "script_ext.hpp"
static QString
myCustomButtonAnalyzer(const qt_monkey_agent::EventInfo &eventInfo)
{
QString res;
if (eventInfo.widget == nullptr
|| eventInfo.event->type() != QEvent::MouseButtonPress)
return res;
auto btn = qobject_cast<MyCustomButton *>(eventInfo.widget);
if (btn == nullptr)
return res;
qDebug("%s: it is our custom button", Q_FUNC_INFO);
return QString("ExtAPI.pressButton(\"%1\");").arg(btn->text());
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ScriptExt scriptExt;
qt_monkey_agent::Agent agent(
QKeySequence(Qt::Key_F12 | Qt::SHIFT), {myCustomButtonAnalyzer},
[&scriptExt](QScriptEngine &engine) {
QScriptValue global = engine.globalObject();
QScriptValue ext_api_js_obj = engine.newQObject(&scriptExt);
QScriptValue metaObject
= engine.newQMetaObject(&ScriptExt::staticMetaObject);
global.setProperty("ExtAPIClass", metaObject);
global.setProperty(QLatin1String("ExtAPI"), ext_api_js_obj);
});
MainWin mainwin;
const QDesktopWidget *desc = QApplication::desktop();
mainwin.resize(desc->width() / 4, desc->height() / 4);
mainwin.show();
return app.exec();
}