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"
|
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
#include <KLocalizedString>
|
2023-03-27 12:49:53 -04:00
|
|
|
#include <QHeaderView>
|
2023-06-15 15:19:34 -04:00
|
|
|
#include <QMenuBar>
|
2023-08-31 13:34:34 +02:00
|
|
|
#include <QTableView>
|
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-08-31 13:55:17 +02:00
|
|
|
MainWindow::MainWindow(const QDir &definitionDirectory, const QDir &assetDirectory, const QDir &dataDirectory, QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
2023-08-31 13:39:00 +02:00
|
|
|
{
|
2023-08-31 13:34:34 +02:00
|
|
|
setWindowTitle(i18nc("@title:window", "Redai"));
|
|
|
|
setMinimumSize(1280, 720);
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
auto menuBar = new QMenuBar();
|
|
|
|
setMenuBar(menuBar);
|
2023-06-15 15:19:34 -04:00
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
auto manageMenu = menuBar->addMenu(i18nc("@title:menu Manage site", "Manage"));
|
2023-06-15 15:19:34 -04:00
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
auto editConfigAction = manageMenu->addAction(i18nc("@action:inmenu", "Edit Config..."));
|
|
|
|
connect(editConfigAction, &QAction::triggered, this, [this, dataDirectory] {
|
2023-08-31 13:39:00 +02:00
|
|
|
auto window = new ArtConfigWindow(dataDirectory.absoluteFilePath("art-config.json"), this);
|
2023-08-31 13:34:34 +02:00
|
|
|
window->show();
|
|
|
|
});
|
2023-06-15 15:19:34 -04:00
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
auto model = new ArtModel(definitionDirectory, assetDirectory);
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:34:34 +02:00
|
|
|
auto pieceListView = new QTableView();
|
2023-08-31 13:39:59 +02:00
|
|
|
pieceListView->setModel(model);
|
|
|
|
pieceListView->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
|
|
|
|
pieceListView->setSelectionMode(QAbstractItemView::SingleSelection);
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:39:59 +02:00
|
|
|
QHeaderView *verticalHeader = pieceListView->verticalHeader();
|
|
|
|
verticalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:39:59 +02:00
|
|
|
QHeaderView *horizontalHeader = pieceListView->horizontalHeader();
|
|
|
|
horizontalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:55:17 +02:00
|
|
|
connect(pieceListView, &QListView::clicked, this, [this, assetDirectory](const QModelIndex index) {
|
2023-08-31 13:39:59 +02:00
|
|
|
const QString filename = index.data(Qt::UserRole + 1).toString();
|
|
|
|
const QJsonObject object = index.data(Qt::UserRole).toJsonObject();
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:39:59 +02:00
|
|
|
auto window = new ArtDetailWindow(filename, assetDirectory, this);
|
|
|
|
window->show();
|
|
|
|
});
|
2023-03-27 12:49:53 -04:00
|
|
|
|
2023-08-31 13:39:59 +02:00
|
|
|
setCentralWidget(pieceListView);
|
2023-03-27 12:49:53 -04:00
|
|
|
}
|