animate halo
This commit is contained in:
parent
24461cddd5
commit
eb7b7dfda1
|
@ -1,5 +1,6 @@
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -10,6 +11,33 @@ Slider::Slider(QWidget *parent)
|
||||||
: QAbstractSlider(parent),
|
: QAbstractSlider(parent),
|
||||||
d_ptr(new SliderPrivate(this))
|
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)));
|
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)
|
void Slider::handleAction(int action)
|
||||||
{
|
{
|
||||||
Q_D(Slider);
|
Q_D(Slider);
|
||||||
|
|
|
@ -10,10 +10,15 @@ class Slider : public QAbstractSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(qreal haloScaleFactor WRITE setHaloScaleFactor READ haloScaleFactor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Slider(QWidget *parent = 0);
|
explicit Slider(QWidget *parent = 0);
|
||||||
~Slider();
|
~Slider();
|
||||||
|
|
||||||
|
void setHaloScaleFactor(qreal factor);
|
||||||
|
qreal haloScaleFactor() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void handleAction(int action);
|
void handleAction(int action);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QSequentialAnimationGroup>
|
||||||
#include "lib/style.h"
|
#include "lib/style.h"
|
||||||
|
|
||||||
#define THUMB_OUTER_SIZE 35
|
#define THUMB_OUTER_SIZE 35
|
||||||
|
@ -15,6 +16,8 @@ class SliderPrivate
|
||||||
public:
|
public:
|
||||||
SliderPrivate(Slider *parent)
|
SliderPrivate(Slider *parent)
|
||||||
: q_ptr(parent),
|
: q_ptr(parent),
|
||||||
|
haloAnimation(new QSequentialAnimationGroup(parent)),
|
||||||
|
haloScaleFactor(1),
|
||||||
hoverTrack(false),
|
hoverTrack(false),
|
||||||
hoverThumb(false),
|
hoverThumb(false),
|
||||||
step(false),
|
step(false),
|
||||||
|
@ -90,7 +93,9 @@ public:
|
||||||
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
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());
|
halo.moveCenter(thumbGeometry().center());
|
||||||
|
|
||||||
painter->drawEllipse(halo);
|
painter->drawEllipse(halo);
|
||||||
|
@ -148,10 +153,12 @@ public:
|
||||||
|
|
||||||
Slider *const q_ptr;
|
Slider *const q_ptr;
|
||||||
|
|
||||||
bool hoverTrack;
|
QSequentialAnimationGroup *const haloAnimation;
|
||||||
bool hoverThumb;
|
qreal haloScaleFactor;
|
||||||
bool step;
|
bool hoverTrack;
|
||||||
int stepTo;
|
bool hoverThumb;
|
||||||
|
bool step;
|
||||||
|
int stepTo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDER_P_H
|
#endif // SLIDER_P_H
|
||||||
|
|
Loading…
Reference in New Issue