-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
83 lines (67 loc) · 2.05 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
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
#include "Gui/MainWindow.h"
#include "Configuration.h"
#include "RuntimeConfigParser.h"
#include <QApplication>
#include <QGraphicsScene>
#include <QFile>
#include <QFileInfo>
#include <QFontDatabase>
#include <QCommandLineParser>
std::optional<QString> LoadStylesheet(const QString &pPath)
{
QFile file(pPath);
if (file.open(QFile::ReadOnly))
{
return QString(file.readAll());
}
else
{
return std::nullopt;
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setApplicationName("Linkuit Studio");
QCoreApplication::setApplicationVersion(QString(FULL_VERSION));
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QCommandLineParser parser;
parser.setApplicationDescription("Linkuit Studio");
parser.addPositionalArgument("file", QCoreApplication::translate("file", "Circuit file to open."));
parser.process(app);
QString path = "";
// Reassemble path from possibly multiple parts, split at the spaces
for (const auto& arg : parser.positionalArguments())
{
path.push_back(arg);
path.push_back(' ');
}
QApplication::setStyle("fusion");
QFontDatabase::addApplicationFont(":/fonts/Quicksand-Medium.ttf");
const auto&& stylesheet = LoadStylesheet(":/styles/style.css");
if (stylesheet.has_value())
{
app.setStyleSheet(stylesheet.value());
}
else
{
qFatal("Could not open stylesheet");
return -1;
}
MainWindow window;
if (parser.positionalArguments().size() > 0)
{
window.GetCoreLogic().GetCircuitFileParser().LoadJson(QFileInfo(path.trimmed().remove("\"")));
}
else
{
if (window.GetCoreLogic().GetRuntimeConfigParser().IsWelcomeDialogEnabledOnStartup())
{
window.ShowWelcomeDialog(gui::SHOW_WELCOME_DIALOG_DELAY);
}
}
window.showMaximized();
app.processEvents();
window.GetView().ResetViewport(); // Reset the viewport AFTER the scrollbars have their final size
return app.exec();
}