workaround for Qt bug on Password echo mode in textfields

This commit is contained in:
gaelle 2025-02-06 14:06:50 +01:00
parent 711feabcf0
commit de0728651e

View file

@ -2,7 +2,7 @@ import QtQuick
import QtQuick.Controls.Basic as Control import QtQuick.Controls.Basic as Control
import QtQuick.Layouts import QtQuick.Layouts
import Linphone import Linphone
import 'qrc:/qt/qml/Linphone/view/Style/buttonStyle.js' as ButtonStyle import "qrc:/qt/qml/Linphone/view/Style/buttonStyle.js" as ButtonStyle
Control.TextField { Control.TextField {
id: mainItem id: mainItem
@ -10,8 +10,18 @@ Control.TextField {
width: (customWidth ? customWidth - 1 : 360) * DefaultStyle.dp width: (customWidth ? customWidth - 1 : 360) * DefaultStyle.dp
height: 49 * DefaultStyle.dp height: 49 * DefaultStyle.dp
leftPadding: 15 * DefaultStyle.dp leftPadding: 15 * DefaultStyle.dp
rightPadding: eyeButton.visible ? 5 * DefaultStyle.dp + eyeButton.width + eyeButton.rightMargin : 15 * DefaultStyle.dp rightPadding: eyeButton.visible
? 5 * DefaultStyle.dp + eyeButton.width + eyeButton.rightMargin
: 15 * DefaultStyle.dp
echoMode: (hidden && !eyeButton.checked) ? TextInput.Password : TextInput.Normal echoMode: (hidden && !eyeButton.checked) ? TextInput.Password : TextInput.Normal
// Workaround for Windows slowness when first typing a password
// due to Qt not initializing the Password echo mode before the first letter is typed
Component.onCompleted: {
text = "workaround"
resetText()
}
verticalAlignment: TextInput.AlignVCenter verticalAlignment: TextInput.AlignVCenter
color: isError ? DefaultStyle.danger_500main : DefaultStyle.main2_600 color: isError ? DefaultStyle.danger_500main : DefaultStyle.main2_600
placeholderTextColor: DefaultStyle.placeholders placeholderTextColor: DefaultStyle.placeholders
@ -41,12 +51,13 @@ Control.TextField {
property var propertyOwner property var propertyOwner
property var propertyOwnerGui property var propertyOwnerGui
property var initialReading: true property var initialReading: true
property var isValid: function(text) { property var isValid: function (text) {
return true return true
} }
property bool toValidate: false property bool toValidate: false
property int idleTimeOut: 200 property int idleTimeOut: 200
property bool empty: propertyOwnerGui ? mainItem.propertyOwnerGui.core != undefined && mainItem.propertyOwnerGui.core[mainItem.propertyName]?.length == 0 property bool empty: propertyOwnerGui
? mainItem.propertyOwnerGui.core != undefined && mainItem.propertyOwnerGui.core[mainItem.propertyName]?.length == 0
: mainItem.propertyOwner != undefined && mainItem.propertyOwner[mainItem.propertyName]?.length == 0 : mainItem.propertyOwner != undefined && mainItem.propertyOwner[mainItem.propertyName]?.length == 0
property bool canBeEmpty: true property bool canBeEmpty: true
@ -56,14 +67,15 @@ Control.TextField {
text = initialText text = initialText
} }
signal enterPressed() signal enterPressed
onAccepted: {// No need to process changing focus because of TextEdited callback. onAccepted: {
// No need to process changing focus because of TextEdited callback.
idleTimer.stop() idleTimer.stop()
updateText() updateText()
} }
onTextEdited: { onTextEdited: {
if(mainItem.toValidate) { if (mainItem.toValidate) {
idleTimer.restart() idleTimer.restart()
} }
} }
@ -77,15 +89,16 @@ Control.TextField {
return return
} }
if (mainItem.propertyName && isValid(text)) { if (mainItem.propertyName && isValid(text)) {
if(mainItem.propertyOwnerGui){ if (mainItem.propertyOwnerGui) {
if (mainItem.propertyOwnerGui.core[mainItem.propertyName] != text) if (mainItem.propertyOwnerGui.core[mainItem.propertyName] != text)
mainItem.propertyOwnerGui.core[mainItem.propertyName] = text mainItem.propertyOwnerGui.core[mainItem.propertyName] = text
}else{ } else {
if (mainItem.propertyOwner[mainItem.propertyName] != text) if (mainItem.propertyOwner[mainItem.propertyName] != text)
mainItem.propertyOwner[mainItem.propertyName] = text mainItem.propertyOwner[mainItem.propertyName] = text
} }
mainItem.validationChecked(true) mainItem.validationChecked(true)
} else mainItem.validationChecked(false) } else
mainItem.validationChecked(false)
} }
// Validation textfield functions // Validation textfield functions
Timer { Timer {
@ -104,11 +117,7 @@ Control.TextField {
anchors.fill: parent anchors.fill: parent
radius: 79 * DefaultStyle.dp radius: 79 * DefaultStyle.dp
color: mainItem.enabled ? mainItem.backgroundColor : mainItem.disabledBackgroundColor color: mainItem.enabled ? mainItem.backgroundColor : mainItem.disabledBackgroundColor
border.color: mainItem.isError border.color: mainItem.isError ? DefaultStyle.danger_500main : mainItem.activeFocus ? DefaultStyle.main1_500_main : mainItem.backgroundBorderColor
? DefaultStyle.danger_500main
: mainItem.activeFocus
? DefaultStyle.main1_500_main
: mainItem.backgroundBorderColor
} }
cursorDelegate: Rectangle { cursorDelegate: Rectangle {
@ -146,17 +155,20 @@ Control.TextField {
} }
} }
} }
Keys.onPressed: (event) => { Keys.onPressed: event => {
if (event.key == Qt.Key_Control) mainItem.controlIsDown = true if (event.key == Qt.Key_Control)
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { mainItem.controlIsDown = true
if (event.key === Qt.Key_Enter
|| event.key === Qt.Key_Return) {
enterPressed() enterPressed()
if (mainItem.controlIsDown) { if (mainItem.controlIsDown) {
} }
} }
} }
Keys.onReleased: (event) => { Keys.onReleased: event => {
if (event.jey == Qt.Key_Control) mainItem.controlIsDown = false if (event.jey == Qt.Key_Control)
mainItem.controlIsDown = false
} }
Button { Button {
@ -177,4 +189,3 @@ Control.TextField {
anchors.rightMargin: rightMargin anchors.rightMargin: rightMargin
} }
} }