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:
parent
4fa55e5474
commit
271b20924e
@ -18,10 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "meter.h"
|
#include "meter.h"
|
||||||
#include "plasma/framesvg.h"
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <kdebug.h>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
|
#include <kdebug.h>
|
||||||
|
#include <kglobalsettings.h>
|
||||||
|
|
||||||
|
#include "plasma/animator.h"
|
||||||
|
#include "plasma/framesvg.h"
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
@ -32,11 +39,41 @@ public:
|
|||||||
: minimum(0),
|
: minimum(0),
|
||||||
maximum(100),
|
maximum(100),
|
||||||
value(0),
|
value(0),
|
||||||
|
targetValue(0),
|
||||||
meterType(Meter::AnalogMeter),
|
meterType(Meter::AnalogMeter),
|
||||||
image(0),
|
image(0),
|
||||||
minrotate(0),
|
minrotate(0),
|
||||||
maxrotate(360),
|
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)
|
void paint(QPainter *p, const QString &elementID)
|
||||||
{
|
{
|
||||||
@ -174,6 +211,7 @@ public:
|
|||||||
int minimum;
|
int minimum;
|
||||||
int maximum;
|
int maximum;
|
||||||
int value;
|
int value;
|
||||||
|
int targetValue;
|
||||||
QStringList labels;
|
QStringList labels;
|
||||||
QList<Qt::Alignment> alignments;
|
QList<Qt::Alignment> alignments;
|
||||||
QList<QColor> colors;
|
QList<QColor> colors;
|
||||||
@ -184,6 +222,7 @@ public:
|
|||||||
int minrotate;
|
int minrotate;
|
||||||
int maxrotate;
|
int maxrotate;
|
||||||
Meter *meter;
|
Meter *meter;
|
||||||
|
int movementId;
|
||||||
};
|
};
|
||||||
|
|
||||||
Meter::Meter(QGraphicsItem *parent) :
|
Meter::Meter(QGraphicsItem *parent) :
|
||||||
@ -220,8 +259,27 @@ int Meter::minimum() const
|
|||||||
|
|
||||||
void Meter::setValue(int value)
|
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;
|
d->value = value;
|
||||||
update();
|
update();
|
||||||
|
} else {
|
||||||
|
d->movementId = Animator::self()->customAnimation(10, 100, Animator::EaseOutCurve,
|
||||||
|
this, "progressChanged");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Meter::value() const
|
int Meter::value() const
|
||||||
|
@ -210,6 +210,7 @@ protected:
|
|||||||
QWidget *widget = 0);
|
QWidget *widget = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Q_PRIVATE_SLOT(d, void progressChanged(qreal))
|
||||||
MeterPrivate *const d;
|
MeterPrivate *const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user