Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
boot.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
23
24#include <QApplication>
25#include <QIcon>
26#include <QElapsedTimer>
27#include <QDebug>
28#include <QTranslator>
29#include <QLocale>
30#include <QSettings>
31#include <QLibraryInfo>
32
34#include "../bridge/router.h"
35
36// Generated by CMake from the repo-root VERSION; provides PSE_VERSION_FULL
37// (e.g. "0.7.0-alpha+g1a2b3c4d"). See notes/reference/versioning.md.
38#include "pse_version.h"
39
40extern void bootDatabase();
41extern void bootQmlLinkage();
42
43// There is only ever one main window.
45
46// Installs the UI translators, before any QML is instantiated, so qsTr()/tr()
47// resolve to the chosen language at load time.
48//
49// Language preference resolves as: an explicit "ui/language" setting (a locale
50// name like "fr" or "de"), else the system locale. English is the source
51// language, so when no .qm matches — or a particular string is untranslated —
52// the UI simply falls back to the source text. That graceful degradation is by
53// design (see notes/context/principles.md): a missing translation never blanks
54// a label or blocks the user. See notes/reference/i18n.md for the pipeline.
55static void installTranslators(QApplication* app)
56{
57 QSettings settings; // uses the org/app names set in createApp()
58 const QString pref = settings.value(QStringLiteral("ui/language")).toString();
59 const QLocale locale = pref.isEmpty() ? QLocale::system() : QLocale(pref);
60
61 // The app's own strings (translations/pse_<locale>.ts → :/i18n/pse_<locale>.qm).
62 auto* appTr = new QTranslator(app);
63 if (appTr->load(locale, QStringLiteral("pse"), QStringLiteral("_"),
64 QStringLiteral(":/i18n")))
65 app->installTranslator(appTr);
66 else
67 delete appTr; // no catalog for this locale — stay on the en_US source strings
68
69 // Qt's own built-in strings (standard dialog buttons, etc.), best-effort.
70 auto* qtTr = new QTranslator(app);
71 if (qtTr->load(locale, QStringLiteral("qtbase"), QStringLiteral("_"),
72 QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
73 app->installTranslator(qtTr);
74 else
75 delete qtTr;
76}
77
78// Sets critical Qt options that must be configured before QApplication is created.
79static void preBootAttributes()
80{
81 // Qt 6: High-DPI scaling is enabled automatically — no setAttribute needed.
82 // Qt 6: AA_CompressHighFrequencyEvents and AA_CompressTabletEvents are on by default.
83 // Qt 6: AA_DisableWindowContextHelpButton is the default on all platforms.
84 // Nothing to set here — kept as a hook for future platform-specific tweaks.
85}
86
87// Creates and configures the QApplication instance.
88[[nodiscard]] static QApplication* createApp(int argc, char* argv[])
89{
91
92 QApplication::setApplicationName("Pokered Save Editor");
93 QApplication::setOrganizationName("Twilight");
94 QApplication::setApplicationVersion(QStringLiteral(PSE_VERSION_FULL));
95 QApplication::setOrganizationDomain("pokeredsaveeditor.twilight.app");
96
97 // Note: Do NOT set a custom QSurfaceFormat with MSAA here.
98 // QQuickWidget renders into an offscreen FBO; requesting MSAA via
99 // setDefaultFormat() causes the scene graph to hang on context creation
100 // on many Windows drivers. Qt Quick handles its own antialiasing internally.
101
102 auto* app = new QApplication(argc, argv);
103
104 // Install translators right after the app exists and before the MainWindow
105 // (and thus any QML) is created, so qsTr()/tr() resolve at load time.
107
108 qSetMessagePattern("[%{type}]: %{message} ~ %{time} %{file} %{function} %{line}");
109
110 app->setWindowIcon(QIcon("qrc:/assets/icons/app/512x512.png"));
111
112 // Qt 6 uses QRandomGenerator internally; no manual seeding required.
113
114 mainWindow = new MainWindow();
115 mainWindow->show();
116
117 return app;
118}
119
120// Performs full program bootstrapping and returns a ready-to-exec QApplication.
121extern QApplication* boot(int argc, char* argv[])
122{
123 QElapsedTimer t;
124 t.start();
125
126 qDebug() << "[boot] bootDatabase() start";
127 bootDatabase();
128 qDebug() << "[boot] bootDatabase() done —" << t.elapsed() << "ms";
129
130 qDebug() << "[boot] bootQmlLinkage() start";
132 qDebug() << "[boot] bootQmlLinkage() done —" << t.elapsed() << "ms";
133
134 qDebug() << "[boot] loadScreens() start";
136 qDebug() << "[boot] loadScreens() done —" << t.elapsed() << "ms";
137
138 qDebug() << "[boot] createApp() start";
139 auto* app = createApp(argc, argv);
140 qDebug() << "[boot] createApp() done (window visible) —" << t.elapsed() << "ms";
141
142 return app;
143}
144
void bootQmlLinkage()
static void installTranslators(QApplication *app)
Definition boot.cpp:55
static QApplication * createApp(int argc, char *argv[])
Definition boot.cpp:88
void bootDatabase()
static void preBootAttributes()
Definition boot.cpp:79
MainWindow * mainWindow
Definition boot.cpp:44
QApplication * boot(int argc, char *argv[])
Definition boot.cpp:121
The top-level window – a QMainWindow hosting the QML UI in a QQuickWidget.
Definition mainwindow.h:51
static void loadScreens()
Register the app's screen set (called at boot).
Definition router.cpp:139