diff --git a/src/kcapacitybar.h b/src/kcapacitybar.h --- a/src/kcapacitybar.h +++ b/src/kcapacitybar.h @@ -64,6 +64,12 @@ }; Q_ENUM(DrawTextMode) + enum State { + Neutral = 0, /// Allow the capacity bar to reflect a neutral state (default) + Positive, /// Allow the capacity bar to reflect a positive state, for instance filling in green + Negative /// Allow the capacity bar to reflect a negative state, for instance filling in red + }; + Q_ENUM(State) /** * Constructs a capacity bar with DrawTextOutline as draw text mode. @@ -110,6 +116,18 @@ */ QString text() const; + /** + * Allow to change the state of the KCapacityBar + * @see KCapacityBar::State + */ + void setState(KCapacityBar::State newState); + + /** + * Returns the state of the KCapacityBar + * @see KCapacityBar::State + */ + KCapacityBar::State state() const; + /** * When the capacity bar is non-continuous, sets whether the last block * shown should be drawn full or can be cut off (depending on the capacity diff --git a/src/kcapacitybar.cpp b/src/kcapacitybar.cpp --- a/src/kcapacitybar.cpp +++ b/src/kcapacitybar.cpp @@ -47,7 +47,8 @@ , barHeight(12) , horizontalTextAlignment(Qt::AlignCenter) , ce_capacityBar(QStyle::ControlElement(0)) - , drawTextMode(drawTextMode) {} + , drawTextMode(drawTextMode) + , state(State::Neutral) {} ~Private() {} @@ -60,6 +61,7 @@ QStyle::ControlElement ce_capacityBar; KCapacityBar::DrawTextMode drawTextMode; + State state; }; KCapacityBar::KCapacityBar(QWidget *parent) @@ -110,6 +112,17 @@ return d->text; } +void KCapacityBar::setState(KCapacityBar::State newState) +{ + d->state = newState; + update(); +} + +KCapacityBar::State KCapacityBar::state() const +{ + return d->state; +} + void KCapacityBar::setFillFullBlocks(bool fillFullBlocks) { d->fillFullBlocks = fillFullBlocks; @@ -265,8 +278,20 @@ internalBar.quadTo(left - roundMargin / 2, drawRect.height() / 2, left + roundMargin / 4, 0); QLinearGradient fillInternalBar(left, 0, right, 0); + QColor fillInternalBarColor; + switch (d->state) { + case Neutral: + fillInternalBarColor = palette().window().color(); + break; + case Positive: + fillInternalBarColor = Qt::green; + break; + case Negative: + fillInternalBarColor = Qt::red; + break; + } fillInternalBar.setColorAt(0, palette().window().color().darker(MidShade)); - fillInternalBar.setColorAt(0.5, palette().window().color().darker(LightShade)); + fillInternalBar.setColorAt(0.5, fillInternalBarColor.light(LightShade)); fillInternalBar.setColorAt(1, palette().window().color().darker(MidShade)); if (d->drawTextMode == KCapacityBar::DrawTextInline) { @@ -322,16 +347,16 @@ p->save(); p->setClipping(false); QRadialGradient topGradient(QPointF(rect.width() / 2, drawRect.top()), rect.width() / 2); - const QColor fillTopColor = palette().window().color().darker(LightShade); + QColor fillTopColor = palette().window().color().darker(LightShade); topGradient.setColorAt(0, QColor(fillTopColor.red(), fillTopColor.green(), fillTopColor.blue(), 127)); topGradient.setColorAt(1, Qt::transparent); p->fillRect(QRect(rect.left(), rect.top() + drawRect.top(), rect.width(), 2), topGradient); p->restore(); p->save(); p->setClipRect(QRect(-1, 0, rect.width(), drawRect.height() / 2), Qt::ReplaceClip); QLinearGradient glassGradient(0, -5, 0, drawRect.height()); - const QColor fillGlassColor = palette().base().color(); + QColor fillGlassColor= palette().base().color(); glassGradient.setColorAt(0, QColor(fillGlassColor.red(), fillGlassColor.green(), fillGlassColor.blue(), 255)); glassGradient.setColorAt(1, Qt::transparent); p->fillPath(internalBar, glassGradient); diff --git a/src/kmessagewidget.cpp b/src/kmessagewidget.cpp --- a/src/kmessagewidget.cpp +++ b/src/kmessagewidget.cpp @@ -315,7 +315,7 @@ ensurePolished(); return QFrame::heightForWidth(width); } -#include + void KMessageWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event)