-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (95 loc) · 5.29 KB
/
Copy pathmain.cpp
File metadata and controls
117 lines (95 loc) · 5.29 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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QFontDatabase>
#include <QDir>
#include <QQuickStyle>
#include "src/backend/NavigationBackend.h"
#include "src/backend/PerceptionBackend.h"
#include "src/backend/GlobalReceiver.h"
#include "src/backend/GlobalTransmitter.h"
#include "src/backend/SettingsBackend.h"
#include "src/backend/LoggerBackend.h"
#include "src/backend/InternetBackend.h"
#include "src/backend/TerminalBackend.h"
#include "src/backend/CameraFramesBackend.h"
#include "src/backend/LogBackupBackend.h"
#include "src/backend/IntelLogsBackend.h"
static void loadAppFonts()
{
// These paths match qt_add_qml_module resource layout: :/qt/qml/<URI>/<path>
// URI is HMI_Mk1, and your files are src/fonts/...
const QString regular = QStringLiteral(":/qt/qml/HMI_Mk1/src/fonts/UniversalSans.ttf");
const QString display = QStringLiteral(":/qt/qml/HMI_Mk1/src/fonts/UniversalSansDisplay.ttf");
QFontDatabase::addApplicationFont(regular);
QFontDatabase::addApplicationFont(display);
// Use the family name as defined inside the font file.
// If the family name differs, this will still usually work after addApplicationFont,
// but you can also query QFontDatabase::applicationFontFamilies(id).
// Use the family name as defined inside the TTF (query with applicationFontFamilies(id) if needed).
// For a heavier body text, add e.g. UniversalSans-SemiBold.ttf to RESOURCES and load it here,
// then use Font.DemiBold or Font.Medium in Theme / default font.
QGuiApplication::setFont(QFont(QStringLiteral("Universal Sans"), 16));
}
int main(int argc, char *argv[])
{
// Optional: on Jetson/Ubuntu touch, set QT_IM_MODULE=qtvirtualkeyboard
// (if Qt6VirtualKeyboard is installed) so an on-screen keyboard appears for text fields
QGuiApplication app(argc, argv);
// Use a style that supports control customization (background, contentItem)
QQuickStyle::setStyle("Material");
loadAppFonts();
QQmlApplicationEngine engine;
auto* navBackend = new NavigationBackend(&engine);
auto* txBackend = new GlobalTransmitter(&engine);
auto* settingsBackend = new SettingsBackend(&engine);
// Connect settings backend to other backends
settingsBackend->setGlobalTransmitter(txBackend);
settingsBackend->setNavigationBackend(navBackend);
// Apply initial settings from QSettings to backends
settingsBackend->applyInitialSettings();
engine.rootContext()->setContextProperty("NavigationBackend", navBackend);
engine.rootContext()->setContextProperty("GlobalTx", txBackend);
engine.rootContext()->setContextProperty("SettingsBackend", settingsBackend);
auto* perceptionBackend = new PerceptionBackend(&engine);
engine.rootContext()->setContextProperty("PerceptionBackend", perceptionBackend);
QObject::connect(navBackend->globalReceiver(), &GlobalReceiver::perceptionFrameReceived,
perceptionBackend, &PerceptionBackend::onPerceptionFrameReceived);
auto* loggerBackend = new LoggerBackend(&engine);
engine.rootContext()->setContextProperty("LoggerBackend", loggerBackend);
auto* logBackupBackend = new LogBackupBackend(&engine);
logBackupBackend->setLoggerBackend(loggerBackend);
logBackupBackend->setSettingsBackend(settingsBackend);
engine.rootContext()->setContextProperty("LogBackupBackend", logBackupBackend);
QObject::connect(loggerBackend, &LoggerBackend::recordingSaved, &engine, [logBackupBackend, settingsBackend]() {
if (settingsBackend->autoBackupLogs())
logBackupBackend->startBackup();
});
engine.rootContext()->setContextProperty("InternetBackend", new InternetBackend(&engine));
engine.rootContext()->setContextProperty("TerminalBackend", new TerminalBackend(&engine));
QObject::connect(navBackend->globalReceiver(), &GlobalReceiver::canBatchReceived,
loggerBackend, &LoggerBackend::onCanBatch);
auto* cameraFramesBackend = new CameraFramesBackend(&engine);
cameraFramesBackend->addImageProviderTo(&engine);
engine.rootContext()->setContextProperty("CameraFramesBackend", cameraFramesBackend);
QObject::connect(navBackend->globalReceiver(), &GlobalReceiver::cameraBatchReceived,
cameraFramesBackend, &CameraFramesBackend::onCameraBatch);
auto* intelLogsBackend = new IntelLogsBackend(&engine);
engine.rootContext()->setContextProperty("IntelLogsBackend", intelLogsBackend);
// Cross-platform maps directory:
// On Linux you used /home/hmi/HMI/maps/. On Windows, use a local "maps" folder next to the exe.
const QString mapsDir = QDir(QCoreApplication::applicationDirPath()).filePath("maps");
const QString mapsDirPath = QDir(mapsDir).absolutePath() + QDir::separator();
engine.rootContext()->setContextProperty("HMIMapsDirUrl", QUrl::fromLocalFile(mapsDirPath));
// Plain path for OSM plugin (offline tiles); plugin expects filesystem path, not file:// URL, so offline works on Linux too
engine.rootContext()->setContextProperty("HMIMapsDirPath", mapsDirPath);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection
);
engine.loadFromModule("HMI_Mk1", "Main");
return app.exec();
}