Move themes to PreferenceEditor
This commit is contained in:
parent
ea9cfa47e5
commit
662fb2a367
7 changed files with 54 additions and 45 deletions
|
@ -2607,8 +2607,6 @@
|
|||
<addaction name="actionCursor_Tile_Outline"/>
|
||||
<addaction name="actionPlayer_View_Rectangle"/>
|
||||
<addaction name="actionBetter_Cursors"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionThemes"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
|
@ -2897,11 +2895,6 @@
|
|||
<string>Ctrl+Shift+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionThemes">
|
||||
<property name="text">
|
||||
<string>Themes...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport_Stitched_Map_Image">
|
||||
<property name="text">
|
||||
<string>Export Map Stitch Image...</string>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<widget class="QGroupBox" name="groupBox_TextEditor">
|
||||
<property name="title">
|
||||
<string>Preferred Text Editor</string>
|
||||
</property>
|
||||
|
@ -60,6 +60,19 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_Themes">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Application Theme</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
|
|
|
@ -65,7 +65,6 @@ public:
|
|||
void displayMapBorder();
|
||||
void displayMapGrid();
|
||||
void displayWildMonTables();
|
||||
void maskNonVisibleConnectionTiles();
|
||||
|
||||
void updateMapBorder();
|
||||
void updateMapConnections();
|
||||
|
@ -154,6 +153,9 @@ public:
|
|||
void shouldReselectEvents();
|
||||
void scaleMapView(int);
|
||||
|
||||
public slots:
|
||||
void maskNonVisibleConnectionTiles();
|
||||
|
||||
private:
|
||||
void setConnectionItemsVisible(bool);
|
||||
void setBorderItemsVisible(bool, qreal = 1);
|
||||
|
|
|
@ -218,7 +218,6 @@ private slots:
|
|||
void on_toolButton_ExpandAll_clicked();
|
||||
void on_toolButton_CollapseAll_clicked();
|
||||
void on_actionAbout_Porymap_triggered();
|
||||
void on_actionThemes_triggered();
|
||||
void on_pushButton_AddCustomHeaderField_clicked();
|
||||
void on_pushButton_DeleteCustomHeaderField_clicked();
|
||||
void on_tableWidget_CustomHeaderFields_cellChanged(int row, int column);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
|
||||
class NoScrollComboBox;
|
||||
class QAbstractButton;
|
||||
|
||||
|
||||
|
@ -18,8 +19,13 @@ public:
|
|||
explicit PreferenceEditor(QWidget *parent = nullptr);
|
||||
~PreferenceEditor();
|
||||
|
||||
signals:
|
||||
void preferencesSaved();
|
||||
void themeChanged(const QString &theme);
|
||||
|
||||
private:
|
||||
Ui::PreferenceEditor *ui;
|
||||
NoScrollComboBox *themeSelector;
|
||||
|
||||
void populateFields();
|
||||
void saveFields();
|
||||
|
|
|
@ -2526,43 +2526,13 @@ void MainWindow::on_actionAbout_Porymap_triggered()
|
|||
window->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionThemes_triggered()
|
||||
{
|
||||
QStringList themes;
|
||||
QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
||||
themes.append("default");
|
||||
QDirIterator it(":/themes", QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString themeName = re.match(it.next()).captured(1);
|
||||
themes.append(themeName);
|
||||
}
|
||||
|
||||
QDialog themeSelectorWindow(this);
|
||||
QFormLayout form(&themeSelectorWindow);
|
||||
|
||||
NoScrollComboBox *themeSelector = new NoScrollComboBox();
|
||||
themeSelector->addItems(themes);
|
||||
themeSelector->setCurrentText(porymapConfig.getTheme());
|
||||
form.addRow(new QLabel("Themes"), themeSelector);
|
||||
|
||||
QDialogButtonBox buttonBox(QDialogButtonBox::Apply | QDialogButtonBox::Close, Qt::Horizontal, &themeSelectorWindow);
|
||||
form.addRow(&buttonBox);
|
||||
connect(&buttonBox, &QDialogButtonBox::clicked, [&buttonBox, themeSelector, this](QAbstractButton *button){
|
||||
if (button == buttonBox.button(QDialogButtonBox::Apply)) {
|
||||
QString theme = themeSelector->currentText();
|
||||
porymapConfig.setTheme(theme);
|
||||
this->setTheme(theme);
|
||||
editor->maskNonVisibleConnectionTiles();
|
||||
}
|
||||
});
|
||||
connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject()));
|
||||
|
||||
themeSelectorWindow.exec();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEdit_Preferences_triggered() {
|
||||
if (!preferenceEditor) {
|
||||
preferenceEditor = new PreferenceEditor(this);
|
||||
connect(preferenceEditor, &PreferenceEditor::themeChanged,
|
||||
this, &MainWindow::setTheme);
|
||||
connect(preferenceEditor, &PreferenceEditor::themeChanged,
|
||||
editor, &Editor::maskNonVisibleConnectionTiles);
|
||||
connect(preferenceEditor, &QObject::destroyed, [=](QObject *) { preferenceEditor = nullptr; });
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
#include "preferenceeditor.h"
|
||||
#include "ui_preferenceeditor.h"
|
||||
#include "config.h"
|
||||
#include "noscrollcombobox.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QDirIterator>
|
||||
#include <QFormLayout>
|
||||
|
||||
|
||||
PreferenceEditor::PreferenceEditor(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::PreferenceEditor)
|
||||
ui(new Ui::PreferenceEditor),
|
||||
themeSelector(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
auto *formLayout = new QFormLayout(ui->groupBox_Themes);
|
||||
themeSelector = new NoScrollComboBox(ui->groupBox_Themes);
|
||||
formLayout->addRow("Themes", themeSelector);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
||||
this, &PreferenceEditor::dialogButtonClicked);
|
||||
|
@ -23,10 +31,28 @@ PreferenceEditor::~PreferenceEditor()
|
|||
|
||||
void PreferenceEditor::populateFields() {
|
||||
ui->lineEdit_TextEditor->setText(porymapConfig.getTextEditorCommand());
|
||||
|
||||
QStringList themes = { "default" };
|
||||
QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
||||
QDirIterator it(":/themes", QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString themeName = re.match(it.next()).captured(1);
|
||||
themes.append(themeName);
|
||||
}
|
||||
themeSelector->addItems(themes);
|
||||
themeSelector->setCurrentText(porymapConfig.getTheme());
|
||||
}
|
||||
|
||||
void PreferenceEditor::saveFields() {
|
||||
porymapConfig.setTextEditorCommand(ui->lineEdit_TextEditor->text());
|
||||
|
||||
if (themeSelector->currentText() != porymapConfig.getTheme()) {
|
||||
const auto theme = themeSelector->currentText();
|
||||
porymapConfig.setTheme(theme);
|
||||
emit themeChanged(theme);
|
||||
}
|
||||
|
||||
emit preferencesSaved();
|
||||
}
|
||||
|
||||
void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) {
|
||||
|
|
Loading…
Reference in a new issue