From 3ee1bb7e5e20ccd5fc1c21ecbe3606effe279c2c Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Fri, 22 Apr 2022 09:39:54 -0500 Subject: [PATCH] Add a font selector to the Console widget. --- src/SeerConsoleWidget.cpp | 40 ++++++++++++++++++---- src/SeerConsoleWidget.h | 1 + src/SeerConsoleWidget.ui | 38 ++++++++++++++------- src/SeerSeerConfigPage.ui | 72 +++++++++++++++++++-------------------- 4 files changed, 96 insertions(+), 55 deletions(-) diff --git a/src/SeerConsoleWidget.cpp b/src/SeerConsoleWidget.cpp index 26ddda4..1044580 100644 --- a/src/SeerConsoleWidget.cpp +++ b/src/SeerConsoleWidget.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,7 @@ SeerConsoleWidget::SeerConsoleWidget (QWidget* parent) : QWidget(parent) { textEdit->setReadOnly(true); textEdit->setTextInteractionFlags(textEdit->textInteractionFlags() | Qt::TextSelectableByKeyboard); // Show cursor textEdit->setFont(font); - textEdit->setLineWrapMode(QPlainTextEdit::NoWrap); // No wrap + textEdit->setLineWrapMode(QPlainTextEdit::NoWrap); // No wrap wrapTextCheckBox->setCheckState(Qt::Unchecked); // No wrap _cursor = QTextCursor(textEdit->document()); @@ -52,6 +53,7 @@ SeerConsoleWidget::SeerConsoleWidget (QWidget* parent) : QWidget(parent) { QObject::connect(clearButton, &QPushButton::clicked, this, &SeerConsoleWidget::handleClearButton); QObject::connect(printButton, &QPushButton::clicked, this, &SeerConsoleWidget::handlePrintButton); QObject::connect(saveButton, &QPushButton::clicked, this, &SeerConsoleWidget::handleSaveButton); + QObject::connect(fontButton, &QPushButton::clicked, this, &SeerConsoleWidget::handleFontButton); QObject::connect(wrapTextCheckBox, &QCheckBox::clicked, this, &SeerConsoleWidget::handleWrapTextCheckBox); QObject::connect(stdinLineEdit, &QLineEdit::returnPressed, this, &SeerConsoleWidget::handleStdinLineEdit); @@ -168,6 +170,21 @@ void SeerConsoleWidget::handleSaveButton () { } } +void SeerConsoleWidget::handleFontButton () { + + bool ok; + + QFont font = QFontDialog::getFont(&ok, textEdit->font(), this, "Seer - Select Console Font", QFontDialog::DontUseNativeDialog|QFontDialog::MonospacedFonts); + + if (ok == false) { + return; + } + + textEdit->setFont(font); + + writeSettings(); +} + void SeerConsoleWidget::handleWrapTextCheckBox () { if (wrapTextCheckBox->checkState() == Qt::Unchecked) { @@ -331,9 +348,10 @@ void SeerConsoleWidget::writeSettings() { QSettings settings; - settings.beginGroup("consolewindow"); - settings.setValue("size", size()); - settings.endGroup(); + settings.beginGroup("consolewindow"); { + settings.setValue("size", size()); + settings.setValue("font", textEdit->font().toString()); + }settings.endGroup(); //qDebug() << size(); } @@ -342,9 +360,17 @@ void SeerConsoleWidget::readSettings() { QSettings settings; - settings.beginGroup("consolewindow"); - resize(settings.value("size", QSize(800, 600)).toSize()); - settings.endGroup(); + settings.beginGroup("consolewindow"); { + resize(settings.value("size", QSize(800, 600)).toSize()); + + QFont f; + if (settings.contains("font")) { + f.fromString(settings.value("font").toString()); + }else{ + f = QFont("Source Code Pro", 10); + } + textEdit->setFont(f); + }settings.endGroup(); //qDebug() << size(); } diff --git a/src/SeerConsoleWidget.h b/src/SeerConsoleWidget.h index 04c299d..0fdea8e 100644 --- a/src/SeerConsoleWidget.h +++ b/src/SeerConsoleWidget.h @@ -26,6 +26,7 @@ class SeerConsoleWidget : public QWidget, protected Ui::SeerConsoleWidgetForm { void handleClearButton (); void handlePrintButton (); void handleSaveButton (); + void handleFontButton (); void handleWrapTextCheckBox (); void handleStdinLineEdit (); void handleConsoleOutput (int socketfd); diff --git a/src/SeerConsoleWidget.ui b/src/SeerConsoleWidget.ui index b3f81f1..1f6b694 100644 --- a/src/SeerConsoleWidget.ui +++ b/src/SeerConsoleWidget.ui @@ -14,7 +14,7 @@ Seer Console - + QPlainTextEdit::NoWrap @@ -40,11 +40,11 @@ - :/seer/resources/RelaxLightIcons/edit-clear.svg:/seer/resources/HighContrast/edit-clear.svg + :/seer/resources/RelaxLightIcons/edit-clear.svg:/seer/resources/RelaxLightIcons/edit-clear.svg - + Print the log output. @@ -57,11 +57,11 @@ - :/seer/resources/RelaxLightIcons/document-print.svg:/seer/resources/HighContrast/document-print.svg + :/seer/resources/RelaxLightIcons/document-print.svg:/seer/resources/RelaxLightIcons/document-print.svg - + Save the log output to a file. @@ -74,11 +74,11 @@ - :/seer/resources/RelaxLightIcons/document-save-as.svg:/seer/resources/HighContrast/document-save-as.svg + :/seer/resources/RelaxLightIcons/document-save-as.svg:/seer/resources/RelaxLightIcons/document-save-as.svg - + Wrap long lines to the next line. @@ -91,7 +91,14 @@ - + + + + [stdin input text] + + + + Qt::Vertical @@ -104,10 +111,17 @@ - - - - [stdin input text] + + + + Select the log output font. + + + + + + + :/seer/resources/font.png:/seer/resources/font.png diff --git a/src/SeerSeerConfigPage.ui b/src/SeerSeerConfigPage.ui index a490001..19e9ea8 100644 --- a/src/SeerSeerConfigPage.ui +++ b/src/SeerSeerConfigPage.ui @@ -6,8 +6,8 @@ 0 0 - 728 - 537 + 671 + 611 @@ -106,6 +106,19 @@ p, li { white-space: pre-wrap; } Console mode on startup + + + + The console is shown minimized in the task bar. + + + Minimized + + + modeButtonGroup + + + @@ -119,24 +132,17 @@ p, li { white-space: pre-wrap; } - - + + - Maximum number of scroll lines. 0 means unlimited. + The console is shown normally. - - 99999 - - - 1000 - - - - - - Number of scroll lines + Normal + + modeButtonGroup + @@ -152,30 +158,17 @@ p, li { white-space: pre-wrap; } - - + + - The console is shown minimized in the task bar. + Maximum number of scroll lines. 0 means unlimited. - - Minimized + + 99999 - - modeButtonGroup - - - - - - - The console is shown normally. + + 1000 - - Normal - - - modeButtonGroup - @@ -191,6 +184,13 @@ p, li { white-space: pre-wrap; } + + + + Number of scroll lines + + +