Add setting for console font
MODIFY
src/console.cpp
src/console.cpp
namespace Ripes {
Console::Console(QWidget* parent) : QPlainTextEdit(parent) {
- QFont font = QFont("Inconsolata", 12);
- setFont(font);
+ if (RipesSettings::value(RIPES_SETTING_CONSOLEFONT).isNull()) {
+ m_font = QFont("Inconsolata", 12);
+ } else {
+ m_font = RipesSettings::value(RIPES_SETTING_CONSOLEFONT).value<QFont>();
+ }
+ setFont(m_font);
+
document()->setMaximumBlockCount(100);
auto paletteChangeFunctor = [=] {
QPalette p = palette();
p.setColor(QPalette::Base, RipesSettings::value(RIPES_SETTING_CONSOLEBG).value<QColor>());
- p.setColor(QPalette::Text, RipesSettings::value(RIPES_SETTING_CONSOLEFONT).value<QColor>());
+ p.setColor(QPalette::Text, RipesSettings::value(RIPES_SETTING_CONSOLEFONTCOLOR).value<QColor>());
setPalette(p);
};
connect(RipesSettings::getObserver(RIPES_SETTING_CONSOLEBG), &SettingObserver::modified, paletteChangeFunctor);
- connect(RipesSettings::getObserver(RIPES_SETTING_CONSOLEFONT), &SettingObserver::modified, paletteChangeFunctor);
+ connect(RipesSettings::getObserver(RIPES_SETTING_CONSOLEFONTCOLOR), &SettingObserver::modified,
+ paletteChangeFunctor);
paletteChangeFunctor();
connect(RipesSettings::getObserver(RIPES_SETTING_CONSOLEECHO), &SettingObserver::modified,
[=](const QVariant& value) { m_localEchoEnabled = value.toBool(); });
+ connect(RipesSettings::getObserver(RIPES_SETTING_CONSOLEFONT), &SettingObserver::modified,
+ [=](const QVariant& value) {
+ m_font = value.value<QFont>();
+ setFont(m_font);
+ });
+
m_localEchoEnabled = RipesSettings::value(RIPES_SETTING_CONSOLEECHO).toBool();
}

MODIFY
src/console.h
src/console.h
#pragma once
+#include <QFont>
#include <QPlainTextEdit>
namespace Ripes {
@@ -20,6 +21,7 @@ protected:
private:
bool m_localEchoEnabled = false;
+ QFont m_font;
};
} // namespace Ripes

MODIFY
src/ripessettings.h
src/ripessettings.h
#pragma once
#include <QColor>
+#include <QFont>
#include <QSettings>
namespace Ripes {
@@ -11,7 +12,8 @@ namespace Ripes {
#define RIPES_SETTING_CCARGS ("compiler_args")
#define RIPES_SETTING_CONSOLEECHO ("console_echo")
#define RIPES_SETTING_CONSOLEBG ("console_bg_color")
-#define RIPES_SETTING_CONSOLEFONT ("console_font_color")
+#define RIPES_SETTING_CONSOLEFONTCOLOR ("console_font_color")
+#define RIPES_SETTING_CONSOLEFONT ("console_font")
// Definitions of all default settings within Ripes
const static std::map<QString, QVariant> s_defaultSettings = {
@@ -20,8 +22,8 @@ const static std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_CCARGS, "-O0"},
{RIPES_SETTING_CONSOLEECHO, "true"},
{RIPES_SETTING_CONSOLEBG, QColor(Qt::white)},
- {RIPES_SETTING_CONSOLEFONT, QColor(Qt::black)},
-};
+ {RIPES_SETTING_CONSOLEFONTCOLOR, QColor(Qt::black)},
+ {RIPES_SETTING_CONSOLEFONT, QVariant() /* Let Console define its own default font */}};
/**
* @brief The SettingObserver class

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
#include <QCheckBox>
#include <QColorDialog>
#include <QFileDialog>
+#include <QFontDialog>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
@@ -77,6 +78,32 @@ std::pair<QLabel*, T_TriggerWidget*> createSettingsWidgets(const QString& settin
// Apply color of current setting
colorSetterFunctor();
+ } else if constexpr (std::is_same<T_EditWidget, QFontDialog>()) {
+ // Create a QPushButton which will trigger a QFontDialog when clicked. Changes in the font settings will
+ // trigger a change in the pushbutton text
+ auto fontSetterFunctor = [=] {
+ const auto& font = settingObserver->value().value<QFont>();
+ const QString text = font.family() + " | " + QString::number(font.pointSize());
+ widget->setText(text);
+ };
+
+ // We want changes in the set font to propagate to the button, while in the dialog. But this connection must be
+ // deleted once the dialog is closed, to avoid a dangling connection between the settings object and the trigger
+ // widget.
+ auto conn = settingObserver->connect(settingObserver, &SettingObserver::modified, fontSetterFunctor);
+ widget->connect(widget, &QObject::destroyed, [=] { settingObserver->disconnect(conn); });
+
+ widget->connect(widget, &QPushButton::clicked, [=](bool) {
+ QFontDialog diag;
+ diag.setCurrentFont(settingObserver->value().value<QFont>());
+ diag.setOption(QFontDialog::MonospacedFonts, true);
+ if (diag.exec()) {
+ settingObserver->setValue(diag.selectedFont());
+ }
+ });
+
+ // Apply font of current setting
+ fontSetterFunctor();
}
return {label, widget};
@@ -198,16 +225,22 @@ QWidget* SettingsDialog::createEnvironmentPage() {
consoleLayout->addWidget(echoCheckbox, 0, 1);
// Setting: RIPES_SETTING_CONSOLEFONT
+ auto [fontLabel, fontButton] =
+ createSettingsWidgets<QPushButton, QFontDialog>(RIPES_SETTING_CONSOLEFONT, "Console font:");
+ consoleLayout->addWidget(fontLabel, 1, 0);
+ consoleLayout->addWidget(fontButton, 1, 1);
+
+ // Setting: RIPES_SETTING_CONSOLEFONTCOLOR
auto [fontColorLabel, fontColorButton] =
- createSettingsWidgets<QPushButton, QColorDialog>(RIPES_SETTING_CONSOLEFONT, "Console font color:");
- consoleLayout->addWidget(fontColorLabel, 1, 0);
- consoleLayout->addWidget(fontColorButton, 1, 1);
+ createSettingsWidgets<QPushButton, QColorDialog>(RIPES_SETTING_CONSOLEFONTCOLOR, "Console font color:");
+ consoleLayout->addWidget(fontColorLabel, 2, 0);
+ consoleLayout->addWidget(fontColorButton, 2, 1);
// Setting: RIPES_SETTING_CONSOLEBG
auto [bgColorLabel, bgColorButton] =
createSettingsWidgets<QPushButton, QColorDialog>(RIPES_SETTING_CONSOLEBG, "Console background color:");
- consoleLayout->addWidget(bgColorLabel, 2, 0);
- consoleLayout->addWidget(bgColorButton, 2, 1);
+ consoleLayout->addWidget(bgColorLabel, 3, 0);
+ consoleLayout->addWidget(bgColorButton, 3, 1);
pageLayout->addWidget(consoleGroupBox);

Add setting for console font