2 * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef PLASMA_THEME_H
21 #define PLASMA_THEME_H
23 #include <QtCore/QObject>
24 #include <QtGui/QFont>
25 #include <QtGui/QFontMetrics>
27 #include <ksharedconfig.h>
29 #include <plasma/plasma_export.h>
30 #include <plasma/packagestructure.h>
38 * @class Theme plasma/theme.h <Plasma/Theme>
40 * @short Interface to the Plasma theme
42 * Accessed via Plasma::Theme::defaultTheme() e.g:
44 * QString imagePath = Plasma::Theme::defaultTheme()->imagePath("widgets/clock")
47 * Plasma::Theme provides access to a common and standardized set of graphic
48 * elements stored in SVG format. This allows artists to create single packages
49 * of SVGs that will affect the look and feel of all workspace components.
51 * Plasma::Svg uses Plasma::Theme internally to locate and load the appropriate
52 * SVG data. Alternatively, Plasma::Theme can be used directly to retrieve
53 * file system paths to SVGs by name.
55 class PLASMA_EXPORT Theme
: public QObject
58 Q_PROPERTY(QString themeName READ themeName
)
62 TextColor
= 0, /**< the text color to be used by items resting on the background */
63 HighlightColor
= 1, /**< the text higlight color to be used by items resting
65 BackgroundColor
= 2, /**< the default background color */
66 ButtonTextColor
= 4, /** text color for buttons */
67 ButtonBackgroundColor
= 8 /** background color for buttons*/
71 DefaultFont
= 0, /**< The standard text font */
72 DesktopFont
/**< The standard text font */
76 * Singleton pattern accessor
78 static Theme
*defaultTheme();
81 * Default constructor. Usually you want to use the singleton instead.
83 explicit Theme(QObject
*parent
= 0);
87 * @return a package structure representing a Theme
89 static PackageStructure::Ptr
packageStructure();
92 * Sets the current theme being used.
94 void setThemeName(const QString
&themeName
);
97 * @return the name of the theme.
99 QString
themeName() const;
102 * Retrieve the path for an SVG image in the current theme.
104 * @arg name the name of the file in the theme directory (without the
105 * ".svg" part or a leading slash)
106 * @return the full path to the requested file for the current theme
108 Q_INVOKABLE QString
imagePath(const QString
&name
) const;
111 * Retreives the default wallpaper associated with this theme.
113 * @arg size the target height and width of the wallpaper; if an invalid size
114 * is passed in, then a default size will be provided instead.
115 * @return the full path to the wallpaper image
117 Q_INVOKABLE QString
wallpaperPath(const QSize
&size
= QSize()) const;
120 * Checks if this theme has an image named in a certain way
122 * @arg name the name of the file in the theme directory (without the
123 * ".svg" part or a leading slash)
124 * @return true if the image exists for this theme
126 Q_INVOKABLE
bool currentThemeHasImage(const QString
&name
) const;
129 * Returns the color scheme configurationthat goes along this theme.
130 * This can be used with KStatefulBrush and KColorScheme to determine
131 * the proper colours to use along with the visual elements in this theme.
133 Q_INVOKABLE KSharedConfigPtr
colorScheme() const;
136 * Returns the text color to be used by items resting on the background
138 * @arg role which role (usage pattern) to get the color for
140 Q_INVOKABLE QColor
color(ColorRole role
) const;
143 * Sets the default font to be used with themed items. Defaults to
144 * the application wide default font.
146 * @arg font the new font
147 * @arg role which role (usage pattern) to set the font for
149 Q_INVOKABLE
void setFont(const QFont
&font
, FontRole role
= DefaultFont
);
152 * Returns the font to be used by themed items
154 * @arg role which role (usage pattern) to get the font for
156 Q_INVOKABLE QFont
font(FontRole role
) const;
159 * Returns the font metrics for the font to be used by themed items
161 Q_INVOKABLE QFontMetrics
fontMetrics() const;
164 * Returns if the window manager effects (e.g. translucency, compositing) is active or not
166 Q_INVOKABLE
bool windowTranslucencyEnabled() const;
169 * Tells the theme whether to follow the global settings or use application
172 * @arg useGlobal pass in true to follow the global settings
174 void setUseGlobalSettings(bool useGlobal
);
177 * @return true if the global settings are followed, false if application
178 * specific settings are used.
180 bool useGlobalSettings() const;
183 * Tries to load pixmap with the specified key from cache.
184 * @return true when pixmap was found and loaded from cache, false otherwise
186 bool findInCache(const QString
&key
, QPixmap
&pix
);
189 * Insert specified pixmap into the cache.
190 * If the cache already contains pixmap with the specified key then it is
193 void insertIntoCache(const QString
& key
, const QPixmap
& pix
);
196 * Sets the maximum size of the cache (in kilobytes). If cache gets bigger
197 * the limit then some entries are removed
198 * Setting cache limit to 0 disables automatic cache size limiting.
200 * Note that the cleanup might not be done immediately, so the cache might
201 * temporarily (for a few seconds) grow bigger than the limit.
203 void setCacheLimit(int kbytes
);
206 * Tries to load the rect of a sub element from a disk cache
208 * @arg image path of the image we want to check
209 * @arg element sub element we want to retrieve
210 * @arg rect output parameter of the element rect found in cache
211 * if not found or if we are sure it doesn't exist it will be QRect()
212 * @return true if the element was found in cache or if we are sure the element doesn't exist
214 bool findInRectsCache(const QString
&image
, const QString
&element
, QRectF
&rect
) const;
217 * Inserts a rectangle of a sub element of an image into a disk cache
219 * @arg image path of the image we want to insert information
220 * @arg element sub element we want insert the rect
221 * @arg rect element rectangle
223 void insertIntoRectsCache(const QString
& image
, const QString
&element
, const QRectF
&rect
);
226 * Discards all the information about a given image from the rectangle disk cache
228 * @arg image the path to the image the cache is assoiated with
230 void invalidateRectsCache(const QString
&image
);
233 * Frees up memory used by cached information for a given image without removing
234 * the permenant record of it on disk.
235 * @see invalidateRectsCache
237 * @arg image the path to the image the cache is assoiated with
239 void releaseRectsCache(const QString
&image
);
243 * Emitted when the user changes the theme. SVGs should be reloaded at
250 * Notifies the Theme object that the theme settings have changed
251 * and should be read from the config file
253 void settingsChanged();
256 friend class ThemeSingleton
;
257 friend class ThemePrivate
;
258 ThemePrivate
*const d
;
260 Q_PRIVATE_SLOT(d
, void compositingChanged())
261 Q_PRIVATE_SLOT(d
, void discardCache())
262 Q_PRIVATE_SLOT(d
, void colorsChanged())
265 } // Plasma namespace
267 #endif // multiple inclusion guard