File indexing completed on 2024-11-10 04:57:00

0001 /*
0002     SPDX-FileCopyrightText: 2009 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "themeconfig.h"
0007 
0008 #include <KConfig>
0009 #include <KConfigGroup>
0010 
0011 #include <QGuiApplication>
0012 #include <QScreen>
0013 
0014 namespace Aurorae
0015 {
0016 
0017 ThemeConfig::ThemeConfig()
0018     : m_activeTextColor(defaultActiveTextColor())
0019     , m_activeFocusedTextColor(defaultActiveFocusedTextColor())
0020     , m_activeUnfocusedTextColor(defaultActiveUnfocusedTextColor())
0021     , m_inactiveTextColor(defaultInactiveTextColor())
0022     , m_inactiveFocusedTextColor(defaultInactiveFocusedTextColor())
0023     , m_inactiveUnfocusedTextColor(defaultInactiveUnfocusedTextColor())
0024     , m_activeTextShadowColor(defaultActiveTextShadowColor())
0025     , m_inactiveTextShadowColor(defaultInactiveTextShadowColor())
0026     , m_textShadowOffsetX(defaultTextShadowOffsetX())
0027     , m_textShadowOffsetY(defaultTextShadowOffsetY())
0028     , m_useTextShadow(defaultUseTextShadow())
0029     , m_haloActive(defaultHaloActive())
0030     , m_haloInactive(defaultHaloInactive())
0031     , m_alignment(defaultAlignment())
0032     , m_verticalAlignment(defaultVerticalAlignment())
0033     // borders
0034     , m_borderLeft(defaultBorderLeft())
0035     , m_borderRight(defaultBorderRight())
0036     , m_borderBottom(defaultBorderBottom())
0037     , m_borderTop(defaultBorderTop())
0038     // title
0039     , m_titleEdgeTop(defaultTitleEdgeTop())
0040     , m_titleEdgeBottom(defaultTitleEdgeBottom())
0041     , m_titleEdgeLeft(defaultTitleEdgeLeft())
0042     , m_titleEdgeRight(defaultTitleEdgeRight())
0043     , m_titleEdgeTopMaximized(defaultTitleEdgeTopMaximized())
0044     , m_titleEdgeBottomMaximized(defaultTitleEdgeBottomMaximized())
0045     , m_titleEdgeLeftMaximized(defaultTitleEdgeLeftMaximized())
0046     , m_titleEdgeRightMaximized(defaultTitleEdgeRightMaximized())
0047     , m_titleBorderLeft(defaultTitleBorderLeft())
0048     , m_titleBorderRight(defaultTitleBorderRight())
0049     , m_titleHeight(defaultTitleHeight())
0050     // buttons
0051     , m_buttonWidth(defaultButtonWidth())
0052     , m_buttonWidthMinimize(defaultButtonWidthMinimize())
0053     , m_buttonWidthMaximizeRestore(defaultButtonWidthMaximizeRestore())
0054     , m_buttonWidthClose(defaultButtonWidthClose())
0055     , m_buttonWidthAllDesktops(defaultButtonWidthAllDesktops())
0056     , m_buttonWidthKeepAbove(defaultButtonWidthKeepAbove())
0057     , m_buttonWidthKeepBelow(defaultButtonWidthKeepBelow())
0058     , m_buttonWidthShade(defaultButtonWidthShade())
0059     , m_buttonWidthHelp(defaultButtonWidthHelp())
0060     , m_buttonWidthMenu(defaultButtonWidthMenu())
0061     , m_buttonWidthAppMenu(defaultButtonWidthAppMenu())
0062     , m_buttonHeight(defaultButtonHeight())
0063     , m_buttonSpacing(defaultButtonSpacing())
0064     , m_buttonMarginTop(defaultButtonMarginTop())
0065     , m_explicitButtonSpacer(defaultExplicitButtonSpacer())
0066     // padding
0067     , m_paddingLeft(defaultPaddingLeft())
0068     , m_paddingRight(defaultPaddingRight())
0069     , m_paddingTop(defaultPaddingTop())
0070     , m_paddingBottom(defaultPaddingBottom())
0071     , m_animationTime(defaultAnimationTime())
0072     , m_shadow(defaultShadow())
0073     , m_decorationPosition(defaultDecorationPosition())
0074 {
0075 }
0076 
0077 void ThemeConfig::load(const KConfig &conf)
0078 {
0079     KConfigGroup general(&conf, QStringLiteral("General"));
0080     m_activeTextColor = general.readEntry("ActiveTextColor", defaultActiveTextColor());
0081     m_inactiveTextColor = general.readEntry("InactiveTextColor", defaultInactiveTextColor());
0082     m_activeFocusedTextColor = general.readEntry("ActiveFocusedTabColor", m_activeTextColor);
0083     m_activeUnfocusedTextColor = general.readEntry("ActiveUnfocusedTabColor", m_inactiveTextColor);
0084     m_inactiveFocusedTextColor = general.readEntry("InactiveFocusedTabColor", m_inactiveTextColor);
0085     m_inactiveUnfocusedTextColor = general.readEntry("InactiveUnfocusedTabColor", m_inactiveTextColor);
0086     m_useTextShadow = general.readEntry("UseTextShadow", defaultUseTextShadow());
0087     m_activeTextShadowColor = general.readEntry("ActiveTextShadowColor", defaultActiveTextColor());
0088     m_inactiveTextShadowColor = general.readEntry("InactiveTextShadowColor", defaultInactiveTextColor());
0089     m_textShadowOffsetX = general.readEntry("TextShadowOffsetX", defaultTextShadowOffsetX());
0090     m_textShadowOffsetY = general.readEntry("TextShadowOffsetY", defaultTextShadowOffsetY());
0091     m_haloActive = general.readEntry("HaloActive", defaultHaloActive());
0092     m_haloInactive = general.readEntry("HaloInactive", defaultHaloInactive());
0093     QString alignment = (general.readEntry("TitleAlignment", "Left")).toLower();
0094     if (alignment == QStringLiteral("left")) {
0095         m_alignment = Qt::AlignLeft;
0096     } else if (alignment == QStringLiteral("center")) {
0097         m_alignment = Qt::AlignHCenter;
0098     } else {
0099         m_alignment = Qt::AlignRight;
0100     }
0101     alignment = (general.readEntry("TitleVerticalAlignment", "Center")).toLower();
0102     if (alignment == QStringLiteral("top")) {
0103         m_verticalAlignment = Qt::AlignTop;
0104     } else if (alignment == QStringLiteral("center")) {
0105         m_verticalAlignment = Qt::AlignVCenter;
0106     } else {
0107         m_verticalAlignment = Qt::AlignBottom;
0108     }
0109     m_animationTime = general.readEntry("Animation", defaultAnimationTime());
0110     m_shadow = general.readEntry("Shadow", defaultShadow());
0111     m_decorationPosition = general.readEntry("DecorationPosition", defaultDecorationPosition());
0112 
0113     qreal scaleFactor = 1;
0114     QScreen *primary = QGuiApplication::primaryScreen();
0115     if (primary) {
0116         const qreal dpi = primary->logicalDotsPerInchX();
0117         scaleFactor = dpi / 96.0f;
0118     }
0119 
0120     KConfigGroup border(&conf, QStringLiteral("Layout"));
0121     // default values taken from KCommonDecoration::layoutMetric() in kcommondecoration.cpp
0122     m_borderLeft = qRound(scaleFactor * border.readEntry("BorderLeft", defaultBorderLeft()));
0123     m_borderRight = qRound(scaleFactor * border.readEntry("BorderRight", defaultBorderRight()));
0124     m_borderBottom = qRound(scaleFactor * border.readEntry("BorderBottom", defaultBorderBottom()));
0125     m_borderTop = qRound(scaleFactor * border.readEntry("BorderTop", defaultBorderTop()));
0126 
0127     m_titleEdgeTop = qRound(scaleFactor * border.readEntry("TitleEdgeTop", defaultTitleEdgeTop()));
0128     m_titleEdgeBottom = qRound(scaleFactor * border.readEntry("TitleEdgeBottom", defaultTitleEdgeBottom()));
0129     m_titleEdgeLeft = qRound(scaleFactor * border.readEntry("TitleEdgeLeft", defaultTitleEdgeLeft()));
0130     m_titleEdgeRight = qRound(scaleFactor * border.readEntry("TitleEdgeRight", defaultTitleEdgeRight()));
0131     m_titleEdgeTopMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeTopMaximized", defaultTitleEdgeTopMaximized()));
0132     m_titleEdgeBottomMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeBottomMaximized", defaultTitleEdgeBottomMaximized()));
0133     m_titleEdgeLeftMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeLeftMaximized", defaultTitleEdgeLeftMaximized()));
0134     m_titleEdgeRightMaximized = qRound(scaleFactor * border.readEntry("TitleEdgeRightMaximized", defaultTitleEdgeRightMaximized()));
0135     m_titleBorderLeft = qRound(scaleFactor * border.readEntry("TitleBorderLeft", defaultTitleBorderLeft()));
0136     m_titleBorderRight = qRound(scaleFactor * border.readEntry("TitleBorderRight", defaultTitleBorderRight()));
0137     m_titleHeight = qRound(scaleFactor * border.readEntry("TitleHeight", defaultTitleHeight()));
0138 
0139     m_buttonWidth = border.readEntry("ButtonWidth", defaultButtonWidth());
0140     m_buttonWidthMinimize = qRound(scaleFactor * border.readEntry("ButtonWidthMinimize", m_buttonWidth));
0141     m_buttonWidthMaximizeRestore = qRound(scaleFactor * border.readEntry("ButtonWidthMaximizeRestore", m_buttonWidth));
0142     m_buttonWidthClose = qRound(scaleFactor * border.readEntry("ButtonWidthClose", m_buttonWidth));
0143     m_buttonWidthAllDesktops = qRound(scaleFactor * border.readEntry("ButtonWidthAlldesktops", m_buttonWidth));
0144     m_buttonWidthKeepAbove = qRound(scaleFactor * border.readEntry("ButtonWidthKeepabove", m_buttonWidth));
0145     m_buttonWidthKeepBelow = qRound(scaleFactor * border.readEntry("ButtonWidthKeepbelow", m_buttonWidth));
0146     m_buttonWidthShade = qRound(scaleFactor * border.readEntry("ButtonWidthShade", m_buttonWidth));
0147     m_buttonWidthHelp = qRound(scaleFactor * border.readEntry("ButtonWidthHelp", m_buttonWidth));
0148     m_buttonWidthMenu = qRound(scaleFactor * border.readEntry("ButtonWidthMenu", m_buttonWidth));
0149     m_buttonWidthAppMenu = qRound(scaleFactor * border.readEntry("ButtonWidthAppMenu", m_buttonWidthMenu));
0150     m_buttonWidth = qRound(m_buttonWidth * scaleFactor);
0151     m_buttonHeight = qRound(scaleFactor * border.readEntry("ButtonHeight", defaultButtonHeight()));
0152     m_buttonSpacing = qRound(scaleFactor * border.readEntry("ButtonSpacing", defaultButtonSpacing()));
0153     m_buttonMarginTop = qRound(scaleFactor * border.readEntry("ButtonMarginTop", defaultButtonMarginTop()));
0154     m_explicitButtonSpacer = qRound(scaleFactor * border.readEntry("ExplicitButtonSpacer", defaultExplicitButtonSpacer()));
0155 
0156     m_paddingLeft = qRound(scaleFactor * border.readEntry("PaddingLeft", defaultPaddingLeft()));
0157     m_paddingRight = qRound(scaleFactor * border.readEntry("PaddingRight", defaultPaddingRight()));
0158     m_paddingTop = qRound(scaleFactor * border.readEntry("PaddingTop", defaultPaddingTop()));
0159     m_paddingBottom = qRound(scaleFactor * border.readEntry("PaddingBottom", defaultPaddingBottom()));
0160 }
0161 
0162 QColor ThemeConfig::activeTextColor(bool useTabs, bool focused) const
0163 {
0164     if (!useTabs) {
0165         return m_activeTextColor;
0166     }
0167     if (focused) {
0168         return m_activeFocusedTextColor;
0169     } else {
0170         return m_activeUnfocusedTextColor;
0171     }
0172 }
0173 
0174 QColor ThemeConfig::inactiveTextColor(bool useTabs, bool focused) const
0175 {
0176     if (!useTabs) {
0177         return m_inactiveTextColor;
0178     }
0179     if (focused) {
0180         return m_inactiveFocusedTextColor;
0181     } else {
0182         return m_inactiveUnfocusedTextColor;
0183     }
0184 }
0185 
0186 } // namespace