From f6c8b74ddd41542a741569a83c20ad9054ad23ef Mon Sep 17 00:00:00 2001 From: laserpants Date: Sat, 30 Apr 2016 13:44:45 +0300 Subject: [PATCH] mess around with slider thumb style --- components/slider.cpp | 19 ++++++++++++++++++- components/slider.h | 19 ++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/slider.cpp b/components/slider.cpp index 9f4c094..87ace7d 100644 --- a/components/slider.cpp +++ b/components/slider.cpp @@ -1,12 +1,20 @@ #include #include #include +#include #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) diff --git a/components/slider.h b/components/slider.h index fcf48c5..7963167 100644 --- a/components/slider.h +++ b/components/slider.h @@ -4,17 +4,20 @@ #include #include +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