mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
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
This commit is contained in:
committed by
Mat Sutcliffe
parent
e463689490
commit
40484a9778
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>280</width>
|
||||
<width>320</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -97,6 +97,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_Reset">
|
||||
<property name="text">
|
||||
<string>reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_CancelOrReset">
|
||||
<property name="text">
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user