2006-12-17 00:04:44 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_THEME_H
|
|
|
|
#define PLASMA_THEME_H
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
2007-12-19 20:56:39 +01:00
|
|
|
#include <QtGui/QFont>
|
|
|
|
#include <QtGui/QFontMetrics>
|
2006-12-17 00:04:44 +01:00
|
|
|
|
2007-11-06 02:23:15 +01:00
|
|
|
#include <KDE/KSharedConfig>
|
2007-11-04 07:57:42 +01:00
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2008-02-15 11:35:00 +01:00
|
|
|
#include <plasma/packagestructure.h>
|
2007-01-01 05:31:43 +01:00
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
|
|
|
|
class ThemePrivate;
|
|
|
|
|
2007-05-22 03:30:03 +02:00
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class Theme plasma/theme.h <Plasma/Theme>
|
|
|
|
*
|
2007-05-22 03:30:03 +02:00
|
|
|
* @short Interface to the Plasma theme
|
|
|
|
*
|
2008-04-22 23:10:14 +02:00
|
|
|
* Accessed via Plasma::Theme::defaultTheme() e.g:
|
2007-05-22 03:30:03 +02:00
|
|
|
* \code
|
2008-04-22 23:10:14 +02:00
|
|
|
* QString imagePath = Plasma::Theme::defaultTheme()->imagePath("widgets/clock")
|
2007-05-22 03:30:03 +02:00
|
|
|
* \endcode
|
|
|
|
*
|
2007-05-24 20:14:54 +02:00
|
|
|
* 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.
|
2007-05-22 03:30:03 +02:00
|
|
|
*/
|
2007-05-20 22:13:46 +02:00
|
|
|
class PLASMA_EXPORT Theme : public QObject
|
2006-12-17 00:04:44 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2008-10-11 18:19:04 +02:00
|
|
|
Q_PROPERTY(QString themeName READ themeName)
|
2006-12-17 00:04:44 +01:00
|
|
|
|
|
|
|
public:
|
2008-10-11 18:19:04 +02:00
|
|
|
enum ColorRole {
|
|
|
|
TextColor = 0, /**< the text color to be used by items resting on the background */
|
|
|
|
HighlightColor = 1, /**< the text higlight color to be used by items resting
|
|
|
|
on the background */
|
|
|
|
BackgroundColor = 2, /**< the default background color */
|
|
|
|
ButtonTextColor = 4, /** text color for buttons */
|
2008-08-04 23:23:40 +02:00
|
|
|
ButtonBackgroundColor = 8 /** background color for buttons*/
|
2008-04-24 00:36:00 +02:00
|
|
|
};
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
enum FontRole {
|
|
|
|
DefaultFont = 0, /**< The standard text font */
|
2008-10-06 06:10:34 +02:00
|
|
|
DesktopFont /**< The standard text font */
|
2008-04-24 00:36:00 +02:00
|
|
|
};
|
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
/**
|
|
|
|
* Singleton pattern accessor
|
|
|
|
**/
|
2008-10-11 18:19:04 +02:00
|
|
|
static Theme *defaultTheme();
|
2007-03-08 00:27:37 +01:00
|
|
|
|
2007-05-29 09:56:58 +02:00
|
|
|
/**
|
|
|
|
* Default constructor. Usually you want to use the singleton instead.
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
explicit Theme(QObject *parent = 0);
|
2006-12-17 00:04:44 +01:00
|
|
|
~Theme();
|
|
|
|
|
2008-02-15 11:35:00 +01:00
|
|
|
/**
|
|
|
|
* @return a package structure representing a Theme
|
|
|
|
*/
|
2008-02-26 05:08:51 +01:00
|
|
|
static PackageStructure::Ptr packageStructure();
|
2008-02-15 11:35:00 +01:00
|
|
|
|
2007-05-22 03:30:03 +02:00
|
|
|
/**
|
2007-11-04 04:04:55 +01:00
|
|
|
* Sets the current theme being used.
|
|
|
|
*/
|
|
|
|
void setThemeName(const QString &themeName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the name of the theme.
|
2007-05-22 03:30:03 +02:00
|
|
|
*/
|
2006-12-17 00:04:44 +01:00
|
|
|
QString themeName() const;
|
2007-05-24 20:14:54 +02:00
|
|
|
|
2007-05-22 03:30:03 +02:00
|
|
|
/**
|
2007-05-29 09:56:58 +02:00
|
|
|
* Retrieve the path for an SVG image in the current theme.
|
|
|
|
*
|
|
|
|
* @arg name the name of the file in the theme directory (without the
|
|
|
|
* ".svg" part or a leading slash)
|
2008-04-13 15:23:39 +02:00
|
|
|
* @return the full path to the requested file for the current theme
|
2007-05-22 03:30:03 +02:00
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
Q_INVOKABLE QString imagePath(const QString &name) const;
|
2008-06-28 20:57:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retreives the default wallpaper associated with this theme.
|
2008-10-11 18:19:04 +02:00
|
|
|
*
|
2008-06-28 20:57:12 +02:00
|
|
|
* @arg size the target height and width of the wallpaper; if an invalid size
|
|
|
|
* is passed in, then a default size will be provided instead.
|
|
|
|
* @return the full path to the wallpaper image
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
Q_INVOKABLE QString wallpaperPath(const QSize &size = QSize()) const;
|
2006-12-17 00:04:44 +01:00
|
|
|
|
2008-06-04 19:44:37 +02:00
|
|
|
/**
|
|
|
|
* Checks if this theme has an image named in a certain way
|
|
|
|
*
|
|
|
|
* @arg name the name of the file in the theme directory (without the
|
|
|
|
* ".svg" part or a leading slash)
|
|
|
|
* @return true if the image exists for this theme
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
Q_INVOKABLE bool currentThemeHasImage(const QString &name) const;
|
2008-06-04 19:44:37 +02:00
|
|
|
|
2007-11-04 07:57:42 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-04-16 17:53:16 +02:00
|
|
|
Q_INVOKABLE KSharedConfigPtr colorScheme() const;
|
2007-11-04 07:57:42 +01:00
|
|
|
|
2007-11-27 22:56:47 +01:00
|
|
|
/**
|
|
|
|
* Returns the text color to be used by items resting on the background
|
2008-04-24 00:36:00 +02:00
|
|
|
*
|
|
|
|
* @arg role which role (usage pattern) to get the color for
|
2007-11-27 22:56:47 +01:00
|
|
|
*/
|
2008-04-24 00:36:00 +02:00
|
|
|
Q_INVOKABLE QColor color(ColorRole role) const;
|
2008-01-08 02:43:13 +01:00
|
|
|
|
2007-12-21 00:44:08 +01:00
|
|
|
/**
|
|
|
|
* Sets the default font to be used with themed items. Defaults to
|
|
|
|
* the application wide default font.
|
2008-04-24 00:36:00 +02:00
|
|
|
*
|
|
|
|
* @arg font the new font
|
|
|
|
* @arg role which role (usage pattern) to set the font for
|
2007-12-21 00:44:08 +01:00
|
|
|
*/
|
2008-04-24 00:36:00 +02:00
|
|
|
Q_INVOKABLE void setFont(const QFont &font, FontRole role = DefaultFont);
|
2007-12-21 00:44:08 +01:00
|
|
|
|
2007-12-19 20:56:39 +01:00
|
|
|
/**
|
|
|
|
* Returns the font to be used by themed items
|
2008-04-24 00:36:00 +02:00
|
|
|
*
|
|
|
|
* @arg role which role (usage pattern) to get the font for
|
2007-12-19 20:56:39 +01:00
|
|
|
*/
|
2008-04-24 00:36:00 +02:00
|
|
|
Q_INVOKABLE QFont font(FontRole role) const;
|
2007-12-19 20:56:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the font metrics for the font to be used by themed items
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE QFontMetrics fontMetrics() const;
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
/**
|
2008-04-24 00:55:30 +02:00
|
|
|
* Returns if the window manager effects (e.g. translucency, compositing) is active or not
|
2008-03-05 22:03:27 +01:00
|
|
|
*/
|
2008-04-24 00:55:30 +02:00
|
|
|
Q_INVOKABLE bool windowTranslucencyEnabled() const;
|
2008-03-05 22:03:27 +01:00
|
|
|
|
2008-05-12 06:53:13 +02:00
|
|
|
/**
|
|
|
|
* Tells the theme whether to follow the global settings or use application
|
|
|
|
* specific settings
|
|
|
|
*
|
|
|
|
* @arg useGlobal pass in true to follow the global settings
|
|
|
|
*/
|
|
|
|
void setUseGlobalSettings(bool useGlobal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the global settings are followed, false if application
|
|
|
|
* specific settings are used.
|
|
|
|
*/
|
|
|
|
bool useGlobalSettings() const;
|
|
|
|
|
2008-10-15 22:55:07 +02:00
|
|
|
/**
|
|
|
|
* Tries to load pixmap with the specified key from cache.
|
|
|
|
* @return true when pixmap was found and loaded from cache, false otherwise
|
|
|
|
**/
|
|
|
|
bool findInCache(const QString &key, QPixmap &pix);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert specified pixmap into the cache.
|
|
|
|
* If the cache already contains pixmap with the specified key then it is
|
|
|
|
* overwritten.
|
|
|
|
**/
|
|
|
|
void insertIntoCache(const QString& key, const QPixmap& pix);
|
|
|
|
|
2008-10-17 04:26:26 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
|
|
|
void setCacheLimit(int kbytes);
|
|
|
|
|
2008-10-16 20:25:20 +02:00
|
|
|
bool findInRectsCache(const QString &image, const QString &element, QRectF &rect) const;
|
|
|
|
void insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect);
|
|
|
|
void invalidateRectsCache(const QString& image);
|
|
|
|
|
2007-04-22 11:35:04 +02:00
|
|
|
Q_SIGNALS:
|
2007-05-29 09:56:58 +02:00
|
|
|
/**
|
|
|
|
* Emitted when the user changes the theme. SVGs should be reloaded at
|
|
|
|
* that point
|
|
|
|
*/
|
2008-04-23 10:35:35 +02:00
|
|
|
void themeChanged();
|
2006-12-17 00:04:44 +01:00
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Notifies the Theme object that the theme settings have changed
|
|
|
|
* and should be read from the config file
|
|
|
|
**/
|
|
|
|
void settingsChanged();
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
private:
|
2008-04-23 06:50:44 +02:00
|
|
|
friend class ThemeSingleton;
|
2008-07-01 20:56:43 +02:00
|
|
|
friend class ThemePrivate;
|
2008-10-11 18:19:04 +02:00
|
|
|
ThemePrivate *const d;
|
2008-04-24 00:55:30 +02:00
|
|
|
|
|
|
|
Q_PRIVATE_SLOT(d, void compositingChanged())
|
2006-12-17 00:04:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|
|
|
|
|