allow setting the background of icon on/off ... a little sad about this, but no time to do something else atm

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=756868
This commit is contained in:
Aaron J. Seigo 2008-01-03 21:22:24 +00:00
parent ac040130bf
commit f07d73ff53
3 changed files with 37 additions and 5 deletions

View File

@ -61,7 +61,8 @@ Icon::Private::Private()
iconSize(48, 48), iconSize(48, 48),
states(Private::NoState), states(Private::NoState),
orientation(Qt::Vertical), orientation(Qt::Vertical),
invertLayout(false) invertLayout(false),
drawBg(false)
{ {
textColor = KColorScheme(QPalette::Active, KColorScheme::Window, textColor = KColorScheme(QPalette::Active, KColorScheme::Window,
Plasma::Theme::self()->colors()).foreground().color(); Plasma::Theme::self()->colors()).foreground().color();
@ -345,6 +346,19 @@ QSizeF Icon::sizeHint() const
return d->currentSize; return d->currentSize;
} }
void Icon::setDrawBackground(bool draw)
{
if (d->drawBg != draw) {
d->drawBg = draw;
update();
}
}
bool Icon::drawBackground() const
{
return d->drawBg;
}
QSizeF Icon::Private::displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const QSizeF Icon::Private::displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const
{ {
if (text.isEmpty() && infoText.isEmpty()) { if (text.isEmpty() && infoText.isEmpty()) {
@ -487,6 +501,10 @@ void Icon::setSvg(const QString &svgFilePath, const QString &elementId)
void Icon::Private::drawBackground(QPainter *painter, IconState state) void Icon::Private::drawBackground(QPainter *painter, IconState state)
{ {
if (!drawBg) {
return;
}
bool darkShadow = shadowColor.value() < 128; bool darkShadow = shadowColor.value() < 128;
QColor shadow = shadowColor; QColor shadow = shadowColor;
@ -780,6 +798,8 @@ QBrush Icon::Private::backgroundBrush(const QStyleOptionGraphicsItem *option) co
void Icon::Private::drawTextItems(QPainter *painter, const QStyleOptionGraphicsItem *option, void Icon::Private::drawTextItems(QPainter *painter, const QStyleOptionGraphicsItem *option,
const QTextLayout &labelLayout, const QTextLayout &infoLayout) const const QTextLayout &labelLayout, const QTextLayout &infoLayout) const
{ {
Q_UNUSED(option)
painter->setPen(textColor); painter->setPen(textColor);
labelLayout.draw(painter, QPointF()); labelLayout.draw(painter, QPointF());

View File

@ -184,6 +184,17 @@ public:
*/ */
QSizeF sizeHint() const; QSizeF sizeHint() const;
/**
* Sets whether or not to draw a background area for the icon
*
* @arg draw true if a background should be drawn or not
*/
void setDrawBackground(bool draw);
/**
* @return true if a background area is to be drawn for the icon
*/
bool drawBackground() const;
public Q_SLOTS: public Q_SLOTS:
/** /**

View File

@ -173,6 +173,7 @@ public:
Qt::Orientation orientation; Qt::Orientation orientation;
int numDisplayLines; int numDisplayLines;
bool invertLayout; bool invertLayout;
bool drawBg;
QSizeF currentSize; QSizeF currentSize;
QList<IconAction*> cornerActions; QList<IconAction*> cornerActions;