KIconThemes 5.109.0
|
Iconloader for KDE. More...
#include <KIconLoader>
Public Types | |
enum | Context { Any , Action , Application , Device , MimeType , Animation , Category , Emblem , Emote , International , Place , StatusIcon } |
Defines the context of the icon. More... | |
enum | Group { NoGroup = -1 , Desktop = 0 , FirstGroup = 0 , Toolbar , MainToolbar , Small , Panel_DEPRECATED_DO_NOT_USE , Dialog , LastGroup , User } |
The group of the icon. More... | |
enum | MatchType { MatchExact , MatchBest } |
The type of a match. More... | |
enum | States { DefaultState , ActiveState , DisabledState , SelectedState , LastState } |
Defines the possible states of an icon. More... | |
enum | StdSizes { SizeSmall = 16 , SizeSmallMedium = 22 , SizeMedium = 32 , SizeLarge = 48 , SizeHuge = 64 , SizeEnormous = 128 } |
These are the standard sizes for icons. More... | |
enum | Type { Fixed , Scalable , Threshold } |
The type of the icon. More... | |
Signals | |
void | iconChanged (int group) |
Emitted when the system icon theme changes. | |
void | iconLoaderSettingsChanged () |
Emitted by newIconLoader once the new settings have been loaded. | |
Public Slots | |
static void | emitChange (Group group) |
Emits an iconChanged() signal on all the KIconLoader instances in the system indicating that a system's icon group has changed in some way. | |
void | newIconLoader () |
Re-initialize the global icon loader. | |
Public Member Functions | |
KIconLoader (const QString &appname=QString(), const QStringList &extraSearchPaths=QStringList(), QObject *parent=nullptr) | |
Constructs an iconloader. | |
~KIconLoader () override | |
Cleanup. | |
void | addAppDir (const QString &appname, const QString &themeBaseDir=QString()) |
Adds appname to the list of application specific directories with themeBaseDir as its base directory. | |
int | currentSize (KIconLoader::Group group) const |
Returns the current size of the icon group. | |
QPalette | customPalette () const |
The colors that will be used for the svg stylesheet in case the loaded icons are svg-based, icons can be colored in different ways in different areas of the application. | |
void | drawOverlays (const QStringList &overlays, QPixmap &pixmap, KIconLoader::Group group, int state=KIconLoader::DefaultState) const |
Draws overlays on the specified pixmap, it takes the width and height of the pixmap into consideration. | |
bool | hasContext (KIconLoader::Context context) const |
bool | hasCustomPalette () const |
bool | hasIcon (const QString &iconName) const |
KIconEffect * | iconEffect () const |
Returns a pointer to the KIconEffect object used by the icon loader. | |
QString | iconPath (const QString &name, int group_or_size, bool canReturnNull, qreal scale) const |
Returns the path of an icon. | |
QString | iconPath (const QString &name, int group_or_size, bool canReturnNull=false) const |
Returns the path of an icon. | |
QStringList | loadAnimated (const QString &name, KIconLoader::Group group, int size=0) const |
Loads an animated icon as a series of still frames. | |
QPixmap | loadIcon (const QString &name, KIconLoader::Group group, int size=0, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=nullptr, bool canReturnNull=false) const |
Loads an icon. | |
QPixmap | loadMimeTypeIcon (const QString &iconName, KIconLoader::Group group, int size=0, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=nullptr) const |
Loads an icon for a mimetype. | |
QMovie * | loadMovie (const QString &name, KIconLoader::Group group, int size=0, QObject *parent=nullptr) const |
Loads an animated icon. | |
KPixmapSequence | loadPixmapSequence (const QString &iconName, int size=SizeSmall) const |
Loads a pixmapSequence given the xdg icon name. | |
QPixmap | loadScaledIcon (const QString &name, KIconLoader::Group group, qreal scale, const QSize &size={}, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=nullptr, bool canReturnNull=false) const |
Loads an icon. | |
QPixmap | loadScaledIcon (const QString &name, KIconLoader::Group group, qreal scale, int size=0, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=nullptr, bool canReturnNull=false) const |
Loads an icon. | |
QString | moviePath (const QString &name, KIconLoader::Group group, int size=0) const |
Returns the path to an animated icon. | |
QStringList | queryIcons (int group_or_size, KIconLoader::Context context=KIconLoader::Any) const |
Queries all available icons for a specific group, having a specific context. | |
QStringList | queryIconsByContext (int group_or_size, KIconLoader::Context context=KIconLoader::Any) const |
Queries all available icons for a specific context. | |
QStringList | queryIconsByDir (const QString &iconsDir) const |
Returns a list of all icons (*.png or *.xpm extension) in the given directory. | |
void | reconfigure (const QString &appname, const QStringList &extraSearchPaths=QStringList()) |
Reconfigure the icon loader, for instance to change the associated app name or extra search paths. | |
void | resetPalette () |
Resets the custom palette used by the KIconLoader to use the QGuiApplication::palette() again (and to follow it in case the application's palette changes) | |
QStringList | searchPaths () const |
Returns all the search paths for this icon loader, either absolute or relative to GenericDataLocation. | |
void | setCustomPalette (const QPalette &palette) |
Sets the colors for this KIconLoader. | |
KIconTheme * | theme () const |
Returns a pointer to the current theme. | |
Static Public Member Functions | |
static KIconLoader * | global () |
Returns the global icon loader initialized with the application name. | |
static QPixmap | unknown () |
Returns the unknown icon. | |
Related Symbols | |
(Note that these are not member symbols.) | |
QIcon | icon (const QString &iconName, const QStringList &overlays, KIconLoader *iconLoader=nullptr) |
Returns a QIcon for the given icon, with additional overlays. | |
QIcon | icon (const QString &iconName, KIconLoader *iconLoader=nullptr) |
Returns a QIcon with an appropriate KIconEngine to perform loading and rendering. | |
Iconloader for KDE.
KIconLoader will load the current icon theme and all its base themes. Icons will be searched in any of these themes. Additionally, it caches icons and applies effects according to the user's preferences.
In KDE, it is encouraged to load icons by "Group". An icon group is a location on the screen where icons are being used. Standard groups are: Desktop, Toolbar, MainToolbar, Small and Panel. Each group has some centrally configured properties bound to it, including the icon size and effects. This makes it possible to offer a consistent icon look in all KDE applications.
The standard groups are defined below.
The icons are stored on disk in an icon theme or in a standalone directory. The icon theme directories contain multiple sizes and/or depths for the same icon. The iconloader will load the correct one based on the icon group and the current theme. Icon themes are stored globally in share/icons, or, application specific in share/apps/$appdir/icons.
The standalone directories contain just one version of an icon. The directories that are searched are: $appdir/pics and $appdir/toolbar. Icons in these directories can be loaded by using the special group "User".
enum KIconLoader::Context |
Defines the context of the icon.
enum KIconLoader::Group |
enum KIconLoader::States |
These are the standard sizes for icons.
enum KIconLoader::Type |
|
explicit |
Constructs an iconloader.
appname | Add the data directories of this application to the icon search path for the "User" group. The default argument adds the directories of the current application. |
extraSearchPaths | additional search paths, either absolute or relative to GenericDataLocation |
Usually, you use the default iconloader, which can be accessed via KIconLoader::global(), so you hardly ever have to create an iconloader object yourself. That one is the application's iconloader.
|
override |
Cleanup.
void KIconLoader::addAppDir | ( | const QString & | appname, |
const QString & | themeBaseDir = QString() |
||
) |
Adds appname
to the list of application specific directories with themeBaseDir
as its base directory.
Assume the icons are in /home/user/app/icons/hicolor/48x48/my_app.png, the base directory would be /home/user/app/icons; KIconLoader automatically searches themeBaseDir
+ "/hicolor" This directory must contain a dir structure as defined by the XDG icons specification
appname | The application name. |
themeBaseDir | The base directory of the application's theme (eg. "/home/user/app/icons") |
int KIconLoader::currentSize | ( | KIconLoader::Group | group | ) | const |
Returns the current size of the icon group.
Using e.g. KIconLoader::SmallIcon will retrieve the icon size that is currently set from System Settings->Appearance->Icon sizes. SmallIcon for instance, would typically be 16x16, but the user could increase it and this setting would change as well.
group | the group to check. |
QPalette KIconLoader::customPalette | ( | ) | const |
The colors that will be used for the svg stylesheet in case the loaded icons are svg-based, icons can be colored in different ways in different areas of the application.
void KIconLoader::drawOverlays | ( | const QStringList & | overlays, |
QPixmap & | pixmap, | ||
KIconLoader::Group | group, | ||
int | state = KIconLoader::DefaultState |
||
) | const |
Draws overlays on the specified pixmap, it takes the width and height of the pixmap into consideration.
overlays | List of up to 4 overlays to blend over the pixmap. The first overlay will be in the bottom right corner, followed by bottom left, top left and top right. An empty QString can be used to leave the specific position blank. |
pixmap | to draw on |
|
staticslot |
Emits an iconChanged() signal on all the KIconLoader instances in the system indicating that a system's icon group has changed in some way.
It will also trigger a reload in all of them to update to the new theme.
group
indicates the group that has changed
|
static |
Returns the global icon loader initialized with the application name.
bool KIconLoader::hasCustomPalette | ( | ) | const |
|
signal |
Emitted when the system icon theme changes.
KIconEffect * KIconLoader::iconEffect | ( | ) | const |
Returns a pointer to the KIconEffect object used by the icon loader.
|
signal |
Emitted by newIconLoader once the new settings have been loaded.
QString KIconLoader::iconPath | ( | const QString & | name, |
int | group_or_size, | ||
bool | canReturnNull, | ||
qreal | scale | ||
) | const |
Returns the path of an icon.
name | The name of the icon, without extension. If an absolute path is supplied for this parameter, iconPath will return it directly. |
group_or_size | If positive, search icons whose size is specified by the icon group group_or_size . If negative, search icons whose size is - group_or_size . See KIconLoader::Group and KIconLoader::StdSizes |
canReturnNull | Can return a null string? If not, a path to the "unknown" icon will be returned. |
scale | The scale of the icon group. |
canReturnNull
. QString KIconLoader::iconPath | ( | const QString & | name, |
int | group_or_size, | ||
bool | canReturnNull = false |
||
) | const |
Returns the path of an icon.
name | The name of the icon, without extension. If an absolute path is supplied for this parameter, iconPath will return it directly. |
group_or_size | If positive, search icons whose size is specified by the icon group group_or_size . If negative, search icons whose size is - group_or_size . See KIconLoader::Group and KIconLoader::StdSizes |
canReturnNull | Can return a null string? If not, a path to the "unknown" icon will be returned. |
canReturnNull
. QStringList KIconLoader::loadAnimated | ( | const QString & | name, |
KIconLoader::Group | group, | ||
int | size = 0 |
||
) | const |
Loads an animated icon as a series of still frames.
If you want to load a .mng animation as QMovie instead, please use loadMovie() instead.
name | The name of the icon. |
group | The icon group. See loadIcon(). |
size | Override the default size for group . See KIconLoader::StdSizes. |
QPixmap KIconLoader::loadIcon | ( | const QString & | name, |
KIconLoader::Group | group, | ||
int | size = 0 , |
||
int | state = KIconLoader::DefaultState , |
||
const QStringList & | overlays = QStringList() , |
||
QString * | path_store = nullptr , |
||
bool | canReturnNull = false |
||
) | const |
Loads an icon.
It will try very hard to find an icon which is suitable. If no exact match is found, a close match is searched. If neither an exact nor a close match is found, a null pixmap or the "unknown" pixmap is returned, depending on the value of the canReturnNull
parameter.
name | The name of the icon, without extension. |
group | The icon group. This will specify the size of and effects to be applied to the icon. |
size | If nonzero, this overrides the size specified by group . See KIconLoader::StdSizes. |
state | The icon state: DefaultState , ActiveState or DisabledState . Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state. |
overlays | a list of emblem icons to overlay, by name |
path_store | If not null, the path of the icon is stored here, if the icon was found. If the icon was not found path_store is unaltered even if the "unknown" pixmap was returned. |
canReturnNull | Can return a null pixmap? If false, the "unknown" pixmap is returned when no appropriate icon has been found. Note: a null pixmap can still be returned in the event of invalid parameters, such as empty names, negative sizes, and etc. |
canReturnNull
. QPixmap KIconLoader::loadMimeTypeIcon | ( | const QString & | iconName, |
KIconLoader::Group | group, | ||
int | size = 0 , |
||
int | state = KIconLoader::DefaultState , |
||
const QStringList & | overlays = QStringList() , |
||
QString * | path_store = nullptr |
||
) | const |
Loads an icon for a mimetype.
This is basically like loadIcon except that extra desktop themes are loaded if necessary.
Consider using QIcon::fromTheme() with a fallback to "application-octet-stream" instead.
iconName | The name of the icon, without extension, usually from KMimeType. |
group | The icon group. This will specify the size of and effects to be applied to the icon. |
size | If nonzero, this overrides the size specified by group . See KIconLoader::StdSizes. |
state | The icon state: DefaultState , ActiveState or DisabledState . Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state. |
path_store | If not null, the path of the icon is stored here. |
overlays | a list of emblem icons to overlay, by name |
QMovie * KIconLoader::loadMovie | ( | const QString & | name, |
KIconLoader::Group | group, | ||
int | size = 0 , |
||
QObject * | parent = nullptr |
||
) | const |
Loads an animated icon.
name | The name of the icon. |
group | The icon group. See loadIcon(). |
size | Override the default size for group . See KIconLoader::StdSizes. |
parent | The parent object of the returned QMovie. |
KPixmapSequence KIconLoader::loadPixmapSequence | ( | const QString & | iconName, |
int | size = SizeSmall |
||
) | const |
Loads a pixmapSequence given the xdg icon name.
iconName | The name of the icon, without extension. |
size | the size/group to be used |
QPixmap KIconLoader::loadScaledIcon | ( | const QString & | name, |
KIconLoader::Group | group, | ||
qreal | scale, | ||
const QSize & | size = {} , |
||
int | state = KIconLoader::DefaultState , |
||
const QStringList & | overlays = QStringList() , |
||
QString * | path_store = nullptr , |
||
bool | canReturnNull = false |
||
) | const |
Loads an icon.
It will try very hard to find an icon which is suitable. If no exact match is found, a close match is searched. If neither an exact nor a close match is found, a null pixmap or the "unknown" pixmap is returned, depending on the value of the canReturnNull
parameter.
name | The name of the icon, without extension. |
group | The icon group. This will specify the size of and effects to be applied to the icon. |
scale | The scale of the icon group to use. If no icon exists in the scaled group, a 1x icon with its size multiplied by the scale will be loaded instead. |
size | If nonzero, this overrides the size specified by group . See KIconLoader::StdSizes. The icon will be fit into size without changing the aspect ratio, which particularly matters for non-square icons. |
state | The icon state: DefaultState , ActiveState or DisabledState . Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state. |
overlays | a list of emblem icons to overlay, by name |
path_store | If not null, the path of the icon is stored here, if the icon was found. If the icon was not found path_store is unaltered even if the "unknown" pixmap was returned. |
canReturnNull | Can return a null pixmap? If false, the "unknown" pixmap is returned when no appropriate icon has been found. Note: a null pixmap can still be returned in the event of invalid parameters, such as empty names, negative sizes, and etc. |
canReturnNull
. QPixmap KIconLoader::loadScaledIcon | ( | const QString & | name, |
KIconLoader::Group | group, | ||
qreal | scale, | ||
int | size = 0 , |
||
int | state = KIconLoader::DefaultState , |
||
const QStringList & | overlays = QStringList() , |
||
QString * | path_store = nullptr , |
||
bool | canReturnNull = false |
||
) | const |
Loads an icon.
It will try very hard to find an icon which is suitable. If no exact match is found, a close match is searched. If neither an exact nor a close match is found, a null pixmap or the "unknown" pixmap is returned, depending on the value of the canReturnNull
parameter.
name | The name of the icon, without extension. |
group | The icon group. This will specify the size of and effects to be applied to the icon. |
scale | The scale of the icon group to use. If no icon exists in the scaled group, a 1x icon with its size multiplied by the scale will be loaded instead. |
size | If nonzero, this overrides the size specified by group . See KIconLoader::StdSizes. |
state | The icon state: DefaultState , ActiveState or DisabledState . Depending on the user's preferences, the iconloader may apply a visual effect to hint about its state. |
overlays | a list of emblem icons to overlay, by name |
path_store | If not null, the path of the icon is stored here, if the icon was found. If the icon was not found path_store is unaltered even if the "unknown" pixmap was returned. |
canReturnNull | Can return a null pixmap? If false, the "unknown" pixmap is returned when no appropriate icon has been found. Note: a null pixmap can still be returned in the event of invalid parameters, such as empty names, negative sizes, and etc. |
canReturnNull
. QString KIconLoader::moviePath | ( | const QString & | name, |
KIconLoader::Group | group, | ||
int | size = 0 |
||
) | const |
Returns the path to an animated icon.
name | The name of the icon. |
group | The icon group. See loadIcon(). |
size | Override the default size for group . See KIconLoader::StdSizes. |
|
slot |
Re-initialize the global icon loader.
QStringList KIconLoader::queryIcons | ( | int | group_or_size, |
KIconLoader::Context | context = KIconLoader::Any |
||
) | const |
Queries all available icons for a specific group, having a specific context.
group_or_size | If positive, search icons whose size is specified by the icon group group_or_size . If negative, search icons whose size is - group_or_size . See KIconLoader::Group and KIconLoader::StdSizes |
context | The icon context. |
QStringList KIconLoader::queryIconsByContext | ( | int | group_or_size, |
KIconLoader::Context | context = KIconLoader::Any |
||
) | const |
Queries all available icons for a specific context.
group_or_size | The icon preferred group or size. If available at this group or size, those icons will be returned, in other case, icons of undefined size will be returned. Positive numbers are groups, negative numbers are negated sizes. See KIconLoader::Group and KIconLoader::StdSizes |
context | The icon context. |
QStringList KIconLoader::queryIconsByDir | ( | const QString & | iconsDir | ) | const |
Returns a list of all icons (*.png or *.xpm extension) in the given directory.
iconsDir | the directory to search in |
void KIconLoader::reconfigure | ( | const QString & | appname, |
const QStringList & | extraSearchPaths = QStringList() |
||
) |
Reconfigure the icon loader, for instance to change the associated app name or extra search paths.
This also clears the in-memory pixmap cache (even if the appname didn't change, which is useful for unittests)
appname | the application name (empty for the global iconloader) |
extraSearchPaths | additional search paths, either absolute or relative to GenericDataLocation |
void KIconLoader::resetPalette | ( | ) |
Resets the custom palette used by the KIconLoader to use the QGuiApplication::palette() again (and to follow it in case the application's palette changes)
QStringList KIconLoader::searchPaths | ( | ) | const |
Returns all the search paths for this icon loader, either absolute or relative to GenericDataLocation.
Mostly internal (for KIconDialog).
void KIconLoader::setCustomPalette | ( | const QPalette & | palette | ) |
Sets the colors for this KIconLoader.
NOTE: if you set a custom palette, if you are using some colors from application's palette, you need to track the application palette changes by yourself. If you no longer wish to use a custom palette, use resetPalette()
KIconTheme * KIconLoader::theme | ( | ) | const |
Returns a pointer to the current theme.
Can be used to query available and default sizes for groups.
|
static |
Returns the unknown icon.
An icon that is used when no other icon can be found.
|
related |
Returns a QIcon for the given icon, with additional overlays.
|
related |
Returns a QIcon with an appropriate KIconEngine to perform loading and rendering.
KIcons thus adhere to KDE style and effect standards.