Plasma::Theme gets API for KWS' background contrast effect

From its api docs:

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
This commit is contained in:
Sebastian Kügler 2014-02-06 00:56:50 +01:00
parent af82f2f0e7
commit 5dd4b51151
4 changed files with 90 additions and 1 deletions

View File

@ -64,7 +64,8 @@ ThemePrivate::ThemePrivate(QObject *parent)
blurActive(false),
isDefault(true),
useGlobal(true),
hasWallpapers(false)
hasWallpapers(false),
backgroundContrastEnabled(true)
{
ThemeConfig config;
cacheTheme = config.cacheTheme();
@ -521,6 +522,20 @@ void ThemePrivate::processWallpaperSettings(KConfigBase *metadata)
defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT);
}
void ThemePrivate::processContrastSettings(KConfigBase* metadata)
{
KConfigGroup cg;
if (metadata->hasGroup("ContrastEffect")) {
cg = KConfigGroup(metadata, "ContrastEffect");
backgroundContrastEnabled = cg.readEntry("enabled", false);
backgroundContrast = cg.readEntry("contrast", 0.45);
backgroundIntensity = cg.readEntry("contrast", 0.45);
backgroundSaturation = cg.readEntry("saturation", 1.7);
} else {
backgroundContrastEnabled = false;
}
}
void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings)
{
QString theme = tempThemeName;
@ -570,6 +585,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
pluginInfo = KPluginInfo(metadataPath);
processWallpaperSettings(&metadata);
processContrastSettings(&metadata);
KConfigGroup cg(&metadata, "Settings");
QString fallback = cg.readEntry("FallbackTheme", QString());

View File

@ -78,6 +78,7 @@ public:
bool useCache();
void setThemeName(const QString &themeName, bool writeSettings);
void processWallpaperSettings(KConfigBase *metadata);
void processContrastSettings(KConfigBase *metadata);
const QString processStyleSheet(const QString &css);
const QString svgStyleSheet();
@ -146,6 +147,11 @@ public:
bool useGlobal : 1;
bool hasWallpapers : 1;
bool cacheTheme : 1;
qreal backgroundContrast;
qreal backgroundIntensity;
qreal backgroundSaturation;
bool backgroundContrastEnabled;
};
}

View File

@ -540,6 +540,26 @@ QSizeF Theme::mSize(const QFont &font) const
return QFontMetrics(font).boundingRect("M").size();
}
bool Theme::backgroundContrastEnabled() const
{
return d->backgroundContrastEnabled;
}
qreal Theme::backgroundContrast() const
{
return d->backgroundContrast;
}
qreal Theme::backgroundIntensity() const
{
return d->backgroundIntensity;
}
qreal Theme::backgroundSaturation() const
{
return d->backgroundSaturation;
}
}

View File

@ -420,6 +420,53 @@ class PLASMA_EXPORT Theme : public QObject
*/
QColor viewFocusColor() 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):
* \code
* [ContrastEffect]
* enabled=true
* contrast=0.45
* intensity=0.45
* saturation=1.7
* \endcode
* @return Whether or not to enable the contrasteffect
* @since 5.0
*/
bool backgroundContrastEnabled() 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.
* @return The contrast provided to the contrasteffect
* @since 5.0
* @see backgroundContrastEnabled
*/
qreal backgroundContrast() 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.
* @return The intensity provided to the contrasteffect
* @since 5.0
* @see backgroundContrastEnabled
*/
qreal backgroundIntensity() 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.
* @return The saturation provided to the contrasteffect
* @since 5.0
* @see backgroundContrastEnabled
*/
qreal backgroundSaturation() const;
/**
* Returns the size of the letter "M" as rendered on the screen with the given font.