From dd2da9e2908e881af6cb1fe90306fe6004081cb6 Mon Sep 17 00:00:00 2001 From: Jordan Brown <31949071+jordanbrown0@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:19:21 -0800 Subject: [PATCH] Make customizer font and size selectable. (#4946) --- src/gui/Preferences.cc | 115 +++++++++++++++------------ src/gui/Preferences.h | 6 ++ src/gui/Preferences.ui | 59 ++++++++++++++ src/gui/TabManager.cc | 3 +- src/gui/parameter/ParameterWidget.cc | 13 +++ src/gui/parameter/ParameterWidget.h | 1 + 6 files changed, 146 insertions(+), 51 deletions(-) diff --git a/src/gui/Preferences.cc b/src/gui/Preferences.cc index 44c13d28a3..cd9323f61c 100644 --- a/src/gui/Preferences.cc +++ b/src/gui/Preferences.cc @@ -88,33 +88,19 @@ void Preferences::init() { this->defaultmap["advanced/consoleFontFamily"] = font2.family(); this->defaultmap["advanced/consoleFontSize"] = font2.pointSize(); + // Leave Customizer font with default if user has not chosen another. + this->defaultmap["advanced/customizerFontFamily"] = font2.family(); + this->defaultmap["advanced/customizerFontSize"] = font2.pointSize(); + #if defined (Q_OS_MAC) this->defaultmap["editor/ctrlmousewheelzoom"] = false; #else this->defaultmap["editor/ctrlmousewheelzoom"] = true; #endif - uint savedsize = getValue("editor/fontsize").toUInt(); - const QFontDatabase db; - BlockSignals fontSize{this->fontSize}; - for (auto size : db.standardSizes()) { - fontSize->addItem(QString::number(size)); - if (static_cast(size) == savedsize) { - fontSize->setCurrentIndex(this->fontSize->count() - 1); - } - } - // reset GUI fontsize if fontSize->addItem emitted signals that changed it. - this->fontSize->setEditText(QString("%1").arg(savedsize) ); - - uint consavedsize = getValue("advanced/consoleFontSize").toUInt(); - BlockSignals consoleFontSize{this->consoleFontSize}; - for (auto size : db.standardSizes()) { - consoleFontSize->addItem(QString::number(size)); - if (static_cast(size) == consavedsize) { - consoleFontSize->setCurrentIndex(this->consoleFontSize->count() - 1); - } - } - this->consoleFontSize->setEditText(QString("%1").arg(consavedsize) ); + createFontSizeMenu(fontSize, "editor/fontsize"); + createFontSizeMenu(consoleFontSize, "advanced/consoleFontSize"); + createFontSizeMenu(customizerFontSize, "advanced/customizerFontSize"); // Setup default settings this->defaultmap["advanced/opencsg_show_warning"] = true; @@ -647,13 +633,28 @@ void Preferences::on_consoleFontChooser_currentFontChanged(const QFont& font) } void Preferences::on_consoleFontSize_currentIndexChanged(int index) -{ +{ uint intsize = this->consoleFontSize->itemText(index).toUInt(); QSettingsCached settings; settings.setValue("advanced/consoleFontSize", intsize); emit consoleFontChanged(getValue("advanced/consoleFontFamily").toString(), intsize); } +void Preferences::on_customizerFontChooser_currentFontChanged(const QFont& font) +{ + QSettingsCached settings; + settings.setValue("advanced/customizerFontFamily", font.family()); + emit customizerFontChanged(font.family(), getValue("advanced/customizerFontSize").toUInt()); +} + +void Preferences::on_customizerFontSize_currentIndexChanged(int index) +{ + uint intsize = this->customizerFontSize->itemText(index).toUInt(); + QSettingsCached settings; + settings.setValue("advanced/customizerFontSize", intsize); + emit customizerFontChanged(getValue("advanced/customizerFontFamily").toString(), intsize); +} + void Preferences::on_checkBoxEnableAutocomplete_toggled(bool state) { QSettingsCached settings; @@ -928,19 +929,8 @@ void Preferences::updateGUI() const auto found = this->colorSchemeChooser->findItems(getValue("3dview/colorscheme").toString(), Qt::MatchExactly); if (!found.isEmpty()) BlockSignals(this->colorSchemeChooser)->setCurrentItem(found.first()); - const auto fontfamily = getValue("editor/fontfamily").toString(); - const auto fidx = this->fontChooser->findText(fontfamily, Qt::MatchContains); - if (fidx >= 0) { - BlockSignals(this->fontChooser)->setCurrentIndex(fidx); - } - - const auto fontsize = getValue("editor/fontsize").toString(); - const auto sidx = this->fontSize->findText(fontsize); - if (sidx >= 0) { - BlockSignals(this->fontSize)->setCurrentIndex(sidx); - } else { - BlockSignals(this->fontSize)->setEditText(fontsize); - } + updateGUIFontFamily(fontChooser, "editor/fontfamily"); + updateGUIFontSize(fontSize, "editor/fontsize"); const auto shighlight = getValue("editor/syntaxhighlight").toString(); const auto shidx = this->syntaxHighlight->findText(shighlight); @@ -971,20 +961,13 @@ void Preferences::updateGUI() BlockSignals(this->timeThresholdOnRenderCompleteSoundEdit)->setText(getValue("advanced/timeThresholdOnRenderCompleteSound").toString()); BlockSignals(this->enableClearConsoleCheckBox)->setChecked(getValue("advanced/consoleAutoClear").toBool()); BlockSignals(this->consoleMaxLinesEdit)->setText(getValue("advanced/consoleMaxLines").toString()); - { - const auto fontfamily = getValue("advanced/consoleFontFamily").toString(); - const auto fidx = this->consoleFontChooser->findText(fontfamily, Qt::MatchContains); - if (fidx >= 0) { - BlockSignals(this->consoleFontChooser)->setCurrentIndex(fidx); - } - const auto fontsize = getValue("advanced/consoleFontSize").toString(); - const auto sidx = this->consoleFontSize->findText(fontsize); - if (sidx >= 0) { - BlockSignals(this->consoleFontSize)->setCurrentIndex(sidx); - } else { - BlockSignals(this->consoleFontSize)->setEditText(fontsize); - } - } + + updateGUIFontFamily(consoleFontChooser, "advanced/consoleFontFamily"); + updateGUIFontSize(consoleFontSize, "advanced/consoleFontSize"); + + updateGUIFontFamily(customizerFontChooser, "advanced/customizerFontFamily"); + updateGUIFontSize(customizerFontSize, "advanced/customizerFontSize"); + BlockSignals(this->enableHardwarningsCheckBox)->setChecked(getValue("advanced/enableHardwarnings").toBool()); BlockSignals(this->traceDepthEdit)->setText(getValue("advanced/traceDepth").toString()); BlockSignals(this->enableTraceUsermoduleParametersCheckBox)->setChecked(getValue("advanced/enableTraceUsermoduleParameters").toBool()); @@ -1088,3 +1071,37 @@ Preferences *Preferences::inst() { } +void Preferences::createFontSizeMenu(QComboBox *boxarg, const QString &setting) +{ + uint savedsize = getValue(setting).toUInt(); + const QFontDatabase db; + BlockSignals box{boxarg}; + for (auto size : db.standardSizes()) { + box->addItem(QString::number(size)); + if (static_cast(size) == savedsize) { + box->setCurrentIndex(box->count() - 1); + } + } + // reset GUI fontsize if fontSize->addItem emitted signals that changed it. + box->setEditText(QString("%1").arg(savedsize) ); +} + +void Preferences::updateGUIFontFamily(QFontComboBox *ffSelector, const QString &setting) +{ + const auto fontfamily = getValue(setting).toString(); + const auto fidx = ffSelector->findText(fontfamily, Qt::MatchContains); + if (fidx >= 0) { + BlockSignals(ffSelector)->setCurrentIndex(fidx); + } +} + +void Preferences::updateGUIFontSize(QComboBox *fsSelector, const QString &setting) +{ + const auto fontsize = getValue(setting).toString(); + const auto sidx = fsSelector->findText(fontsize); + if (sidx >= 0) { + BlockSignals(fsSelector)->setCurrentIndex(sidx); + } else { + BlockSignals(fsSelector)->setEditText(fontsize); + } +} diff --git a/src/gui/Preferences.h b/src/gui/Preferences.h index a075c363eb..d7ee0ea17d 100644 --- a/src/gui/Preferences.h +++ b/src/gui/Preferences.h @@ -67,6 +67,8 @@ public slots: void on_consoleMaxLinesEdit_textChanged(const QString&); void on_consoleFontChooser_currentFontChanged(const QFont&); void on_consoleFontSize_currentIndexChanged(int); + void on_customizerFontChooser_currentFontChanged(const QFont&); + void on_customizerFontSize_currentIndexChanged(int); void on_checkBoxEnableAutocomplete_toggled(bool); void on_lineEditCharacterThreshold_textChanged(const QString&); // @@ -115,6 +117,7 @@ public slots: void updateReorderMode(bool undockMode) const; void fontChanged(const QString& family, uint size) const; void consoleFontChanged(const QString& family, uint size) const; + void customizerFontChanged(const QString& family, uint size) const; void colorSchemeChanged(const QString& scheme) const; void openCSGSettingsChanged() const; void syntaxHighlightChanged(const QString& s) const; @@ -142,6 +145,9 @@ private slots: void writeSettings(); void hidePasswords(); void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget); + void createFontSizeMenu(QComboBox *box, const QString &setting); + void updateGUIFontFamily(QFontComboBox *fontSelector, const QString &setting); + void updateGUIFontSize(QComboBox *fsSelector, const QString &setting); /** Set value from combobox to settings */ void applyComboBox(QComboBox *comboBox, int val, Settings::SettingsEntryEnum& entry); diff --git a/src/gui/Preferences.ui b/src/gui/Preferences.ui index 791b9069f2..222a918f50 100644 --- a/src/gui/Preferences.ui +++ b/src/gui/Preferences.ui @@ -2023,6 +2023,65 @@ + + + + Customizer + + + + + + 6 + + + + + Font + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + DejaVu Sans + 12 + + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/src/gui/TabManager.cc b/src/gui/TabManager.cc index 0c75c772ab..46f4910370 100644 --- a/src/gui/TabManager.cc +++ b/src/gui/TabManager.cc @@ -165,6 +165,7 @@ void TabManager::createTab(const QString& filename) assert(par != nullptr); editor = new ScintillaEditor(tabWidget); + Preferences::create(editor->colorSchemes()); // needs to be done only once, however handled par->activeEditor = editor; editor->parameterWidget = new ParameterWidget(par->parameterDock); connect(editor->parameterWidget, SIGNAL(parametersChanged()), par, SLOT(actionRenderPreview())); @@ -177,8 +178,6 @@ void TabManager::createTab(const QString& filename) qcmd = qcmdset->boundTo(Qt::ControlModifier | Qt::Key_Minus); qcmd->setKey(0); - Preferences::create(editor->colorSchemes()); // needs to be done only once, however handled - connect(editor, SIGNAL(uriDropped(const QUrl&)), par, SLOT(handleFileDrop(const QUrl&))); connect(editor, SIGNAL(previewRequest()), par, SLOT(actionRenderPreview())); connect(editor, SIGNAL(showContextMenuEvent(const QPoint&)), this, SLOT(showContextMenuEvent(const QPoint&))); diff --git a/src/gui/parameter/ParameterWidget.cc b/src/gui/parameter/ParameterWidget.cc index 23bf9252b6..b3ec6cd028 100644 --- a/src/gui/parameter/ParameterWidget.cc +++ b/src/gui/parameter/ParameterWidget.cc @@ -34,6 +34,7 @@ #include "ParameterCheckBox.h" #include "ParameterText.h" #include "ParameterVector.h" +#include "Preferences.h" #include @@ -58,6 +59,13 @@ ParameterWidget::ParameterWidget(QWidget *parent) : QWidget(parent) //connect(comboBoxPreset, SIGNAL(editTextChanged(const QString&)), this, SLOT(onSetNameChanged())); connect(addButton, SIGNAL(clicked()), this, SLOT(onSetAdd())); connect(deleteButton, SIGNAL(clicked()), this, SLOT(onSetDelete())); + + QString fontfamily = Preferences::inst()->getValue("advanced/customizerFontFamily").toString(); + uint fontsize = Preferences::inst()->getValue("advanced/customizerFontSize").toUInt(); + setFontFamilySize(fontfamily, fontsize); + + connect(Preferences::inst(), SIGNAL(customizerFontChanged(const QString&, uint)), this, + SLOT(setFontFamilySize(const QString&, uint))); } // Can only be called before the initial setParameters(). @@ -421,3 +429,8 @@ void ParameterWidget::cleanSets() } } } + +void ParameterWidget::setFontFamilySize(const QString &fontFamily, uint fontSize) +{ + scrollArea->setStyleSheet(QString("font-family: \"%1\"; font-size: %2pt;").arg(fontFamily).arg(fontSize)); +} diff --git a/src/gui/parameter/ParameterWidget.h b/src/gui/parameter/ParameterWidget.h index 4fc37aef3a..b82662410e 100644 --- a/src/gui/parameter/ParameterWidget.h +++ b/src/gui/parameter/ParameterWidget.h @@ -59,6 +59,7 @@ class ParameterWidget : public QWidget, public Ui::ParameterWidget public slots: void setModified(bool modified = true); + void setFontFamilySize(const QString &fontfamily, uint fontsize); protected slots: void autoPreview(bool immediate = false);