minor adjustments on Slider animation params

This commit is contained in:
laserpants 2016-05-15 21:35:50 +03:00
parent 1974fef9e8
commit 32272b05eb
2 changed files with 39 additions and 16 deletions

View File

@ -165,9 +165,11 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
minState->assignProperty(thumb, "fillColor", canvasColor); minState->assignProperty(thumb, "fillColor", canvasColor);
minState->assignProperty(thumb, "haloColor", minHaloColor); minState->assignProperty(thumb, "haloColor", minHaloColor);
minState->assignProperty(thumb, "borderColor", style.themeColor("accent3"));
minState->assignProperty(thumb, "borderWidth", 2); minState->assignProperty(thumb, "borderWidth", 2);
normalState->assignProperty(thumb, "fillColor", fillColor); normalState->assignProperty(thumb, "fillColor", fillColor);
normalState->assignProperty(thumb, "haloColor", haloColor); normalState->assignProperty(thumb, "haloColor", haloColor);
normalState->assignProperty(thumb, "borderColor", fillColor);
normalState->assignProperty(thumb, "borderWidth", 0); normalState->assignProperty(thumb, "borderWidth", 0);
sndState->setInitialState(minState); sndState->setInitialState(minState);
@ -183,8 +185,12 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
animation->setDuration(200); animation->setDuration(200);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation(thumb, "borderColor");
animation->setDuration(200);
transition->addAnimation(animation);
animation = new QPropertyAnimation(thumb, "borderWidth"); animation = new QPropertyAnimation(thumb, "borderWidth");
animation->setDuration(400); animation->setDuration(200);
transition->addAnimation(animation); transition->addAnimation(animation);
minState->addTransition(transition); minState->addTransition(transition);
@ -200,8 +206,12 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
animation->setDuration(200); animation->setDuration(200);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation(thumb, "borderColor");
animation->setDuration(200);
transition->addAnimation(animation);
animation = new QPropertyAnimation(thumb, "borderWidth"); animation = new QPropertyAnimation(thumb, "borderWidth");
animation->setDuration(400); animation->setDuration(200);
transition->addAnimation(animation); transition->addAnimation(animation);
normalState->addTransition(transition); normalState->addTransition(transition);
@ -274,9 +284,9 @@ void SliderThumb::paintEvent(QPaintEvent *event)
: Style::instance().themeColor("disabled")); : Style::instance().themeColor("disabled"));
painter.setBrush(brush); painter.setBrush(brush);
if (_borderWidth > 0 && slider->isEnabled()) { if (slider->isEnabled()) {
QPen pen; QPen pen;
pen.setColor(Style::instance().themeColor("accent3")); pen.setColor(_borderColor);
pen.setWidthF(_borderWidth); pen.setWidthF(_borderWidth);
painter.setPen(pen); painter.setPen(pen);
} else { } else {
@ -315,7 +325,7 @@ void SliderThumb::paintEvent(QPaintEvent *event)
SliderTrack::SliderTrack(Slider *slider) SliderTrack::SliderTrack(Slider *slider)
: QWidget(slider->parentWidget()), : QWidget(slider->parentWidget()),
slider(slider), slider(slider),
_width(2) _trackWidth(2)
{ {
slider->installEventFilter(this); slider->installEventFilter(this);
setAttribute(Qt::WA_TransparentForMouseEvents, true); setAttribute(Qt::WA_TransparentForMouseEvents, true);
@ -362,26 +372,26 @@ void SliderTrack::paintEvent(QPaintEvent *event)
if (Qt::Horizontal == slider->orientation()) { if (Qt::Horizontal == slider->orientation()) {
painter.translate(slider->x() + SLIDER_MARGIN, painter.translate(slider->x() + SLIDER_MARGIN,
slider->y() + slider->height()/2 slider->y() + slider->height()/2
- static_cast<qreal>(_width)/2); - static_cast<qreal>(_trackWidth)/2);
} else { } else {
painter.translate(slider->x() + slider->width()/2 painter.translate(slider->x() + slider->width()/2
- static_cast<qreal>(_width)/2, - static_cast<qreal>(_trackWidth)/2,
slider->y() + SLIDER_MARGIN); slider->y() + SLIDER_MARGIN);
} }
QRectF geometry = Qt::Horizontal == slider->orientation() QRectF geometry = Qt::Horizontal == slider->orientation()
? QRectF(0, 0, slider->width() - SLIDER_MARGIN*2, _width) ? QRectF(0, 0, slider->width() - SLIDER_MARGIN*2, _trackWidth)
: QRectF(0, 0, _width, slider->height() - SLIDER_MARGIN*2); : QRectF(0, 0, _trackWidth, slider->height() - SLIDER_MARGIN*2);
QRectF bgRect; QRectF bgRect;
QRectF fgRect; QRectF fgRect;
if (Qt::Horizontal == slider->orientation()) { if (Qt::Horizontal == slider->orientation()) {
fgRect = QRectF(0, 0, offset, _width); fgRect = QRectF(0, 0, offset, _trackWidth);
bgRect = QRectF(offset, 0, slider->width(), _width).intersected(geometry); bgRect = QRectF(offset, 0, slider->width(), _trackWidth).intersected(geometry);
} else { } else {
fgRect = QRectF(0, 0, _width, offset); fgRect = QRectF(0, 0, _trackWidth, offset);
bgRect = QRectF(0, offset, _width, slider->height()).intersected(geometry); bgRect = QRectF(0, offset, _trackWidth, slider->height()).intersected(geometry);
} }
if (!slider->isEnabled()) { if (!slider->isEnabled()) {

View File

@ -32,6 +32,7 @@ class SliderThumb : public QWidget
Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter) Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter)
Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth) Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth)
Q_PROPERTY(QColor borderColor WRITE setBorderColor READ borderColor)
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor) Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize) Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
Q_PROPERTY(QColor haloColor WRITE setHaloColor READ haloColor) Q_PROPERTY(QColor haloColor WRITE setHaloColor READ haloColor)
@ -62,6 +63,17 @@ public:
return _borderWidth; return _borderWidth;
} }
inline void setBorderColor(const QColor &color)
{
_borderColor = color;
update();
}
inline QColor borderColor() const
{
return _borderColor;
}
inline void setFillColor(const QColor &color) inline void setFillColor(const QColor &color)
{ {
_fillColor = color; _fillColor = color;
@ -106,6 +118,7 @@ private:
qreal _diameter; qreal _diameter;
qreal _borderWidth; qreal _borderWidth;
qreal _haloSize; qreal _haloSize;
QColor _borderColor;
QColor _fillColor; QColor _fillColor;
QColor _haloColor; QColor _haloColor;
}; };
@ -133,13 +146,13 @@ public:
void setTrackWidth(int width) void setTrackWidth(int width)
{ {
_width = width; _trackWidth = width;
update(); update();
} }
int trackWidth() const int trackWidth() const
{ {
return _width; return _trackWidth;
} }
protected: protected:
@ -151,7 +164,7 @@ private:
const Slider *const slider; const Slider *const slider;
QColor _fillColor; QColor _fillColor;
int _width; int _trackWidth;
}; };
#endif // SLIDERINTERNAL_H #endif // SLIDERINTERNAL_H