diff options
Diffstat (limited to 'src/templates/qquickrangeslider.cpp')
-rw-r--r-- | src/templates/qquickrangeslider.cpp | 124 |
1 files changed, 65 insertions, 59 deletions
diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 69529f65..6dcd7fcb 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -87,7 +87,7 @@ public: isPendingValue(false), pendingValue(0), position(0), - handle(Q_NULLPTR), + handle(nullptr), slider(slider), pressed(false) { @@ -224,35 +224,36 @@ QQuickItem *QQuickRangeSliderNode::handle() const void QQuickRangeSliderNode::setHandle(QQuickItem *handle) { Q_D(QQuickRangeSliderNode); - if (d->handle != handle) { - delete d->handle; - d->handle = handle; - if (handle) { - if (!handle->parentItem()) - handle->setParentItem(d->slider); - - QQuickItem *firstHandle = d->slider->first()->handle(); - QQuickItem *secondHandle = d->slider->second()->handle(); - if (firstHandle && secondHandle) { - // The order of property assignments in QML is undefined, - // but we need the first handle to be before the second due - // to focus order constraints, so check for that here. - const QList<QQuickItem *> childItems = d->slider->childItems(); - const int firstIndex = childItems.indexOf(firstHandle); - const int secondIndex = childItems.indexOf(secondHandle); - if (firstIndex != -1 && secondIndex != -1 && firstIndex > secondIndex) { - firstHandle->stackBefore(secondHandle); - // Ensure we have some way of knowing which handle is above - // the other when it comes to mouse presses, and also that - // they are rendered in the correct order. - secondHandle->setZ(secondHandle->z() + 1); - } - } + if (d->handle == handle) + return; - handle->setActiveFocusOnTab(true); + delete d->handle; + d->handle = handle; + if (handle) { + if (!handle->parentItem()) + handle->setParentItem(d->slider); + + QQuickItem *firstHandle = d->slider->first()->handle(); + QQuickItem *secondHandle = d->slider->second()->handle(); + if (firstHandle && secondHandle) { + // The order of property assignments in QML is undefined, + // but we need the first handle to be before the second due + // to focus order constraints, so check for that here. + const QList<QQuickItem *> childItems = d->slider->childItems(); + const int firstIndex = childItems.indexOf(firstHandle); + const int secondIndex = childItems.indexOf(secondHandle); + if (firstIndex != -1 && secondIndex != -1 && firstIndex > secondIndex) { + firstHandle->stackBefore(secondHandle); + // Ensure we have some way of knowing which handle is above + // the other when it comes to mouse presses, and also that + // they are rendered in the correct order. + secondHandle->setZ(secondHandle->z() + 1); + } } - emit handleChanged(); + + handle->setActiveFocusOnTab(true); } + emit handleChanged(); } bool QQuickRangeSliderNode::isPressed() const @@ -264,11 +265,12 @@ bool QQuickRangeSliderNode::isPressed() const void QQuickRangeSliderNode::setPressed(bool pressed) { Q_D(QQuickRangeSliderNode); - if (d->pressed != pressed) { - d->pressed = pressed; - d->slider->setAccessibleProperty("pressed", pressed || d->slider->second()->isPressed()); - emit pressedChanged(); - } + if (d->pressed == pressed) + return; + + d->pressed = pressed; + d->slider->setAccessibleProperty("pressed", pressed || d->slider->second()->isPressed()); + emit pressedChanged(); } void QQuickRangeSliderNode::increase() @@ -297,11 +299,11 @@ public: from(defaultFrom), to(defaultTo), stepSize(0), - first(Q_NULLPTR), - second(Q_NULLPTR), + first(nullptr), + second(nullptr), orientation(Qt::Horizontal), snapMode(QQuickRangeSlider::NoSnap), - track(Q_NULLPTR) + track(nullptr) { } @@ -552,10 +554,11 @@ qreal QQuickRangeSlider::stepSize() const void QQuickRangeSlider::setStepSize(qreal step) { Q_D(QQuickRangeSlider); - if (!qFuzzyCompare(d->stepSize, step)) { - d->stepSize = step; - emit stepSizeChanged(); - } + if (qFuzzyCompare(d->stepSize, step)) + return; + + d->stepSize = step; + emit stepSizeChanged(); } /*! @@ -579,10 +582,11 @@ QQuickRangeSlider::SnapMode QQuickRangeSlider::snapMode() const void QQuickRangeSlider::setSnapMode(SnapMode mode) { Q_D(QQuickRangeSlider); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } + if (d->snapMode == mode) + return; + + d->snapMode = mode; + emit snapModeChanged(); } /*! @@ -603,10 +607,11 @@ Qt::Orientation QQuickRangeSlider::orientation() const void QQuickRangeSlider::setOrientation(Qt::Orientation orientation) { Q_D(QQuickRangeSlider); - if (d->orientation != orientation) { - d->orientation = orientation; - emit orientationChanged(); - } + if (d->orientation == orientation) + return; + + d->orientation = orientation; + emit orientationChanged(); } /*! @@ -625,13 +630,14 @@ QQuickItem *QQuickRangeSlider::track() const void QQuickRangeSlider::setTrack(QQuickItem *track) { Q_D(QQuickRangeSlider); - if (d->track != track) { - delete d->track; - d->track = track; - if (track && !track->parentItem()) - track->setParentItem(this); - emit trackChanged(); - } + if (d->track == track) + return; + + delete d->track; + d->track = track; + if (track && !track->parentItem()) + track->setParentItem(this); + emit trackChanged(); } /*! @@ -715,7 +721,7 @@ void QQuickRangeSlider::keyPressEvent(QKeyEvent *event) QQuickControl::keyPressEvent(event); QQuickRangeSliderNode *focusNode = d->first->handle()->hasActiveFocus() - ? d->first : (d->second->handle()->hasActiveFocus() ? d->second : Q_NULLPTR); + ? d->first : (d->second->handle()->hasActiveFocus() ? d->second : nullptr); if (!focusNode) return; @@ -766,8 +772,8 @@ void QQuickRangeSlider::mousePressEvent(QMouseEvent *event) QQuickItem *secondHandle = d->second->handle(); const bool firstHit = firstHandle && firstHandle->contains(mapToItem(firstHandle, d->pressPoint)); const bool secondHit = secondHandle && secondHandle->contains(mapToItem(secondHandle, d->pressPoint)); - QQuickRangeSliderNode *hitNode = Q_NULLPTR; - QQuickRangeSliderNode *otherNode = Q_NULLPTR; + QQuickRangeSliderNode *hitNode = nullptr; + QQuickRangeSliderNode *otherNode = nullptr; if (firstHit && secondHit) { // choose highest @@ -825,7 +831,7 @@ void QQuickRangeSlider::mouseMoveEvent(QMouseEvent *event) setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().y() - d->pressPoint.y(), Qt::YAxis, event)); } if (keepMouseGrab()) { - QQuickRangeSliderNode *pressedNode = d->first->isPressed() ? d->first : (d->second->isPressed() ? d->second : Q_NULLPTR); + QQuickRangeSliderNode *pressedNode = d->first->isPressed() ? d->first : (d->second->isPressed() ? d->second : nullptr); if (pressedNode) { qreal pos = positionAt(this, pressedNode->handle(), event->pos()); if (d->snapMode == SnapAlways) @@ -844,7 +850,7 @@ void QQuickRangeSlider::mouseReleaseEvent(QMouseEvent *event) if (!keepMouseGrab()) return; - QQuickRangeSliderNode *pressedNode = d->first->isPressed() ? d->first : (d->second->isPressed() ? d->second : Q_NULLPTR); + QQuickRangeSliderNode *pressedNode = d->first->isPressed() ? d->first : (d->second->isPressed() ? d->second : nullptr); if (!pressedNode) return; |