diff --git a/src/kcapacitybar.h b/src/kcapacitybar.h --- a/src/kcapacitybar.h +++ b/src/kcapacitybar.h @@ -64,6 +64,16 @@ }; Q_ENUM(DrawTextMode) + /** + * Represents a state of the capacity bar + * @since 5.69 + */ + 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 +120,20 @@ */ QString text() const; + /** + * Allow to change the state of the KCapacityBar + * @see KCapacityBar::State + * @since 5.69 + */ + void setState(KCapacityBar::State newState); + + /** + * Returns the state of the KCapacityBar + * @see KCapacityBar::State + * @since 5.69 + */ + 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) { 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)