mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 11:45:40 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -18,166 +18,163 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
namespace BlackGui::Components
|
||||
{
|
||||
namespace Components
|
||||
CSettingsFontComponent::CSettingsFontComponent(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CSettingsFontComponent)
|
||||
{
|
||||
CSettingsFontComponent::CSettingsFontComponent(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CSettingsFontComponent)
|
||||
ui->setupUi(this);
|
||||
this->setMode(CSettingsFontComponent::DirectUpdate);
|
||||
|
||||
// due to the problems with overriding a color (e.g T571) we use "no color" as default
|
||||
this->initValues();
|
||||
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, 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);
|
||||
}
|
||||
|
||||
CSettingsFontComponent::~CSettingsFontComponent()
|
||||
{ }
|
||||
|
||||
void CSettingsFontComponent::setMode(CSettingsFontComponent::Mode m)
|
||||
{
|
||||
m_mode = m;
|
||||
if (m == CSettingsFontComponent::DirectUpdate)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setMode(CSettingsFontComponent::DirectUpdate);
|
||||
|
||||
// due to the problems with overriding a color (e.g T571) we use "no color" as default
|
||||
this->initValues();
|
||||
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, 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);
|
||||
ui->pb_CancelOrReset->setText("reset");
|
||||
ui->pb_Reset->setVisible(false);
|
||||
}
|
||||
|
||||
CSettingsFontComponent::~CSettingsFontComponent()
|
||||
{ }
|
||||
|
||||
void CSettingsFontComponent::setMode(CSettingsFontComponent::Mode m)
|
||||
else
|
||||
{
|
||||
m_mode = m;
|
||||
if (m == CSettingsFontComponent::DirectUpdate)
|
||||
ui->pb_CancelOrReset->setText("cancel");
|
||||
ui->pb_Reset->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setFont(const QFont &font)
|
||||
{
|
||||
m_cancelFont = font;
|
||||
this->resetFont();
|
||||
}
|
||||
|
||||
QFont CSettingsFontComponent::getFont() const
|
||||
{
|
||||
return ui->cb_SettingsGuiFont->font();
|
||||
}
|
||||
|
||||
QStringList CSettingsFontComponent::getFamilySizeStyle() const
|
||||
{
|
||||
const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt");
|
||||
const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family();
|
||||
const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText();
|
||||
return QStringList({ fontFamily, fontSize, fontStyleCombined });
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setWithColorSelection(bool withColor)
|
||||
{
|
||||
ui->le_SettingsGuiFontColor->setVisible(withColor);
|
||||
ui->tb_SettingsGuiFontColor->setVisible(withColor);
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setStyleSheetDefaultColor()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
m_noColorDefault = false;
|
||||
this->initValues();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::changeFont()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
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 = m_selectedColor.name();
|
||||
if (!m_selectedColor.isValid() || m_selectedColor.name().isEmpty())
|
||||
{
|
||||
fontColor.clear();
|
||||
}
|
||||
ui->le_SettingsGuiFontColor->setText(fontColor);
|
||||
m_qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor);
|
||||
if (m_mode == CSettingsFontComponent::DirectUpdate)
|
||||
{
|
||||
const bool ok = sGui->updateFont(m_qss);
|
||||
if (ok)
|
||||
{
|
||||
ui->pb_CancelOrReset->setText("reset");
|
||||
ui->pb_Reset->setVisible(false);
|
||||
CLogMessage(this).info(u"Updated font style");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->pb_CancelOrReset->setText("cancel");
|
||||
ui->pb_Reset->setVisible(true);
|
||||
CLogMessage(this).warning(u"Updating style failed");
|
||||
}
|
||||
}
|
||||
emit this->accept();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setFont(const QFont &font)
|
||||
void CSettingsFontComponent::fontColorDialog()
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::noColor()
|
||||
{
|
||||
m_selectedColor = QColor(); // invalid color
|
||||
m_noColorDefault = true;
|
||||
ui->le_SettingsGuiFontColor->clear();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::initValues()
|
||||
{
|
||||
// Font
|
||||
if (!sGui) { return; }
|
||||
m_cancelFont = this->font();
|
||||
const QString colorString(sGui->getStyleSheetUtility().fontColorString());
|
||||
m_cancelColor = colorString.isEmpty() ? QColor() : QColor(colorString);
|
||||
this->initUiValues(m_cancelFont, m_noColorDefault ? QColor() : m_cancelColor);
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::initUiValues(const QFont &font, const QColor &color)
|
||||
{
|
||||
ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font));
|
||||
ui->cb_SettingsGuiFont->setCurrentFont(font);
|
||||
ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize()));
|
||||
|
||||
const bool valid = color.isValid();
|
||||
m_selectedColor = color; // color
|
||||
ui->le_SettingsGuiFontColor->setText(valid ? m_selectedColor.name() : "");
|
||||
m_qss.clear();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::resetFont()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
this->initUiValues(m_cancelFont, m_noColorDefault ? QColor() : m_cancelColor);
|
||||
if (m_mode == CSettingsFontComponent::DirectUpdate)
|
||||
{
|
||||
m_cancelFont = font;
|
||||
this->resetFont();
|
||||
sGui->resetFont();
|
||||
}
|
||||
}
|
||||
|
||||
QFont CSettingsFontComponent::getFont() const
|
||||
{
|
||||
return ui->cb_SettingsGuiFont->font();
|
||||
}
|
||||
void CSettingsFontComponent::resetFontAndReject()
|
||||
{
|
||||
this->resetFont();
|
||||
emit this->reject();
|
||||
}
|
||||
|
||||
QStringList CSettingsFontComponent::getFamilySizeStyle() const
|
||||
{
|
||||
const QString fontSize = ui->cb_SettingsGuiFontSize->currentText().append("pt");
|
||||
const QString fontFamily = ui->cb_SettingsGuiFont->currentFont().family();
|
||||
const QString fontStyleCombined = ui->cb_SettingsGuiFontStyle->currentText();
|
||||
return QStringList({ fontFamily, fontSize, fontStyleCombined });
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setWithColorSelection(bool withColor)
|
||||
{
|
||||
ui->le_SettingsGuiFontColor->setVisible(withColor);
|
||||
ui->tb_SettingsGuiFontColor->setVisible(withColor);
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::setStyleSheetDefaultColor()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
m_noColorDefault = false;
|
||||
this->initValues();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::changeFont()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
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 = m_selectedColor.name();
|
||||
if (!m_selectedColor.isValid() || m_selectedColor.name().isEmpty())
|
||||
{
|
||||
fontColor.clear();
|
||||
}
|
||||
ui->le_SettingsGuiFontColor->setText(fontColor);
|
||||
m_qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor);
|
||||
if (m_mode == CSettingsFontComponent::DirectUpdate)
|
||||
{
|
||||
const bool ok = sGui->updateFont(m_qss);
|
||||
if (ok)
|
||||
{
|
||||
CLogMessage(this).info(u"Updated font style");
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).warning(u"Updating style failed");
|
||||
}
|
||||
}
|
||||
emit this->accept();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::fontColorDialog()
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::noColor()
|
||||
{
|
||||
m_selectedColor = QColor(); // invalid color
|
||||
m_noColorDefault = true;
|
||||
ui->le_SettingsGuiFontColor->clear();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::initValues()
|
||||
{
|
||||
// Font
|
||||
if (!sGui) { return; }
|
||||
m_cancelFont = this->font();
|
||||
const QString colorString(sGui->getStyleSheetUtility().fontColorString());
|
||||
m_cancelColor = colorString.isEmpty() ? QColor() : QColor(colorString);
|
||||
this->initUiValues(m_cancelFont, m_noColorDefault ? QColor() : m_cancelColor);
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::initUiValues(const QFont &font, const QColor &color)
|
||||
{
|
||||
ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font));
|
||||
ui->cb_SettingsGuiFont->setCurrentFont(font);
|
||||
ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize()));
|
||||
|
||||
const bool valid = color.isValid();
|
||||
m_selectedColor = color; // color
|
||||
ui->le_SettingsGuiFontColor->setText(valid ? m_selectedColor.name() : "");
|
||||
m_qss.clear();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::resetFont()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
this->initUiValues(m_cancelFont, m_noColorDefault ? QColor() : m_cancelColor);
|
||||
if (m_mode == CSettingsFontComponent::DirectUpdate)
|
||||
{
|
||||
sGui->resetFont();
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::resetFontAndReject()
|
||||
{
|
||||
this->resetFont();
|
||||
emit this->reject();
|
||||
}
|
||||
|
||||
void CSettingsFontComponent::clearQssAndResetFont()
|
||||
{
|
||||
m_qss.clear();
|
||||
this->resetFont();
|
||||
emit this->accept();
|
||||
}
|
||||
} // ns
|
||||
void CSettingsFontComponent::clearQssAndResetFont()
|
||||
{
|
||||
m_qss.clear();
|
||||
this->resetFont();
|
||||
emit this->accept();
|
||||
}
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user