use property animation instead of timer event for circular progress rotation
This commit is contained in:
parent
fff7078542
commit
37d58b4a75
|
@ -12,7 +12,6 @@ CircularProgressPrivate::CircularProgressPrivate(CircularProgress *q)
|
|||
delegate(0),
|
||||
progressType(Material::IndeterminateProgress),
|
||||
size(64),
|
||||
angle(0),
|
||||
penWidth(6.25),
|
||||
useThemeColors(true)
|
||||
{
|
||||
|
@ -31,7 +30,6 @@ void CircularProgressPrivate::init()
|
|||
QSizePolicy policy(QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::MinimumExpanding);
|
||||
q->setSizePolicy(policy);
|
||||
q->startTimer(4);
|
||||
|
||||
QParallelAnimationGroup *group = new QParallelAnimationGroup(q);
|
||||
group->setLoopCount(-1);
|
||||
|
@ -64,6 +62,15 @@ void CircularProgressPrivate::init()
|
|||
|
||||
group->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(q);
|
||||
animation->setPropertyName("angle");
|
||||
animation->setTargetObject(delegate);
|
||||
animation->setStartValue(0);
|
||||
animation->setEndValue(719);
|
||||
animation->setDuration(2050);
|
||||
|
||||
group->addAnimation(animation);
|
||||
|
||||
group->start();
|
||||
}
|
||||
|
||||
|
@ -178,7 +185,7 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
|||
painter.drawRect(rect());
|
||||
|
||||
painter.translate(width()/2, height()/2);
|
||||
painter.rotate(d->angle);
|
||||
painter.rotate(d->delegate->angle());
|
||||
|
||||
QPen pen;
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
|
@ -202,15 +209,3 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
void CircularProgress::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
Q_D(CircularProgress);
|
||||
|
||||
if (++d->angle > 360) {
|
||||
d->angle -= 360;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ public:
|
|||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<CircularProgressPrivate> d_ptr;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "circularprogress_internal.h"
|
||||
#include "circularprogress.h"
|
||||
|
||||
CircularProgressDelegate::CircularProgressDelegate(CircularProgress *parent)
|
||||
: QObject(parent),
|
||||
progress(parent),
|
||||
_dashOffset(0),
|
||||
_dashLength(89)
|
||||
_dashLength(89),
|
||||
_angle(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -13,24 +13,3 @@ CircularProgressDelegate::~CircularProgressDelegate()
|
|||
{
|
||||
}
|
||||
|
||||
void CircularProgressDelegate::setDashOffset(qreal offset)
|
||||
{
|
||||
_dashOffset = offset;
|
||||
progress->update();
|
||||
}
|
||||
|
||||
qreal CircularProgressDelegate::dashOffset() const
|
||||
{
|
||||
return _dashOffset;
|
||||
}
|
||||
|
||||
void CircularProgressDelegate::setDashLength(qreal value)
|
||||
{
|
||||
_dashLength = value;
|
||||
progress->update();
|
||||
}
|
||||
|
||||
qreal CircularProgressDelegate::dashLength() const
|
||||
{
|
||||
return _dashLength;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
#define CIRCULARPROGRESS_INTERNAL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class CircularProgress;
|
||||
#include "circularprogress.h"
|
||||
|
||||
class CircularProgressDelegate : public QObject
|
||||
{
|
||||
|
@ -11,16 +10,20 @@ class CircularProgressDelegate : public QObject
|
|||
|
||||
Q_PROPERTY(qreal dashOffset WRITE setDashOffset READ dashOffset)
|
||||
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
||||
Q_PROPERTY(int angle WRITE setAngle READ angle)
|
||||
|
||||
public:
|
||||
CircularProgressDelegate(CircularProgress *parent);
|
||||
~CircularProgressDelegate();
|
||||
|
||||
void setDashOffset(qreal offset);
|
||||
qreal dashOffset() const;
|
||||
void setDashOffset(qreal offset) { _dashOffset = offset; progress->update(); }
|
||||
qreal dashOffset() const { return _dashOffset; }
|
||||
|
||||
void setDashLength(qreal value);
|
||||
qreal dashLength() const;
|
||||
void setDashLength(qreal value) { _dashLength = value; progress->update(); }
|
||||
qreal dashLength() const { return _dashLength; }
|
||||
|
||||
void setAngle(int angle) { _angle = angle; progress->update(); }
|
||||
int angle() const { return _angle; }
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(CircularProgressDelegate)
|
||||
|
@ -28,6 +31,7 @@ private:
|
|||
CircularProgress *const progress;
|
||||
qreal _dashOffset;
|
||||
qreal _dashLength;
|
||||
int _angle;
|
||||
};
|
||||
|
||||
#endif // CIRCULARPROGRESS_INTERNAL_H
|
||||
|
|
|
@ -22,7 +22,6 @@ public:
|
|||
CircularProgressDelegate *delegate;
|
||||
Material::ProgressType progressType;
|
||||
int size;
|
||||
int angle;
|
||||
qreal penWidth;
|
||||
QColor color;
|
||||
bool useThemeColors;
|
||||
|
|
Loading…
Reference in New Issue