From fac4e005d0c2bd1d0049c8ccabc58d9726ef2446 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Wed, 15 Apr 2009 22:21:29 +0000 Subject: [PATCH] Replace the "i" icon for showing/hiding jobs and notifications in the systray with a spinner widget. When jobs are running it is animated. It also shows one or two numbers in front of the widget to indicate the amount of completed, and the total amount of items. (only one number if all items are completed) Apparently I also had something else uncomitted: showing an eta in the applicationjobs dataengine, and no using double margins in extenderitems. svn path=/trunk/KDE/kdelibs/; revision=954560 --- extenderitem.cpp | 9 ++++----- widgets/busywidget.cpp | 45 ++++++++++++++++++++++++++++++++++++++++-- widgets/busywidget.h | 26 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/extenderitem.cpp b/extenderitem.cpp index 1f7467cb0..33075594e 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -185,8 +185,7 @@ void ExtenderItem::setWidget(QGraphicsItem *widget) QSizeF panelSize(QSizeF(size().width() - d->bgLeft - d->bgRight, d->iconSize + d->dragTop + d->dragBottom)); - widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() + - d->bgTop + d->dragTop)); + widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() + d->bgTop)); d->widget = widget; d->updateSizeHints(); } @@ -796,7 +795,7 @@ void ExtenderItemPrivate::themeChanged() //reposition the widget based on the new margins. if (widget) { widget->setPos(QPointF(bgLeft + dragLeft, panelSize.height() + - bgTop + dragTop)); + bgTop)); } //reposition the toolbox. @@ -832,7 +831,7 @@ void ExtenderItemPrivate::resizeContent(const QSizeF &newSize) if (widget && widget->isWidget()) { QSizeF newWidgetSize(width - bgLeft - bgRight - dragLeft - dragRight, height - dragHandleRect().height() - bgTop - bgBottom - - 2 * dragTop - 2 * dragBottom); + dragTop - dragBottom); QGraphicsWidget *graphicsWidget = static_cast(widget); graphicsWidget->resize(newWidgetSize); @@ -871,7 +870,7 @@ void ExtenderItemPrivate::updateSizeHints() } qreal marginWidth = bgLeft + bgRight + dragLeft + dragRight; - qreal marginHeight = bgTop + bgBottom + 2 * dragTop + 2 * dragBottom; + qreal marginHeight = bgTop + bgBottom + dragTop + dragBottom; QSizeF min; QSizeF pref; diff --git a/widgets/busywidget.cpp b/widgets/busywidget.cpp index c6396252d..b76b68af5 100644 --- a/widgets/busywidget.cpp +++ b/widgets/busywidget.cpp @@ -23,6 +23,7 @@ #include #include #include +#include //Plasma #include "plasma/theme.h" @@ -38,7 +39,8 @@ public: : svg(0), timerId(0), rotationAngle(0), - rotation(0) + rotation(0), + running(true) { } @@ -62,6 +64,8 @@ public: QHash frames; qreal rotationAngle; qreal rotation; + bool running; + QString label; }; @@ -82,6 +86,33 @@ BusyWidget::~BusyWidget() delete d; } +void BusyWidget::setRunning(bool running) +{ + if (running && !d->timerId && isVisible()) { + d->timerId = startTimer(150); + } else if (!running && d->timerId) { + killTimer(d->timerId); + d->timerId = 0; + } + d->running = running; +} + +bool BusyWidget::isRunning() const +{ + return d->running; +} + +void BusyWidget::setLabel(const QString &label) +{ + d->label = label; + update(); +} + +QString BusyWidget::label() const +{ + return d->label; +} + void BusyWidget::timerEvent(QTimerEvent *event) { if (event->timerId() != d->timerId) { @@ -134,12 +165,16 @@ void BusyWidget::paint(QPainter *painter, } painter->drawPixmap(spinnerRect.topLeft(), d->frames[intRotation]); + painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::HighlightColor)); + painter->drawText(boundingRect(), d->label, QTextOption(Qt::AlignVCenter | Qt::AlignHCenter)); } void BusyWidget::showEvent(QShowEvent *event) { Q_UNUSED(event) - d->timerId = startTimer(150); + if (d->running) { + d->timerId = startTimer(150); + } } void BusyWidget::hideEvent(QHideEvent *event) @@ -158,6 +193,12 @@ void BusyWidget::resizeEvent(QGraphicsSceneResizeEvent *event) d->frames.clear(); } +void BusyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event) + emit clicked(); +} + } // namespace Plasma #include diff --git a/widgets/busywidget.h b/widgets/busywidget.h index 1660ba38b..aa73a9fd5 100644 --- a/widgets/busywidget.h +++ b/widgets/busywidget.h @@ -41,6 +41,8 @@ class BusyWidgetPrivate; class PLASMA_EXPORT BusyWidget : public QGraphicsWidget { Q_OBJECT + Q_PROPERTY(bool running READ isRunning WRITE setRunning) + Q_PROPERTY(QString label READ label WRITE setLabel) public: /** @@ -51,6 +53,29 @@ public: explicit BusyWidget(QGraphicsWidget *parent = 0); ~BusyWidget(); + /** + * @param running whether or not the spinner has to be animated. defaults to true. + */ + void setRunning(bool running); + + /** + * @return whether or not the spinner is animated. + */ + bool isRunning() const; + + /** + * @param label a string to be shown in front of the icon. + */ + void setLabel(const QString &label); + + /** + * @param label the string that is shown in front of the icon. + */ + QString label() const; + +Q_SIGNALS: + void clicked(); + protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, @@ -59,6 +84,7 @@ protected: void showEvent(QShowEvent *event); void hideEvent(QHideEvent *event); void resizeEvent(QGraphicsSceneResizeEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); protected Q_SLOTS: void timerEvent(QTimerEvent *event);