fix(StatusPinInput): `forceFocus` function exposed
This commit is contained in:
parent
05250a6eab
commit
2b4398830a
|
@ -110,7 +110,7 @@ Item {
|
||||||
|
|
||||||
Initializes pin input bringing it to its initial state.
|
Initializes pin input bringing it to its initial state.
|
||||||
|
|
||||||
It is directly called in Component.onCompleted slot and can be called whenever you need resetting it.
|
It can be called whenever you need resetting it.
|
||||||
*/
|
*/
|
||||||
function statesInitialization() {
|
function statesInitialization() {
|
||||||
d.currentPinIndex = 0
|
d.currentPinIndex = 0
|
||||||
|
@ -118,12 +118,41 @@ Item {
|
||||||
for (var i = 1; i < root.pinLen; i++) {
|
for (var i = 1; i < root.pinLen; i++) {
|
||||||
repeater.itemAt(i).innerState = "EMPTY"
|
repeater.itemAt(i).innerState = "EMPTY"
|
||||||
}
|
}
|
||||||
|
inputText.text = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
width: (root.circleDiameter + root.circleSpacing) * root.pinLen
|
/*
|
||||||
height: root.circleDiameter
|
\qmlmethod StatusPinInput::forceFocus()
|
||||||
|
|
||||||
Component.onCompleted: { statesInitialization() }
|
Convenient method to force active focus in case it gets stolen by any other component.
|
||||||
|
*/
|
||||||
|
function forceFocus() {
|
||||||
|
inputText.forceActiveFocus()
|
||||||
|
d.activateBlink()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
\qmlmethod StatusPinInput::setPin(pin)
|
||||||
|
|
||||||
|
Sets the pin input, setting state of each digit to "FILLED".
|
||||||
|
|
||||||
|
It won't do anything if pin length is different from the set `pinLen`.
|
||||||
|
*/
|
||||||
|
function setPin(pin) {
|
||||||
|
if(pin.length !== root.pinLen)
|
||||||
|
return
|
||||||
|
|
||||||
|
d.currentPinIndex = root.pinLen - 1
|
||||||
|
inputText.text = pin
|
||||||
|
|
||||||
|
for (var i = 0; i < root.pinLen; i++) {
|
||||||
|
const currItem = repeater.itemAt(i)
|
||||||
|
currItem.innerState = "FILLED"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
width: (root.circleDiameter + root.circleSpacing) * root.pinLen - root.circleSpacing
|
||||||
|
height: root.circleDiameter
|
||||||
|
|
||||||
// Pin input data management object:
|
// Pin input data management object:
|
||||||
TextInput {
|
TextInput {
|
||||||
|
@ -147,6 +176,7 @@ Item {
|
||||||
else if (text.length <= (d.currentPinIndex + 1)) {
|
else if (text.length <= (d.currentPinIndex + 1)) {
|
||||||
if(d.currentPinIndex < root.pinLen)
|
if(d.currentPinIndex < root.pinLen)
|
||||||
repeater.itemAt(d.currentPinIndex).innerState = "EMPTY"
|
repeater.itemAt(d.currentPinIndex).innerState = "EMPTY"
|
||||||
|
if(d.currentPinIndex > 0)
|
||||||
d.currentPinIndex--
|
d.currentPinIndex--
|
||||||
repeater.itemAt(d.currentPinIndex).innerState = "NEXT"
|
repeater.itemAt(d.currentPinIndex).innerState = "NEXT"
|
||||||
}
|
}
|
||||||
|
@ -226,10 +256,7 @@ Item {
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
|
||||||
// MouseArea behavior:
|
// MouseArea behavior:
|
||||||
onClicked: {
|
onClicked: forceFocus()
|
||||||
inputText.forceActiveFocus()
|
|
||||||
d.activateBlink ()
|
|
||||||
}
|
|
||||||
onContainsMouseChanged: { if(containsMouse) { cursorShape = Qt.PointingHandCursor } }
|
onContainsMouseChanged: { if(containsMouse) { cursorShape = Qt.PointingHandCursor } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue