-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
113 lines (89 loc) · 4.07 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
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
/*
This file is part of the KDAB Nautical UI demo.
SPDX-FileCopyrightText: 2013-2021 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
SPDX-License-Identifier: MIT
Contact [email protected] for more information about this software.
*/
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QGuiApplication>
#include <QCursor>
#include <QCommandLineParser>
#include <QScreen>
/**
* KDAB Boat demo
*/
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGuiApplication app(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("KDAB Nautical UI - concept of the next generation UI for sailing boats");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption quitOption(QStringList() << "q"
<< "quit",
"Show quit button.");
parser.addOption(quitOption);
QCommandLineOption cursorDisableOption("no-cursor",
"Make sure no pointer is hidden.");
parser.addOption(cursorDisableOption);
QCommandLineOption fullscreenOption("fullscreen",
"Open the demo in fullscreen");
parser.addOption(fullscreenOption);
QCommandLineOption landscapeOption("landscape",
"Open the demo in landscape mode (default: autodetect)");
parser.addOption(landscapeOption);
QCommandLineOption portraitOption("portrait",
"Open the demo in portrait mode (default: autodetect)");
parser.addOption(portraitOption);
QCommandLineOption lowresOption("lowres",
"Open the demo in low resolution");
parser.addOption(lowresOption);
parser.process(app);
if (parser.isSet(cursorDisableOption))
app.setOverrideCursor(QCursor(Qt::BlankCursor));
QScreen *primaryScreen = QGuiApplication::primaryScreen();
if (!primaryScreen)
qFatal("Cannot determine the primary screen");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("_canCloseDemoFromUI", QVariant::fromValue(parser.isSet(quitOption)));
engine.rootContext()->setContextProperty("_showFullscreen", QVariant::fromValue(parser.isSet(fullscreenOption)));
if (parser.isSet(portraitOption) && parser.isSet(landscapeOption))
qFatal("Cannot set both landscape and portrait at the same time");
const bool portrait = [&]() {
if (parser.isSet(portraitOption)) {
return true;
} else if (parser.isSet(landscapeOption)) {
return false;
} else {
QSize primaryGeometry = primaryScreen->size();
return (primaryGeometry.height() > primaryGeometry.width());
}
}();
engine.rootContext()->setContextProperty("_portrait", QVariant::fromValue(portrait));
const bool isLowRes = [&]() {
if (parser.isSet(lowresOption))
return true;
QSize primaryGeometry = primaryScreen->size();
return primaryGeometry.width() < 1280 || primaryGeometry.height() < 720;
}();
engine.rootContext()->setContextProperty("_isLowRes", QVariant::fromValue(isLowRes));
if (isLowRes) {
engine.rootContext()->setContextProperty("_windowWidth", QVariant::fromValue(portrait ? 480 : 800));
engine.rootContext()->setContextProperty("_windowHeight", QVariant::fromValue(portrait ? 800 : 480));
} else {
engine.rootContext()->setContextProperty("_windowWidth", QVariant::fromValue(portrait ? 720 : 1280));
engine.rootContext()->setContextProperty("_windowHeight", QVariant::fromValue(portrait ? 1280 : 720));
}
const QUrl url(QStringLiteral("qrc:/resources/Main.qml"));
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}