diff --git a/components/slider.cpp b/components/slider.cpp index 113d9cb..658ed0c 100644 --- a/components/slider.cpp +++ b/components/slider.cpp @@ -1,5 +1,6 @@ #include "slider.h" #include +#include #include #include #include @@ -10,6 +11,33 @@ Slider::Slider(QWidget *parent) : QAbstractSlider(parent), d_ptr(new SliderPrivate(this)) { + QPropertyAnimation *animation; + + animation = new QPropertyAnimation; + + animation->setPropertyName("haloScaleFactor"); + animation->setTargetObject(this); + animation->setStartValue(0.8); + animation->setEndValue(1); + animation->setDuration(900); + animation->setEasingCurve(QEasingCurve::InOutQuad); + + d_ptr->haloAnimation->addAnimation(animation); + + animation = new QPropertyAnimation; + + animation->setPropertyName("haloScaleFactor"); + animation->setTargetObject(this); + animation->setStartValue(1); + animation->setEndValue(0.8); + animation->setDuration(900); + animation->setEasingCurve(QEasingCurve::InOutQuad); + + d_ptr->haloAnimation->addAnimation(animation); + + d_ptr->haloAnimation->setLoopCount(-1); + d_ptr->haloAnimation->start(); + connect(this, SIGNAL(actionTriggered(int)), this, SLOT(handleAction(int))); } @@ -17,6 +45,21 @@ Slider::~Slider() { } +void Slider::setHaloScaleFactor(qreal factor) +{ + Q_D(Slider); + + d->haloScaleFactor = factor; + update(); +} + +qreal Slider::haloScaleFactor() const +{ + Q_D(const Slider); + + return d->haloScaleFactor; +} + void Slider::handleAction(int action) { Q_D(Slider); diff --git a/components/slider.h b/components/slider.h index 1863364..8e07c35 100644 --- a/components/slider.h +++ b/components/slider.h @@ -10,10 +10,15 @@ class Slider : public QAbstractSlider { Q_OBJECT + Q_PROPERTY(qreal haloScaleFactor WRITE setHaloScaleFactor READ haloScaleFactor) + public: explicit Slider(QWidget *parent = 0); ~Slider(); + void setHaloScaleFactor(qreal factor); + qreal haloScaleFactor() const; + protected slots: void handleAction(int action); diff --git a/components/slider_p.h b/components/slider_p.h index f6d4cb0..a614a1d 100644 --- a/components/slider_p.h +++ b/components/slider_p.h @@ -3,6 +3,7 @@ #include "slider.h" #include +#include #include "lib/style.h" #define THUMB_OUTER_SIZE 35 @@ -15,6 +16,8 @@ class SliderPrivate public: SliderPrivate(Slider *parent) : q_ptr(parent), + haloAnimation(new QSequentialAnimationGroup(parent)), + haloScaleFactor(1), hoverTrack(false), hoverThumb(false), step(false), @@ -90,7 +93,9 @@ public: painter->setRenderHint(QPainter::Antialiasing); - QRectF halo(0, 0, THUMB_OUTER_SIZE, THUMB_OUTER_SIZE); + qreal size = THUMB_OUTER_SIZE * haloScaleFactor; + + QRectF halo(0, 0, size, size); halo.moveCenter(thumbGeometry().center()); painter->drawEllipse(halo); @@ -148,10 +153,12 @@ public: Slider *const q_ptr; - bool hoverTrack; - bool hoverThumb; - bool step; - int stepTo; + QSequentialAnimationGroup *const haloAnimation; + qreal haloScaleFactor; + bool hoverTrack; + bool hoverThumb; + bool step; + int stepTo; }; #endif // SLIDER_P_H