From 9c15f89a1777f7404c00ed11e520ddf8d7f131d9 Mon Sep 17 00:00:00 2001 From: laserpants Date: Sun, 1 May 2016 15:54:37 +0300 Subject: [PATCH] draw Slider handle as outline when value = minimum --- components/slider.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/components/slider.cpp b/components/slider.cpp index 7585433..b2e738e 100644 --- a/components/slider.cpp +++ b/components/slider.cpp @@ -36,14 +36,28 @@ void Handle::paintEvent(QPaintEvent *event) QBrush brush; brush.setColor(QColor(0, 0, 0)); brush.setStyle(Qt::SolidPattern); - painter.setBrush(brush); painter.setPen(Qt::NoPen); - painter.drawEllipse(QRectF((width()-_knobSize)/2, (height()-_knobSize)/2, _knobSize, _knobSize)); + if (_haloSize > 12) { + painter.save(); + painter.setOpacity(0.1); + painter.drawEllipse(QRectF((width()-_haloSize)/2, (height()-_haloSize)/2, _haloSize, _haloSize)); + painter.restore(); + } - painter.setOpacity(0.2); - painter.drawEllipse(QRectF((width()-_haloSize)/2, (height()-_haloSize)/2, _haloSize, _haloSize)); + if (_slider->minimum() == _slider->value()) { + QPen pen; + pen.setColor(QColor(0, 0, 0, 80)); + pen.setWidth(2); + painter.setPen(pen); + QBrush brush; + brush.setColor(Qt::white); + brush.setStyle(Qt::SolidPattern); + painter.setBrush(brush); + } + + painter.drawEllipse(QRectF((width()-_knobSize)/2, (height()-_knobSize)/2, _knobSize, _knobSize)); QWidget::paintEvent(event); } @@ -111,9 +125,9 @@ void Slider::paintEvent(QPaintEvent *event) void Slider::mousePressEvent(QMouseEvent *event) { const QPoint pos = event->pos(); - const bool oh = overHandle(pos); + const bool touchesHandle = overHandle(pos); - if (oh || overTrack(pos)) { + if (touchesHandle || overTrack(pos)) { const QSize handle = _handle->sizeHint(); _handle->setOffset((pos - QPoint(handle.width(), handle.height())/2) - event->globalPos()); _handle->setRelativePosition(event->globalPos()); @@ -121,7 +135,7 @@ void Slider::mousePressEvent(QMouseEvent *event) _knobAnimation->setDirection(QAbstractAnimation::Forward); _knobAnimation->start(); - if (oh) { + if (touchesHandle) { _haloAnimation->setDirection(QAbstractAnimation::Backward); _haloAnimation->start(); } else { @@ -241,6 +255,6 @@ void Slider::endHover() _haloAnimation->setDirection(QAbstractAnimation::Backward); _haloAnimation->start(); } - update(); } + update(); }