Libplasma

theme.h
1/*
2 SPDX-FileCopyrightText: 2006-2007 Aaron Seigo <aseigo@kde.org>
3 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef PLASMA_THEME_H
9#define PLASMA_THEME_H
10
11#include <QFont>
12#include <QGuiApplication>
13#include <QObject>
14
15#include <KSharedConfig>
16#include <plasma/plasma_export.h>
17
18class KPluginMetaData;
19
20namespace Plasma
21{
22class ThemePrivate;
23class SvgPrivate;
24
25/**
26 * @class Theme plasma/theme.h <Plasma/Theme>
27 *
28 * @short Interface to the Plasma theme
29 *
30 *
31 * Plasma::Theme provides access to a common and standardized set of graphic
32 * elements stored in SVG format. This allows artists to create single packages
33 * of SVGs that will affect the look and feel of all workspace components.
34 *
35 * Plasma::Svg uses Plasma::Theme internally to locate and load the appropriate
36 * SVG data. Alternatively, Plasma::Theme can be used directly to retrieve
37 * file system paths to SVGs by name.
38 */
39class PLASMA_EXPORT Theme : public QObject
40{
41 Q_OBJECT
42
43 Q_PROPERTY(QString themeName READ themeName NOTIFY themeChanged)
44 Q_PROPERTY(bool useGlobalSettings READ useGlobalSettings NOTIFY themeChanged)
45 Q_PROPERTY(QString wallpaperPath READ wallpaperPath NOTIFY themeChanged)
46
47 // fonts
48 Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged)
49 Q_PROPERTY(QFont smallestFont READ smallestFont NOTIFY smallestFontChanged)
50
51 Q_PROPERTY(QPalette palette READ palette NOTIFY themeChanged)
52
53public:
54 enum ColorRole {
55 TextColor = 0, /**< the text color to be used by items resting on the background */
56 BackgroundColor = 1, /**< the default background color */
57 HighlightColor = 2, /**< the text highlight color to be used by items resting
58 on the background */
59 HoverColor = 3, /**< color for hover effect on view */
60 FocusColor = 4, /**< color for focus effect on view */
61 LinkColor = 5, /**< color for clickable links */
62 VisitedLinkColor = 6, /**< color visited clickable links */
63 HighlightedTextColor = 7, /**< color contrasting with HighlightColor, to be used for instance with */
64 PositiveTextColor = 8, /**< color of foreground objects with a "positive message" connotation (usually green) */
65 NeutralTextColor = 9, /**< color of foreground objects with a "neutral message" connotation (usually yellow) */
66 NegativeTextColor = 10, /**< color of foreground objects with a "negative message" connotation (usually red) */
67 DisabledTextColor = 11, /**< color of disabled text @since 5.64 */
68 };
69
70 enum ColorGroup {
71 NormalColorGroup = 0,
72 ButtonColorGroup = 1,
73 ViewColorGroup = 2,
74 ComplementaryColorGroup = 3,
75 HeaderColorGroup,
76 ToolTipColorGroup,
77 };
78 Q_ENUM(ColorGroup)
79
80 /**
81 * Default constructor. It will be the global theme configured in plasmarc
82 * @param parent the parent object
83 */
84 explicit Theme(QObject *parent = nullptr);
85
86 /**
87 * Construct a theme. It will be a custom theme instance of themeName.
88 * @param themeName the name of the theme to create
89 * @param parent the parent object
90 * @since 4.3
91 */
92 explicit Theme(const QString &themeName, QObject *parent = nullptr);
93
94 ~Theme() override;
95
96 /**
97 * Sets the current theme being used.
98 */
99 void setThemeName(const QString &themeName);
100
101 /**
102 * @return the name of the theme.
103 */
104 QString themeName() const;
105
106 /**
107 * Retrieve the path for an SVG image in the current theme.
108 *
109 * @param name the name of the file in the theme directory (without the
110 * ".svg" part or a leading slash)
111 * @return the full path to the requested file for the current theme
112 */
113 QString imagePath(const QString &name) const;
114
115 /**
116 * Retrieves the default wallpaper associated with this theme.
117 *
118 * @param size the target height and width of the wallpaper; if an invalid size
119 * is passed in, then a default size will be provided instead.
120 * @return the full path to the wallpaper image
121 */
122 QString wallpaperPath(const QSize &size = QSize()) const;
123
124 Q_INVOKABLE QString wallpaperPathForSize(int width = -1, int height = -1) const;
125
126 /**
127 * Checks if this theme has an image named in a certain way
128 *
129 * @param name the name of the file in the theme directory (without the
130 * ".svg" part or a leading slash)
131 * @return true if the image exists for this theme
132 */
133 bool currentThemeHasImage(const QString &name) const;
134
135 /**
136 * Returns the color scheme configurationthat goes along this theme.
137 * This can be used with KStatefulBrush and KColorScheme to determine
138 * the proper colours to use along with the visual elements in this theme.
139 */
140 KSharedConfigPtr colorScheme() const;
141
142 /**
143 * Returns the text color to be used by items resting on the background
144 *
145 * @param role which role (usage pattern) to get the color for
146 * @param group which group we want a color of
147 */
148 QColor color(ColorRole role, ColorGroup group = NormalColorGroup) const;
149
150 /**
151 * Tells the theme whether to follow the global settings or use application
152 * specific settings
153 *
154 * @param useGlobal pass in true to follow the global settings
155 */
156 void setUseGlobalSettings(bool useGlobal);
157
158 /**
159 * @return true if the global settings are followed, false if application
160 * specific settings are used.
161 */
162 bool useGlobalSettings() const;
163
164 /**
165 * Returns a QPalette with the colors set as defined by the theme.
166 * @since 5.68
167 */
168 QPalette palette() const;
169
170 /**
171 * @return plugin metadata for this theme, with information such as
172 * name, description, author, website etc
173 * @since 5.95
174 */
175 KPluginMetaData metadata() const;
176
177 /**
178 * @return The default application font
179 * @since 5.0
180 */
181 QFont defaultFont() const;
182
183 /**
184 * @return The smallest readable font
185 * @since 5.0
186 */
187 QFont smallestFont() const;
188
189 /** This method allows Plasma to enable and disable the background
190 * contrast effect for a given theme, improving readability. The
191 * value is read from the "enabled" key in the "ContrastEffect"
192 * group in the Theme's metadata file.
193 * The configuration in the metadata.desktop file of the theme
194 * could look like this (for a lighter background):
195 * \code
196 * [ContrastEffect]
197 * enabled=true
198 * contrast=0.45
199 * intensity=0.45
200 * saturation=1.7
201 * \endcode
202 * @return Whether or not to enable the contrasteffect
203 * @since 5.0
204 */
205 bool backgroundContrastEnabled() const;
206
207 /** This method allows Plasma to enable and disable the adaptive
208 * transparency option of the panel, which allows user to decide
209 * whether the panel should be always transparent, always opaque
210 * or only opaque when a window is maximized.
211 * The configuration in the metadata.desktop file of the theme
212 * could look like this (for a lighter background):
213 * \code
214 * [AdaptiveTransparency]
215 * enabled=true
216 * \endcode
217 * @return Whether or not to enable the adaptive transparency
218 * @since 5.20
219 */
220 bool adaptiveTransparencyEnabled() const;
221
222 /** This method allows Plasma to set a background contrast effect
223 * for a given theme, improving readability. The value is read
224 * from the "contrast" key in the "ContrastEffect" group in the
225 * Theme's metadata file.
226 * @return The contrast provided to the contrasteffect
227 * @since 5.0
228 * @see backgroundContrastEnabled
229 */
230 qreal backgroundContrast() const;
231
232 /** This method allows Plasma to set a background contrast effect
233 * for a given theme, improving readability. The value is read
234 * from the "intensity" key in the "ContrastEffect" group in the
235 * Theme's metadata file.
236 * @return The intensity provided to the contrasteffect
237 * @since 5.0
238 * @see backgroundContrastEnabled
239 */
240 qreal backgroundIntensity() const;
241
242 /** This method allows Plasma to set a background contrast effect
243 * for a given theme, improving readability. The value is read
244 * from the "saturation" key in the "ContrastEffect" group in the
245 * Theme's metadata file.
246 * @return The saturation provided to the contrasteffect
247 * @since 5.0
248 * @see backgroundContrastEnabled
249 */
250 qreal backgroundSaturation() const;
251
252 /** This method allows Plasma to enable and disable the blurring
253 * of what is behind the background for a given theme. The
254 * value is read from the "enabled" key in the "BlurBehindEffect"
255 * group in the Theme's metadata file. Default is @c true.
256 *
257 * The configuration in the metadata.desktop file of the theme
258 * could look like this:
259 * \code
260 * [BlurBehindEffect]
261 * enabled=false
262 * \endcode
263 * @return Whether or not to enable blurring of what is behind
264 * @since 5.57
265 */
266 bool blurBehindEnabled() const;
267
268 /**
269 * Returns the size of the letter "M" as rendered on the screen with the given font.
270 * This values gives you a base size that:
271 * * scales dependent on the DPI of the screen
272 * * Scales with the default font as set by the user
273 * You can use it like this in QML Items:
274 * \code
275 * Item {
276 * width: PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height
277 * height: width
278 * }
279 * \endcode
280 * This allows you to dynamically scale elements of your user interface with different font settings and
281 * different physical outputs (with different DPI).
282 * @param font The font to use for the metrics.
283 * @return The size of the letter "M" as rendered on the screen with the given font.
284 * @since 5.0
285 */
286 Q_INVOKABLE QSizeF mSize(const QFont &font = QGuiApplication::font()) const;
287
288 QString backgroundPath(const QString &image) const;
289
290 static QPalette globalPalette();
291
292 static KSharedConfigPtr globalColorScheme();
293
294Q_SIGNALS:
295 /**
296 * Emitted when the user changes the theme. Stylesheet usage, colors, etc. should
297 * be updated at this point. However, SVGs should *not* be repainted in response
298 * to this signal; connect to Svg::repaintNeeded() instead for that, as Svg objects
299 * need repainting not only when themeChanged() is emitted; moreover Svg objects
300 * connect to and respond appropriately to themeChanged() internally, emitting
301 * Svg::repaintNeeded() at an appropriate time.
302 */
304
305 /** Notifier for change of defaultFont property */
307 /** Notifier for change of smallestFont property */
309
310private:
311 friend class SvgPrivate;
312 friend class FrameSvg;
313 friend class FrameSvgPrivate;
314 friend class ThemePrivate;
315 ThemePrivate *d;
316};
317
318} // Plasma namespace
319
320#endif // multiple inclusion guard
Interface to the Plasma theme.
Definition theme.h:40
void defaultFontChanged()
Notifier for change of defaultFont property.
void smallestFontChanged()
Notifier for change of smallestFont property.
void themeChanged()
Emitted when the user changes the theme.
Namespace for everything in libplasma.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.