animate halo
This commit is contained in:
parent
24461cddd5
commit
eb7b7dfda1
|
@ -1,5 +1,6 @@
|
|||
#include "slider.h"
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QStringBuilder>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "slider.h"
|
||||
#include <QPainter>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue