diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-09 10:51:50 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-09 10:58:43 +0000 |
commit | 5c5bbfd5b8a313919da3567f003ab412eab606ec (patch) | |
tree | 51d9785f1d809b77d57c23d78f0e2f45a4f47392 /src/templates | |
parent | e75bbe782def5cbcc8e7f69640c7cdb107164f4a (diff) |
RangeSlider: choose the nearest handle
The handles were hard to touch. This change makes it choose the nearest
handle, so that the interaction becomes similar to what Slider has.
Change-Id: Ie94eeed6a8466f44e8eee0ce0ba0a45cfb3f6924
Task-number: QTBUG-50972
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates')
-rw-r--r-- | src/templates/qquickrangeslider.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 13f5e338..55b5bd8c 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -761,6 +761,31 @@ void QQuickRangeSlider::mousePressEvent(QMouseEvent *event) } else if (secondHit) { hitNode = d->second; otherNode = d->first; + } else { + // find the nearest + const qreal firstDistance = QLineF(firstHandle->boundingRect().center(), + mapToItem(firstHandle, event->pos())).length(); + const qreal secondDistance = QLineF(secondHandle->boundingRect().center(), + mapToItem(secondHandle, event->pos())).length(); + + if (qFuzzyCompare(firstDistance, secondDistance)) { + // same distance => choose the one that can be moved towards the press position + const bool inverted = d->from > d->to; + const qreal pos = positionAt(this, firstHandle, event->pos()); + if ((!inverted && pos < d->first->position()) || (inverted && pos > d->first->position())) { + hitNode = d->first; + otherNode = d->second; + } else { + hitNode = d->second; + otherNode = d->first; + } + } else if (firstDistance < secondDistance) { + hitNode = d->first; + otherNode = d->second; + } else { + hitNode = d->second; + otherNode = d->first; + } } if (hitNode) { |