KIconThemes

kicontheme.h
1/*
2
3 This file is part of the KDE project, module kdecore.
4 SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org>
5 SPDX-FileCopyrightText: 2000 Antonio Larrosa <larrosa@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-only
8*/
9
10#ifndef KICONTHEME_H
11#define KICONTHEME_H
12
13#include <kiconthemes_export.h>
14
15#include <QList>
16#include <QString>
17#include <QStringList>
18
19#include <memory>
20
21#include "kiconloader.h"
22
23class QAction;
24
25/**
26 * @internal
27 * Class to use/access icon themes in KDE. This class is used by the
28 * iconloader but can be used by others too.
29 * @warning You should not use this class externally. This class is exported because
30 * the KCM needs it.
31 * @see KIconLoader
32 */
33class KICONTHEMES_EXPORT KIconTheme
34{
35public:
36 /**
37 * Load an icon theme by name.
38 * @param name the name of the theme (e.g. "hicolor" or "keramik")
39 * @param appName the name of the application. Can be null. This argument
40 * allows applications to have themed application icons.
41 * @param basePathHint optional hint where to search the app themes.
42 * This is appended at the end of the search paths
43 */
44 explicit KIconTheme(const QString &name, const QString &appName = QString(), const QString &basePathHint = QString());
46
47 KIconTheme(const KIconTheme &) = delete;
48 KIconTheme &operator=(const KIconTheme &) = delete;
49
50 /**
51 * The stylized name of the icon theme.
52 * @return the (human-readable) name of the theme
53 */
54 QString name() const;
55
56 /**
57 * The internal name of the icon theme (same as the name argument passed
58 * to the constructor).
59 * @return the internal name of the theme
60 */
61 QString internalName() const;
62
63 /**
64 * A description for the icon theme.
65 * @return a human-readable description of the theme, QString()
66 * if there is none
67 */
68 QString description() const;
69
70 /**
71 * Return the name of the "example" icon. This can be used to
72 * present the theme to the user.
73 * @return the name of the example icon, QString() if there is none
74 */
75 QString example() const;
76
77 /**
78 * Return the name of the screenshot.
79 * @return the name of the screenshot, QString() if there is none
80 */
81 QString screenshot() const;
82
83 /**
84 * Returns the toplevel theme directory.
85 * @return the directory of the theme
86 */
87 QString dir() const;
88
89 /**
90 * The themes this icon theme falls back on.
91 * @return a list of icon themes that are used as fall-backs
92 */
93 QStringList inherits() const;
94
95 /**
96 * The icon theme exists?
97 * @return true if the icon theme is valid
98 */
99 bool isValid() const;
100
101 /**
102 * The icon theme should be hidden to the user?
103 * @return true if the icon theme is hidden
104 */
105 bool isHidden() const;
106
107 /**
108 * The minimum display depth required for this theme. This can either
109 * be 8 or 32.
110 * @return the minimum bpp (8 or 32)
111 */
112 int depth() const;
113
114 /**
115 * The default size of this theme for a certain icon group.
116 * @param group The icon group. See KIconLoader::Group.
117 * @return The default size in pixels for the given icon group.
118 */
119 int defaultSize(KIconLoader::Group group) const;
120
121 /**
122 * Query available sizes for a group.
123 * @param group The icon group. See KIconLoader::Group.
124 * @return a list of available sizes for the given group
125 */
127
128 /**
129 * Query all available icons.
130 * @return the list of icon names
131 * @since 6.11
132 */
133 [[nodiscard]] QStringList queryIcons() const;
134
135 /**
136 * Query available icons for a size and context.
137 * @param size the size of the icons
138 * @param context the context of the icons
139 * @return the list of icon names
140 */
142
143 /**
144 * Query available icons for a context and preferred size.
145 * @param size the size of the icons
146 * @param context the context of the icons
147 * @return the list of icon names
148 */
150
151 /**
152 * Lookup an icon in the theme.
153 * @param name The name of the icon, with extension.
154 * @param size The desired size of the icon.
155 * @param match The matching mode. KIconLoader::MatchExact returns an icon
156 * only if matches exactly. KIconLoader::MatchBest returns the best matching
157 * icon.
158 * @return An absolute path to the file of the icon if it's found, QString() otherwise.
159 * @see KIconLoader::isValid will return true, and false otherwise.
160 */
161 QString iconPath(const QString &name, int size, KIconLoader::MatchType match) const;
162
163 /**
164 * Lookup an icon in the theme.
165 * @param name The name of the icon, with extension.
166 * @param size The desired size of the icon.
167 * @param match The matching mode. KIconLoader::MatchExact returns an icon
168 * only if matches exactly. KIconLoader::MatchBest returns the best matching
169 * icon.
170 * @param scale The scale of the icon group.
171 * @return An absolute path to the file of the icon if it's found, QString() otherwise.
172 * @see KIconLoader::isValid will return true, and false otherwise.
173 * @since 5.48
174 */
175 // TODO KF6 merge iconPath() with and without "scale" and move that argument after "size"
176 QString iconPath(const QString &name, int size, KIconLoader::MatchType match, qreal scale) const;
177
178 /**
179 * Lookup an icon in the theme.
180 * @param name The name of the icon, without extension.
181 * @param size The desired size of the icon.
182 * @param match The matching mode. KIconLoader::MatchExact returns an icon
183 * only if matches exactly. KIconLoader::MatchBest returns the best matching
184 * icon.
185 * @return An absolute path to the file of the icon if it's found, QString() otherwise.
186 * @see KIconLoader::isValid will return true, and false otherwise.
187 *
188 * @since 5.22
189 */
190 QString iconPathByName(const QString &name, int size, KIconLoader::MatchType match) const;
191
192 /**
193 * Lookup an icon in the theme.
194 * @param name The name of the icon, without extension.
195 * @param size The desired size of the icon.
196 * @param match The matching mode. KIconLoader::MatchExact returns an icon
197 * only if matches exactly. KIconLoader::MatchBest returns the best matching
198 * icon.
199 * @param scale The scale of the icon group.
200 * @return An absolute path to the file of the icon if it's found, QString() otherwise.
201 * @see KIconLoader::isValid will return true, and false otherwise.
202 *
203 * @since 5.48
204 */
205 // TODO KF6 merge iconPathByName() with and without "scale" and move that argument after "size"
206 QString iconPathByName(const QString &name, int size, KIconLoader::MatchType match, qreal scale) const;
207
208 /**
209 * Returns true if the theme has any icons for the given context.
210 */
211 bool hasContext(KIconLoader::Context context) const;
212
213 /**
214 * If true, this theme is made of SVG icons that will be colorized following the system
215 * color scheme. This is necessary for monochrome themes that should look visible on both
216 * light and dark color schemes.
217 * @return true if the SVG will be colorized with a stylesheet.
218 * @since 5.22
219 */
220 bool followsColorScheme() const;
221
222 /**
223 * List all icon themes installed on the system, global and local.
224 * @return the list of all icon themes
225 */
226 static QStringList list();
227
228 /**
229 * Returns the current icon theme.
230 * @return the name of the current theme
231 */
232 static QString current();
233
234 /**
235 * Force a current theme and disable automatic resolution of the current
236 * theme in favor of the forced theme.
237 *
238 * To reset a forced theme, simply set an empty themeName.
239 *
240 * @param themeName name of the theme to force as current theme, or an
241 * empty string to unset theme forcing.
242 *
243 * @note This should only be used when a very precise expectation about
244 * the current theme is present. Most notably in unit tests
245 * this can be used to force a given theme.
246 *
247 * @warning A forced theme persists across reconfigure() calls!
248 *
249 * @see current
250 * @since 5.23
251 */
252 static void forceThemeForTests(const QString &themeName);
253
254 /**
255 * Reconfigure the theme.
256 */
257 static void reconfigure();
258
259 /**
260 * Returns the default icon theme.
261 * @return the name of the default theme name
262 */
263 static QString defaultThemeName();
264
265 /**
266 * Enforces the Breeze icon theme (including our KIconEngine for re-coloring).
267 *
268 * If the user has configured a different icon set, that one will be taken.
269 *
270 * (following the settings in the application configuration with fallback to kdeglobals)
271 *
272 * Must be called before the construction of the first Q(Core)Application, as it
273 * might need to modify plugin loading and installs a startup function.
274 *
275 * If the application is already using the KDE platform theme, the icon set will not
276 * be touched and the platform theme will ensure proper theming.
277 *
278 * Does setup the needed KColorSchemeManager to follow the system color mode starting
279 * with version 6.6.
280 *
281 * @since 6.3
282 */
283 static void initTheme();
284
285private:
286 std::unique_ptr<class KIconThemePrivate> const d;
287};
288
289#endif
Group
The group of the icon.
Context
Defines the context of the icon.
Definition kiconloader.h:80
@ Any
Some icon with unknown purpose.
Definition kiconloader.h:81
MatchType
The type of a match.
static QStringList list()
List all icon themes installed on the system, global and local.
bool isValid() const
The icon theme exists?
QStringList queryIcons() const
Query all available icons.
QList< int > querySizes(KIconLoader::Group group) const
Query available sizes for a group.
QString iconPathByName(const QString &name, int size, KIconLoader::MatchType match) const
Lookup an icon in the theme.
QString internalName() const
The internal name of the icon theme (same as the name argument passed to the constructor).
QString screenshot() const
Return the name of the screenshot.
static void reconfigure()
Reconfigure the theme.
static void forceThemeForTests(const QString &themeName)
Force a current theme and disable automatic resolution of the current theme in favor of the forced th...
bool isHidden() const
The icon theme should be hidden to the user?
KIconTheme(const QString &name, const QString &appName=QString(), const QString &basePathHint=QString())
Load an icon theme by name.
QStringList queryIconsByContext(int size, KIconLoader::Context context=KIconLoader::Any) const
Query available icons for a context and preferred size.
QString description() const
A description for the icon theme.
static QString current()
Returns the current icon theme.
bool followsColorScheme() const
If true, this theme is made of SVG icons that will be colorized following the system color scheme.
QString dir() const
Returns the toplevel theme directory.
bool hasContext(KIconLoader::Context context) const
Returns true if the theme has any icons for the given context.
QString name() const
The stylized name of the icon theme.
QString iconPath(const QString &name, int size, KIconLoader::MatchType match) const
Lookup an icon in the theme.
static void initTheme()
Enforces the Breeze icon theme (including our KIconEngine for re-coloring).
QStringList inherits() const
The themes this icon theme falls back on.
QString example() const
Return the name of the "example" icon.
int defaultSize(KIconLoader::Group group) const
The default size of this theme for a certain icon group.
static QString defaultThemeName()
Returns the default icon theme.
int depth() const
The minimum display depth required for this theme.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:57 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.