Skip to content

Commit 3882199

Browse files
committed
fix: allow editing float spinbox manually
1 parent 1aa9029 commit 3882199

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

package/contents/ui/components/SpinBoxDecimal.qml

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ TextField {
1111
property real value: 0
1212

1313
placeholderText: "0-1"
14-
text: value.toFixed(validator.decimals).toString() ?? "0.00"
14+
text: "0.00"
15+
16+
onTextChanged: {
17+
if (!acceptableInput) return
18+
value = parseFloat(text).toFixed(2)
19+
}
1520

1621
validator: DoubleValidator {
1722
bottom: root.from
@@ -22,6 +27,7 @@ TextField {
2227

2328
onValueChanged: {
2429
root.value = isNaN(value) ? 0 : value
30+
text = root.value.toFixed(validator.decimals).toString() ?? "0.00"
2531
}
2632

2733
ValueMouseControl {

package/contents/ui/components/ValueMouseControl.qml

+32-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ Item {
1919
radius: 2
2020
}
2121

22+
function up() {
23+
if (value < to) value += stepSize
24+
value = Math.max(from, Math.min(to, value)).toFixed(decimals)
25+
}
26+
function down() {
27+
if (value > from) value -= stepSize
28+
value = Math.max(from, Math.min(to, value)).toFixed(decimals)
29+
}
30+
2231
Kirigami.Icon {
2332
source: "arrow-up"
2433
height: parent.height / 2
@@ -31,10 +40,17 @@ Item {
3140
id: upMouse
3241
anchors.fill: parent
3342
hoverEnabled: true
34-
onClicked: {
35-
root.parent.forceActiveFocus()
36-
if (value < to) value += stepSize
37-
value = Math.max(from, Math.min(to, value)).toFixed(decimals)
43+
onPressed: { timerUp.start() }
44+
onReleased: { timerUp.stop() }
45+
}
46+
Timer {
47+
id: timerUp
48+
interval: 150
49+
repeat: true
50+
triggeredOnStart: true
51+
running: false
52+
onTriggered: {
53+
up()
3854
}
3955
}
4056
}
@@ -51,17 +67,25 @@ Item {
5167
id: downMouse
5268
anchors.fill: parent
5369
hoverEnabled: true
54-
onClicked: {
55-
root.parent.forceActiveFocus()
56-
if (value > from) value -= stepSize
57-
value = Math.max(from, Math.min(to, value)).toFixed(decimals)
70+
onPressed: { timerDown.start() }
71+
onReleased: { timerDown.stop() }
72+
}
73+
Timer {
74+
id: timerDown
75+
interval: 150
76+
repeat: true
77+
triggeredOnStart: true
78+
running: false
79+
onTriggered: {
80+
down()
5881
}
5982
}
6083
}
6184

6285
MouseArea {
6386
anchors.fill: parent
6487
propagateComposedEvents: true
88+
acceptedButtons: Qt.MiddleButton
6589
onWheel: (wheel) => {
6690
root.parent.forceActiveFocus()
6791
if(wheel.angleDelta.y > 0 && value < to) {

0 commit comments

Comments
 (0)