diff --git a/forms/preferenceeditor.ui b/forms/preferenceeditor.ui index 0fcaf17e..d3ec7cea 100644 --- a/forms/preferenceeditor.ui +++ b/forms/preferenceeditor.ui @@ -6,8 +6,8 @@ 0 0 - 530 - 432 + 549 + 476 @@ -38,98 +38,194 @@ 12 - - - <html><head/><body><p>If checked, a prompt to reload your project will appear if relevant project files are edited</p></body></html> - - - Monitor project files + + + true + + + + 0 + 0 + 493 + 374 + + + + + + + <html><head/><body><p>If checked, a prompt to reload your project will appear if relevant project files are edited</p></body></html> + + + Monitor project files + + + + + + + <html><head/><body><p>If checked, Porymap will automatically open your most recently opened project on startup</p></body></html> + + + Open recent project on launch + + + + + + + <html><head/><body><p>If checked, Porymap will automatically alert you on startup if a new release is available</p></body></html> + + + Automatically check for updates + + + + + + + + 0 + 0 + + + + Application Theme + + + + + + + Fonts + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Reset + + + + + + + Customize... + + + + + + + Map List Font + + + + + + + Reset + + + + + + + Customize... + + + + + + + Application Font + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Logging + + + + + + Status bar message types + + + + + + + Errors + + + + + + + Warnings + + + + + + + Information + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + - - - - <html><head/><body><p>If checked, Porymap will automatically open your most recently opened project on startup</p></body></html> - - - Open recent project on launch - - - - - - - <html><head/><body><p>If checked, Porymap will automatically alert you on startup if a new release is available</p></body></html> - - - Automatically check for updates - - - - - - - - 0 - 0 - - - - Application Theme - - - - - - - Logging - - - - - - Status bar message types - - - - - - - Errors - - - - - - - Warnings - - - - - - - Information - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - @@ -198,7 +294,7 @@ - Qt::Orientation::Vertical + Qt::Vertical @@ -210,7 +306,7 @@ - + Text Editor @@ -227,7 +323,7 @@ - QFrame::Shape::NoFrame + QFrame::NoFrame true @@ -243,7 +339,7 @@ - QLayout::SizeConstraint::SetMinimumSize + QLayout::SetMinimumSize @@ -251,7 +347,7 @@ <html><head/><body><p>When this command is set a button will appear next to the <span style=" font-weight:600; font-style:italic;">Script</span> combo-box in the <span style=" font-weight:600; font-style:italic;">Events</span> tab which executes this command.<span style=" font-weight:600;"> %F</span> will be substituted with the file path of the script and <span style=" font-weight:600;">%L</span> will be substituted with the line number of the script in that file. <span style=" font-weight:600;">%F </span><span style=" font-style:italic;">must</span> be given if <span style=" font-weight:600;">%L</span> is given. If <span style=" font-weight:600;">%F</span> is <span style=" font-style:italic;">not</span> given then the script's file path will be added to the end of the command. If the script can't be found then the current map's scripts file is opened.</p></body></html> - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop true @@ -284,7 +380,7 @@ <html><head/><body><p>This is the command that is executed when clicking <span style=" font-weight:600; font-style:italic;">Open Project in Text Editor</span> in the <span style=" font-weight:600; font-style:italic;">Tools</span> menu. <span style=" font-weight:600;">%D</span> will be substituted with the project's root directory. If <span style=" font-weight:600;">%D</span> is <span style=" font-style:italic;">not</span> specified then the project directory will be added to the end of the command.</p></body></html> - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop true @@ -314,10 +410,10 @@ - Qt::Orientation::Vertical + Qt::Vertical - QSizePolicy::Policy::Fixed + QSizePolicy::Fixed @@ -330,7 +426,7 @@ - Qt::Orientation::Vertical + Qt::Vertical @@ -351,7 +447,7 @@ - QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/include/config.h b/include/config.h index 11006e56..171e3850 100644 --- a/include/config.h +++ b/include/config.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include "events.h" @@ -64,6 +66,7 @@ class PorymapConfig: public KeyValueConfigBase public: PorymapConfig(); virtual void reset() override { + setRoot(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); this->recentProjects.clear(); this->projectManuallyClosed = false; this->reopenOnLaunch = true; @@ -110,6 +113,8 @@ public: this->shownInGameReloadMessage = false; this->gridSettings = GridSettings(); this->statusBarLogTypes = { LogType::LOG_ERROR, LogType::LOG_WARN }; + this->applicationFont = QFont(); + this->mapListFont = PorymapConfig::defaultMapListFont(); } void addRecentProject(QString project); void setRecentProjects(QStringList projects); @@ -128,6 +133,8 @@ public: QMap getProjectSettingsEditorGeometry(); QMap getCustomScriptsEditorGeometry(); + static QFont defaultMapListFont() { return QFontDatabase::systemFont(QFontDatabase::FixedFont); } + bool reopenOnLaunch; bool projectManuallyClosed; int mapListTab; @@ -177,6 +184,8 @@ public: GridSettings gridSettings; // Prefer over QSet to prevent shuffling elements when writing the config file. std::set statusBarLogTypes; + QFont applicationFont; + QFont mapListFont; protected: virtual void parseConfigKeyValue(QString key, QString value) override; @@ -502,7 +511,10 @@ class ShortcutsConfig : public KeyValueConfigBase public: ShortcutsConfig(); - virtual void reset() override { user_shortcuts.clear(); } + virtual void reset() override { + setRoot(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + user_shortcuts.clear(); + } // Call this before applying user shortcuts so that the user can restore defaults. void setDefaultShortcuts(const QObjectList &objects); diff --git a/include/core/utility.h b/include/core/utility.h index 154e1f1b..f7f5da61 100644 --- a/include/core/utility.h +++ b/include/core/utility.h @@ -15,6 +15,7 @@ namespace Util { Qt::Orientations getOrientation(bool xflip, bool yflip); QString replaceExtension(const QString &path, const QString &newExtension); void setErrorStylesheet(QLineEdit *lineEdit, bool isError); + QString toStylesheetString(const QFont &font); } #endif // UTILITY_H diff --git a/include/ui/maplistmodels.h b/include/ui/maplistmodels.h index ed2c1a09..b19918a7 100644 --- a/include/ui/maplistmodels.h +++ b/include/ui/maplistmodels.h @@ -3,7 +3,6 @@ #define MAPLISTMODELS_H #include -#include #include #include #include @@ -24,7 +23,6 @@ class MapTree : public QTreeView { public: MapTree(QWidget *parent) : QTreeView(parent) { this->setDropIndicatorShown(true); - this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); this->setFocusPolicy(Qt::StrongFocus); this->setContextMenuPolicy(Qt::CustomContextMenu); } diff --git a/include/ui/preferenceeditor.h b/include/ui/preferenceeditor.h index e4541495..64647f0e 100644 --- a/include/ui/preferenceeditor.h +++ b/include/ui/preferenceeditor.h @@ -28,10 +28,12 @@ signals: private: Ui::PreferenceEditor *ui; NoScrollComboBox *themeSelector; + QFont applicationFont; + QFont mapListFont; void initFields(); void saveFields(); - + void openFontDialog(QFont *font); private slots: void dialogButtonClicked(QAbstractButton *button); diff --git a/src/config.cpp b/src/config.cpp index 52f2b6bc..4f5188bd 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -310,7 +309,6 @@ PorymapConfig porymapConfig; PorymapConfig::PorymapConfig() : KeyValueConfigBase(QStringLiteral("porymap.cfg")) { reset(); - setRoot(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); } void PorymapConfig::parseConfigKeyValue(QString key, QString value) { @@ -485,6 +483,12 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { LogType type = static_cast(getConfigInteger(key, typeString, 0, 2)); this->statusBarLogTypes.insert(type); } + } else if (key == "application_font") { + this->applicationFont = QFont(); + this->applicationFont.fromString(value); + } else if (key == "map_list_font") { + this->mapListFont = QFont(); + this->mapListFont.fromString(value); } else { logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->filepath()).arg(key)); } @@ -574,6 +578,8 @@ QMap PorymapConfig::getKeyValueMap() { logTypesStrings.append(QString::number(type)); } map.insert("status_bar_log_types", logTypesStrings.join(",")); + map.insert("application_font", this->applicationFont.toString()); + map.insert("map_list_font", this->mapListFont.toString()); return map; } @@ -1285,7 +1291,6 @@ ShortcutsConfig shortcutsConfig; ShortcutsConfig::ShortcutsConfig() : KeyValueConfigBase(QStringLiteral("porymap.shortcuts.cfg")), user_shortcuts({ }), default_shortcuts({ }) { - setRoot(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); } void ShortcutsConfig::parseConfigKeyValue(QString key, QString value) { diff --git a/src/core/utility.cpp b/src/core/utility.cpp index 81b5157e..904a6785 100644 --- a/src/core/utility.cpp +++ b/src/core/utility.cpp @@ -48,6 +48,25 @@ QString Util::toHtmlParagraph(const QString &text) { return QString("

%1

").arg(text); } +QString Util::toStylesheetString(const QFont &font) { + QString s = QString("font-family: \"%1\";").arg(font.family()); + + if (font.pixelSize() >= 0) { + s.append(QString(" font-size: %1px;").arg(font.pixelSize())); + } else if (font.pointSize() >= 0) { + s.append(QString(" font-size: %1pt;").arg(font.pointSize())); + } + if (font.bold()) { + s.append(" font-weight: bold;"); + } + if (font.style() == QFont::StyleItalic) { + s.append(" font-style: italic;"); + } else if (font.style() == QFont::StyleOblique) { + s.append(" font-style: oblique;"); + } + return s; +} + QString Util::stripPrefix(const QString &s, const QString &prefix) { if (!s.startsWith(prefix)) { return s; diff --git a/src/log.cpp b/src/log.cpp index 200f4438..0c23470c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -12,6 +12,7 @@ namespace Log { static QString path; static QFile file; static QTextStream textStream; + static bool initialized = false; struct Display { QPointer statusBar; @@ -155,12 +156,16 @@ void log(const QString &message, LogType type) { break; } - updateLogDisplays(message, type); - QString fullMessage = QString("%1 %2 %3").arg(now).arg(typeString).arg(message); qDebug().noquote() << colorizeMessage(fullMessage, type); + if (!Log::initialized) { + return; + } + + updateLogDisplays(message, type); + Log::textStream << fullMessage << Qt::endl; Log::file.flush(); } @@ -194,4 +199,5 @@ void logInit() { if (cleanupLargeLog()) { logWarn(QString("Previous log file %1 was cleared due to being over 20MB in size.").arg(Log::path)); } + Log::initialized = true; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9d26a739..8259c315 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -687,6 +687,10 @@ void MainWindow::setTheme(QString theme) { QFile File(QString(":/themes/%1.qss").arg(theme)); File.open(QFile::ReadOnly); QString stylesheet = QLatin1String(File.readAll()); + + stylesheet.append(QString("QWidget { %1 } ").arg(Util::toStylesheetString(porymapConfig.applicationFont))); + stylesheet.append(QString("MapTree { %1 } ").arg(Util::toStylesheetString(porymapConfig.mapListFont))); + setStyleSheet(stylesheet); } @@ -2940,10 +2944,7 @@ void MainWindow::on_actionPreferences_triggered() { } void MainWindow::togglePreferenceSpecificUi() { - if (porymapConfig.textEditorOpenFolder.isEmpty()) - ui->actionOpen_Project_in_Text_Editor->setEnabled(false); - else - ui->actionOpen_Project_in_Text_Editor->setEnabled(true); + ui->actionOpen_Project_in_Text_Editor->setEnabled(!porymapConfig.textEditorOpenFolder.isEmpty()); if (this->updatePromoter) this->updatePromoter->updatePreferences(); diff --git a/src/ui/preferenceeditor.cpp b/src/ui/preferenceeditor.cpp index aa5ad513..4189d650 100644 --- a/src/ui/preferenceeditor.cpp +++ b/src/ui/preferenceeditor.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include PreferenceEditor::PreferenceEditor(QWidget *parent) : @@ -21,8 +23,23 @@ PreferenceEditor::PreferenceEditor(QWidget *parent) : themeSelector->setMinimumContentsLength(0); formLayout->addRow("Themes", themeSelector); setAttribute(Qt::WA_DeleteOnClose); - connect(ui->buttonBox, &QDialogButtonBox::clicked, - this, &PreferenceEditor::dialogButtonClicked); + connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &PreferenceEditor::dialogButtonClicked); + + connect(ui->pushButton_CustomizeApplicationFont, &QPushButton::clicked, [this] { + openFontDialog(&this->applicationFont); + }); + connect(ui->pushButton_CustomizeMapListFont, &QPushButton::clicked, [this] { + openFontDialog(&this->mapListFont); + }); + connect(ui->pushButton_ResetApplicationFont, &QPushButton::clicked, [this] { + this->applicationFont = QFont(); + QToolTip::showText(ui->pushButton_ResetApplicationFont->mapToGlobal(QPoint(0, 0)), "Font reset!"); + }); + connect(ui->pushButton_ResetMapListFont, &QPushButton::clicked, [this] { + this->mapListFont = PorymapConfig::defaultMapListFont(); + QToolTip::showText(ui->pushButton_ResetMapListFont->mapToGlobal(QPoint(0, 0)), "Font reset!"); + }); + initFields(); updateFields(); } @@ -64,13 +81,16 @@ void PreferenceEditor::updateFields() { ui->checkBox_StatusErrors->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_ERROR) != logTypeEnd); ui->checkBox_StatusWarnings->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_WARN) != logTypeEnd); ui->checkBox_StatusInformation->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_INFO) != logTypeEnd); + + this->applicationFont = porymapConfig.applicationFont; + this->mapListFont = porymapConfig.mapListFont; } void PreferenceEditor::saveFields() { + bool changedTheme = false; if (themeSelector->currentText() != porymapConfig.theme) { - const auto theme = themeSelector->currentText(); - porymapConfig.theme = theme; - emit themeChanged(theme); + porymapConfig.theme = themeSelector->currentText(); + changedTheme = true; } bool loadAllEventScripts = ui->checkBox_AutocompleteAllScripts->isChecked(); if (loadAllEventScripts != porymapConfig.loadAllEventScripts) { @@ -90,9 +110,22 @@ void PreferenceEditor::saveFields() { if (ui->checkBox_StatusWarnings->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_WARN); if (ui->checkBox_StatusInformation->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_INFO); + if (porymapConfig.applicationFont != this->applicationFont) { + porymapConfig.applicationFont = this->applicationFont; + changedTheme = true; + } + if (porymapConfig.mapListFont != this->mapListFont) { + porymapConfig.mapListFont = this->mapListFont; + changedTheme = true; + } + porymapConfig.save(); emit preferencesSaved(); + + if (changedTheme) { + emit themeChanged(porymapConfig.theme); + } } void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) { @@ -106,3 +139,12 @@ void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) { close(); } } + +void PreferenceEditor::openFontDialog(QFont *font) { + auto dialog = new QFontDialog(*font, this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + connect(dialog, &QFontDialog::fontSelected, [font](const QFont &selectedFont) { + *font = selectedFont; + }); + dialog->open(); +}