From 40484a9778e05120cde9896d0302ba0c35ef8176 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 20 Mar 2019 00:35:24 +0100 Subject: [PATCH] Ref T571, follow up of font dialog for radar component * utility function renaming "fontColorString" * added reset button to erase qss generate by font dialog * set font color as invalid as default --- .../components/settingsfontcomponent.cpp | 32 +++++++++++++++---- .../components/settingsfontcomponent.h | 6 ++-- .../components/settingsfontcomponent.ui | 9 +++++- src/blackgui/stylesheetutility.cpp | 8 ++--- src/blackgui/stylesheetutility.h | 6 ++-- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/blackgui/components/settingsfontcomponent.cpp b/src/blackgui/components/settingsfontcomponent.cpp index 40cdd7a18..c3df23103 100644 --- a/src/blackgui/components/settingsfontcomponent.cpp +++ b/src/blackgui/components/settingsfontcomponent.cpp @@ -31,8 +31,9 @@ namespace BlackGui this->initValues(); // most likely default font at ctor call time connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsFontComponent::fontColorDialog); connect(ui->tb_SettingsGuiNoFontColor, &QToolButton::clicked, this, &CSettingsFontComponent::noColor); - connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont); - connect(ui->pb_CancelOrReset, &QToolButton::clicked, this, &CSettingsFontComponent::resetFont); + connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont, Qt::QueuedConnection); + connect(ui->pb_CancelOrReset, &QToolButton::clicked, this, &CSettingsFontComponent::resetFontAndReject, Qt::QueuedConnection); + connect(ui->pb_Reset, &QToolButton::clicked, this, &CSettingsFontComponent::clearQssAndResetFont, Qt::QueuedConnection); // only after the complete startup style sheet font overrides are available connect(sGui, &CGuiApplication::startUpCompleted, this, &CSettingsFontComponent::initValues); @@ -47,10 +48,12 @@ namespace BlackGui if (m == CSettingsFontComponent::DirectUpdate) { ui->pb_CancelOrReset->setText("reset"); + ui->pb_Reset->setVisible(false); } else { ui->pb_CancelOrReset->setText("cancel"); + ui->pb_Reset->setVisible(true); } } @@ -111,8 +114,8 @@ namespace BlackGui void CSettingsFontComponent::fontColorDialog() { - const QColor c = QColorDialog::getColor(m_selectedColor, this, "Font color"); - if (c == m_selectedColor) return; + const QColor c = QColorDialog::getColor(m_selectedColor.isValid() ? m_selectedColor : m_cancelColor, this, "Font color"); + if (c == m_selectedColor) { return; } m_selectedColor = c; ui->le_SettingsGuiFontColor->setText(m_selectedColor.name()); } @@ -127,7 +130,8 @@ namespace BlackGui { // Font m_cancelFont = this->font(); - m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor()); + const QString colorString(sGui->getStyleSheetUtility().fontColorString()); + m_cancelColor = colorString.isEmpty() ? QColor() : QColor(colorString); this->initUiValues(m_cancelFont, m_cancelColor); } @@ -136,8 +140,10 @@ namespace BlackGui ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font)); ui->cb_SettingsGuiFont->setCurrentFont(font); ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize())); - ui->le_SettingsGuiFontColor->setText(color.name()); - m_selectedColor = color; + + Q_UNUSED(color); // due to the problems with overriding a color (e.g T571) we use "no color" as default + m_selectedColor = QColor(); // invalid, no color + ui->le_SettingsGuiFontColor->setText(m_selectedColor.isValid() ? m_selectedColor.name() : ""); m_qss.clear(); } @@ -149,7 +155,19 @@ namespace BlackGui { sGui->resetFont(); } + } + + void CSettingsFontComponent::resetFontAndReject() + { + this->resetFont(); emit this->reject(); } + + void CSettingsFontComponent::clearQssAndResetFont() + { + m_qss.clear(); + this->resetFont(); + emit this->accept(); + } } // ns } // ns diff --git a/src/blackgui/components/settingsfontcomponent.h b/src/blackgui/components/settingsfontcomponent.h index b0698bf8f..ee4539e72 100644 --- a/src/blackgui/components/settingsfontcomponent.h +++ b/src/blackgui/components/settingsfontcomponent.h @@ -29,8 +29,8 @@ namespace BlackGui //! How to update enum Mode { - DirectUpdate, - GenerateQssOnly + DirectUpdate, //!< directly updating a font qss file + GenerateQssOnly //!< builds a qss style string }; //! Constructor @@ -74,6 +74,8 @@ namespace BlackGui void changeFont(); void resetFont(); + void resetFontAndReject(); + void clearQssAndResetFont(); void fontColorDialog(); void noColor(); void initValues(); diff --git a/src/blackgui/components/settingsfontcomponent.ui b/src/blackgui/components/settingsfontcomponent.ui index e0f9a8e84..25abf4125 100644 --- a/src/blackgui/components/settingsfontcomponent.ui +++ b/src/blackgui/components/settingsfontcomponent.ui @@ -6,7 +6,7 @@ 0 0 - 280 + 320 80 @@ -97,6 +97,13 @@ + + + + reset + + + diff --git a/src/blackgui/stylesheetutility.cpp b/src/blackgui/stylesheetutility.cpp index fc3a2b528..fb0368800 100644 --- a/src/blackgui/stylesheetutility.cpp +++ b/src/blackgui/stylesheetutility.cpp @@ -121,13 +121,13 @@ namespace BlackGui ); } - QString CStyleSheetUtility::fontColor() const + QString CStyleSheetUtility::fontColorString() const { const QString s = this->style(fileNameFonts()).toLower(); - if (!s.contains("color:")) return "red"; + if (!s.contains("color:")) return ""; thread_local const QRegularExpression rx("color:\\s*(#*\\w+);"); const QString c = rx.match(s).captured(1); - return c.isEmpty() ? "red" : c; + return c.isEmpty() ? "" : c; } bool CStyleSheetUtility::read() @@ -253,7 +253,7 @@ namespace BlackGui bool CStyleSheetUtility::resetFont() { - QFile fontFile(CDirectoryUtils::stylesheetsDirectory() + "/" + fileNameFontsModified()); + QFile fontFile(CFileUtils::appendFilePaths(CDirectoryUtils::stylesheetsDirectory(), fileNameFontsModified())); return fontFile.remove(); } diff --git a/src/blackgui/stylesheetutility.h b/src/blackgui/stylesheetutility.h index bb2374c72..41953447a 100644 --- a/src/blackgui/stylesheetutility.h +++ b/src/blackgui/stylesheetutility.h @@ -56,13 +56,13 @@ namespace BlackGui bool updateFont(const QString &qss); //! Update the fonts - bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor); + bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColorString); //! Reset font bool resetFont(); //! Current font color from style sheet - QString fontColor() const; + QString fontColorString() const; //! Read the *.qss files bool read(); @@ -138,7 +138,7 @@ namespace BlackGui //! Parameters as stylesheet static QString asStylesheet(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, - const QString &fontWeight, const QString &fontColor = {}); + const QString &fontWeight, const QString &fontColorString = {}); //! Widget's font as stylesheet static QString asStylesheet(const QWidget *widget, int pointSize = -1);