Add art config window
This commit is contained in:
parent
acb9e0ef9c
commit
1257459237
6 changed files with 132 additions and 7 deletions
86
ArtConfigWindow.cpp
Normal file
86
ArtConfigWindow.cpp
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#include "ArtConfigWindow.h"
|
||||||
|
|
||||||
|
#include <QDateEdit>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
|
ArtConfigWindow::ArtConfigWindow(const QString& filename, QWidget* parent) : QDialog(parent) {
|
||||||
|
setWindowModality(Qt::WindowModality::WindowModal);
|
||||||
|
setWindowTitle(filename);
|
||||||
|
|
||||||
|
auto mainLayout = new QHBoxLayout();
|
||||||
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
auto formLayout = new QFormLayout();
|
||||||
|
auto formLayoutWidget = new QWidget();
|
||||||
|
formLayoutWidget->setMaximumWidth(450);
|
||||||
|
formLayoutWidget->setLayout(formLayout);
|
||||||
|
mainLayout->addWidget(formLayoutWidget);
|
||||||
|
|
||||||
|
QScrollArea* galleryScrollArea = new QScrollArea();
|
||||||
|
formLayout->addWidget(galleryScrollArea);
|
||||||
|
|
||||||
|
m_newBannerEdit = new QLineEdit();
|
||||||
|
formLayout->addRow("New Banner", m_newBannerEdit);
|
||||||
|
|
||||||
|
m_commissionsOpen = new QCheckBox();
|
||||||
|
formLayout->addRow("Commissions Open", m_commissionsOpen);
|
||||||
|
|
||||||
|
auto bottomButtonLayout = new QHBoxLayout();
|
||||||
|
formLayout->addRow(bottomButtonLayout);
|
||||||
|
|
||||||
|
auto cancelButton = new QPushButton(QIcon::fromTheme("dialog-close"), "Cancel");
|
||||||
|
connect(cancelButton, &QPushButton::clicked, this, [=] {
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
bottomButtonLayout->addWidget(cancelButton);
|
||||||
|
bottomButtonLayout->addStretch(1);
|
||||||
|
|
||||||
|
auto saveButton = new QPushButton(QIcon::fromTheme("dialog-ok"), "Save");
|
||||||
|
connect(saveButton, &QPushButton::clicked, this, [=] {
|
||||||
|
saveData(filename);
|
||||||
|
});
|
||||||
|
bottomButtonLayout->addWidget(saveButton);
|
||||||
|
|
||||||
|
if(QFile::exists(filename)) {
|
||||||
|
loadData(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtConfigWindow::loadData(const QString& filename) {
|
||||||
|
qDebug() << "Loading data from" << filename;
|
||||||
|
|
||||||
|
QFile artFile(filename);
|
||||||
|
artFile.open(QFile::ReadOnly);
|
||||||
|
QJsonDocument artJson = QJsonDocument::fromJson(artFile.readAll());
|
||||||
|
|
||||||
|
m_newBannerEdit->setText(artJson["new-banner"].toString());
|
||||||
|
m_commissionsOpen->setChecked(artJson["commissions"].toBool());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtConfigWindow::saveData(const QString& filename) {
|
||||||
|
qDebug() << "Saving data to" << filename;
|
||||||
|
|
||||||
|
QJsonObject object;
|
||||||
|
object["new-banner"] = m_newBannerEdit->text();
|
||||||
|
object["commissions"] = m_commissionsOpen->isChecked();
|
||||||
|
|
||||||
|
QJsonDocument jsonDoc(object);
|
||||||
|
QFile file(filename);
|
||||||
|
file.open(QFile::WriteOnly);
|
||||||
|
file.write(jsonDoc.toJson());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
22
ArtConfigWindow.h
Normal file
22
ArtConfigWindow.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QDateEdit>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QStringListModel>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
class ArtConfigWindow : public QDialog {
|
||||||
|
public:
|
||||||
|
ArtConfigWindow(const QString& filename, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadData(const QString& filename);
|
||||||
|
void saveData(const QString& filename);
|
||||||
|
|
||||||
|
QLineEdit* m_newBannerEdit = nullptr;
|
||||||
|
QCheckBox* m_commissionsOpen = nullptr;
|
||||||
|
};
|
|
@ -13,7 +13,7 @@ find_package(Qt5 COMPONENTS
|
||||||
Concurrent
|
Concurrent
|
||||||
REQUIRED)
|
REQUIRED)
|
||||||
|
|
||||||
add_executable(Redai main.cpp MainWindow.cpp MainWindow.h ArtModel.cpp ArtModel.h ArtDetailWindow.cpp ArtDetailWindow.h imagelabel.cpp imagelabel.h)
|
add_executable(Redai main.cpp ArtConfigWindow.cpp ArtDetailWindow.h MainWindow.cpp MainWindow.h ArtModel.cpp ArtModel.h ArtDetailWindow.cpp ArtDetailWindow.h imagelabel.cpp imagelabel.h)
|
||||||
target_link_libraries(Redai
|
target_link_libraries(Redai
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::Gui
|
Qt5::Gui
|
||||||
|
|
|
@ -2,14 +2,27 @@
|
||||||
|
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QMenuBar>
|
||||||
|
|
||||||
|
#include "ArtConfigWindow.h"
|
||||||
#include "ArtDetailWindow.h"
|
#include "ArtDetailWindow.h"
|
||||||
#include "ArtModel.h"
|
#include "ArtModel.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(const QString& definitionDirectory, const QString& assetDirectory) {
|
MainWindow::MainWindow(const QString& definitionDirectory, const QString& assetDirectory, const QString& dataDirectory) {
|
||||||
setWindowTitle("Redai");
|
setWindowTitle("Redai");
|
||||||
setMinimumSize(1280, 720);
|
setMinimumSize(1280, 720);
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
auto model = new ArtModel(definitionDirectory, assetDirectory);
|
auto model = new ArtModel(definitionDirectory, assetDirectory);
|
||||||
|
|
||||||
auto pieceListView = new QTableView();
|
auto pieceListView = new QTableView();
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(const QString& definitionDirectory, const QString& assetDirectory);
|
explicit MainWindow(const QString& definitionDirectory, const QString& assetDirectory, const QString& dataDirectory);
|
||||||
};
|
};
|
||||||
|
|
12
main.cpp
12
main.cpp
|
@ -7,18 +7,22 @@ int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addPositionalArgument("definition-path", QCoreApplication::translate("main", "Art definition directory."));
|
parser.addPositionalArgument("site-path", QCoreApplication::translate("main", "Site directory."));
|
||||||
parser.addPositionalArgument("asset-path", QCoreApplication::translate("main", "Art asset directory."));
|
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
auto args = parser.positionalArguments();
|
auto args = parser.positionalArguments();
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow window(args[0], args[1]);
|
QString sitePath = args[0];
|
||||||
|
QString defPath = QString("%1/art").arg(sitePath);
|
||||||
|
QString assetPath = QString("%1/assets/art").arg(sitePath);
|
||||||
|
QString dataPath = QString("%1/data").arg(sitePath);
|
||||||
|
|
||||||
|
MainWindow window(defPath, assetPath, dataPath);
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
return QApplication::exec();
|
return QApplication::exec();
|
||||||
|
|
Loading…
Add table
Reference in a new issue