mess around with slider thumb style
This commit is contained in:
parent
6440b937db
commit
f6c8b74ddd
|
@ -1,12 +1,20 @@
|
|||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QPropertyAnimation>
|
||||
#include "slider.h"
|
||||
|
||||
Handle::Handle(Slider *slider)
|
||||
: QWidget(slider),
|
||||
_slider(slider)
|
||||
_slider(slider),
|
||||
_animation(new QPropertyAnimation(this)),
|
||||
_scaleFactor(1)
|
||||
{
|
||||
_animation->setPropertyName("scaleFactor");
|
||||
_animation->setTargetObject(this);
|
||||
_animation->setStartValue(1);
|
||||
_animation->setEndValue(2);
|
||||
_animation->setDuration(200);
|
||||
}
|
||||
|
||||
Handle::~Handle()
|
||||
|
@ -51,6 +59,15 @@ void Handle::paintEvent(QPaintEvent *event)
|
|||
void Handle::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
_offset = pos() - event->globalPos();
|
||||
|
||||
_animation->setDirection(QAbstractAnimation::Forward);
|
||||
_animation->start();
|
||||
}
|
||||
|
||||
void Handle::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
_animation->setDirection(QAbstractAnimation::Backward);
|
||||
_animation->start();
|
||||
}
|
||||
|
||||
void Handle::mouseMoveEvent(QMouseEvent *event)
|
||||
|
|
|
@ -4,17 +4,20 @@
|
|||
#include <QAbstractSlider>
|
||||
#include <QPoint>
|
||||
|
||||
class QPropertyAnimation;
|
||||
class Slider;
|
||||
|
||||
class Handle : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal scaleFactor WRITE setScaleFactor READ scaleFactor)
|
||||
|
||||
public:
|
||||
explicit Handle(Slider *slider);
|
||||
~Handle();
|
||||
|
||||
inline QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(12, 12); }
|
||||
inline QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(12, 12)*_scaleFactor; }
|
||||
|
||||
inline void setRelativePosition(const QPoint &pos) { setPosition(_offset + pos); }
|
||||
|
||||
|
@ -24,18 +27,24 @@ public:
|
|||
inline void setOffset(const QPoint &offset) { _offset = offset; update(); }
|
||||
inline const QPoint &offset() const { return _offset; }
|
||||
|
||||
inline void setScaleFactor (qreal factor ) { _scaleFactor = factor; refreshGeometry(); }
|
||||
inline qreal scaleFactor() const { return _scaleFactor; }
|
||||
|
||||
void refreshGeometry();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Slider *const _slider;
|
||||
QPoint _position;
|
||||
QPoint _eventPos;
|
||||
QPoint _offset;
|
||||
Slider *const _slider;
|
||||
QPropertyAnimation *const _animation;
|
||||
QPoint _position;
|
||||
QPoint _eventPos;
|
||||
QPoint _offset;
|
||||
qreal _scaleFactor;
|
||||
};
|
||||
|
||||
class Slider : public QAbstractSlider
|
||||
|
|
Loading…
Reference in New Issue