9#include <QtCore/qscopedpointer.h>
10#include <QtQuick/private/qquickwindow_p.h>
11#include <QtQuickTemplates2/private/qtquicktemplates2math_p.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
66 Q_DECLARE_PUBLIC(QQuickRangeSliderNode)
76 void setPosition(qreal position,
bool ignoreOtherPosition =
false);
97 return this == get(slider->first());
102 Q_Q(QQuickRangeSliderNode);
104 const qreal min = isFirst() || ignoreOtherPosition ? 0.0 : qMax<qreal>(0.0, slider->first()->position());
105 const qreal max = !isFirst() || ignoreOtherPosition ? 1.0 : qMin<qreal>(1.0, slider->second()->position());
106 position = qBound(min, position, max);
107 if (!qFuzzyCompare(
this->position, position)) {
108 this->position = position;
109 emit q->positionChanged();
110 emit q->visualPositionChanged();
117 if (!qFuzzyCompare(slider->from(), slider->to()))
118 pos = (value - slider->from()) / (slider->to() - slider->from());
119 setPosition(pos, ignoreOtherPosition);
124 Q_Q(QQuickRangeSliderNode);
125 quickCancelDeferred(q, handleName());
130 Q_Q(QQuickRangeSliderNode);
131 if (handle.wasExecuted())
134 if (!handle || complete)
135 quickBeginDeferred(q, handleName(), handle);
137 quickCompleteDeferred(q, handleName(), handle);
142 return node->d_func();
145QQuickRangeSliderNode::QQuickRangeSliderNode(qreal value, QQuickRangeSlider *slider)
146 : QObject(*(
new QQuickRangeSliderNodePrivate(value, slider)), slider)
150QQuickRangeSliderNode::~QQuickRangeSliderNode()
154qreal QQuickRangeSliderNode::value()
const
156 Q_D(
const QQuickRangeSliderNode);
160void QQuickRangeSliderNode::setValue(qreal value)
162 Q_D(QQuickRangeSliderNode);
163 if (!d->slider->isComponentComplete()) {
164 d->pendingValue = value;
165 d->isPendingValue =
true;
170 const qreal smaller = qMin(d->slider->to(), d->slider->from());
171 const qreal larger = qMax(d->slider->to(), d->slider->from());
172 value = qBound(smaller, value, larger);
176 const bool invertedRange = d->slider->from() > d->slider->to();
179 if (value < d->slider->second()->value())
180 value = d->slider->second()->value();
182 if (value > d->slider->second()->value())
183 value = d->slider->second()->value();
187 if (value > d->slider->first()->value())
188 value = d->slider->first()->value();
190 if (value < d->slider->first()->value())
191 value = d->slider->first()->value();
195 if (!qFuzzyCompare(d->value, value)) {
202qreal QQuickRangeSliderNode::position()
const
204 Q_D(
const QQuickRangeSliderNode);
208qreal QQuickRangeSliderNode::visualPosition()
const
210 Q_D(
const QQuickRangeSliderNode);
211 if (d->slider->orientation() == Qt::Vertical || d->slider->isMirrored())
212 return 1.0 - d->position;
216QQuickItem *QQuickRangeSliderNode::handle()
const
218 QQuickRangeSliderNodePrivate *d =
const_cast<QQuickRangeSliderNodePrivate *>(d_func());
224void QQuickRangeSliderNode::setHandle(QQuickItem *handle)
226 Q_D(QQuickRangeSliderNode);
227 if (d->handle == handle)
230 QQuickControlPrivate::warnIfCustomizationNotSupported(d->slider, handle, QStringLiteral(
"handle"));
232 if (!d->handle.isExecuting())
235 const qreal oldImplicitHandleWidth = implicitHandleWidth();
236 const qreal oldImplicitHandleHeight = implicitHandleHeight();
238 QQuickControlPrivate::get(d->slider)->removeImplicitSizeListener(d->handle);
239 QQuickControlPrivate::hideOldItem(d->handle);
243 if (!handle->parentItem())
244 handle->setParentItem(d->slider);
246 QQuickItem *firstHandle = QQuickRangeSliderNodePrivate::get(d->slider->first())->handle;
247 QQuickItem *secondHandle = QQuickRangeSliderNodePrivate::get(d->slider->second())->handle;
248 if (firstHandle && secondHandle) {
252 const QList<QQuickItem *> childItems = d->slider->childItems();
253 const int firstIndex = childItems.indexOf(firstHandle);
254 const int secondIndex = childItems.indexOf(secondHandle);
255 if (firstIndex != -1 && secondIndex != -1 && firstIndex > secondIndex) {
256 firstHandle->stackBefore(secondHandle);
260 secondHandle->setZ(secondHandle->z() + 1);
264 handle->setActiveFocusOnTab(
true);
265 QQuickControlPrivate::get(d->slider)->addImplicitSizeListener(handle);
268 if (!qFuzzyCompare(oldImplicitHandleWidth, implicitHandleWidth()))
269 emit implicitHandleWidthChanged();
270 if (!qFuzzyCompare(oldImplicitHandleHeight, implicitHandleHeight()))
271 emit implicitHandleHeightChanged();
272 if (!d->handle.isExecuting())
273 emit handleChanged();
276bool QQuickRangeSliderNode::isPressed()
const
278 Q_D(
const QQuickRangeSliderNode);
282void QQuickRangeSliderNode::setPressed(
bool pressed)
284 Q_D(QQuickRangeSliderNode);
285 if (d->pressed == pressed)
288 d->pressed = pressed;
289 d->slider->setAccessibleProperty(
"pressed", pressed || d->slider->second()->isPressed());
290 emit pressedChanged();
293bool QQuickRangeSliderNode::isHovered()
const
295 Q_D(
const QQuickRangeSliderNode);
299void QQuickRangeSliderNode::setHovered(
bool hovered)
301 Q_D(QQuickRangeSliderNode);
302 if (d->hovered == hovered)
305 d->hovered = hovered;
306 emit hoveredChanged();
309qreal QQuickRangeSliderNode::implicitHandleWidth()
const
311 Q_D(
const QQuickRangeSliderNode);
314 return d->handle->implicitWidth();
317qreal QQuickRangeSliderNode::implicitHandleHeight()
const
319 Q_D(
const QQuickRangeSliderNode);
322 return d->handle->implicitHeight();
325void QQuickRangeSliderNode::increase()
327 Q_D(QQuickRangeSliderNode);
328 qreal step = qFuzzyIsNull(d->slider->stepSize()) ? 0.1 : d->slider->stepSize();
329 setValue(d->value + step);
332void QQuickRangeSliderNode::decrease()
334 Q_D(QQuickRangeSliderNode);
335 qreal step = qFuzzyIsNull(d->slider->stepSize()) ? 0.1 : d->slider->stepSize();
336 setValue(d->value - step);
344 Q_DECLARE_PUBLIC(QQuickRangeSlider)
351#if QT_CONFIG(quicktemplates2_multitouch)
355 bool handleMove(
const QPointF &point, ulong timestamp)
override;
371 QQuickRangeSliderNode *
first =
nullptr;
382 qreal value = slider->from() + (slider->to() - slider->from()) * position;
385 if (QQuickRangeSliderPrivate::get(slider)->allValuesAreInteger)
386 value = qRound(value);
393 const qreal range = slider->to() - slider->from();
394 if (qFuzzyIsNull(range))
397 const qreal effectiveStep = slider->stepSize() / range;
398 if (qFuzzyIsNull(effectiveStep))
401 return qRound(position / effectiveStep) * effectiveStep;
404static qreal positionAt(
const QQuickRangeSlider *slider, QQuickItem *handle,
const QPointF &point)
406 if (slider->orientation() == Qt::Horizontal) {
407 const qreal hw = handle ? handle->width() : 0;
408 const qreal offset = hw / 2;
409 const qreal extent = slider->availableWidth() - hw;
410 if (!qFuzzyIsNull(extent)) {
411 if (slider->isMirrored())
412 return (slider->width() - point.x() - slider->rightPadding() - offset) / extent;
413 return (point.x() - slider->leftPadding() - offset) / extent;
416 const qreal hh = handle ? handle->height() : 0;
417 const qreal offset = hh / 2;
418 const qreal extent = slider->availableHeight() - hh;
419 if (!qFuzzyIsNull(extent))
420 return (slider->height() - point.y() - slider->bottomPadding() - offset) / extent;
427 return slider->d_func();
441#if QT_CONFIG(quicktemplates2_multitouch)
442bool QQuickRangeSliderPrivate::acceptTouch(
const QTouchEvent::TouchPoint &point)
444 int firstId = QQuickRangeSliderNodePrivate::get(first)->touchId;
445 int secondId = QQuickRangeSliderNodePrivate::get(second)->touchId;
447 if (((firstId == -1 || secondId == -1) && point.state() == QEventPoint::Pressed) || point.id() == firstId || point.id() == secondId) {
448 touchId = point.id();
458 Q_Q(QQuickRangeSlider);
459 QQuickControlPrivate::handlePress(point, timestamp);
462 QQuickItem *firstHandle =
first->handle();
463 QQuickItem *secondHandle =
second->handle();
464 const bool firstHit = firstHandle && !first->isPressed() && firstHandle->contains(q->mapToItem(firstHandle, point));
465 const bool secondHit = secondHandle && !second->isPressed() && secondHandle->contains(q->mapToItem(secondHandle, point));
466 QQuickRangeSliderNode *hitNode =
nullptr;
467 QQuickRangeSliderNode *otherNode =
nullptr;
469 if (firstHit && secondHit) {
471 hitNode = firstHandle->z() > secondHandle->z() ?
first :
second;
472 otherNode = firstHandle->z() > secondHandle->z() ?
second :
first;
473 }
else if (firstHit) {
476 }
else if (secondHit) {
481 const qreal firstPos = positionAt(q, firstHandle, point);
482 const qreal secondPos = positionAt(q, secondHandle, point);
483 const qreal firstDistance = qAbs(firstPos -
first->position());
484 const qreal secondDistance = qAbs(secondPos -
second->position());
486 if (qFuzzyCompare(firstDistance, secondDistance)) {
488 const bool inverted = from > to;
489 if ((!inverted && firstPos <
first->position()) || (inverted && firstPos >
first->position())) {
496 }
else if (firstDistance < secondDistance) {
506 hitNode->setPressed(
true);
507 if (QQuickItem *handle = hitNode->handle()) {
512 if (focusPolicy & Qt::ClickFocus)
513 handle->forceActiveFocus(Qt::MouseFocusReason);
515 QQuickRangeSliderNodePrivate::get(hitNode)->touchId = touchId;
518 if (QQuickItem *handle = otherNode->handle())
526 Q_Q(QQuickRangeSlider);
527 QQuickControlPrivate::handleMove(point, timestamp);
528 QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId);
530 const qreal oldPos = pressedNode->position();
531 qreal pos = positionAt(q, pressedNode->handle(), point);
532 if (snapMode == QQuickRangeSlider::SnapAlways)
533 pos = snapPosition(q, pos);
535 pressedNode->setValue(valueAt(q, pos));
539 if (!qFuzzyCompare(pressedNode->position(), oldPos))
540 emit pressedNode->moved();
547 Q_Q(QQuickRangeSlider);
548 QQuickControlPrivate::handleRelease(point, timestamp);
549 pressPoint = QPointF();
551 QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId);
556 const qreal oldPos = pressedNode->position();
557 qreal pos = positionAt(q, pressedNode->handle(), point);
558 if (snapMode != QQuickRangeSlider::NoSnap)
559 pos = snapPosition(q, pos);
560 qreal val = valueAt(q, pos);
561 if (!qFuzzyCompare(val, pressedNode->value()))
562 pressedNode->setValue(val);
563 else if (snapMode != QQuickRangeSlider::NoSnap)
564 pressedNodePrivate->setPosition(pos);
565 q->setKeepMouseGrab(
false);
566 q->setKeepTouchGrab(
false);
568 if (!qFuzzyCompare(pressedNode->position(), oldPos))
569 emit pressedNode->moved();
571 pressedNode->setPressed(
false);
578 QQuickControlPrivate::handleUngrab();
579 pressPoint = QPointF();
580 first->setPressed(
false);
581 second->setPressed(
false);
588 Q_Q(QQuickRangeSlider);
589 QQuickItem *firstHandle =
first->handle();
590 QQuickItem *secondHandle =
second->handle();
591 bool firstHandleHovered = firstHandle && firstHandle->isEnabled()
592 && firstHandle->contains(q->mapToItem(firstHandle, pos));
593 bool secondHandleHovered = secondHandle && secondHandle->isEnabled()
594 && secondHandle->contains(q->mapToItem(secondHandle, pos));
596 if (firstHandleHovered && secondHandleHovered) {
598 const bool firstHandleHasHigherZ = firstHandle->z() > secondHandle->z();
599 firstHandleHovered = firstHandleHasHigherZ;
600 secondHandleHovered = !firstHandleHasHigherZ;
602 first->setHovered(firstHandleHovered);
603 second->setHovered(secondHandleHovered);
608 QQuickControlPrivate::itemImplicitWidthChanged(item);
609 if (item ==
first->handle())
610 emit first->implicitHandleWidthChanged();
611 else if (item ==
second->handle())
612 emit second->implicitHandleWidthChanged();
617 QQuickControlPrivate::itemImplicitHeightChanged(item);
618 if (item ==
first->handle())
619 emit first->implicitHandleHeightChanged();
620 else if (item ==
second->handle())
621 emit second->implicitHandleHeightChanged();
626 QQuickControlPrivate::itemDestroyed(item);
627 if (item ==
first->handle())
628 first->setHandle(
nullptr);
629 else if (item ==
second->handle())
630 second->setHandle(
nullptr);
635 allValuesAreInteger = areRepresentableAsInteger(to, from, stepSize) && stepSize != 0.0;
638QQuickRangeSlider::QQuickRangeSlider(QQuickItem *parent)
639 : QQuickControl(*(
new QQuickRangeSliderPrivate), parent)
641 Q_D(QQuickRangeSlider);
642 d->first =
new QQuickRangeSliderNode(0.0,
this);
643 d->second =
new QQuickRangeSliderNode(1.0,
this);
644 d->setSizePolicy(QLayoutPolicy::Expanding, QLayoutPolicy::Fixed);
646 setFlag(QQuickItem::ItemIsFocusScope);
648 setFocusPolicy(Qt::TabFocus);
650 setFocusPolicy(Qt::StrongFocus);
652 setAcceptedMouseButtons(Qt::LeftButton);
653#if QT_CONFIG(quicktemplates2_multitouch)
654 setAcceptTouchEvents(
true);
657 setCursor(Qt::ArrowCursor);
661QQuickRangeSlider::~QQuickRangeSlider()
663 Q_D(QQuickRangeSlider);
664 d->removeImplicitSizeListener(d->first->handle());
665 d->removeImplicitSizeListener(d->second->handle());
669
670
671
672
673
674
675qreal QQuickRangeSlider::from()
const
677 Q_D(
const QQuickRangeSlider);
681void QQuickRangeSlider::setFrom(qreal from)
683 Q_D(QQuickRangeSlider);
684 if (qFuzzyCompare(d->from, from))
689 d->updateAllValuesAreInteger();
691 if (isComponentComplete()) {
692 d->first->setValue(d->first->value());
693 d->second->setValue(d->second->value());
694 auto *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
695 auto *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
696 firstPrivate->updatePosition(
true);
697 secondPrivate->updatePosition();
702
703
704
705
706
707
708qreal QQuickRangeSlider::to()
const
710 Q_D(
const QQuickRangeSlider);
714void QQuickRangeSlider::setTo(qreal to)
716 Q_D(QQuickRangeSlider);
717 if (qFuzzyCompare(d->to, to))
722 d->updateAllValuesAreInteger();
724 if (isComponentComplete()) {
725 d->first->setValue(d->first->value());
726 d->second->setValue(d->second->value());
727 auto *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
728 auto *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
729 firstPrivate->updatePosition(
true);
730 secondPrivate->updatePosition();
735
736
737
738
739
740
741
742
743
744
745qreal QQuickRangeSlider::touchDragThreshold()
const
747 Q_D(
const QQuickRangeSlider);
748 return d->touchDragThreshold;
751void QQuickRangeSlider::setTouchDragThreshold(qreal touchDragThreshold)
753 Q_D(QQuickRangeSlider);
754 if (d->touchDragThreshold == touchDragThreshold)
757 d->touchDragThreshold = touchDragThreshold;
758 emit touchDragThresholdChanged();
761void QQuickRangeSlider::resetTouchDragThreshold()
763 setTouchDragThreshold(-1);
767
768
769
770
771
772
773
774qreal QQuickRangeSlider::valueAt(qreal position)
const
776 Q_D(
const QQuickRangeSlider);
777 const qreal value = (d->to - d->from) * position;
778 if (qFuzzyIsNull(d->stepSize))
779 return d->from + value;
780 return d->from + qRound(value / d->stepSize) * d->stepSize;
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844QQuickRangeSliderNode *QQuickRangeSlider::first()
const
846 Q_D(
const QQuickRangeSlider);
851
852
853
854
855
856
857
858
859
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922QQuickRangeSliderNode *QQuickRangeSlider::second()
const
924 Q_D(
const QQuickRangeSlider);
929
930
931
932
933
934
935qreal QQuickRangeSlider::stepSize()
const
937 Q_D(
const QQuickRangeSlider);
941void QQuickRangeSlider::setStepSize(qreal step)
943 Q_D(QQuickRangeSlider);
944 if (qFuzzyCompare(d->stepSize, step))
948 emit stepSizeChanged();
949 d->updateAllValuesAreInteger();
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970QQuickRangeSlider::SnapMode QQuickRangeSlider::snapMode()
const
972 Q_D(
const QQuickRangeSlider);
976void QQuickRangeSlider::setSnapMode(SnapMode mode)
978 Q_D(QQuickRangeSlider);
979 if (d->snapMode == mode)
983 emit snapModeChanged();
987
988
989
990
991
992
993
994
995
996
997Qt::Orientation QQuickRangeSlider::orientation()
const
999 Q_D(
const QQuickRangeSlider);
1000 return d->orientation;
1003void QQuickRangeSlider::setOrientation(Qt::Orientation orientation)
1005 Q_D(QQuickRangeSlider);
1006 if (d->orientation == orientation)
1009 if (orientation == Qt::Horizontal)
1010 d->setSizePolicy(QLayoutPolicy::Expanding, QLayoutPolicy::Fixed);
1012 d->setSizePolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Expanding);
1014 d->orientation = orientation;
1015 emit orientationChanged();
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036void QQuickRangeSlider::setValues(qreal firstValue, qreal secondValue)
1038 Q_D(QQuickRangeSlider);
1040 const qreal smaller = qMin(d->to, d->from);
1041 const qreal larger = qMax(d->to, d->from);
1042 firstValue = qBound(smaller, firstValue, larger);
1043 secondValue = qBound(smaller, secondValue, larger);
1045 if (d->from > d->to) {
1048 if (secondValue > firstValue)
1049 secondValue = firstValue;
1052 if (firstValue > secondValue)
1053 firstValue = secondValue;
1057 QQuickRangeSliderNodePrivate *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
1058 if (firstValue != firstPrivate->value) {
1059 firstPrivate->value = firstValue;
1060 emit d->first->valueChanged();
1063 QQuickRangeSliderNodePrivate *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
1064 if (secondValue != secondPrivate->value) {
1065 secondPrivate->value = secondValue;
1066 emit d->second->valueChanged();
1071 firstPrivate->updatePosition(
true);
1072 secondPrivate->updatePosition();
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086bool QQuickRangeSlider::live()
const
1088 Q_D(
const QQuickRangeSlider);
1092void QQuickRangeSlider::setLive(
bool live)
1094 Q_D(QQuickRangeSlider);
1095 if (d->live == live)
1103
1104
1105
1106
1107
1108
1109
1110
1111bool QQuickRangeSlider::isHorizontal()
const
1113 Q_D(
const QQuickRangeSlider);
1114 return d->orientation == Qt::Horizontal;
1118
1119
1120
1121
1122
1123
1124
1125
1126bool QQuickRangeSlider::isVertical()
const
1128 Q_D(
const QQuickRangeSlider);
1129 return d->orientation == Qt::Vertical;
1132void QQuickRangeSlider::focusInEvent(QFocusEvent *event)
1134 Q_D(QQuickRangeSlider);
1135 QQuickControl::focusInEvent(event);
1141 QQuickItem *handle = nextItemInFocusChain();
1144 if (!handle || handle ==
this)
1145 handle = d->first->handle();
1147 handle->forceActiveFocus(event->reason());
1150void QQuickRangeSlider::keyPressEvent(QKeyEvent *event)
1152 Q_D(QQuickRangeSlider);
1153 QQuickControl::keyPressEvent(event);
1155 QQuickRangeSliderNode *focusNode = d->first->handle()->hasActiveFocus()
1156 ? d->first : (d->second->handle()->hasActiveFocus() ? d->second :
nullptr);
1160 const qreal oldValue = focusNode->value();
1161 if (d->orientation == Qt::Horizontal) {
1162 if (event->key() == Qt::Key_Left) {
1163 focusNode->setPressed(
true);
1165 focusNode->increase();
1167 focusNode->decrease();
1169 }
else if (event->key() == Qt::Key_Right) {
1170 focusNode->setPressed(
true);
1172 focusNode->decrease();
1174 focusNode->increase();
1178 if (event->key() == Qt::Key_Up) {
1179 focusNode->setPressed(
true);
1180 focusNode->increase();
1182 }
else if (event->key() == Qt::Key_Down) {
1183 focusNode->setPressed(
true);
1184 focusNode->decrease();
1188 if (!qFuzzyCompare(focusNode->value(), oldValue))
1189 emit focusNode->moved();
1192void QQuickRangeSlider::hoverEnterEvent(QHoverEvent *event)
1194 Q_D(QQuickRangeSlider);
1195 QQuickControl::hoverEnterEvent(event);
1196 d->updateHover(event->position());
1200void QQuickRangeSlider::hoverMoveEvent(QHoverEvent *event)
1202 Q_D(QQuickRangeSlider);
1203 QQuickControl::hoverMoveEvent(event);
1204 d->updateHover(event->position());
1208void QQuickRangeSlider::hoverLeaveEvent(QHoverEvent *event)
1210 Q_D(QQuickRangeSlider);
1211 QQuickControl::hoverLeaveEvent(event);
1212 d->first->setHovered(
false);
1213 d->second->setHovered(
false);
1217void QQuickRangeSlider::keyReleaseEvent(QKeyEvent *event)
1219 Q_D(QQuickRangeSlider);
1220 QQuickControl::keyReleaseEvent(event);
1221 d->first->setPressed(
false);
1222 d->second->setPressed(
false);
1225void QQuickRangeSlider::mousePressEvent(QMouseEvent *event)
1227 Q_D(QQuickRangeSlider);
1228 QQuickControl::mousePressEvent(event);
1229 d->handleMove(event->position(), event->timestamp());
1230 setKeepMouseGrab(
true);
1233#if QT_CONFIG(quicktemplates2_multitouch)
1234void QQuickRangeSlider::touchEvent(QTouchEvent *event)
1236 Q_D(QQuickRangeSlider);
1237 switch (event->type()) {
1238 case QEvent::TouchUpdate:
1239 for (
const QTouchEvent::TouchPoint &point : event->points()) {
1240 if (!d->acceptTouch(point))
1243 switch (point.state()) {
1244 case QEventPoint::Pressed:
1245 d->handlePress(point.position(), event->timestamp());
1247 case QEventPoint::Updated:
1248 if (!keepTouchGrab()) {
1249 if (d->orientation == Qt::Horizontal) {
1250 setKeepTouchGrab(QQuickDeliveryAgentPrivate::dragOverThreshold(point.position().x() - point.pressPosition().x(),
1251 Qt::XAxis, point, qRound(d->touchDragThreshold)));
1253 setKeepTouchGrab(QQuickDeliveryAgentPrivate::dragOverThreshold(point.position().y() - point.pressPosition().y(),
1254 Qt::YAxis, point, qRound(d->touchDragThreshold)));
1257 if (keepTouchGrab())
1258 d->handleMove(point.position(), event->timestamp());
1260 case QEventPoint::Released:
1261 d->handleRelease(point.position(), event->timestamp());
1270 QQuickControl::touchEvent(event);
1276void QQuickRangeSlider::mirrorChange()
1278 Q_D(QQuickRangeSlider);
1279 QQuickControl::mirrorChange();
1280 emit d->first->visualPositionChanged();
1281 emit d->second->visualPositionChanged();
1284void QQuickRangeSlider::classBegin()
1286 Q_D(QQuickRangeSlider);
1287 QQuickControl::classBegin();
1289 QQmlContext *context = qmlContext(
this);
1291 QQmlEngine::setContextForObject(d->first, context);
1292 QQmlEngine::setContextForObject(d->second, context);
1296void QQuickRangeSlider::componentComplete()
1298 Q_D(QQuickRangeSlider);
1299 QQuickRangeSliderNodePrivate *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
1300 QQuickRangeSliderNodePrivate *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
1301 firstPrivate->executeHandle(
true);
1302 secondPrivate->executeHandle(
true);
1304 QQuickControl::componentComplete();
1306 if (firstPrivate->isPendingValue || secondPrivate->isPendingValue
1307 || !qFuzzyCompare(d->from, defaultFrom) || !qFuzzyCompare(d->to, defaultTo)) {
1311 setValues(firstPrivate->isPendingValue ? firstPrivate->pendingValue : firstPrivate->value,
1312 secondPrivate->isPendingValue ? secondPrivate->pendingValue : secondPrivate->value);
1314 firstPrivate->pendingValue = 0;
1315 firstPrivate->isPendingValue =
false;
1316 secondPrivate->pendingValue = 0;
1317 secondPrivate->isPendingValue =
false;
1323 firstPrivate->updatePosition();
1324 secondPrivate->updatePosition();
1327 d->updateAllValuesAreInteger();
1331
1332
1333
1334
1335
1336
1339
1340
1341
1342
1343
1344
1347
1348
1349
1350
1351
1352
1355
1356
1357
1358
1359
1360
1362#if QT_CONFIG(accessibility)
1363QAccessible::Role QQuickRangeSlider::accessibleRole()
const
1365 return QAccessible::Slider;
1371#include "moc_qquickrangeslider_p.cpp"
Used to select a range of values by sliding two handles along a track.
void setPosition(qreal position, bool ignoreOtherPosition=false)
void executeHandle(bool complete=false)
static QQuickRangeSliderNodePrivate * get(QQuickRangeSliderNode *node)
QQuickDeferredPointer< QQuickItem > handle
QQuickRangeSlider * slider
void updatePosition(bool ignoreOtherPosition=false)
void updateAllValuesAreInteger()
bool handleMove(const QPointF &point, ulong timestamp) override
Qt::Orientation orientation
void itemDestroyed(QQuickItem *item) override
void handleUngrab() override
bool handleRelease(const QPointF &point, ulong timestamp) override
QQuickRangeSliderNode * pressedNode(int touchId=-1) const
QQuickRangeSliderNode * first
void itemImplicitHeightChanged(QQuickItem *item) override
bool handlePress(const QPointF &point, ulong timestamp) override
void updateHover(const QPointF &pos)
QQuickRangeSliderNode * second
void itemImplicitWidthChanged(QQuickItem *item) override
Combined button and popup list for selecting options.
static const qreal defaultFrom
static const qreal defaultTo
static qreal valueAt(const QQuickRangeSlider *slider, qreal position)
static qreal positionAt(const QQuickRangeSlider *slider, QQuickItem *handle, const QPointF &point)
static qreal snapPosition(const QQuickRangeSlider *slider, qreal position)