1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-05-09 18:57:44 +00:00
novus/apps/armoury/src/settingswindow.cpp

127 lines
4.8 KiB
C++

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "settingswindow.h"
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <QFileDialog>
#include <QFormLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QVBoxLayout>
SettingsWindow::SettingsWindow(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(i18n("Settings"));
auto layout = new QVBoxLayout();
setLayout(layout);
auto sourcesBox = new QGroupBox(i18n("Sources Output"));
layout->addWidget(sourcesBox);
auto sourcesLayout = new QFormLayout();
sourcesBox->setLayout(sourcesLayout);
auto sourcesBoxLayoutContainer = new QWidget(this);
auto sourcesBoxLayout = new QHBoxLayout(sourcesBoxLayoutContainer);
sourcesBoxLayout->setContentsMargins(0, 0, 0, 0);
KConfig config(QStringLiteral("novusrc"));
KConfigGroup game = config.group(QStringLiteral("Armoury"));
m_sourcesLineEdit = new QLineEdit();
m_sourcesLineEdit->setText(game.readEntry("SourcesOutputDirectory"));
m_sourcesLineEdit->setClearButtonEnabled(true);
sourcesBoxLayout->addWidget(m_sourcesLineEdit);
auto selectSourceUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
connect(selectSourceUrlButton, &QPushButton::clicked, this, [this] {
QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString());
if (!url.isEmpty()) {
m_sourcesLineEdit->setText(url.toDisplayString(QUrl::PreferLocalFile));
}
});
sourcesBoxLayout->addWidget(selectSourceUrlButton);
sourcesLayout->addRow(i18n("Sources directory:"), sourcesBoxLayoutContainer);
auto penumbraBox = new QGroupBox(i18n("Penumbra Output"));
layout->addWidget(penumbraBox);
auto penumbraLayout = new QFormLayout();
penumbraBox->setLayout(penumbraLayout);
auto outputBoxLayoutContainer = new QWidget(this);
auto outputBoxLayout = new QHBoxLayout(outputBoxLayoutContainer);
outputBoxLayout->setContentsMargins(0, 0, 0, 0);
m_outputLineEdit = new QLineEdit();
m_outputLineEdit->setText(game.readEntry("PenumbraOutputDirectory"));
m_outputLineEdit->setClearButtonEnabled(true);
outputBoxLayout->addWidget(m_outputLineEdit);
auto selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
connect(selectHomeUrlButton, &QPushButton::clicked, this, [this] {
QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString());
if (!url.isEmpty()) {
m_outputLineEdit->setText(url.toDisplayString(QUrl::PreferLocalFile));
}
});
outputBoxLayout->addWidget(selectHomeUrlButton);
penumbraLayout->addRow(i18n("Output directory:"), outputBoxLayoutContainer);
auto blenderBox = new QGroupBox(i18n("Blender"));
layout->addWidget(blenderBox);
auto blenderLayout = new QFormLayout();
blenderBox->setLayout(blenderLayout);
auto blenderBoxLayoutContainer = new QWidget(this);
auto blenderBoxLayout = new QHBoxLayout(blenderBoxLayoutContainer);
blenderBoxLayout->setContentsMargins(0, 0, 0, 0);
m_blenderPath = new QLineEdit();
m_blenderPath->setText(game.readEntry("BlenderPath"));
m_blenderPath->setClearButtonEnabled(true);
blenderBoxLayout->addWidget(m_blenderPath);
auto selectBlenderButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString());
connect(selectBlenderButton, &QPushButton::clicked, this, [this] {
QUrl url = QFileDialog::getOpenFileUrl(this, QString());
if (!url.isEmpty()) {
m_blenderPath->setText(url.toDisplayString(QUrl::PreferLocalFile));
}
});
blenderBoxLayout->addWidget(selectBlenderButton);
blenderLayout->addRow(i18n("Blender path:"), blenderBoxLayoutContainer);
auto bottomButtonLayout = new QHBoxLayout();
layout->addLayout(bottomButtonLayout);
auto cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-close")), i18n("Cancel"));
connect(cancelButton, &QPushButton::clicked, this, &QWidget::close);
bottomButtonLayout->addWidget(cancelButton);
bottomButtonLayout->addStretch(1);
auto saveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-ok")), i18n("Apply"));
connect(saveButton, &QPushButton::clicked, this, [this] {
applySettings();
close();
});
bottomButtonLayout->addWidget(saveButton);
}
void SettingsWindow::applySettings()
{
KConfig config(QStringLiteral("novusrc"));
KConfigGroup game = config.group(QStringLiteral("Armoury"));
game.writeEntry("PenumbraOutputDirectory", m_outputLineEdit->text());
game.writeEntry("SourcesOutputDirectory", m_sourcesLineEdit->text());
game.writeEntry("BlenderPath", m_blenderPath->text());
}