Skip to content

Commit 6606582

Browse files
committed
Merge pull request #7 from buttleofx/QuickEditableNumberInput
Default increment on arrow buttons
2 parents f80aa24 + 340ed8b commit 6606582

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

example/quickEditableNumberInput/source.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Rectangle
1111

1212
property string linkedText: "42.42"
1313

14+
FocusHandler {
15+
16+
}
17+
1418
QuickEditableNumberInput {
1519
id: numberInput
1620
width: 150
@@ -20,6 +24,7 @@ Rectangle
2024
minValue: -25
2125
maxValue: 50
2226
decimals: 3
27+
defaultIncrement: 0.5
2328

2429
// Access to all properties of a classic qml textInput by textInput.<textIntproperty>
2530
textInput.text: root.linkedText

qml/QuickMamba/QuickEditableNumberInput.qml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Rectangle {
88
property real minValue: Number.NEGATIVE_INFINITY
99
property real maxValue: Number.POSITIVE_INFINITY
1010
property int decimals: 0
11+
property real defaultIncrement: 1
1112

1213
property alias textInput: textInput
1314

@@ -42,14 +43,16 @@ Rectangle {
4243
var oldValueFloat = parseFloat(oldValueStr)
4344
var pointPosition = oldValueStr.indexOf(".")
4445

45-
var increment = 1
46+
var increment = root.defaultIncrement
4647

4748
/* Calcul the increment value in function of the right digit to the cursor
48-
* e.g. 12.2|32 : increment is then 0.01
49-
* If cursor is left to the point or negative sign, increment is just default value (1)
49+
* e.g. 12.2|32 : increment is then 0.01 *
50+
* The increment is equal to default value in some case :
51+
* - If cursor is left to the point or to the negative sign
52+
* - If there is no focus (e.g. Just by clicking on arrow buttons)
5053
* The point is added if there is not and cursor is top right
5154
*/
52-
if (!(oldValueFloat < 0 && oldCursorPos == 0)) {
55+
if (!(oldValueFloat < 0 && oldCursorPos == 0) && textInput.focus) {
5356
if (pointPosition == -1)
5457
increment = Math.pow(10, oldValueStr.length - oldCursorPos - 1)
5558
else if (oldCursorPos < pointPosition)

0 commit comments

Comments
 (0)