-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
134 lines (105 loc) · 4.69 KB
/
main.cpp
File metadata and controls
134 lines (105 loc) · 4.69 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QXmlStreamReader>
#include <QIcon>
#include "luascriptcontroller.h"
#include "luascriptqmladapter.h"
#include "luascriptadapter.h"
#include "appcommunicator.h"
#include "model/luaeditormodel.h"
#include "model/apimodel.h"
#include "qml/luaeditorqml.h"
#include <QQuickWindow>
#include <QDebug>
void activateWindow(const QQmlApplicationEngine& engine)
{
// Get the root object, which should be the ApplicationWindow or your main window component
QObject* rootObject = engine.rootObjects().first();
QQuickWindow* qmlWindow = qobject_cast<QQuickWindow*>(rootObject);
// Assuming you already have the QQuickWindow pointer (qmlWindow)
if (qmlWindow)
{
// Ensure the window is visible
qmlWindow->show();
// Bring the window to the front
qmlWindow->raise();
// Set the window to stay on top temporarily
qmlWindow->setFlag(Qt::WindowStaysOnTopHint, true);
// Request activation (focus)
qmlWindow->requestActivate();
// Temporarily force the window to stay on top
qmlWindow->setFlag(Qt::WindowStaysOnTopHint, false);
qmlWindow->showMaximized();
}
}
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
app.setOrganizationName("NOWA");
app.setOrganizationDomain("https://lukas-kalinowski.com");
app.setApplicationName("NOWALuaScript");
#ifdef Q_OS_WIN
app.setWindowIcon(QIcon(":/icons/NOWALuaScript.ico")); // Windows
#endif
#ifdef Q_OS_LINUX
app.setWindowIcon(QIcon(":/icons/NOWALuaScript.png")); // Linux
#endif
#ifdef Q_OS_MAC
app.setWindowIcon(QIcon(":/icons/NOWALuaScript.icns")); // macOS
#endif
QQmlApplicationEngine engine;
// For custom modules
engine.addImportPath(QStringLiteral("qrc:/qml_files"));
qmlRegisterSingletonType<LuaScriptQmlAdapter>("NOWALuaScript", 1, 0, "LuaScriptQmlAdapter", LuaScriptQmlAdapter::getSingletonTypeProvider);
qmlRegisterSingletonType<LuaEditorModel>("NOWALuaScript", 1, 0, "NOWALuaEditorModel", LuaEditorModel::getSingletonTypeProvider);
qmlRegisterUncreatableType<LuaEditorModelItem>("NOWALuaScript", 1, 0, "LuaScriptModelItem", "Not ment to be created in qml.");
qmlRegisterSingletonType<ApiModel>("NOWALuaScript", 1, 0, "NOWAApiModel", ApiModel::getSingletonTypeProvider);
// Register LuaEditorQml as a QML type
qmlRegisterType<LuaEditorQml>("NOWALuaScript", 1, 0, "LuaEditorQml");
QString initialLuaScriptPath;
// Handle initial Lua script path from command-line arguments
if (argc > 1)
{
initialLuaScriptPath = argv[1]; // First argument is the Lua script file path
qDebug() << "Opening Lua script at:" << initialLuaScriptPath;
// Handle the initial Lua script (open in editor)
}
QSharedPointer<LuaScriptAdapter> ptrLuaScriptAdapter(new LuaScriptAdapter());
QSharedPointer<LuaScriptController> ptrLuaScriptController(new LuaScriptController(&engine, ptrLuaScriptAdapter, &app));
const QUrl url(QStringLiteral("qrc:/qml_files/Main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.load(url);
#ifdef QT_NO_DEBUG
if (true == AppCommunicator::isInstanceRunning())
{
if (false == initialLuaScriptPath.isEmpty())
{
activateWindow(engine);
AppCommunicator::sendFileToRunningInstance(initialLuaScriptPath);
}
return 0;
}
#endif
QSharedPointer<AppCommunicator> ptrAppCommunicator(new AppCommunicator(ptrLuaScriptController));
QObject::connect(ptrAppCommunicator.get(), &AppCommunicator::fileReceived,
[=, &engine](const QString& filePath)
{
ptrLuaScriptController.get()->slot_createLuaScript(filePath);
activateWindow(engine);
});
// Delete any existing communication file at start
ptrAppCommunicator->deleteCommunicationFile();
// Connect the QCoreApplication's aboutToQuit signal to delete the file when the app closes
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]()
{
ptrAppCommunicator->deleteRunningFile();
});
// After QML is ready, set a potential first lua script and load it, if it comes from the args
if (false == initialLuaScriptPath.isEmpty())
{
ptrLuaScriptController->slot_createLuaScript(initialLuaScriptPath);
}
return app.exec();
}