draw Slider handle as outline when value = minimum

This commit is contained in:
laserpants 2016-05-01 15:54:37 +03:00
parent 72b9ea2495
commit 9c15f89a17
1 changed files with 22 additions and 8 deletions

View File

@ -36,14 +36,28 @@ void Handle::paintEvent(QPaintEvent *event)
QBrush brush; QBrush brush;
brush.setColor(QColor(0, 0, 0)); brush.setColor(QColor(0, 0, 0));
brush.setStyle(Qt::SolidPattern); brush.setStyle(Qt::SolidPattern);
painter.setBrush(brush); painter.setBrush(brush);
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.drawEllipse(QRectF((width()-_knobSize)/2, (height()-_knobSize)/2, _knobSize, _knobSize)); if (_haloSize > 12) {
painter.save();
painter.setOpacity(0.2); painter.setOpacity(0.1);
painter.drawEllipse(QRectF((width()-_haloSize)/2, (height()-_haloSize)/2, _haloSize, _haloSize)); painter.drawEllipse(QRectF((width()-_haloSize)/2, (height()-_haloSize)/2, _haloSize, _haloSize));
painter.restore();
}
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); QWidget::paintEvent(event);
} }
@ -111,9 +125,9 @@ void Slider::paintEvent(QPaintEvent *event)
void Slider::mousePressEvent(QMouseEvent *event) void Slider::mousePressEvent(QMouseEvent *event)
{ {
const QPoint pos = event->pos(); 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(); const QSize handle = _handle->sizeHint();
_handle->setOffset((pos - QPoint(handle.width(), handle.height())/2) - event->globalPos()); _handle->setOffset((pos - QPoint(handle.width(), handle.height())/2) - event->globalPos());
_handle->setRelativePosition(event->globalPos()); _handle->setRelativePosition(event->globalPos());
@ -121,7 +135,7 @@ void Slider::mousePressEvent(QMouseEvent *event)
_knobAnimation->setDirection(QAbstractAnimation::Forward); _knobAnimation->setDirection(QAbstractAnimation::Forward);
_knobAnimation->start(); _knobAnimation->start();
if (oh) { if (touchesHandle) {
_haloAnimation->setDirection(QAbstractAnimation::Backward); _haloAnimation->setDirection(QAbstractAnimation::Backward);
_haloAnimation->start(); _haloAnimation->start();
} else { } else {
@ -241,6 +255,6 @@ void Slider::endHover()
_haloAnimation->setDirection(QAbstractAnimation::Backward); _haloAnimation->setDirection(QAbstractAnimation::Backward);
_haloAnimation->start(); _haloAnimation->start();
} }
update();
} }
update();
} }