25#include <QGuiApplication>
27#include <QElapsedTimer>
60 qDebug() <<
"[MainWindow] setupUi —" << t.elapsed() <<
"ms";
63 MainWindow::instance =
this;
68 qDebug() <<
"[MainWindow] FileManagement —" << t.elapsed() <<
"ms";
72 qDebug() <<
"[MainWindow] injectIntoQML —" << t.elapsed() <<
"ms";
76 qDebug() <<
"[MainWindow] setupProviders —" << t.elapsed() <<
"ms";
81 connect(ui.app, &QQuickWidget::statusChanged,
this, [
this](QQuickWidget::Status status) {
82 if (status == QQuickWidget::Error) {
84 for (const auto& err : ui.app->errors())
85 msg += err.toString() +
"\n";
86 qCritical() <<
"[QML]" << msg;
88 QMessageBox::critical(this,
"QML Error", msg);
94 ui.app->setSource(QUrl(QStringLiteral(
"qrc:/ui/app/App.qml")));
95 qDebug() <<
"[MainWindow] setSource —" << t.elapsed() <<
"ms";
104 reUpdateRecentFiles(file->getRecentFiles());
105 onPathChanged(file->getPath());
107 qDebug() <<
"[MainWindow] constructor done —" << t.elapsed() <<
"ms";
127 return MainWindow::instance;
130void MainWindow::reUpdateRecentFiles(QList<QString> files)
139 QString
file{files.at(i)};
147void MainWindow::onRecentFileClick()
149 QShortcut* shortcut{qobject_cast<QShortcut*>(sender())};
150 var8 index{
static_cast<var8>(shortcut->property(
"index").toInt())};
151 file->openFileRecent(index);
154void MainWindow::onPathChanged(QString path)
157 this->setWindowTitle(
"Pokered Save Editor - New File");
159 this->setWindowTitle(
"Pokered Save Editor - " + path);
162void MainWindow::closeEvent(QCloseEvent *event)
168void MainWindow::saveState()
170 settings.beginGroup(
"WindowState");
171 settings.setValue(
"size", this->size());
172 settings.setValue(
"pos", this->pos());
176void MainWindow::loadState()
178 settings.beginGroup(
"WindowState");
179 QSize savedSize = settings.value(
"size", QSize(1130, 740)).toSize();
180 QPoint savedPos = settings.value(
"pos", QPoint(200, 200)).toPoint();
183 this->resize(savedSize);
187 bool onScreen =
false;
188 const QPoint titleBarPt = savedPos + QPoint(savedSize.width() / 2, 10);
189 for (
const QScreen* screen : QGuiApplication::screens()) {
190 if (screen->availableGeometry().contains(titleBarPt)) {
195 this->move(onScreen ? savedPos : QPoint(200, 200));
198void MainWindow::setupShortcuts()
209 connect(
recentFileShortcuts[i], &QShortcut::activated,
this, &MainWindow::onRecentFileClick);
219 for (
auto it = keymap.constBegin(); it != keymap.constEnd(); ++it)
220 os.insert(it.key(),
new QShortcut(it.value(),
this));
225 for (
auto it = actions.constBegin(); it != actions.constEnd(); ++it) {
226 QShortcut* sc = os.value(it.key(),
nullptr);
228 const std::function<void()> verb = it.value();
229 connect(sc, &QShortcut::activated,
this, [verb]{ verb(); });
233void MainWindow::setupProviders()
235 auto engine = ui.app->engine();
236 engine->addImageProvider(
"tileset",
new TilesetProvider);
237 engine->addImageProvider(
"font",
new FontPreviewProvider(
file->data->dataExpanded));
240void MainWindow::injectIntoQML()
242 auto* context = ui.app->rootContext();
244 context->setContextProperty(
"brg",
bridge);
254void MainWindow::ssConnect()
The single QML<->C++ doorway – everything the UI touches hangs off here.
void qmlProtect(const QQmlEngine *const engine) const
Pin the DB aggregate (and every sub-DB) to C++ ownership so QML never GCs them.
static DB * inst()
< Raw parsed JSON assets behind every DB.
Owns the on-disk side of a save: the current path, the recent-files list, and the live SaveFile.
protected::void pathChanged(QString newPath, QString oldPath)
The active path changed.
void recentFilesChanged(QList< QString > files)
The recent-files list changed.
The top-level window – a QMainWindow hosting the QML UI in a QQuickWidget.
static QQmlEngine * engine
The QML engine behind the hosted QQuickWidget.
QShortcut * recentFileShortcuts[5]
Ctrl+1..5 open-recent shortcuts.
QHash< QString, QShortcut * > otherShortcuts
Other global keyboard shortcuts by name.
MainWindow(QWidget *parent=nullptr)
< The live save controller.
static MainWindow * getInstance()
The single MainWindow instance.
static Bridge * bridge
The brg aggregate (created here, injected into QML).
Project-wide fixed-width integer aliases (var8, var16, ...).
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
constexpr var8 MAX_RECENT_FILES
How many recent paths to remember.
QHash< QString, QKeySequence > shortcutKeyMap()
Named global shortcuts: action id -> key sequence.
QHash< QString, std::function< void()> > shortcutActions(FileManagement *file, std::function< void()> onExit)
What each named shortcut DOES, action id -> callable, over a live FileManagement.
QKeySequence recentFileShortcutKey(int i)
Recent-file shortcut i (0..MAX_RECENT_FILES-1) == Ctrl+Shift+(0+i), i.e.
Single source of truth for the global keyboard shortcut KEY SEQUENCES.