Skip to content

Commit d6a2153

Browse files
committed
Theme: font size handling added
1 parent 2d904eb commit d6a2153

File tree

5 files changed

+283
-67
lines changed

5 files changed

+283
-67
lines changed

storybook/pages/ThemePage.qml

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,80 @@ Item {
2525
id: page
2626

2727
footer: ColumnLayout {
28-
Slider {
29-
from: 0
30-
to: 50
31-
stepSize: 1
28+
RowLayout {
29+
Button {
30+
text: "reset padding"
3231

33-
value: panel.Theme.padding
32+
onClicked: {
33+
panel.Theme.padding = undefined
34+
}
3435

35-
onValueChanged: {
36-
if (value !== panel.Theme.padding)
37-
panel.Theme.padding = value
36+
enabled: panel.Theme.explicitPadding
37+
}
38+
39+
Slider {
40+
Layout.preferredWidth: 150
41+
42+
from: 0
43+
to: 50
44+
stepSize: 1
45+
46+
value: panel.Theme.padding
47+
48+
onValueChanged: {
49+
if (value !== panel.Theme.padding)
50+
panel.Theme.padding = value
51+
}
52+
}
53+
54+
Label {
55+
Layout.fillWidth: true
56+
wrapMode: Text.Wrap
57+
58+
font.pixelSize: Theme.fontSize(13)
59+
text: `padding: ${panel.Theme.padding}`
3860
}
3961
}
4062

4163
RowLayout {
4264
Button {
43-
text: "reset padding"
65+
text: "reset font size"
4466

4567
onClicked: {
46-
panel.Theme.padding = undefined
47-
//panel.Theme.resetPadding()
68+
panel.Theme.fontSizeOffset = undefined
4869
}
4970

50-
enabled: panel.Theme.explicitPadding
71+
enabled: panel.Theme.explicitFontSizeOffset
72+
}
73+
74+
Slider {
75+
Layout.preferredWidth: 150
76+
77+
from: -5
78+
to: 10
79+
stepSize: 1
80+
81+
value: panel.Theme.fontSizeOffset
82+
83+
onValueChanged: {
84+
if (value !== panel.Theme.fontSizeOffset)
85+
panel.Theme.fontSizeOffset = value
86+
}
5187
}
5288

5389
Label {
54-
text: `padding: ${panel.Theme.padding}`
90+
Layout.fillWidth: true
91+
wrapMode: Text.Wrap
92+
93+
font.pixelSize: Theme.fontSize(13)
94+
text: `font size offset: ${panel.Theme.fontSizeOffset}`
5595
}
96+
}
5697

98+
RowLayout {
99+
Label {
100+
text: `theme:`
101+
}
57102
Button {
58103
text: "Dark"
59104
onClicked: panel.Theme.style = Theme.Dark

ui/StatusQ/include/StatusQ/theme.h

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,53 @@
22

33
#include "StatusQ/themepalette.h"
44

5-
#include <QObject>
5+
#include <QJSValue>
66
#include <QQmlEngine>
77
#include <QQuickAttachedPropertyPropagator>
88

99
class Theme : public QQuickAttachedPropertyPropagator
1010
{
1111
Q_OBJECT
1212

13-
Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged)
13+
Q_PROPERTY(qreal padding READ padding WRITE setPadding
14+
RESET resetPadding NOTIFY paddingChanged)
1415
Q_PROPERTY(qreal xlPadding READ xlPadding NOTIFY paddingChanged)
1516
Q_PROPERTY(qreal bigPadding READ bigPadding NOTIFY paddingChanged)
1617
Q_PROPERTY(qreal halfPadding READ halfPadding NOTIFY paddingChanged)
1718
Q_PROPERTY(qreal smallPadding READ smallPadding NOTIFY paddingChanged)
1819

19-
Q_PROPERTY(bool explicitPadding READ explicitPadding NOTIFY explicitPaddingChanged)
20+
Q_PROPERTY(bool explicitPadding READ explicitPadding
21+
NOTIFY explicitPaddingChanged)
2022

21-
Q_PROPERTY(Style style READ style WRITE setStyle RESET resetStyle NOTIFY styleChanged)
22-
Q_PROPERTY(const ThemePalette* palette READ palette NOTIFY styleChanged)
23+
Q_PROPERTY(Style style READ style WRITE setStyle RESET resetStyle
24+
NOTIFY styleChanged)
25+
Q_PROPERTY(const ThemePalette* palette READ palette
26+
NOTIFY styleChanged)
2327

24-
Q_PROPERTY(bool explicitStyle READ explicitStyle NOTIFY explicitStyleChanged)
28+
Q_PROPERTY(bool explicitStyle READ explicitStyle
29+
NOTIFY explicitStyleChanged)
30+
31+
Q_PROPERTY(int fontSizeOffset READ fontSizeOffset WRITE setFontSizeOffset
32+
RESET resetFontSizeOffset NOTIFY fontSizeOffsetChanged)
33+
34+
Q_PROPERTY(int secondaryAdditionalTextSize
35+
READ secondaryAdditionalTextSize
36+
NOTIFY fontSizeOffsetChanged)
37+
Q_PROPERTY(int primaryTextFontSize READ primaryTextFontSize
38+
NOTIFY fontSizeOffsetChanged)
39+
Q_PROPERTY(int secondaryTextFontSize READ secondaryTextFontSize
40+
NOTIFY fontSizeOffsetChanged)
41+
Q_PROPERTY(int additionalTextSize READ additionalTextSize
42+
NOTIFY fontSizeOffsetChanged)
43+
Q_PROPERTY(int tertiaryTextFontSize READ tertiaryTextFontSize
44+
NOTIFY fontSizeOffsetChanged)
45+
Q_PROPERTY(int asideTextFontSize READ asideTextFontSize
46+
NOTIFY fontSizeOffsetChanged)
47+
48+
Q_PROPERTY(bool explicitFontSizeOffset READ explicitFontSizeOffset
49+
NOTIFY explicitFontSizeOffsetChanged)
50+
51+
Q_PROPERTY(QJSValue fontSize READ fontSize NOTIFY fontSizeOffsetChanged)
2552

2653
enum class Style {
2754
Light,
@@ -33,6 +60,7 @@ class Theme : public QQuickAttachedPropertyPropagator
3360
public:
3461
explicit Theme(QObject *parent = nullptr);
3562

63+
// paddings
3664
qreal padding() const;
3765
qreal xlPadding() const;
3866
qreal bigPadding() const;
@@ -41,35 +69,57 @@ class Theme : public QQuickAttachedPropertyPropagator
4169

4270
void setPadding(qreal padding);
4371
void resetPadding();
44-
45-
void inheritPadding(qreal padding);
46-
void propagatePadding();
47-
4872
bool explicitPadding() const;
4973

74+
// light/dark style
5075
Style style() const;
76+
const ThemePalette* palette() const;
77+
5178
void setStyle(Style style);
5279
void resetStyle();
80+
bool explicitStyle() const;
5381

54-
void inheritStyle(Style style);
55-
void propagateStyle();
82+
// font size
83+
int fontSizeOffset() const;
84+
int secondaryAdditionalTextSize() const;
85+
int primaryTextFontSize() const;
86+
int secondaryTextFontSize() const;
87+
int additionalTextSize() const;
88+
int tertiaryTextFontSize() const;
89+
int asideTextFontSize() const;
5690

57-
bool explicitStyle() const;
91+
QJSValue fontSize() const;
5892

59-
const ThemePalette* palette() const;
93+
void setFontSizeOffset(int fontSizeOffset);
94+
void resetFontSizeOffset();
95+
bool explicitFontSizeOffset() const;
6096

97+
// top level object access
6198
Q_INVOKABLE Theme* rootTheme();
6299

100+
// attached object instantiation
63101
static Theme *qmlAttachedProperties(QObject *object);
64102

65103
signals:
66104
void paddingChanged();
67105
void explicitPaddingChanged();
68106

69-
void explicitStyleChanged();
70107
void styleChanged();
108+
void explicitStyleChanged();
109+
110+
void fontSizeOffsetChanged();
111+
void explicitFontSizeOffsetChanged();
71112

72113
protected:
114+
void inheritPadding(qreal padding);
115+
void propagatePadding();
116+
117+
void inheritStyle(Style style);
118+
void propagateStyle();
119+
120+
void inheritFontSizeOffset(int fontSizeOffset);
121+
void propagateFontSizeOffset();
122+
73123
void attachedParentChange(
74124
QQuickAttachedPropertyPropagator *newParent,
75125
QQuickAttachedPropertyPropagator *oldParent) override;
@@ -80,6 +130,10 @@ class Theme : public QQuickAttachedPropertyPropagator
80130

81131
bool m_explicitStyle = false;
82132
Style m_style = Style::Light;
133+
134+
bool m_explicitFontSizeOffset = false;
135+
int m_fontSizeOffset = 0;
136+
mutable QJSValue m_fontSizeFn;
83137
};
84138

85139
QML_DECLARE_TYPEINFO(Theme, QML_HAS_ATTACHED_PROPERTIES)

ui/StatusQ/include/StatusQ/themepalette.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ class CustomisationColors {
158158
Q_PROPERTY(QColor yinYang MEMBER yinYang CONSTANT)
159159
Q_PROPERTY(QColor purple2 MEMBER purple2 CONSTANT)
160160
public:
161-
QColor blue, purple, orange, army, turquoise, sky, yellow, pink, copper, camel, magenta, yinYang, purple2;
161+
QColor blue, purple, orange, army, turquoise, sky, yellow, pink, copper,
162+
camel, magenta, yinYang, purple2;
162163
};
163164

164165
class PrivacyModeColors {

0 commit comments

Comments
 (0)