Plasma::Theme Class
Interface to the Plasma theme. More...
Header: | #include <Plasma/Theme> |
CMake: | find_package(Plasma REQUIRED) target_link_libraries(mytarget PRIVATE Plasma::Plasma) |
Inherits: | QObject |
Public Types
enum | ColorGroup { NormalColorGroup, ButtonColorGroup, ViewColorGroup, ComplementaryColorGroup, HeaderColorGroup, ToolTipColorGroup } |
enum | ColorRole { TextColor, BackgroundColor, HighlightColor, HoverColor, FocusColor, …, DisabledTextColor } |
Properties
|
|
Public Functions
Theme(QObject *parent = nullptr) | |
(since 4.3) | Theme(const QString &themeName, QObject *parent = nullptr) |
(since 5.20) bool | adaptiveTransparencyEnabled() const |
(since 5.0) qreal | backgroundContrast() const |
(since 5.0) bool | backgroundContrastEnabled() const |
(since 5.0) qreal | backgroundIntensity() const |
QString | backgroundPath(const QString &image) const |
(since 5.0) qreal | backgroundSaturation() const |
(since 5.57) bool | blurBehindEnabled() const |
QColor | color(Plasma::Theme::ColorRole role, Plasma::Theme::ColorGroup group = NormalColorGroup) const |
KSharedConfigPtr | colorScheme() const |
bool | currentThemeHasImage(const QString &name) const |
(since 5.0) QFont | defaultFont() const |
QString | imagePath(const QString &name) const |
(since 5.0) QSizeF | mSize(const QFont &font = QGuiApplication::font()) const |
(since 5.95) KPluginMetaData | metadata() const |
(since 5.68) QPalette | palette() const |
void | setThemeName(const QString &themeName) |
void | setUseGlobalSettings(bool useGlobal) |
(since 5.0) QFont | smallestFont() const |
QString | themeName() const |
bool | useGlobalSettings() const |
QString | wallpaperPath(const QSize &size = QSize()) const |
QString | wallpaperPathForSize(int width = -1, int height = -1) const |
Signals
void | defaultFontChanged() |
void | smallestFontChanged() |
void | themeChanged() |
Static Public Members
KSharedConfigPtr | globalColorScheme() |
QPalette | globalPalette() |
Detailed Description
Plasma::Theme provides access to a common and standardized set of graphic elements stored in SVG format. This allows artists to create single packages of SVGs that will affect the look and feel of all workspace components.
Plasma::Svg uses Plasma::Theme internally to locate and load the appropriate SVG data. Alternatively, Plasma::Theme can be used directly to retrieve file system paths to SVGs by name.
Member Type Documentation
enum Theme::ColorGroup
Constant | Value |
---|---|
Plasma::Theme::NormalColorGroup | 0 |
Plasma::Theme::ButtonColorGroup | 1 |
Plasma::Theme::ViewColorGroup | 2 |
Plasma::Theme::ComplementaryColorGroup | 3 |
Plasma::Theme::HeaderColorGroup | 4 |
Plasma::Theme::ToolTipColorGroup | 5 |
enum Theme::ColorRole
Constant | Value | Description |
---|---|---|
Plasma::Theme::TextColor | 0 | The text color to be used by items resting on the background |
Plasma::Theme::BackgroundColor | 1 | The default background color |
Plasma::Theme::HighlightColor | 2 | The text highlight color to be used by items resting on the background |
Plasma::Theme::HoverColor | 3 | Color for hover effect on view |
Plasma::Theme::FocusColor | 4 | Color for focus effect on view |
Plasma::Theme::LinkColor | 5 | Color for clickable links |
Plasma::Theme::VisitedLinkColor | 6 | Color visited clickable links |
Plasma::Theme::HighlightedTextColor | 7 | Color contrasting with HighlightColor, to be used for instance with |
Plasma::Theme::PositiveTextColor | 8 | Color of foreground objects with a "positive message" connotation (usually green) |
Plasma::Theme::NeutralTextColor | 9 | Color of foreground objects with a "neutral message" connotation (usually yellow) |
Plasma::Theme::NegativeTextColor | 10 | Color of foreground objects with a "negative message" connotation (usually red) |
Plasma::Theme::DisabledTextColor (since Qt 5.64) | 11 | color of disabled text |
Property Documentation
[read-only]
defaultFont : const QFont
Access functions:
QFont | defaultFont() const |
Notifier signal:
void | defaultFontChanged() |
[read-only]
palette : const QPalette
Access functions:
QPalette | palette() const |
Notifier signal:
void | themeChanged() |
[read-only]
smallestFont : const QFont
Access functions:
QFont | smallestFont() const |
Notifier signal:
void | smallestFontChanged() |
[read-only]
themeName : const QString
Access functions:
QString | themeName() const |
Notifier signal:
void | themeChanged() |
[read-only]
useGlobalSettings : const bool
Access functions:
bool | useGlobalSettings() const |
Notifier signal:
void | themeChanged() |
[read-only]
wallpaperPath : const QString
Access functions:
QString | wallpaperPath(const QSize &size = QSize()) const |
Notifier signal:
void | themeChanged() |
Member Function Documentation
[explicit]
Theme::Theme(QObject *parent = nullptr)
Default constructor. It will be the global theme configured in plasmarc
parent the parent object
[explicit, since 4.3]
Theme::Theme(const QString &themeName, QObject *parent = nullptr)
Construct a theme. It will be a custom theme instance of themeName.
themeName the name of the theme to create
parent the parent object
This function was introduced in 4.3.
[since 5.20]
bool Theme::adaptiveTransparencyEnabled() const
This method allows Plasma to enable and disable the adaptive transparency option of the panel, which allows user to decide whether the panel should be always transparent, always opaque or only opaque when a window is maximized. The configuration in the metadata.desktop file of the theme could look like this (for a lighter background):
[AdaptiveTransparency] enabled=true
Returns Whether or not to enable the adaptive transparency
This function was introduced in 5.20.
[since 5.0]
qreal Theme::backgroundContrast() const
This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "contrast" key in the "ContrastEffect" group in the Theme's metadata file.
Returns The contrast provided to the contrasteffect
Note: Getter function for property backgroundContrast.
This function was introduced in 5.0.
See also backgroundContrastEnabled.
[since 5.0]
bool Theme::backgroundContrastEnabled() const
This method allows Plasma to enable and disable the background contrast effect for a given theme, improving readability. The value is read from the "enabled" key in the "ContrastEffect" group in the Theme's metadata file. The configuration in the metadata.desktop file of the theme could look like this (for a lighter background):
[ContrastEffect] enabled=true contrast=0.45 intensity=0.45 saturation=1.7
Returns Whether or not to enable the contrasteffect
This function was introduced in 5.0.
[since 5.0]
qreal Theme::backgroundIntensity() const
This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "intensity" key in the "ContrastEffect" group in the Theme's metadata file.
Returns The intensity provided to the contrasteffect
Note: Getter function for property backgroundIntensity.
This function was introduced in 5.0.
See also backgroundContrastEnabled.
QString Theme::backgroundPath(const QString &image) const
[since 5.0]
qreal Theme::backgroundSaturation() const
This method allows Plasma to set a background contrast effect for a given theme, improving readability. The value is read from the "saturation" key in the "ContrastEffect" group in the Theme's metadata file.
Returns The saturation provided to the contrasteffect
Note: Getter function for property backgroundSaturation.
This function was introduced in 5.0.
See also backgroundContrastEnabled.
[since 5.57]
bool Theme::blurBehindEnabled() const
This method allows Plasma to enable and disable the blurring of what is behind the background for a given theme. The value is read from the "enabled" key in the "BlurBehindEffect" group in the Theme's metadata file. Default is @c true.
The configuration in the metadata.desktop file of the theme could look like this:
[BlurBehindEffect] enabled=false
Returns Whether or not to enable blurring of what is behind
This function was introduced in 5.57.
QColor Theme::color(Plasma::Theme::ColorRole role, Plasma::Theme::ColorGroup group = NormalColorGroup) const
Returns the text color to be used by items resting on the background
role which role (usage pattern) to get the color for
group which group we want a color of
KSharedConfigPtr Theme::colorScheme() const
Returns the color scheme configurationthat goes along this theme.
This can be used with KStatefulBrush and KColorScheme to determine the proper colours to use along with the visual elements in this theme.
bool Theme::currentThemeHasImage(const QString &name) const
Checks if this theme has an image named in a certain way
name the name of the file in the theme directory (without the ".svg" part or a leading slash)
Returns true if the image exists for this theme
[since 5.0]
QFont Theme::defaultFont() const
Returns The default application font
Note: Getter function for property defaultFont.
This function was introduced in 5.0.
[signal]
void Theme::defaultFontChanged()
Notifier for change of defaultFont property
Note: Notifier signal for property defaultFont.
[static]
KSharedConfigPtr Theme::globalColorScheme()
[static]
QPalette Theme::globalPalette()
QString Theme::imagePath(const QString &name) const
Retrieve the path for an SVG image in the current theme.
name the name of the file in the theme directory (without the ".svg" part or a leading slash)
Returns the full path to the requested file for the current theme
[invokable, since 5.0]
QSizeF Theme::mSize(const QFont &font = QGuiApplication::font()) const
Returns the size of the letter "M" as rendered on the screen with the given font. This values gives you a base size that: * scales dependent on the DPI of the screen * Scales with the default font as set by the user You can use it like this in QML Items:
Item { width: PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height height: width }
This allows you to dynamically scale elements of your user interface with different font settings and different physical outputs (with different DPI).
font The font to use for the metrics.
Returns The size of the letter "M" as rendered on the screen with the given font.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
This function was introduced in 5.0.
[since 5.95]
KPluginMetaData Theme::metadata() const
Returns plugin metadata for this theme, with information such as name, description, author, website etc
This function was introduced in 5.95.
[since 5.68]
QPalette Theme::palette() const
Returns a QPalette with the colors set as defined by the theme.
Note: Getter function for property palette.
This function was introduced in 5.68.
void Theme::setThemeName(const QString &themeName)
Sets the current theme being used.
See also themeName().
void Theme::setUseGlobalSettings(bool useGlobal)
Tells the theme whether to follow the global settings or use application specific settings
useGlobal pass in true to follow the global settings
See also useGlobalSettings().
[since 5.0]
QFont Theme::smallestFont() const
Returns The smallest readable font
Note: Getter function for property smallestFont.
This function was introduced in 5.0.
[signal]
void Theme::smallestFontChanged()
Notifier for change of smallestFont property
Note: Notifier signal for property smallestFont.
[signal]
void Theme::themeChanged()
Emitted when the user changes the theme. Stylesheet usage, colors, etc. should be updated at this point. However, SVGs should *not* be repainted in response to this signal; connect to Svg::repaintNeeded() instead for that, as Svg objects need repainting not only when themeChanged() is emitted; moreover Svg objects connect to and respond appropriately to themeChanged() internally, emitting Svg::repaintNeeded() at an appropriate time.
Note: Notifier signal for property backgroundContrast. Notifier signal for property backgroundIntensity. Notifier signal for property backgroundSaturation. Notifier signal for property palette. Notifier signal for property themeName. Notifier signal for property useGlobalSettings. Notifier signal for property wallpaperPath.
QString Theme::themeName() const
Returns the name of the theme.
Note: Getter function for property themeName.
See also setThemeName().
bool Theme::useGlobalSettings() const
Returns true if the global settings are followed, false if application specific settings are used.
Note: Getter function for property useGlobalSettings.
See also setUseGlobalSettings().
QString Theme::wallpaperPath(const QSize &size = QSize()) const
Retrieves the default wallpaper associated with this theme.
size the target height and width of the wallpaper; if an invalid size is passed in, then a default size will be provided instead.
Returns the full path to the wallpaper image
Note: Getter function for property wallpaperPath.
[invokable]
QString Theme::wallpaperPathForSize(int width = -1, int height = -1) const
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.