paint track for toggle component

This commit is contained in:
laserpants 2016-03-26 15:38:24 +03:00
parent 3871deda30
commit 72ca134fc1
3 changed files with 14 additions and 8 deletions

View File

@ -84,8 +84,8 @@ void Slider::paintEvent(QPaintEvent *event)
void Slider::mousePressEvent(QMouseEvent *event)
{
if (Qt::Horizontal == _orientation
? touchesRail(event->y(), height()/2)
: touchesRail(event->x(), width()/2))
? isOnTrack(event->y(), height()/2)
: isOnTrack(event->x(), width()/2))
{
const QSize s = _handle->sizeHint();
_handle->setOffset((event->pos() - QPoint(s.width()/2, s.height()/2)) - event->globalPos());

View File

@ -57,7 +57,7 @@ protected:
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
inline bool touchesRail(int p, int x) const { return (p >= x-2 && p < x+2); }
inline bool isOnTrack(int p, int x) const { return (p >= x-2 && p < x+2); }
bool _drag;
Handle *const _handle;

View File

@ -19,11 +19,17 @@ void Toggle::paintEvent(QPaintEvent *event)
Q_UNUSED(event)
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen;
pen.setColor(Qt::black);
pen.setWidth(2);
painter.setPen(pen);
const int h = height()/2;
QBrush brush;
brush.setColor(QColor(180, 180, 180));
brush.setStyle(Qt::SolidPattern);
painter.setBrush(brush);
painter.setPen(Qt::NoPen);
painter.drawRoundedRect(QRect(0, h-h/2, width(), h+h/2), h, h);
painter.drawRect(rect());
}