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),
|
delegate(0),
|
||||||
progressType(Material::IndeterminateProgress),
|
progressType(Material::IndeterminateProgress),
|
||||||
size(64),
|
size(64),
|
||||||
angle(0),
|
|
||||||
penWidth(6.25),
|
penWidth(6.25),
|
||||||
useThemeColors(true)
|
useThemeColors(true)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +30,6 @@ void CircularProgressPrivate::init()
|
||||||
QSizePolicy policy(QSizePolicy::MinimumExpanding,
|
QSizePolicy policy(QSizePolicy::MinimumExpanding,
|
||||||
QSizePolicy::MinimumExpanding);
|
QSizePolicy::MinimumExpanding);
|
||||||
q->setSizePolicy(policy);
|
q->setSizePolicy(policy);
|
||||||
q->startTimer(4);
|
|
||||||
|
|
||||||
QParallelAnimationGroup *group = new QParallelAnimationGroup(q);
|
QParallelAnimationGroup *group = new QParallelAnimationGroup(q);
|
||||||
group->setLoopCount(-1);
|
group->setLoopCount(-1);
|
||||||
|
@ -64,6 +62,15 @@ void CircularProgressPrivate::init()
|
||||||
|
|
||||||
group->addAnimation(animation);
|
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();
|
group->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +185,7 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
||||||
painter.drawRect(rect());
|
painter.drawRect(rect());
|
||||||
|
|
||||||
painter.translate(width()/2, height()/2);
|
painter.translate(width()/2, height()/2);
|
||||||
painter.rotate(d->angle);
|
painter.rotate(d->delegate->angle());
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setCapStyle(Qt::RoundCap);
|
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:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
const QScopedPointer<CircularProgressPrivate> d_ptr;
|
const QScopedPointer<CircularProgressPrivate> d_ptr;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "circularprogress_internal.h"
|
#include "circularprogress_internal.h"
|
||||||
#include "circularprogress.h"
|
|
||||||
|
|
||||||
CircularProgressDelegate::CircularProgressDelegate(CircularProgress *parent)
|
CircularProgressDelegate::CircularProgressDelegate(CircularProgress *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
progress(parent),
|
progress(parent),
|
||||||
_dashOffset(0),
|
_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
|
#define CIRCULARPROGRESS_INTERNAL_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include "circularprogress.h"
|
||||||
class CircularProgress;
|
|
||||||
|
|
||||||
class CircularProgressDelegate : public QObject
|
class CircularProgressDelegate : public QObject
|
||||||
{
|
{
|
||||||
|
@ -11,16 +10,20 @@ class CircularProgressDelegate : public QObject
|
||||||
|
|
||||||
Q_PROPERTY(qreal dashOffset WRITE setDashOffset READ dashOffset)
|
Q_PROPERTY(qreal dashOffset WRITE setDashOffset READ dashOffset)
|
||||||
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
||||||
|
Q_PROPERTY(int angle WRITE setAngle READ angle)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CircularProgressDelegate(CircularProgress *parent);
|
CircularProgressDelegate(CircularProgress *parent);
|
||||||
~CircularProgressDelegate();
|
~CircularProgressDelegate();
|
||||||
|
|
||||||
void setDashOffset(qreal offset);
|
void setDashOffset(qreal offset) { _dashOffset = offset; progress->update(); }
|
||||||
qreal dashOffset() const;
|
qreal dashOffset() const { return _dashOffset; }
|
||||||
|
|
||||||
void setDashLength(qreal value);
|
void setDashLength(qreal value) { _dashLength = value; progress->update(); }
|
||||||
qreal dashLength() const;
|
qreal dashLength() const { return _dashLength; }
|
||||||
|
|
||||||
|
void setAngle(int angle) { _angle = angle; progress->update(); }
|
||||||
|
int angle() const { return _angle; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(CircularProgressDelegate)
|
Q_DISABLE_COPY(CircularProgressDelegate)
|
||||||
|
@ -28,6 +31,7 @@ private:
|
||||||
CircularProgress *const progress;
|
CircularProgress *const progress;
|
||||||
qreal _dashOffset;
|
qreal _dashOffset;
|
||||||
qreal _dashLength;
|
qreal _dashLength;
|
||||||
|
int _angle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CIRCULARPROGRESS_INTERNAL_H
|
#endif // CIRCULARPROGRESS_INTERNAL_H
|
||||||
|
|
|
@ -22,7 +22,6 @@ public:
|
||||||
CircularProgressDelegate *delegate;
|
CircularProgressDelegate *delegate;
|
||||||
Material::ProgressType progressType;
|
Material::ProgressType progressType;
|
||||||
int size;
|
int size;
|
||||||
int angle;
|
|
||||||
qreal penWidth;
|
qreal penWidth;
|
||||||
QColor color;
|
QColor color;
|
||||||
bool useThemeColors;
|
bool useThemeColors;
|
||||||
|
|
Loading…
Reference in New Issue