simplify slider code
This commit is contained in:
parent
db1c8ddee4
commit
ef57d5b79d
|
@ -83,16 +83,13 @@ void Slider::paintEvent(QPaintEvent *event)
|
|||
|
||||
void Slider::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
const QSize s = _handle->sizeHint();
|
||||
const QPoint p = event->pos();
|
||||
|
||||
if (Qt::Horizontal == _orientation
|
||||
? touchesRail(p.y(), height()/2)
|
||||
: touchesRail(p.x(), width()/2))
|
||||
? touchesRail(event->y(), height()/2)
|
||||
: touchesRail(event->x(), width()/2))
|
||||
{
|
||||
const QPoint newPos = p - QPoint(s.width()/2, s.height()/2);
|
||||
_handle->setPosition(newPos);
|
||||
_handle->setOffset(newPos - event->globalPos());
|
||||
const QSize s = _handle->sizeHint();
|
||||
_handle->setOffset((event->pos() - QPoint(s.width()/2, s.height()/2)) - event->globalPos());
|
||||
_handle->setRelativePosition(event->globalPos());
|
||||
_drag = true;
|
||||
} else {
|
||||
_drag = false;
|
||||
|
@ -113,9 +110,3 @@ void Slider::resizeEvent(QResizeEvent *event)
|
|||
_handle->refreshGeometry();
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
bool Slider::touchesRail(int p, int x) const
|
||||
{
|
||||
return (p >= x-2 && p < x+2);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ protected:
|
|||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
bool touchesRail(int p, int x) const;
|
||||
inline bool touchesRail(int p, int x) const { return (p >= x-2 && p < x+2); }
|
||||
|
||||
bool _drag;
|
||||
Handle *const _handle;
|
||||
|
|
Loading…
Reference in New Issue