-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (71 loc) · 2.2 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (71 loc) · 2.2 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
#include "MainWindow.h"
#include <QApplication>
#include <QPainter>
#include <QSplashScreen>
#include <QTextStream>
#include <QTimer>
namespace {
QPixmap makeSplashPixmap() {
QPixmap pix(520, 320);
pix.fill(QColor(20, 24, 28));
QPainter painter(&pix);
painter.setPen(Qt::white);
QFont titleFont = painter.font();
titleFont.setPointSize(28);
titleFont.setBold(true);
painter.setFont(titleFont);
painter.drawText(QRect(0, 70, pix.width(), 60), Qt::AlignHCenter, "DLDViewer");
QFont subFont = painter.font();
subFont.setPointSize(12);
subFont.setBold(false);
painter.setFont(subFont);
painter.setPen(QColor(200, 200, 200));
painter.drawText(QRect(0, 140, pix.width(), 30), Qt::AlignHCenter, "Loading...");
return pix;
}
} // namespace
int main(int argc, char *argv[]) {
QString filePath;
bool bench = false;
int frames = 200;
for (int i = 1; i < argc; ++i) {
QString arg = QString::fromLocal8Bit(argv[i]);
if (arg == "--file" && i + 1 < argc) {
filePath = QString::fromLocal8Bit(argv[++i]);
} else if (arg == "--bench") {
bench = true;
} else if (arg == "--frames" && i + 1 < argc) {
frames = QString::fromLocal8Bit(argv[++i]).toInt();
}
}
QApplication app(argc, argv);
QSplashScreen splash(makeSplashPixmap());
splash.showMessage("Starting...", Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
splash.show();
app.processEvents();
MainWindow w;
w.setSplashScreen(&splash);
w.resize(1000, 600);
w.show();
if (bench) {
QObject::connect(&w, &MainWindow::benchmarkFinished, &app, [&](double msPerFrame) {
QTextStream(stdout) << "Benchmark (QPainter) ms/frame: " << msPerFrame << "\n";
app.quit();
});
}
QTimer::singleShot(0, [&]() {
if (!filePath.isEmpty()) {
if (!w.loadFilePath(filePath)) {
w.finishSplash();
app.quit();
return;
}
} else {
w.finishSplash();
}
if (bench) {
QTimer::singleShot(0, [&]() { w.startBenchmark(frames); });
}
});
return app.exec();
}