lock: simplify shake anim impl

This commit is contained in:
end-4
2025-10-30 09:58:52 +01:00
parent 3faa20a29b
commit 06514ed7b7
@@ -99,52 +99,47 @@ MouseArea {
opacity: root.toolbarOpacity
ToolbarTextField {
id: passwordBox
placeholderText: GlobalStates.screenUnlockFailed ? Translation.tr("Incorrect password") : Translation.tr("Enter password")
clip: true
font.pixelSize: Appearance.font.pixelSize.small
enabled: !root.context.unlockInProgress
echoMode: TextInput.Password
inputMethodHints: Qt.ImhSensitiveData
onTextChanged: root.context.currentText = this.text
onAccepted: root.context.tryUnlock()
Connections {
target: root.context
function onCurrentTextChanged() {
passwordBox.text = root.context.currentText;
}
}
Keys.onPressed: event => {
root.context.resetClearTimer();
}
id: passwordBox
placeholderText: GlobalStates.screenUnlockFailed ? Translation.tr("Incorrect password") : Translation.tr("Enter password")
// Idk but it work lol
property bool isShaking: false
function startShake() {
shakeAnim.running = false; // reset if running
x = 0; // reset position
shakeAnim.running = true;
}
// Style
clip: true
font.pixelSize: Appearance.font.pixelSize.small
SequentialAnimation {
id: shakeAnim
running: false
NumberAnimation { target: passwordBox; property: "x"; to: -40; duration: 50 }
NumberAnimation { target: passwordBox; property: "x"; to: 40; duration: 50 }
NumberAnimation { target: passwordBox; property: "x"; to: -20; duration: 40 }
NumberAnimation { target: passwordBox; property: "x"; to: 20; duration: 40 }
NumberAnimation { target: passwordBox; property: "x"; to: 0; duration: 30 }
}
// Password
enabled: !root.context.unlockInProgress
echoMode: TextInput.Password
inputMethodHints: Qt.ImhSensitiveData
Connections {
target: GlobalStates
function onScreenUnlockFailedChanged() {
if (GlobalStates.screenUnlockFailed) {
passwordBox.startShake();
// Synchronizing (across monitors) and unlocking
onTextChanged: root.context.currentText = this.text
onAccepted: root.context.tryUnlock()
Connections {
target: root.context
function onCurrentTextChanged() {
passwordBox.text = root.context.currentText;
}
}
Keys.onPressed: event => {
root.context.resetClearTimer();
}
SequentialAnimation {
id: wrongPasswordShakeAnim
NumberAnimation { target: passwordBox; property: "x"; to: -30; duration: 50 }
NumberAnimation { target: passwordBox; property: "x"; to: 30; duration: 50 }
NumberAnimation { target: passwordBox; property: "x"; to: -15; duration: 40 }
NumberAnimation { target: passwordBox; property: "x"; to: 15; duration: 40 }
NumberAnimation { target: passwordBox; property: "x"; to: 0; duration: 30 }
}
Connections {
target: GlobalStates
function onScreenUnlockFailedChanged() {
if (GlobalStates.screenUnlockFailed) wrongPasswordShakeAnim.restart();
}
}
}
}
}
ToolbarButton {
id: confirmButton