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
This commit is contained in:
Rob Scheepmaker 2009-04-15 22:21:29 +00:00
parent 7df3fb6228
commit fac4e005d0
3 changed files with 73 additions and 7 deletions

View File

@ -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<QGraphicsWidget*>(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;

View File

@ -23,6 +23,7 @@
#include <QPainter>
#include <QTimer>
#include <QGraphicsSceneResizeEvent>
#include <QTextOption>
//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<int, QPixmap> 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 <busywidget.moc>

View File

@ -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);