3#include "qml_material/control/control.hpp"
4#include "qml_material/input/input_host.hpp"
11class QML_MATERIAL_API Slider :
public Control {
13 QML_NAMED_ELEMENT(SliderBase)
14 Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL)
15 Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL)
16 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL)
17 Q_PROPERTY(qreal previewValue READ previewValue NOTIFY previewValueChanged FINAL)
18 Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL)
19 Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL)
20 Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL)
21 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL)
22 Q_PROPERTY(InteractionSource* interactionSource READ interactionSource WRITE
23 setInteractionSource NOTIFY interactionSourceChanged FINAL)
24 Q_PROPERTY(
bool focusVisible READ focusVisible NOTIFY focusVisibleChanged FINAL)
25 Q_PROPERTY(
bool live READ live WRITE setLive NOTIFY liveChanged FINAL)
27 bool wheelEnabled READ wheelEnabled WRITE setWheelEnabled NOTIFY wheelEnabledChanged FINAL)
28 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY
29 orientationChanged FINAL)
30 Q_PROPERTY(
bool horizontal READ horizontal NOTIFY orientationChanged FINAL)
31 Q_PROPERTY(
bool vertical READ vertical NOTIFY orientationChanged FINAL)
32 Q_PROPERTY(QQuickItem* handle READ handle WRITE setHandle NOTIFY handleChanged FINAL)
34 qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL)
35 Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY
36 implicitHandleHeightChanged FINAL)
37 Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET
38 resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL)
47 explicit Slider(QQuickItem* parent =
nullptr);
49 qreal from()
const {
return m_from; }
50 qreal to()
const {
return m_to; }
51 qreal value()
const {
return m_value; }
52 qreal previewValue()
const;
53 qreal position()
const {
return m_position; }
54 qreal visualPosition()
const {
return vertical() || mirrored() ? 1 - m_position : m_position; }
55 qreal stepSize()
const {
return m_step; }
56 SnapMode snapMode()
const {
return m_snap; }
57 InteractionSource* interactionSource() {
return m_input.source(); }
58 void setInteractionSource(InteractionSource* source) { m_input.setSource(source); }
59 bool focusVisible()
const {
return m_input.focusVisible(); }
60 bool live()
const {
return m_live; }
61 bool wheelEnabled()
const {
return m_wheel_enabled; }
62 Qt::Orientation orientation()
const {
return m_orientation; }
63 bool horizontal()
const {
return m_orientation == Qt::Horizontal; }
64 bool vertical()
const {
return m_orientation == Qt::Vertical; }
65 QQuickItem* handle()
const {
return m_handle; }
66 qreal implicitHandleWidth()
const;
67 qreal implicitHandleHeight()
const;
68 qreal touchDragThreshold()
const {
return m_touch_threshold; }
72 void setStepSize(qreal);
73 void setSnapMode(SnapMode);
75 void setWheelEnabled(
bool);
76 void setOrientation(Qt::Orientation);
77 void setHandle(QQuickItem*);
78 void setTouchDragThreshold(qreal);
79 void resetTouchDragThreshold();
80 Q_INVOKABLE qreal valueAt(qreal position)
const;
82 Q_INVOKABLE
void requestValue(qreal value);
83 Q_INVOKABLE
void increase();
84 Q_INVOKABLE
void decrease();
85 Q_INVOKABLE
void cancelInteraction();
86 Q_SIGNAL
void fromChanged();
87 Q_SIGNAL
void toChanged();
88 Q_SIGNAL
void valueChanged();
89 Q_SIGNAL
void previewValueChanged();
90 Q_SIGNAL
void positionChanged();
91 Q_SIGNAL
void visualPositionChanged();
92 Q_SIGNAL
void stepSizeChanged();
93 Q_SIGNAL
void snapModeChanged();
94 Q_SIGNAL
void interactionSourceChanged();
95 Q_SIGNAL
void focusVisibleChanged();
96 Q_SIGNAL
void liveChanged();
97 Q_SIGNAL
void wheelEnabledChanged();
98 Q_SIGNAL
void orientationChanged();
99 Q_SIGNAL
void handleChanged();
100 Q_SIGNAL
void implicitHandleWidthChanged();
101 Q_SIGNAL
void implicitHandleHeightChanged();
102 Q_SIGNAL
void touchDragThresholdChanged();
103 Q_SIGNAL
void valueChangeRequested(qreal value);
104 Q_SIGNAL
void interactionFinished(
bool cancelled);
107 void componentComplete()
override;
108 bool event(QEvent*)
override;
109 void mousePressEvent(QMouseEvent*)
override;
110 void mouseMoveEvent(QMouseEvent*)
override;
111 void mouseReleaseEvent(QMouseEvent*)
override;
112 void mouseDoubleClickEvent(QMouseEvent*)
override;
113 void touchEvent(QTouchEvent*)
override;
114 void mouseUngrabEvent()
override;
115 void touchUngrabEvent()
override;
116 void focusInEvent(QFocusEvent*)
override;
117 void hoverEnterEvent(QHoverEvent*)
override;
118 void hoverMoveEvent(QHoverEvent*)
override;
119 void hoverLeaveEvent(QHoverEvent*)
override;
120 void keyPressEvent(QKeyEvent*)
override;
121 void keyReleaseEvent(QKeyEvent*)
override;
122 void wheelEvent(QWheelEvent*)
override;
123 void focusOutEvent(QFocusEvent*)
override;
124 void itemChange(ItemChange,
const ItemChangeData&)
override;
127 void setPosition(qreal);
128 void updatePosition();
129 qreal positionAt(
const QPointF&)
const;
130 qreal snapPosition(qreal)
const;
131 bool requestChange(qreal);
132 void moveTo(
const QPointF&,
bool release);
133 bool prepareChange();
135 void finishPointer(
bool cancelled);
136 void observeWindow();
137 qreal m_from = 0, m_to = 1, m_value = 0, m_position = 0, m_step = 0;
138 qreal m_touch_threshold = -1;
139 Qt::Orientation m_orientation = Qt::Horizontal;
140 SnapMode m_snap = NoSnap;
141 bool m_live =
true, m_wheel_enabled =
false;
143 quint64 m_generation = 0;
144 bool m_pointerActive =
false, m_dragging =
false;
147 quint64 m_handleRevision = 0;
148 QPointer<QQuickItem> m_handle;
149 QList<QMetaObject::Connection> m_handle_connections;
150 QMetaObject::Connection m_window_connection;