-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZMainApplication.cpp
More file actions
75 lines (60 loc) · 2.53 KB
/
ZMainApplication.cpp
File metadata and controls
75 lines (60 loc) · 2.53 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
#include "ZMainApplication.h"
ZMainApplication::ZMainApplication(QObject* parent):QObject(parent)
{
m_cppTranslaterTool = new ZTranslaterTool(qApp);
m_cppOcrProcess = new ZOcrProcess(qApp);
QmlInit();
ConnectSig();
RegisterHotKey();
}
void ZMainApplication::OnFinishOCR()
{
QVariant returnedValue;
QVariant param = true;
QObject* pRoot = m_engine.rootObjects().first();
auto aah = m_engine.rootObjects().count();
auto objectName = pRoot->objectName();
QMetaObject::invokeMethod(pRoot, "updateInputText", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, param));
}
void ZMainApplication::OnFinishTranslate(int errorCode)
{
QVariant returnedValue;
QVariant param = true;
QObject* pRoot = m_engine.rootObjects().first();
auto aah = m_engine.rootObjects().count();
auto objectName = pRoot->objectName();
//QObject* mainWindowQml = pRoot->findChild<QObject*>("quickWin");
//auto obj = pRoot->findChild<QObject*>("mainWindow");
//auto ch = pRoot->children();
QMetaObject::invokeMethod(pRoot, "showTranslateResultTxt", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, param));
}
void ZMainApplication::QmlInit()
{
QQmlDebuggingEnabler enabler;
m_engine.rootContext()->setContextProperty("cppTranslaterTool", m_cppTranslaterTool);
m_engine.rootContext()->setContextProperty("cppOcrProcess", m_cppOcrProcess);
const QUrl url(u"qrc:/Translater/main.qml"_qs);
QObject::connect(&m_engine, &QQmlApplicationEngine::objectCreated,
qApp, [url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
m_engine.load(url);
}
void ZMainApplication::ConnectSig()
{
QObject::connect(m_cppTranslaterTool,&ZTranslaterTool::finish ,this, &ZMainApplication::OnFinishTranslate);
QObject::connect(m_cppOcrProcess, &ZOcrProcess::finish, this, &ZMainApplication::OnFinishOCR);
}
void ZMainApplication::RegisterHotKey()
{
auto hotkey = new QHotkey(Qt::Key_F2,Qt::NoModifier, true, qApp); //The hotkey will be automatically registered
qDebug() << "RegisterHotKey F2:" << hotkey->isRegistered();
QObject::connect(hotkey, &QHotkey::activated, qApp, [&]() {
QVariant returnedValue;
QVariant param = true;
QObject* pRoot = m_engine.rootObjects().first();
auto objectName = pRoot->objectName();
QMetaObject::invokeMethod(pRoot, "showScreenShotWindow", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, param));
});
}