adds a busy indicator spinning widget
to be used to indicate a wait of unknown duration svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=879671
This commit is contained in:
parent
babf165d5d
commit
8a29bcddc8
@ -81,6 +81,7 @@ set(plasma_LIB_SRCS
|
||||
widgets/scrollbar.cpp
|
||||
widgets/signalplotter.cpp
|
||||
widgets/slider.cpp
|
||||
widgets/busywidget.cpp
|
||||
widgets/svgwidget.cpp
|
||||
widgets/tabbar.cpp
|
||||
widgets/treeview.cpp
|
||||
@ -196,6 +197,7 @@ install(FILES
|
||||
widgets/scrollbar.h
|
||||
widgets/signalplotter.h
|
||||
widgets/slider.h
|
||||
widgets/busywidget.h
|
||||
widgets/svgwidget.h
|
||||
widgets/tabbar.h
|
||||
widgets/treeview.h
|
||||
@ -257,6 +259,7 @@ includes/Service
|
||||
includes/ServiceJob
|
||||
includes/SignalPlotter
|
||||
includes/Slider
|
||||
includes/BusyWidget
|
||||
includes/Svg
|
||||
includes/SvgWidget
|
||||
includes/TabBar
|
||||
|
1
includes/BusyWidget
Normal file
1
includes/BusyWidget
Normal file
@ -0,0 +1 @@
|
||||
#include "../../plasma/widgets/busywidget.h"
|
130
widgets/busywidget.cpp
Normal file
130
widgets/busywidget.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "busywidget.h"
|
||||
|
||||
//Qt
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsSceneResizeEvent>
|
||||
|
||||
//Plasma
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/svg.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class BusyWidgetPrivate
|
||||
{
|
||||
public:
|
||||
BusyWidgetPrivate()
|
||||
: svg(0),
|
||||
timerId(0)
|
||||
{
|
||||
}
|
||||
|
||||
~BusyWidgetPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void themeChanged()
|
||||
{
|
||||
rotationAngle = svg->elementSize("hint-rotation-angle").width();
|
||||
}
|
||||
|
||||
Svg *svg;
|
||||
QString styleSheet;
|
||||
int timerId;
|
||||
qreal rotationAngle;
|
||||
qreal rotation;
|
||||
};
|
||||
|
||||
|
||||
BusyWidget::BusyWidget(QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
d(new BusyWidgetPrivate)
|
||||
{
|
||||
d->svg = new Plasma::Svg(this);
|
||||
d->svg->setImagePath("widgets/busywidget");
|
||||
d->svg->setContainsMultipleImages(true);
|
||||
d->rotationAngle = d->svg->elementSize("hint-rotation-angle").width();
|
||||
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(themeChanged()));
|
||||
}
|
||||
|
||||
BusyWidget::~BusyWidget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void BusyWidget::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
d->rotation += d->rotationAngle;
|
||||
|
||||
qreal overflow = d->rotation - 360;
|
||||
if ( overflow > 0) {
|
||||
d->rotation = overflow;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void BusyWidget::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
QPointF translatedPos(size().width()/2.0, size().height()/2.0);
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHints(QPainter::SmoothPixmapTransform);
|
||||
painter->translate(translatedPos);
|
||||
|
||||
painter->save();
|
||||
painter->translate(2,2);
|
||||
painter->rotate(d->rotation);
|
||||
d->svg->paint(painter, QRect(-translatedPos.toPoint(), size().toSize()), "busywidget-shadow");
|
||||
painter->restore();
|
||||
|
||||
painter->rotate(d->rotation);
|
||||
d->svg->paint(painter, QRect(-translatedPos.toPoint(), size().toSize()), "busywidget");
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void BusyWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
d->timerId = startTimer(150);
|
||||
}
|
||||
|
||||
void BusyWidget::hideEvent(QHideEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
killTimer(d->timerId);
|
||||
d->timerId = 0;
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include <busywidget.moc>
|
||||
|
73
widgets/busywidget.h
Normal file
73
widgets/busywidget.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_BUSYWIDGET_H
|
||||
#define PLASMA_BUSYWIDGET_H
|
||||
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QFrame;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class BusyWidgetPrivate;
|
||||
|
||||
/**
|
||||
* @class BusyWidget plasma/widgets/spinner.h <Plasma/Widgets/BusyWidget>
|
||||
*
|
||||
* @short A widget that provides a waiting spinner
|
||||
*
|
||||
* A simple spinner widget that can be used to represent a wait of unknown length
|
||||
*/
|
||||
class PLASMA_EXPORT BusyWidget : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new BusyWidget
|
||||
*
|
||||
* @arg parent the parent of this widget
|
||||
*/
|
||||
explicit BusyWidget(QGraphicsWidget *parent = 0);
|
||||
~BusyWidget();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget = 0);
|
||||
|
||||
void showEvent(QShowEvent *event);
|
||||
void hideEvent(QHideEvent *event);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private:
|
||||
BusyWidgetPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
Loading…
x
Reference in New Issue
Block a user