Commit 836e1b8a authored by Wouter's avatar Wouter

More customization options

- Title font can be chosen separately
- Dice radius can be defined
- Button radius can also be set
parent a2523371
Pipeline #317 passed with stages
in 5 minutes and 37 seconds
......@@ -91,6 +91,7 @@ ApplicationWindow
Layout.preferredWidth: mainGrid.width * .4
Layout.maximumWidth: 200
Layout.maximumHeight: 200
radius: width * theme.diceRadius
color: theme.diceBackground
dotColor: rolling ? theme.rollingDiceDots : theme.diceDots
border.color: rolling ? theme.rollingDiceBorder : theme.diceBorder
......@@ -108,6 +109,7 @@ ApplicationWindow
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
Layout.maximumWidth: 200
Layout.maximumHeight: 200
radius: width * theme.diceRadius
color: theme.diceBackground
dotColor: rolling ? theme.rollingDiceDots : theme.diceDots
border.color: rolling ? theme.rollingDiceBorder : theme.diceBorder
......@@ -130,7 +132,7 @@ ApplicationWindow
property int value1: dice1.rolling ? 0 : dice1.value
property int value2: dice2.rolling ? 0 : dice2.value
font.family: root.fontFamily
font.family: theme.titleFont
font.pointSize: root.titleFontSize
font.bold: true
color: theme.titleColor
......@@ -161,7 +163,7 @@ ApplicationWindow
Layout.alignment: Qt.AlignRight | Qt.AlignTop
width: parent.width * .25
height: width
dotSize: width/10
radius: width * theme.diceRadius
color: theme.diceBackground
dotColor: rolling ? theme.rollingDiceDots : theme.diceDots
border.color: rolling ? theme.rollingDiceBorder : theme.diceBorder
......@@ -214,6 +216,7 @@ ApplicationWindow
PropertyChanges {
target: newChallengeButton.background
color: theme.buttonBackground
radius: theme.buttonRadius
}
PropertyChanges {
target: newChallengeButton.contentItem
......@@ -225,6 +228,7 @@ ApplicationWindow
PropertyChanges {
target: newChallengeButton.background
color: theme.pressedButtonBackground
radius: theme.buttonRadius
}
PropertyChanges {
target: newChallengeButton.contentItem
......
......@@ -40,11 +40,14 @@ Theme::Theme(QObject* parent)
, m_rollingDiceDots(Qt::red)
, m_titleColor(QGuiApplication::palette().color(QPalette::Text))
, m_textColor(QGuiApplication::palette().color(QPalette::Text))
, m_titleFont(QGuiApplication::font())
, m_font(QGuiApplication::font())
, m_titlePointSize(m_font.pointSizeF() * 2)
, m_challengePointSize(m_font.pointSizeF())
, m_creditPointSize(m_font.pointSizeF() * 0.9)
, m_buttonPointSize(m_font.pointSizeF())
, m_diceRadius(0)
, m_buttonRadius(0)
{
}
......@@ -78,18 +81,26 @@ Theme::Theme(QString fileName, QObject* parent)
themeSettings.endGroup();
themeSettings.beginGroup("Fonts");
QString titleFamily = themeSettings.value("title font", m_titleFont.family()).toString();
QString family = themeSettings.value("font", m_font.family()).toString();
loadFontSize(themeSettings, "title size", &m_titlePointSize);
loadFontSize(themeSettings, "challenge size", &m_challengePointSize);
loadFontSize(themeSettings, "credit size", &m_creditPointSize);
loadFontSize(themeSettings, "button size", &m_buttonPointSize);
loadQRealSetting(themeSettings, "title size", &m_titlePointSize);
loadQRealSetting(themeSettings, "challenge size", &m_challengePointSize);
loadQRealSetting(themeSettings, "credit size", &m_creditPointSize);
loadQRealSetting(themeSettings, "button size", &m_buttonPointSize);
// Resolve font through QFontDatabase
QFontDatabase db;
auto titleFont = db.font(titleFamily, QString(), static_cast<int>(m_titlePointSize));
m_titleFont = titleFont.family();
auto font = db.font(family, QString(), static_cast<int>(m_challengePointSize));
m_font = font.family();
themeSettings.endGroup();
themeSettings.beginGroup("Other");
loadQRealSetting(themeSettings, "dice radius", &m_diceRadius);
loadQRealSetting(themeSettings, "button radius", &m_buttonRadius);
themeSettings.endGroup();
}
QColor Challenger::Theme::loadColor(const QSettings& s, const QString& name, const QColor& defaultValue)
......@@ -110,7 +121,7 @@ QColor Challenger::Theme::loadColor(const QSettings& s, const QString& name, con
return defaultValue;
}
void Challenger::Theme::loadFontSize(const QSettings& s, const QString& name, qreal* field)
void Challenger::Theme::loadQRealSetting(const QSettings& s, const QString& name, qreal* field)
{
bool ok;
qreal tmp = s.value(name, *field).toReal(&ok);
......@@ -189,6 +200,11 @@ QColor Challenger::Theme::textColor() const
return m_textColor;
}
QFont Challenger::Theme::titleFont() const
{
return m_titleFont;
}
QFont Challenger::Theme::font() const
{
return m_font;
......@@ -214,3 +230,12 @@ qreal Challenger::Theme::buttonPointSize() const
return m_buttonPointSize;
}
qreal Challenger::Theme::diceRadius() const
{
return m_diceRadius;
}
qreal Challenger::Theme::buttonRadius() const
{
return m_buttonRadius;
}
......@@ -49,12 +49,16 @@ class Theme : public QObject
Q_PROPERTY(QColor titleColor READ titleColor CONSTANT)
Q_PROPERTY(QColor textColor READ textColor CONSTANT)
Q_PROPERTY(QFont titleFont READ titleFont CONSTANT)
Q_PROPERTY(QFont font READ font CONSTANT)
Q_PROPERTY(qreal titlePointSize READ titlePointSize CONSTANT)
Q_PROPERTY(qreal challengePointSize READ challengePointSize CONSTANT)
Q_PROPERTY(qreal creditPointSize READ creditPointSize CONSTANT)
Q_PROPERTY(qreal buttonPointSize READ buttonPointSize CONSTANT)
Q_PROPERTY(qreal diceRadius READ diceRadius CONSTANT)
Q_PROPERTY(qreal buttonRadius READ buttonRadius CONSTANT)
public:
/**
* Constructor for the default theme.
......@@ -82,15 +86,19 @@ public:
QColor titleColor() const;
QColor textColor() const;
QFont titleFont() const;
QFont font() const;
qreal titlePointSize() const;
qreal challengePointSize() const;
qreal creditPointSize() const;
qreal buttonPointSize() const;
qreal diceRadius() const;
qreal buttonRadius() const;
private:
QColor loadColor(const QSettings& s, const QString& name, const QColor& defaultValue);
void loadFontSize(const QSettings& s, const QString& name, qreal* field);
void loadQRealSetting(const QSettings& s, const QString& name, qreal* field);
QVector<QColor> m_background;
QColor m_buttonBackground;
......@@ -105,11 +113,15 @@ private:
QColor m_titleColor;
QColor m_textColor;
QFont m_titleFont;
QFont m_font;
qreal m_titlePointSize;
qreal m_challengePointSize;
qreal m_creditPointSize;
qreal m_buttonPointSize;
qreal m_diceRadius;
qreal m_buttonRadius;
};
}
......
......@@ -20,8 +20,17 @@
; text = "black"
[Fonts]
; title font = "Sans Serif"
; font = "Sans Serif"
; title size = 24
; challenge size = 16
; credit size = 12
; button size = 16
[Other]
;; Round the button corners as fraction of the dice width. Should be a value of 0.00 (no rounding)
;; to 0.50 (circle))
dice radius = 0.50
;; Round the button corners (in pixels)
; button radius = 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment