consolidate color and font methods into one method for each with a role enumeration

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800334
This commit is contained in:
Aaron J. Seigo 2008-04-23 22:36:00 +00:00
parent 7f09f15378
commit d28a4c277a
5 changed files with 40 additions and 23 deletions

View File

@ -89,7 +89,7 @@ protected:
Q_UNUSED(widget)
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QColor wash = Plasma::Theme::defaultTheme()->backgroundColor();
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
wash.setAlphaF(.6);
painter->fillPath(parentItem()->shape(), wash);
painter->restore();

View File

@ -173,7 +173,7 @@ class Svg::Private
// Apply current color scheme if the svg asks for it
if (applyColors) {
QImage itmp = p.toImage();
KIconEffect::colorize(itmp, Theme::defaultTheme()->backgroundColor(), 1.0);
KIconEffect::colorize(itmp, Theme::defaultTheme()->color(Theme::BackgroundColor), 1.0);
p = p.fromImage(itmp);
}

View File

@ -260,26 +260,30 @@ KSharedConfigPtr Theme::colorScheme() const
return d->colors;
}
QColor Theme::textColor() const
QColor Theme::color(ColorRole role) const
{
KColorScheme colorScheme(QPalette::Active, KColorScheme::Window, Theme::defaultTheme()->colorScheme());
return colorScheme.foreground(KColorScheme::NormalText).color();
switch (role) {
case TextColor:
return colorScheme.foreground(KColorScheme::NormalText).color();
break;
case BackgroundColor:
return colorScheme.background().color();
break;
}
}
QColor Theme::backgroundColor() const
{
KColorScheme colorScheme(QPalette::Active, KColorScheme::Window, Theme::defaultTheme()->colorScheme());
return colorScheme.background().color();
}
void Theme::setFont(const QFont &font)
void Theme::setFont(const QFont &font, FontRole role)
{
Q_UNUSED(role)
d->generalFont = font;
}
QFont Theme::font() const
QFont Theme::font(FontRole role) const
{
//TODO: allow this to be overridden with a plasma specific font?
Q_UNUSED(role)
return d->generalFont;
}

29
theme.h
View File

@ -53,6 +53,17 @@ class PLASMA_EXPORT Theme : public QObject
Q_PROPERTY( QString themeName READ themeName )
public:
enum ColorRole
{
TextColor = 0 /**< the text color to be used by items resting on the background */,
BackgroundColor /**< the default background color */
};
enum FontRole
{
DefaultFont = 0 /**< The standard text font */
};
/**
* Singleton pattern accessor
**/
@ -106,24 +117,26 @@ class PLASMA_EXPORT Theme : public QObject
/**
* Returns the text color to be used by items resting on the background
*
* @arg role which role (usage pattern) to get the color for
*/
Q_INVOKABLE QColor textColor() const;
/**
* Returns the background color to be used by items resting on the background
*/
Q_INVOKABLE QColor backgroundColor() const;
Q_INVOKABLE QColor color(ColorRole role) const;
/**
* Sets the default font to be used with themed items. Defaults to
* the application wide default font.
*
* @arg font the new font
* @arg role which role (usage pattern) to set the font for
*/
Q_INVOKABLE void setFont(const QFont &font);
Q_INVOKABLE void setFont(const QFont &font, FontRole role = DefaultFont);
/**
* Returns the font to be used by themed items
*
* @arg role which role (usage pattern) to get the font for
*/
Q_INVOKABLE QFont font() const;
Q_INVOKABLE QFont font(FontRole role) const;
/**
* Returns the font metrics for the font to be used by themed items

View File

@ -79,8 +79,8 @@ Icon::Private::~Private()
void Icon::readColors()
{
d->textColor = Plasma::Theme::defaultTheme()->textColor();
d->shadowColor = Plasma::Theme::defaultTheme()->backgroundColor();
d->textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
d->shadowColor = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
}