2023-08-31 09:09:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-03-27 12:49:53 -04:00
|
|
|
#include "MainWindow.h"
|
|
|
|
|
|
|
|
#include <QTableView>
|
|
|
|
#include <QHeaderView>
|
2023-06-15 15:19:34 -04:00
|
|
|
#include <QMenuBar>
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-06-15 15:19:34 -04:00
|
|
|
#include "ArtConfigWindow.h"
|
2023-03-27 12:49:53 -04:00
|
|
|
#include "ArtDetailWindow.h"
|
|
|
|
#include "ArtModel.h"
|
|
|
|
|
2023-06-15 15:19:34 -04:00
|
|
|
MainWindow::MainWindow(const QString& definitionDirectory, const QString& assetDirectory, const QString& dataDirectory) {
|
2023-03-27 12:49:53 -04:00
|
|
|
setWindowTitle("Redai");
|
|
|
|
setMinimumSize(1280, 720);
|
|
|
|
|
2023-06-15 15:19:34 -04:00
|
|
|
auto menuBar = new QMenuBar();
|
|
|
|
setMenuBar(menuBar);
|
|
|
|
|
|
|
|
auto manageMenu = menuBar->addMenu("Manage");
|
|
|
|
|
|
|
|
auto editConfigAction = manageMenu->addAction("Edit Config...");
|
|
|
|
connect(editConfigAction, &QAction::triggered, this, [this, dataDirectory] {
|
|
|
|
auto window = new ArtConfigWindow(QStringLiteral("%1/art-config.json").arg(dataDirectory), this);
|
|
|
|
window->show();
|
|
|
|
});
|
|
|
|
|
2023-03-27 12:49:53 -04:00
|
|
|
auto model = new ArtModel(definitionDirectory, assetDirectory);
|
|
|
|
|
|
|
|
auto pieceListView = new QTableView();
|
|
|
|
pieceListView->setModel(model);
|
|
|
|
pieceListView->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
|
|
|
|
pieceListView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
QHeaderView *verticalHeader = pieceListView->verticalHeader();
|
|
|
|
verticalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
|
|
|
|
QHeaderView *horizontalHeader = pieceListView->horizontalHeader();
|
|
|
|
horizontalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
|
2023-06-15 13:54:52 -04:00
|
|
|
connect(pieceListView, &QListView::clicked, this, [this, assetDirectory](QModelIndex index) {
|
2023-03-27 12:49:53 -04:00
|
|
|
const QString filename = index.data(Qt::UserRole + 1).toString();
|
|
|
|
const QJsonObject object = index.data(Qt::UserRole).toJsonObject();
|
|
|
|
|
2023-06-15 13:54:52 -04:00
|
|
|
auto window = new ArtDetailWindow(filename, assetDirectory, this);
|
2023-03-27 12:49:53 -04:00
|
|
|
window->show();
|
|
|
|
});
|
|
|
|
|
|
|
|
setCentralWidget(pieceListView);
|
|
|
|
}
|