Plasma::Theme

Search for usage in LXR

#include <Plasma/Theme>

Inheritance diagram for Plasma::Theme:

Public Types

enum  ColorGroup {
  NormalColorGroup = 0, ButtonColorGroup = 1, ViewColorGroup = 2, ComplementaryColorGroup = 3,
  HeaderColorGroup, ToolTipColorGroup
}
 
enum  ColorRole {
  TextColor = 0, BackgroundColor = 1, HighlightColor = 2, HoverColor = 3,
  FocusColor = 4, LinkColor = 5, VisitedLinkColor = 6, HighlightedTextColor = 7,
  PositiveTextColor = 8, NeutralTextColor = 9, NegativeTextColor = 10, DisabledTextColor = 11
}
 

Properties

QFont defaultFont
 
QPalette palette
 
QFont smallestFont
 
QString styleSheet
 
QString themeName
 
bool useGlobalSettings
 
QString wallpaperPath
 
- Properties inherited from QObject
 objectName
 

Signals

void defaultFontChanged ()
 
void smallestFontChanged ()
 
void themeChanged ()
 

Public Member Functions

 Theme (const QString &themeName, QObject *parent=nullptr)
 
 Theme (QObject *parent=nullptr)
 
bool adaptiveTransparencyEnabled () const
 
qreal backgroundContrast () const
 
bool backgroundContrastEnabled () const
 
qreal backgroundIntensity () const
 
QString backgroundPath (const QString &image) const
 
qreal backgroundSaturation () const
 
bool blurBehindEnabled () const
 
QColor color (ColorRole role, ColorGroup group=NormalColorGroup) const
 
KSharedConfigPtr colorScheme () const
 
bool currentThemeHasImage (const QString &name) const
 
QFont defaultFont () const
 
bool findInCache (const QString &key, QPixmap &pix, unsigned int lastModified=0)
 
bool findInRectsCache (const QString &image, const QString &element, QRectF &rect) const
 
QString imagePath (const QString &name) const
 
void insertIntoCache (const QString &key, const QPixmap &pix)
 
void insertIntoCache (const QString &key, const QPixmap &pix, const QString &id)
 
void insertIntoRectsCache (const QString &image, const QString &element, const QRectF &rect)
 
void invalidateRectsCache (const QString &image)
 
QStringList listCachedRectKeys (const QString &image) const
 
KPluginMetaData metadata () const
 
Q_INVOKABLE QSizeF mSize (const QFont &font=QGuiApplication::font()) const
 
QPalette palette () const
 
KPluginInfo pluginInfo () const
 
void releaseRectsCache (const QString &image)
 
void setCacheLimit (int kbytes)
 
void setThemeName (const QString &themeName)
 
void setUseGlobalSettings (bool useGlobal)
 
QFont smallestFont () const
 
QString styleSheet (const QString &css=QString()) const
 
QString themeName () const
 
bool useGlobalSettings () const
 
QString wallpaperPath (const QSize &size=QSize()) const
 
Q_INVOKABLE QString wallpaperPathForSize (int width=-1, int height=-1) const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QPalette globalPalette ()
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

Interface to the Plasma theme.

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.

Definition at line 42 of file theme.h.

Member Enumeration Documentation

◆ ColorRole

Enumerator
TextColor 

the text color to be used by items resting on the background

BackgroundColor 

the default background color

HighlightColor 

the text highlight color to be used by items resting on the background

HoverColor 

color for hover effect on view

FocusColor 

color for focus effect on view

LinkColor 

color for clickable links

VisitedLinkColor 

color visited clickable links

HighlightedTextColor 

color contrasting with HighlightColor, to be used for instance with

PositiveTextColor 

color of foreground objects with a "positive message" connotation (usually green)

NeutralTextColor 

color of foreground objects with a "neutral message" connotation (usually yellow)

NegativeTextColor 

color of foreground objects with a "negative message" connotation (usually red)

DisabledTextColor 

color of disabled text

Since
5.64

Definition at line 60 of file theme.h.

Constructor & Destructor Documentation

◆ Theme() [1/2]

Theme::Theme ( QObject parent = nullptr)
explicit

Default constructor.

It will be the global theme configured in plasmarc

Parameters
parentthe parent object

Definition at line 35 of file theme.cpp.

◆ Theme() [2/2]

Theme::Theme ( const QString themeName,
QObject parent = nullptr 
)
explicit

Construct a theme.

It will be a custom theme instance of themeName.

Parameters
themeNamethe name of the theme to create
parentthe parent object
Since
4.3

Definition at line 53 of file theme.cpp.

Member Function Documentation

◆ adaptiveTransparencyEnabled()

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
Since
5.20

Definition at line 417 of file theme.cpp.

◆ backgroundContrast()

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
Since
5.0
See also
backgroundContrastEnabled

Definition at line 422 of file theme.cpp.

◆ backgroundContrastEnabled()

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
Since
5.0

Definition at line 412 of file theme.cpp.

◆ backgroundIntensity()

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
Since
5.0
See also
backgroundContrastEnabled

Definition at line 437 of file theme.cpp.

◆ backgroundSaturation()

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
Since
5.0
See also
backgroundContrastEnabled

Definition at line 449 of file theme.cpp.

◆ blurBehindEnabled()

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 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
Since
5.57

Definition at line 457 of file theme.cpp.

◆ color()

QColor Theme::color ( ColorRole  role,
ColorGroup  group = NormalColorGroup 
) const

Returns the text color to be used by items resting on the background.

Parameters
rolewhich role (usage pattern) to get the color for
groupwhich group we want a color of

Definition at line 252 of file theme.cpp.

◆ colorScheme()

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.

Definition at line 247 of file theme.cpp.

◆ currentThemeHasImage()

bool Theme::currentThemeHasImage ( const QString name) const

Checks if this theme has an image named in a certain way.

Parameters
namethe 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

Definition at line 233 of file theme.cpp.

◆ defaultFont()

QFont Plasma::Theme::defaultFont ( ) const
Returns
The default application font
Since
5.0

◆ defaultFontChanged

void Plasma::Theme::defaultFontChanged ( )
signal

Notifier for change of defaultFont property.

◆ findInCache()

bool Theme::findInCache ( const QString key,
QPixmap pix,
unsigned int  lastModified = 0 
)

This is an overloaded member provided to check with file timestamp where cache is still valid.

Parameters
keythe name to use in the cache for this image
pixthe pixmap object to populate with the resulting data if found
lastModifiedif non-zero, the time stamp is also checked on the file, and must be newer than the timestamp to be loaded
Note
Since KF 5.75, a lastModified value of 0 is deprecated. If used, it will now always return false. Use a proper file timestamp instead so modification can be properly tracked.
Returns
true when pixmap was found and loaded from cache, false otherwise
Since
4.3

Definition at line 274 of file theme.cpp.

◆ findInRectsCache()

bool Theme::findInRectsCache ( const QString image,
const QString element,
QRectF rect 
) const

Tries to load the rect of a sub element from a disk cache.

Parameters
imagepath of the image we want to check
elementsub element we want to retrieve
rectoutput parameter of the element rect found in cache if not found or if we are sure it doesn't exist it will be QRect()
Returns
true if the element was found in cache or if we are sure the element doesn't exist

Definition at line 326 of file theme.cpp.

◆ imagePath()

QString Theme::imagePath ( const QString name) const

Retrieve the path for an SVG image in the current theme.

Parameters
namethe 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

Definition at line 124 of file theme.cpp.

◆ insertIntoCache() [1/2]

void Theme::insertIntoCache ( const QString key,
const QPixmap pix 
)

Insert specified pixmap into the cache.

If the cache already contains pixmap with the specified key then it is overwritten.

Parameters
keythe name to use in the cache for this pixmap
pixthe pixmap data to store in the cache

Definition at line 306 of file theme.cpp.

◆ insertIntoCache() [2/2]

void Theme::insertIntoCache ( const QString key,
const QPixmap pix,
const QString id 
)

Insert specified pixmap into the cache.

If the cache already contains pixmap with the specified key then it is overwritten. The actual insert is delayed for optimization reasons and the id parameter is used to discard repeated inserts in the delay time, useful when for instance the graphics to insert comes from a quickly resizing object: the frames between the start and destination sizes aren't useful in the cache and just cause overhead.

Parameters
keythe name to use in the cache for this pixmap
pixthe pixmap data to store in the cache
ida name that identifies the caller class of this function in an unique fashion. This is needed to limit disk writes of the cache. If an image with the same id changes quickly, only the last size where insertIntoCache was called is actually stored on disk
Since
4.3

Definition at line 313 of file theme.cpp.

◆ insertIntoRectsCache()

void Theme::insertIntoRectsCache ( const QString image,
const QString element,
const QRectF rect 
)

Inserts a rectangle of a sub element of an image into a disk cache.

Parameters
imagepath of the image we want to insert information
elementsub element we want insert the rect
rectelement rectangle

Definition at line 350 of file theme.cpp.

◆ invalidateRectsCache()

void Theme::invalidateRectsCache ( const QString image)

Discards all the information about a given image from the rectangle disk cache.

Parameters
imagethe path to the image the cache is associated with

Definition at line 366 of file theme.cpp.

◆ listCachedRectKeys()

QStringList Theme::listCachedRectKeys ( const QString image) const

Returns a list of all keys of cached rects for the given image.

Parameters
imagepath of the image for which the keys should be returned
Returns
a QStringList whose elements are the entry keys in the rects cache
Since
4.6

Definition at line 341 of file theme.cpp.

◆ metadata()

KPluginMetaData Theme::metadata ( ) const
Returns
plugin metadata for this theme, with information such as name, description, author, website etc
Since
5.95

Definition at line 392 of file theme.cpp.

◆ mSize()

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:
    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).
    Parameters
    fontThe font to use for the metrics.
    Returns
    The size of the letter "M" as rendered on the screen with the given font.
    Since
    5.0

Definition at line 407 of file theme.cpp.

◆ palette()

QPalette Plasma::Theme::palette ( ) const

Returns a QPalette with the colors set as defined by the theme.

Since
5.68

◆ pluginInfo()

KPluginInfo Theme::pluginInfo ( ) const
Returns
plugin info for this theme, with information such as name, description, author, website etc
Since
5.0
Deprecated:
since 5.67, use KPluginMetaData

Definition at line 386 of file theme.cpp.

◆ releaseRectsCache()

void Theme::releaseRectsCache ( const QString image)

Frees up memory used by cached information for a given image without removing the permanent record of it on disk.

See also
invalidateRectsCache
Parameters
imagethe path to the image the cache is associated with

Definition at line 371 of file theme.cpp.

◆ setCacheLimit()

void Theme::setCacheLimit ( int  kbytes)

Sets the maximum size of the cache (in kilobytes).

If cache gets bigger the limit then some entries are removed Setting cache limit to 0 disables automatic cache size limiting.

Note that the cleanup might not be done immediately, so the cache might temporarily (for a few seconds) grow bigger than the limit.

Definition at line 378 of file theme.cpp.

◆ setThemeName()

void Theme::setThemeName ( const QString themeName)

Sets the current theme being used.

Definition at line 92 of file theme.cpp.

◆ setUseGlobalSettings()

void Theme::setUseGlobalSettings ( bool  useGlobal)

Tells the theme whether to follow the global settings or use application specific settings.

Parameters
useGlobalpass in true to follow the global settings

Definition at line 257 of file theme.cpp.

◆ smallestFont()

QFont Plasma::Theme::smallestFont ( ) const
Returns
The smallest readable font
Since
5.0

◆ smallestFontChanged

void Plasma::Theme::smallestFontChanged ( )
signal

Notifier for change of smallestFont property.

◆ styleSheet()

QString Theme::styleSheet ( const QString css = QString()) const

Provides a Plasma::Theme-themed stylesheet for hybrid (web / native Plasma) widgets.

You can use this method to retrieve a basic default stylesheet, or to theme your custom stylesheet you use for example in Plasma::WebView. The QString you can pass into this method does not have to be a valid stylesheet, in fact you can use this method to replace color placeholders with the theme's color in any QString.

In order to use this method with a custom stylesheet, just put for example textcolor in your QString and it will be replaced with the theme's text (or foreground) color.

Just like in many other methods for retrieving theme information, do not forget to update your stylesheet upon the themeChanged() signal.

The following tags will be replaced by corresponding colors from Plasma::Theme:

textcolor backgroundcolor buttonbackgroundcolor

link activatedlink hoveredlink visitedlink

fontfamily fontsize smallfontsize

Parameters
cssa stylesheet to theme, leave empty for a default stylesheet containing theming for some commonly used elements, body text and links, for example.
Returns
a piece of CSS that sets the most commonly used style elements to a theme matching Plasma::Theme.
Since
4.5

Definition at line 165 of file theme.cpp.

◆ themeChanged

void Plasma::Theme::themeChanged ( )
signal

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.

◆ themeName()

QString Plasma::Theme::themeName ( ) const
Returns
the name of the theme.

◆ useGlobalSettings()

bool Plasma::Theme::useGlobalSettings ( ) const
Returns
true if the global settings are followed, false if application specific settings are used.

◆ wallpaperPath()

QString Theme::wallpaperPath ( const QSize size = QSize()) const

Retrieves the default wallpaper associated with this theme.

Parameters
sizethe 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

Definition at line 184 of file theme.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:18:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.