tonights shinyness: make meters progress smoothly instead of jump if the change is both large enough and animations are enabled

also: keep the value within the min/max bounds and don't update if the value hasn't actually changed.

svn path=/trunk/KDE/kdelibs/; revision=881849
This commit is contained in:
Aaron J. Seigo 2008-11-09 04:16:27 +00:00
parent 4fa55e5474
commit 271b20924e
2 changed files with 64 additions and 5 deletions

View File

@ -18,10 +18,17 @@
*/
#include "meter.h"
#include "plasma/framesvg.h"
#include <cmath>
#include <kdebug.h>
#include <QPainter>
#include <QTimeLine>
#include <kdebug.h>
#include <kglobalsettings.h>
#include "plasma/animator.h"
#include "plasma/framesvg.h"
namespace Plasma {
@ -32,11 +39,41 @@ public:
: minimum(0),
maximum(100),
value(0),
targetValue(0),
meterType(Meter::AnalogMeter),
image(0),
minrotate(0),
maxrotate(360),
meter(m) {}
meter(m),
movementId(0)
{
}
void progressChanged(qreal progress)
{
bool over = qFuzzyCompare(progress, 1.0);
if (value == targetValue) {
if (!over && movementId) {
Animator::self()->stopCustomAnimation(movementId);
}
return;
}
if (over) {
value = targetValue;
//kDebug() << "done";
movementId = 0;
} else {
int frame = progress * 10;
int delta = targetValue - value;
value += (delta / qreal(10 - frame));
//kDebug() << frame << value << targetValue;
}
meter->update();
}
void paint(QPainter *p, const QString &elementID)
{
@ -174,6 +211,7 @@ public:
int minimum;
int maximum;
int value;
int targetValue;
QStringList labels;
QList<Qt::Alignment> alignments;
QList<QColor> colors;
@ -184,6 +222,7 @@ public:
int minrotate;
int maxrotate;
Meter *meter;
int movementId;
};
Meter::Meter(QGraphicsItem *parent) :
@ -220,8 +259,27 @@ int Meter::minimum() const
void Meter::setValue(int value)
{
if (value == d->targetValue) {
return;
}
d->targetValue = qBound(d->minimum, value, d->maximum);
int delta = abs(d->value - d->targetValue);
if (d->movementId) {
Animator::self()->stopCustomAnimation(d->movementId);
d->movementId = 0;
}
//kDebug() << d->targetValue << d->value << delta;
if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ||
delta / qreal(d->maximum) < 0.1) {
d->value = value;
update();
} else {
d->movementId = Animator::self()->customAnimation(10, 100, Animator::EaseOutCurve,
this, "progressChanged");
}
}
int Meter::value() const

View File

@ -210,6 +210,7 @@ protected:
QWidget *widget = 0);
private:
Q_PRIVATE_SLOT(d, void progressChanged(qreal))
MeterPrivate *const d;
};