diff --git a/components/circularprogress.cpp b/components/circularprogress.cpp index a32be1e..d24c780 100644 --- a/components/circularprogress.cpp +++ b/components/circularprogress.cpp @@ -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(); -} diff --git a/components/circularprogress.h b/components/circularprogress.h index 1472881..a900e88 100644 --- a/components/circularprogress.h +++ b/components/circularprogress.h @@ -37,7 +37,6 @@ public: protected: void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; const QScopedPointer d_ptr; diff --git a/components/circularprogress_internal.cpp b/components/circularprogress_internal.cpp index 1077172..41c0a77 100644 --- a/components/circularprogress_internal.cpp +++ b/components/circularprogress_internal.cpp @@ -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; -} diff --git a/components/circularprogress_internal.h b/components/circularprogress_internal.h index e17627e..05b7935 100644 --- a/components/circularprogress_internal.h +++ b/components/circularprogress_internal.h @@ -2,8 +2,7 @@ #define CIRCULARPROGRESS_INTERNAL_H #include - -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 diff --git a/components/circularprogress_p.h b/components/circularprogress_p.h index d7387a6..30d2714 100644 --- a/components/circularprogress_p.h +++ b/components/circularprogress_p.h @@ -22,7 +22,6 @@ public: CircularProgressDelegate *delegate; Material::ProgressType progressType; int size; - int angle; qreal penWidth; QColor color; bool useThemeColors;