From d3480c41b3f3c7aff0f751fc51e0a0f17eaeff2b Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 9 Jan 2018 05:44:41 +0100 Subject: [PATCH] Ref T220, fixed font settings so correct font is displayed Remark: The qss based font info is not available at ctor call time, but only if everything is initialized --- .../components/settingsfontcomponent.cpp | 46 +++++++++++-------- .../components/settingsfontcomponent.h | 3 +- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/blackgui/components/settingsfontcomponent.cpp b/src/blackgui/components/settingsfontcomponent.cpp index 92d651ba3..6093de2fc 100644 --- a/src/blackgui/components/settingsfontcomponent.cpp +++ b/src/blackgui/components/settingsfontcomponent.cpp @@ -8,6 +8,7 @@ */ #include "blackgui/guiapplication.h" +#include "blackgui/guiutility.h" #include "blackmisc/logmessage.h" #include "settingsfontcomponent.h" #include "ui_settingsfontcomponent.h" @@ -26,17 +27,15 @@ namespace BlackGui ui(new Ui::CSettingsFontComponent) { ui->setupUi(this); - - // Font - const QFont font = this->font(); - m_cancelFont = font; - m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor()); this->setMode(CSettingsFontComponent::DirectUpdate); - this->initUiValues(); + this->initValues(); // most likely default font at ctor call time connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsFontComponent::fontColorDialog); connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont); connect(ui->pb_CancelOrReset, &QToolButton::pressed, this, &CSettingsFontComponent::resetFont); + + // only after the complete startup style sheet font overrides are available + connect(sGui, &CGuiApplication::startUpCompleted, this, &CSettingsFontComponent::initValues); } CSettingsFontComponent::~CSettingsFontComponent() @@ -66,8 +65,8 @@ namespace BlackGui const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt"); const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family(); const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText(); - QString fontColor = this->m_selectedColor.name(); - if (!this->m_selectedColor.isValid() || this->m_selectedColor.name().isEmpty()) + QString fontColor = m_selectedColor.name(); + if (!m_selectedColor.isValid() || m_selectedColor.name().isEmpty()) { fontColor = sGui->getStyleSheetUtility().fontColor(); } @@ -90,25 +89,34 @@ namespace BlackGui void CSettingsFontComponent::fontColorDialog() { - const QColor c = QColorDialog::getColor(this->m_selectedColor, this, "Font color"); - if (c == this->m_selectedColor) return; - this->m_selectedColor = c; - ui->le_SettingsGuiFontColor->setText(this->m_selectedColor.name()); + const QColor c = QColorDialog::getColor(m_selectedColor, this, "Font color"); + if (c == m_selectedColor) return; + m_selectedColor = c; + ui->le_SettingsGuiFontColor->setText(m_selectedColor.name()); } - void CSettingsFontComponent::initUiValues() + void CSettingsFontComponent::initValues() { - ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(m_cancelFont)); - ui->cb_SettingsGuiFont->setCurrentFont(m_cancelFont); - ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(m_cancelFont.pointSize())); - ui->le_SettingsGuiFontColor->setText(this->m_cancelColor.name()); - m_selectedColor = m_cancelColor; + // Font + m_cancelFont = this->font(); + m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor()); + this->initUiValues(m_cancelFont, m_cancelColor); + } + + void CSettingsFontComponent::initUiValues(const QFont &font, const QColor &color) + { + const QString family = font.family(); + 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; m_qss.clear(); } void CSettingsFontComponent::resetFont() { - this->initUiValues(); + this->initUiValues(m_cancelFont, m_cancelColor); if (m_mode == CSettingsFontComponent::DirectUpdate) { sGui->resetFont(); diff --git a/src/blackgui/components/settingsfontcomponent.h b/src/blackgui/components/settingsfontcomponent.h index d3a802843..fae308e79 100644 --- a/src/blackgui/components/settingsfontcomponent.h +++ b/src/blackgui/components/settingsfontcomponent.h @@ -67,7 +67,8 @@ namespace BlackGui void changeFont(); void resetFont(); void fontColorDialog(); - void initUiValues(); + void initValues(); + void initUiValues(const QFont &font, const QColor &color); }; } // ns } // ns