refs #304, changed font settings

* QFontDialog is not working, as it is affected by the style sheets itself
* Added font settings to the GUI settings tab
* Added font color dialog for fonts
* Several utility methods
This commit is contained in:
Klaus Basan
2014-08-14 01:28:22 +02:00
parent bbb342b905
commit 98942a6395
10 changed files with 489 additions and 46 deletions

View File

@@ -261,6 +261,12 @@ namespace BlackGui
this->selectArea(static_cast<InfoArea>(index));
}
void CMainInfoAreaComponent::selectSettingsTab(int index)
{
this->selectArea(InfoAreaSettings);
this->ui->comp_Settings->setSettingsTab(static_cast<CSettingsComponent::SettingTab>(index));
}
void CMainInfoAreaComponent::ps_setDockArea(Qt::DockWidgetArea area)
{
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)

View File

@@ -115,6 +115,9 @@ namespace BlackGui
//! Select area
void selectArea(int index);
//! Select settings with given area
void selectSettingsTab(int index);
protected:
//! Override close event
virtual void closeEvent(QCloseEvent *event) override;

View File

@@ -42,8 +42,8 @@
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Aircrafts">
<property name="minimumSize">
<size>
<width>127</width>
<height>38</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="features">
@@ -103,8 +103,8 @@
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_AtcStations">
<property name="minimumSize">
<size>
<width>127</width>
<height>38</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="floating">
@@ -162,6 +162,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Users">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -202,6 +208,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_TextMessages">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -242,6 +254,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Simulator">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -282,6 +300,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_FlightPlan">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -322,6 +346,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Weather">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -365,6 +395,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Mappings">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -405,6 +441,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Log">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
@@ -445,6 +487,12 @@
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dw_Settings">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>

View File

@@ -10,10 +10,12 @@
#include "settingscomponent.h"
#include "ui_settingscomponent.h"
#include "blackgui/models/atcstationlistmodel.h"
#include "blackgui/stylesheetutility.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_network.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include "blackmisc/setaudio.h"
#include <QColorDialog>
using namespace BlackCore;
using namespace BlackMisc;
@@ -147,23 +149,35 @@ namespace BlackGui
this->ui->cb_SettingsAudioNotificationVoiceRoom->setChecked(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationVoiceRoomJoined));
}
/*
* Set tab
*/
void CSettingsComponent::setSettingsTab(CSettingsComponent::SettingTab tab)
{
this->setCurrentIndex(static_cast<int>(tab));
}
/*
* Runtime set
*/
void CSettingsComponent::runtimeHasBeenSet()
{
if (!this->getIContextSettings()) qFatal("Settings missing");
this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsComponent::changedSettings);
this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &CSettingsComponent::audioTestUpdate);
this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsComponent::ps_changedSettings);
this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &CSettingsComponent::ps_audioTestUpdate);
// based on audio context
Q_ASSERT(this->getIContextAudio());
bool connected = false;
if (this->getIContextAudio())
{
this->initAudioDeviceLists();
bool connected = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &CSettingsComponent::audioTestUpdate);
connected = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &CSettingsComponent::ps_audioTestUpdate);
Q_ASSERT(connected);
connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int)));
connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_audioDeviceSelected(int)));
Q_ASSERT(connected);
connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int)));
connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_audioDeviceSelected(int)));
Q_ASSERT(connected);
this->connect(this->ui->pb_SettingsAudioMicrophoneTest, &QPushButton::clicked, this, &CSettingsComponent::ps_startAudioTest);
this->connect(this->ui->pb_SettingsAudioSquelchTest, &QPushButton::clicked, this, &CSettingsComponent::ps_startAudioTest);
@@ -186,6 +200,20 @@ namespace BlackGui
this->connect(this->ui->pb_SettingsMiscSave, &QPushButton::clicked, this, &CSettingsComponent::ps_saveHotkeys);
this->connect(this->ui->pb_SettingsMiscRemove, &QPushButton::clicked, this, &CSettingsComponent::ps_clearHotkey);
// Font
const QFont font = this->font();
this->ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font));
this->ui->cb_SettingsGuiFont->setCurrentFont(font);
this->ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize()));
this->m_fontColor = QColor(CStyleSheetUtility::instance().fontColor());
this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name());
connected = this->connect(this->ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged()));
Q_ASSERT(connected);
connected = this->connect(this->ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged()));
Q_ASSERT(connected);
connected = this->connect(this->ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged()));
Q_ASSERT(connected);
this->connect(this->ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsComponent::ps_fontColorDialog);
}
/*
@@ -335,6 +363,43 @@ namespace BlackGui
}
}
/*
* Font has been changed
*/
void CSettingsComponent::ps_fontChanged()
{
QString fontSize = this->ui->cb_SettingsGuiFontSize->currentText().append("pt");
QString fontFamily = this->ui->cb_SettingsGuiFont->currentFont().family();
QString fontStyleCombined = this->ui->cb_SettingsGuiFontStyle->currentText();
QString fontColor = this->m_fontColor.name();
if (!this->m_fontColor.isValid() || this->m_fontColor.name().isEmpty())
{
fontColor = CStyleSheetUtility::instance().fontColor();
}
this->ui->le_SettingsGuiFontColor->setText(fontColor);
bool ok = CStyleSheetUtility::instance().updateFonts(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor);
if (ok)
{
this->sendStatusMessage(CStatusMessage::getInfoMessage("Updated font style", CStatusMessage::TypeSettings));
}
else
{
this->sendStatusMessage(CStatusMessage::getErrorMessage("Updating style failed", CStatusMessage::TypeSettings));
}
}
/*
* Font color dialog
*/
void CSettingsComponent::ps_fontColorDialog()
{
QColor c = QColorDialog::getColor(this->m_fontColor, this, "Font color");
if (c == this->m_fontColor) return;
this->m_fontColor = c;
this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name());
this->ps_fontChanged();
}
/*
* Start the voice tests
*/

View File

@@ -17,7 +17,6 @@
#include <QModelIndex>
#include <QTimer>
namespace Ui { class CSettingsComponent; }
namespace BlackGui
@@ -31,6 +30,18 @@ namespace BlackGui
Q_OBJECT
public:
//! Tabs
enum SettingTab
{
SettingTabNetwork = 0,
SettingTabAircraft,
SettingTabAircraftAudio,
SettingTabSimulator,
SettingTabGui,
SettingTabMisc
};
//! Constructor
explicit CSettingsComponent(QWidget *parent = nullptr);
@@ -81,6 +92,9 @@ namespace BlackGui
//! Reload settings
void reloadSettings();
//! Set the tab
void setSettingsTab(SettingTab tab);
protected:
//! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet
virtual void runtimeHasBeenSet() override;
@@ -123,6 +137,12 @@ namespace BlackGui
*/
void ps_audioDeviceSelected(int index);
//! Font has been changed
void ps_fontChanged();
//! Font color dialof
void ps_fontColorDialog();
private:
//! Audio test modes
enum AudioTest
@@ -135,9 +155,11 @@ namespace BlackGui
Ui::CSettingsComponent *ui;
QTimer *m_timerAudioTests; //!< audio tests: progress bar, disable/enable buttons
AudioTest m_audioTestRunning;
QColor m_fontColor;
//! Audio device lists from settings
void initAudioDeviceLists();
};
}
} // namespace

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<width>354</width>
<height>323</height>
</rect>
</property>
@@ -20,7 +20,7 @@
<string>Settings</string>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tb_SettingsTrafficNetwork">
<attribute name="title">
@@ -190,6 +190,12 @@
</property>
<item>
<widget class="QPushButton" name="pb_SettingsTnSaveServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Save</string>
</property>
@@ -197,6 +203,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsTnRemoveServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
</property>
@@ -204,6 +216,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsTnCurrentServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Current server</string>
</property>
@@ -423,6 +441,12 @@
<layout class="QHBoxLayout" name="hl_SettingsAudioTests">
<item>
<widget class="QPushButton" name="pb_SettingsAudioSquelchTest">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
@@ -433,12 +457,18 @@
<bool>false</bool>
</property>
<property name="text">
<string>Start squelch test</string>
<string>Squelch test</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_SettingsAudioMicrophoneTest">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
@@ -446,7 +476,7 @@
</size>
</property>
<property name="text">
<string>Start microphone test</string>
<string>Mic. test</string>
</property>
</widget>
</item>
@@ -563,6 +593,12 @@
</item>
<item row="0" column="1">
<widget class="QSlider" name="hs_SettingsGuiOpacity">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>100</number>
</property>
@@ -586,6 +622,12 @@
</item>
<item row="1" column="1">
<widget class="QSlider" name="hs_SettingsGuiAircraftRefreshTime">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>5</number>
</property>
@@ -618,6 +660,12 @@
</item>
<item row="2" column="1">
<widget class="QSlider" name="hs_SettingsGuiAtcRefreshTime">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>5</number>
</property>
@@ -647,6 +695,12 @@
</item>
<item row="3" column="1">
<widget class="QSlider" name="hs_SettingsGuiUserRefreshTime">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>5</number>
</property>
@@ -667,6 +721,135 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFont">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QFontComboBox" name="cb_SettingsGuiFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFontSize">
<property name="text">
<string>Font size (pt)</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="cb_SettingsGuiFontSize">
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>11</string>
</property>
</item>
<item>
<property name="text">
<string>12</string>
</property>
</item>
<item>
<property name="text">
<string>14</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFontStyle">
<property name="text">
<string>Font style</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="cb_SettingsGuiFontStyle">
<item>
<property name="text">
<string>normal</string>
</property>
</item>
<item>
<property name="text">
<string>bold</string>
</property>
</item>
<item>
<property name="text">
<string>italic</string>
</property>
</item>
<item>
<property name="text">
<string>bold italic</string>
</property>
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lbl_SettingsGuiFontColor">
<property name="text">
<string>Font color</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="hl_SettingsGuiFontColor">
<item>
<widget class="QToolButton" name="tb_SettingsGuiFontColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_SettingsGuiFontColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@@ -719,6 +902,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsMiscRemove">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
</property>
@@ -726,6 +915,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsMiscCancel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>

View File

@@ -72,6 +72,12 @@
<layout class="QHBoxLayout" name="hl_SettingsSimconnectCfgButtons">
<item>
<widget class="QPushButton" name="pb_SettingsFsxOpenSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open</string>
</property>
@@ -79,6 +85,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxDeleteSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete</string>
</property>
@@ -86,6 +98,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxSaveSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Save</string>
</property>
@@ -93,8 +111,14 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxTestConnection">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Test connection</string>
<string extracomment="Test connection">Test con.</string>
</property>
</widget>
</item>
@@ -134,6 +158,12 @@
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxExistsSimconncetCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Check</string>
</property>

View File

@@ -12,6 +12,7 @@
#include <QDir>
#include <QTextStream>
#include <QDebug>
#include <QRegExp>
namespace BlackGui
{
@@ -66,6 +67,28 @@ namespace BlackGui
}
}
QString CStyleSheetUtility::fontAsCombinedWeightStyle(const QFont &font)
{
QString w = fontWeightAsString(font);
QString s = fontStyleAsString(font);
if (w == s) return w; // avoid "normal" "normal"
if (w.isEmpty() && s.isEmpty()) return "normal";
if (w.isEmpty()) return s;
if (s.isEmpty()) return w;
if (s == "normal") return w;
return w.append(" ").append(s);
}
QString CStyleSheetUtility::fontColor()
{
QString s = this->style(fileNameFonts()).toLower();
if (!s.contains("color:")) return "red";
QRegExp rx("color:\\s*(#*\\w+);");
rx.indexIn(s);
QString c = rx.cap(1);
return c.isEmpty() ? "red" : c;
}
bool CStyleSheetUtility::read()
{
QDir directory(qssDirectory());
@@ -109,7 +132,7 @@ namespace BlackGui
QString s = this->m_styleSheets[fileName.toLower()];
if (s.isEmpty()) continue;
if (!style.isEmpty()) style.append("\n\n");
style.append("/** file: %1 **/\n").arg(fileName);
style.append("/** file: ").append(fileName).append(" **/\n");
style.append(s);
}
return style;
@@ -123,24 +146,29 @@ namespace BlackGui
bool CStyleSheetUtility::updateFonts(const QFont &font)
{
const QString indent(" ");
QString fontStyleSheet;
fontStyleSheet.append(indent).append("font-family: \"").append(font.family()).append("\";\n");
fontStyleSheet.append(indent).append("font-size: ");
QString fs;
if (font.pixelSize() >= 0)
{
fontStyleSheet.append(font.pixelSize()).append("px\n");
fs.append(font.pixelSize()).append("px");
}
else
{
fontStyleSheet.append(QString::number(font.pointSizeF())).append("pt;\n");
fs.append(QString::number(font.pointSizeF())).append("pt");
}
fontStyleSheet.append(indent).append("font-style: ").append(fontStyleAsString(font)).append(";\n");
fontStyleSheet.append(indent).append("font-weight: ").append(fontWeightAsString(font)).append(";\n");
qDebug() << fontStyleSheet;
return updateFonts(font.family(), fs, fontStyleAsString(font), fontWeightAsString(font), "white");
}
bool CStyleSheetUtility::updateFonts(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor)
{
const QString indent(" ");
QString fontStyleSheet;
fontStyleSheet.append(indent).append("font-family: \"").append(fontFamily).append("\";\n");
fontStyleSheet.append(indent).append("font-size: ").append(fontSize).append(";\n");
fontStyleSheet.append(indent).append("font-style: ").append(fontStyle).append(";\n");
fontStyleSheet.append(indent).append("font-weight: ").append(fontWeight).append(";\n");
fontStyleSheet.append(indent).append("color: ").append(fontColor).append(";\n");
QString qss("QWidget {\n");
qss.append(indent).append("color: white;\n");
qss.append(fontStyleSheet);
qss.append("}\n");
@@ -156,6 +184,34 @@ namespace BlackGui
return ok;
}
QString CStyleSheetUtility::fontStyle(const QString &combinedStyleAndWeight)
{
static const QString n("normal");
QString c = combinedStyleAndWeight.toLower();
foreach(QString s, fontStyles())
{
if (c.contains(s))
{
return s;
}
}
return n;
}
QString CStyleSheetUtility::fontWeight(const QString &combinedStyleAndWeight)
{
static const QString n("normal");
QString c = combinedStyleAndWeight.toLower();
foreach(QString w, fontWeights())
{
if (c.contains(w))
{
return w;
}
}
return n;
}
QString CStyleSheetUtility::qssDirectory()
{
QString dirPath = QCoreApplication::applicationDirPath();

View File

@@ -15,6 +15,7 @@
#include <QMap>
#include <QObject>
#include <QFont>
#include <QStringList>
namespace BlackGui
{
@@ -40,6 +41,18 @@ namespace BlackGui
//! Update the fonts
bool updateFonts(const QFont &font);
//! Update the fonts
bool updateFonts(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
//! Current font color from style sheet
QString fontColor();
//! Get the font style
static QString fontStyle(const QString &combinedStyleAndWeight);
//! Get the font weight
static QString fontWeight(const QString &combinedStyleAndWeight);
//! Central reader
static CStyleSheetUtility &instance()
{
@@ -82,9 +95,32 @@ namespace BlackGui
return f;
}
//! Font weights
static const QStringList &fontWeights()
{
static const QStringList w( {"bold", "semibold", "light", "black", "normal"});
return w;
}
//! Font styles
static const QStringList &fontStyles()
{
static const QStringList s( {"italic", "oblique", "normal"});
return s;
}
//! qss directory
static QString qssDirectory();
//! Font style as string
static const QString &fontStyleAsString(const QFont &font);
//! Font weight as string
static const QString &fontWeightAsString(const QFont &font);
//! Font as combined weight and style
static QString fontAsCombinedWeightStyle(const QFont &font);
signals:
//! Sheets have been changed
void styleSheetsChanged();
@@ -94,12 +130,6 @@ namespace BlackGui
//! Constructor
explicit CStyleSheetUtility(QObject *parent = nullptr);
//! Font style as string
static const QString &fontStyleAsString(const QFont &font);
//! Font weight as string
static const QString &fontWeightAsString(const QFont &font);
};
}

View File

@@ -49,20 +49,8 @@ void MainWindow::ps_onMenuClicked()
}
else if (sender == this->ui->menu_FileFont)
{
// KB: There seems to be a bug with the font Dialog (Win 7/32), it only works once
// Then the font cannot be changed anymore
bool ok = false;
QFont font = QFontDialog::getFont(&ok, this->font(), this, "Application fonts", QFontDialog::ProportionalFonts);
if (ok)
{
// the user clicked OK and font is set to the font the user selected
this->setFont(font);
CStyleSheetUtility::instance().updateFonts(font);
}
else
{
// the user canceled the dialog; font is set to the initial
}
this->ps_setMainPage(MainPageFoo);
this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui);
}
else if (sender == this->ui->menu_FileClose)
{