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
This commit is contained in:
Klaus Basan
2018-01-09 05:44:41 +01:00
parent 407c4f8414
commit d3480c41b3
2 changed files with 29 additions and 20 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "settingsfontcomponent.h" #include "settingsfontcomponent.h"
#include "ui_settingsfontcomponent.h" #include "ui_settingsfontcomponent.h"
@@ -26,17 +27,15 @@ namespace BlackGui
ui(new Ui::CSettingsFontComponent) ui(new Ui::CSettingsFontComponent)
{ {
ui->setupUi(this); ui->setupUi(this);
// Font
const QFont font = this->font();
m_cancelFont = font;
m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor());
this->setMode(CSettingsFontComponent::DirectUpdate); 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->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsFontComponent::fontColorDialog);
connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont); connect(ui->pb_Ok, &QPushButton::clicked, this, &CSettingsFontComponent::changeFont);
connect(ui->pb_CancelOrReset, &QToolButton::pressed, this, &CSettingsFontComponent::resetFont); 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() CSettingsFontComponent::~CSettingsFontComponent()
@@ -66,8 +65,8 @@ namespace BlackGui
const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt"); const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt");
const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family(); const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family();
const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText(); const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText();
QString fontColor = this->m_selectedColor.name(); QString fontColor = m_selectedColor.name();
if (!this->m_selectedColor.isValid() || this->m_selectedColor.name().isEmpty()) if (!m_selectedColor.isValid() || m_selectedColor.name().isEmpty())
{ {
fontColor = sGui->getStyleSheetUtility().fontColor(); fontColor = sGui->getStyleSheetUtility().fontColor();
} }
@@ -90,25 +89,34 @@ namespace BlackGui
void CSettingsFontComponent::fontColorDialog() void CSettingsFontComponent::fontColorDialog()
{ {
const QColor c = QColorDialog::getColor(this->m_selectedColor, this, "Font color"); const QColor c = QColorDialog::getColor(m_selectedColor, this, "Font color");
if (c == this->m_selectedColor) return; if (c == m_selectedColor) return;
this->m_selectedColor = c; m_selectedColor = c;
ui->le_SettingsGuiFontColor->setText(this->m_selectedColor.name()); ui->le_SettingsGuiFontColor->setText(m_selectedColor.name());
} }
void CSettingsFontComponent::initUiValues() void CSettingsFontComponent::initValues()
{ {
ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(m_cancelFont)); // Font
ui->cb_SettingsGuiFont->setCurrentFont(m_cancelFont); m_cancelFont = this->font();
ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(m_cancelFont.pointSize())); m_cancelColor = QColor(sGui->getStyleSheetUtility().fontColor());
ui->le_SettingsGuiFontColor->setText(this->m_cancelColor.name()); this->initUiValues(m_cancelFont, m_cancelColor);
m_selectedColor = 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(); m_qss.clear();
} }
void CSettingsFontComponent::resetFont() void CSettingsFontComponent::resetFont()
{ {
this->initUiValues(); this->initUiValues(m_cancelFont, m_cancelColor);
if (m_mode == CSettingsFontComponent::DirectUpdate) if (m_mode == CSettingsFontComponent::DirectUpdate)
{ {
sGui->resetFont(); sGui->resetFont();

View File

@@ -67,7 +67,8 @@ namespace BlackGui
void changeFont(); void changeFont();
void resetFont(); void resetFont();
void fontColorDialog(); void fontColorDialog();
void initUiValues(); void initValues();
void initUiValues(const QFont &font, const QColor &color);
}; };
} // ns } // ns
} // ns } // ns