KWin
Loading...
Searching...
No Matches
themeconfig.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6#include "themeconfig.h"
7
8#include <KConfig>
9#include <KConfigGroup>
10
11#include <QGuiApplication>
12#include <QScreen>
13
14namespace Aurorae
15{
16
18 : m_activeTextColor(defaultActiveTextColor())
19 , m_activeFocusedTextColor(defaultActiveFocusedTextColor())
20 , m_activeUnfocusedTextColor(defaultActiveUnfocusedTextColor())
21 , m_inactiveTextColor(defaultInactiveTextColor())
22 , m_inactiveFocusedTextColor(defaultInactiveFocusedTextColor())
23 , m_inactiveUnfocusedTextColor(defaultInactiveUnfocusedTextColor())
24 , m_activeTextShadowColor(defaultActiveTextShadowColor())
25 , m_inactiveTextShadowColor(defaultInactiveTextShadowColor())
26 , m_textShadowOffsetX(defaultTextShadowOffsetX())
27 , m_textShadowOffsetY(defaultTextShadowOffsetY())
28 , m_useTextShadow(defaultUseTextShadow())
29 , m_haloActive(defaultHaloActive())
30 , m_haloInactive(defaultHaloInactive())
31 , m_alignment(defaultAlignment())
32 , m_verticalAlignment(defaultVerticalAlignment())
33 // borders
34 , m_borderLeft(defaultBorderLeft())
35 , m_borderRight(defaultBorderRight())
36 , m_borderBottom(defaultBorderBottom())
37 , m_borderTop(defaultBorderTop())
38 // title
39 , m_titleEdgeTop(defaultTitleEdgeTop())
40 , m_titleEdgeBottom(defaultTitleEdgeBottom())
41 , m_titleEdgeLeft(defaultTitleEdgeLeft())
42 , m_titleEdgeRight(defaultTitleEdgeRight())
43 , m_titleEdgeTopMaximized(defaultTitleEdgeTopMaximized())
44 , m_titleEdgeBottomMaximized(defaultTitleEdgeBottomMaximized())
45 , m_titleEdgeLeftMaximized(defaultTitleEdgeLeftMaximized())
46 , m_titleEdgeRightMaximized(defaultTitleEdgeRightMaximized())
47 , m_titleBorderLeft(defaultTitleBorderLeft())
48 , m_titleBorderRight(defaultTitleBorderRight())
49 , m_titleHeight(defaultTitleHeight())
50 // buttons
51 , m_buttonWidth(defaultButtonWidth())
52 , m_buttonWidthMinimize(defaultButtonWidthMinimize())
53 , m_buttonWidthMaximizeRestore(defaultButtonWidthMaximizeRestore())
54 , m_buttonWidthClose(defaultButtonWidthClose())
55 , m_buttonWidthAllDesktops(defaultButtonWidthAllDesktops())
56 , m_buttonWidthKeepAbove(defaultButtonWidthKeepAbove())
57 , m_buttonWidthKeepBelow(defaultButtonWidthKeepBelow())
58 , m_buttonWidthShade(defaultButtonWidthShade())
59 , m_buttonWidthHelp(defaultButtonWidthHelp())
60 , m_buttonWidthMenu(defaultButtonWidthMenu())
61 , m_buttonWidthAppMenu(defaultButtonWidthAppMenu())
62 , m_buttonHeight(defaultButtonHeight())
63 , m_buttonSpacing(defaultButtonSpacing())
64 , m_buttonMarginTop(defaultButtonMarginTop())
65 , m_explicitButtonSpacer(defaultExplicitButtonSpacer())
66 // padding
67 , m_paddingLeft(defaultPaddingLeft())
68 , m_paddingRight(defaultPaddingRight())
69 , m_paddingTop(defaultPaddingTop())
70 , m_paddingBottom(defaultPaddingBottom())
71 , m_animationTime(defaultAnimationTime())
72 , m_shadow(defaultShadow())
73 , m_decorationPosition(defaultDecorationPosition())
74{
75}
76
77void ThemeConfig::load(const KConfig &conf)
78{
79 KConfigGroup general(&conf, QStringLiteral("General"));
80 m_activeTextColor = general.readEntry("ActiveTextColor", defaultActiveTextColor());
81 m_inactiveTextColor = general.readEntry("InactiveTextColor", defaultInactiveTextColor());
82 m_activeFocusedTextColor = general.readEntry("ActiveFocusedTabColor", m_activeTextColor);
83 m_activeUnfocusedTextColor = general.readEntry("ActiveUnfocusedTabColor", m_inactiveTextColor);
84 m_inactiveFocusedTextColor = general.readEntry("InactiveFocusedTabColor", m_inactiveTextColor);
85 m_inactiveUnfocusedTextColor = general.readEntry("InactiveUnfocusedTabColor", m_inactiveTextColor);
86 m_useTextShadow = general.readEntry("UseTextShadow", defaultUseTextShadow());
87 m_activeTextShadowColor = general.readEntry("ActiveTextShadowColor", defaultActiveTextColor());
88 m_inactiveTextShadowColor = general.readEntry("InactiveTextShadowColor", defaultInactiveTextColor());
89 m_textShadowOffsetX = general.readEntry("TextShadowOffsetX", defaultTextShadowOffsetX());
90 m_textShadowOffsetY = general.readEntry("TextShadowOffsetY", defaultTextShadowOffsetY());
91 m_haloActive = general.readEntry("HaloActive", defaultHaloActive());
92 m_haloInactive = general.readEntry("HaloInactive", defaultHaloInactive());
93 QString alignment = (general.readEntry("TitleAlignment", "Left")).toLower();
94 if (alignment == QStringLiteral("left")) {
95 m_alignment = Qt::AlignLeft;
96 } else if (alignment == QStringLiteral("center")) {
97 m_alignment = Qt::AlignHCenter;
98 } else {
99 m_alignment = Qt::AlignRight;
100 }
101 alignment = (general.readEntry("TitleVerticalAlignment", "Center")).toLower();
102 if (alignment == QStringLiteral("top")) {
103 m_verticalAlignment = Qt::AlignTop;
104 } else if (alignment == QStringLiteral("center")) {
105 m_verticalAlignment = Qt::AlignVCenter;
106 } else {
107 m_verticalAlignment = Qt::AlignBottom;
108 }
109 m_animationTime = general.readEntry("Animation", defaultAnimationTime());
110 m_shadow = general.readEntry("Shadow", defaultShadow());
111 m_decorationPosition = general.readEntry("DecorationPosition", defaultDecorationPosition());
112
113 qreal scaleFactor = 1;
114 QScreen *primary = QGuiApplication::primaryScreen();
115 if (primary) {
116 const qreal dpi = primary->logicalDotsPerInchX();
117 scaleFactor = dpi / 96.0f;
118 }
119
120 KConfigGroup border(&conf, QStringLiteral("Layout"));
121 // default values taken from KCommonDecoration::layoutMetric() in kcommondecoration.cpp
122 m_borderLeft = qRound(scaleFactor * border.readEntry("BorderLeft", defaultBorderLeft()));
123 m_borderRight = qRound(scaleFactor * border.readEntry("BorderRight", defaultBorderRight()));
124 m_borderBottom = qRound(scaleFactor * border.readEntry("BorderBottom", defaultBorderBottom()));
125 m_borderTop = qRound(scaleFactor * border.readEntry("BorderTop", defaultBorderTop()));
126
127 m_titleEdgeTop = qRound(scaleFactor * border.readEntry("TitleEdgeTop", defaultTitleEdgeTop()));
128 m_titleEdgeBottom = qRound(scaleFactor * border.readEntry("TitleEdgeBottom", defaultTitleEdgeBottom()));
129 m_titleEdgeLeft = qRound(scaleFactor * border.readEntry("TitleEdgeLeft", defaultTitleEdgeLeft()));
130 m_titleEdgeRight = qRound(scaleFactor * border.readEntry("TitleEdgeRight", defaultTitleEdgeRight()));
131 m_titleEdgeTopMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeTopMaximized", defaultTitleEdgeTopMaximized()));
132 m_titleEdgeBottomMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeBottomMaximized", defaultTitleEdgeBottomMaximized()));
133 m_titleEdgeLeftMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeLeftMaximized", defaultTitleEdgeLeftMaximized()));
134 m_titleEdgeRightMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeRightMaximized", defaultTitleEdgeRightMaximized()));
135 m_titleBorderLeft = qRound(scaleFactor * border.readEntry("TitleBorderLeft", defaultTitleBorderLeft()));
136 m_titleBorderRight = qRound(scaleFactor * border.readEntry("TitleBorderRight", defaultTitleBorderRight()));
137 m_titleHeight = qRound(scaleFactor * border.readEntry("TitleHeight", defaultTitleHeight()));
138
139 m_buttonWidth = border.readEntry("ButtonWidth", defaultButtonWidth());
140 m_buttonWidthMinimize = qRound(scaleFactor * border.readEntry("ButtonWidthMinimize", m_buttonWidth));
141 m_buttonWidthMaximizeRestore = qRound(scaleFactor * border.readEntry("ButtonWidthMaximizeRestore", m_buttonWidth));
142 m_buttonWidthClose = qRound(scaleFactor * border.readEntry("ButtonWidthClose", m_buttonWidth));
143 m_buttonWidthAllDesktops = qRound(scaleFactor * border.readEntry("ButtonWidthAlldesktops", m_buttonWidth));
144 m_buttonWidthKeepAbove = qRound(scaleFactor * border.readEntry("ButtonWidthKeepabove", m_buttonWidth));
145 m_buttonWidthKeepBelow = qRound(scaleFactor * border.readEntry("ButtonWidthKeepbelow", m_buttonWidth));
146 m_buttonWidthShade = qRound(scaleFactor * border.readEntry("ButtonWidthShade", m_buttonWidth));
147 m_buttonWidthHelp = qRound(scaleFactor * border.readEntry("ButtonWidthHelp", m_buttonWidth));
148 m_buttonWidthMenu = qRound(scaleFactor * border.readEntry("ButtonWidthMenu", m_buttonWidth));
149 m_buttonWidthAppMenu = qRound(scaleFactor * border.readEntry("ButtonWidthAppMenu", m_buttonWidthMenu));
150 m_buttonWidth = qRound(m_buttonWidth * scaleFactor);
151 m_buttonHeight = qRound(scaleFactor * border.readEntry("ButtonHeight", defaultButtonHeight()));
152 m_buttonSpacing = qRound(scaleFactor * border.readEntry("ButtonSpacing", defaultButtonSpacing()));
153 m_buttonMarginTop = qRound(scaleFactor * border.readEntry("ButtonMarginTop", defaultButtonMarginTop()));
154 m_explicitButtonSpacer = qRound(scaleFactor * border.readEntry("ExplicitButtonSpacer", defaultExplicitButtonSpacer()));
155
156 m_paddingLeft = qRound(scaleFactor * border.readEntry("PaddingLeft", defaultPaddingLeft()));
157 m_paddingRight = qRound(scaleFactor * border.readEntry("PaddingRight", defaultPaddingRight()));
158 m_paddingTop = qRound(scaleFactor * border.readEntry("PaddingTop", defaultPaddingTop()));
159 m_paddingBottom = qRound(scaleFactor * border.readEntry("PaddingBottom", defaultPaddingBottom()));
160}
161
162QColor ThemeConfig::activeTextColor(bool useTabs, bool focused) const
163{
164 if (!useTabs) {
165 return m_activeTextColor;
166 }
167 if (focused) {
168 return m_activeFocusedTextColor;
169 } else {
170 return m_activeUnfocusedTextColor;
171 }
172}
173
174QColor ThemeConfig::inactiveTextColor(bool useTabs, bool focused) const
175{
176 if (!useTabs) {
177 return m_inactiveTextColor;
178 }
179 if (focused) {
180 return m_inactiveFocusedTextColor;
181 } else {
182 return m_inactiveUnfocusedTextColor;
183 }
184}
185
186} // namespace
static int defaultPaddingTop()
static int defaultAnimationTime()
static int defaultTextShadowOffsetY()
static int defaultTitleEdgeTop()
static int defaultPaddingRight()
static bool defaultShadow()
static int defaultButtonWidth()
QColor activeTextColor(bool useTabs=false, bool focused=true) const
static int defaultBorderRight()
static int defaultBorderLeft()
static int defaultPaddingLeft()
static QColor defaultInactiveTextColor()
static bool defaultHaloInactive()
void load(const KConfig &conf)
static int defaultTitleEdgeTopMaximized()
static int defaultTitleEdgeRight()
static QColor defaultActiveTextColor()
static int defaultTitleHeight()
static int defaultExplicitButtonSpacer()
static bool defaultUseTextShadow()
QColor inactiveTextColor(bool useTabs=false, bool focused=true) const
static int defaultTitleBorderRight()
static int defaultButtonMarginTop()
static int defaultBorderBottom()
static int defaultTitleBorderLeft()
static int defaultTitleEdgeBottomMaximized()
Qt::Alignment alignment() const
Definition themeconfig.h:56
static int defaultButtonSpacing()
static int defaultTitleEdgeRightMaximized()
static bool defaultHaloActive()
static int defaultTitleEdgeLeft()
static int defaultTitleEdgeBottom()
static int defaultBorderTop()
static int defaultTextShadowOffsetX()
static int defaultButtonHeight()
static int defaultTitleEdgeLeftMaximized()
static int defaultPaddingBottom()
static int defaultDecorationPosition()