import QtQuick // A labelled single-line input with an inline error and optional secret echo. // // It forwards the arrow/Escape keys as signals so a wrapping combo box can // implement keyboard selection without the field knowing about suggestions. Column { id: field property string label: "" property string placeholder: "" property string error: "" property bool secret: false property bool showSecret: false // When true, an Escape key is consumed here (used to close a suggestion // list). Otherwise it bubbles so the window can react to it. property bool escapeConsumed: false // When true, Return/Enter is consumed here (used to select a highlighted // suggestion). Otherwise it bubbles so the page can advance. property bool returnConsumed: false property alias text: input.text property alias inputItem: input property int maxLength: 256 signal edited(string value) signal accepted signal keyUp signal keyDown signal keyEscape width: parent ? parent.width : implicitWidth spacing: 6 function forceFocus() { input.forceActiveFocus(); } Text { width: parent.width text: field.label color: Theme.warmWhite font.family: Theme.family font.pixelSize: Theme.fontSmall font.weight: Font.DemiBold visible: field.label.length > 0 } Rectangle { width: parent.width height: Theme.controlHeight radius: Theme.radiusSmall color: Theme.charcoal border.width: input.activeFocus ? 2 : 1 border.color: field.error.length > 0 ? Theme.danger : input.activeFocus ? Theme.focusRing : Theme.border TextInput { id: input anchors.fill: parent anchors.leftMargin: 12 anchors.rightMargin: field.secret ? 52 : 12 verticalAlignment: TextInput.AlignVCenter color: Theme.warmWhite font.family: Theme.family font.pixelSize: Theme.fontBody selectionColor: Theme.amberDeep selectedTextColor: Theme.warmWhite echoMode: (field.secret && !field.showSecret) ? TextInput.Password : TextInput.Normal passwordCharacter: "\u2022" selectByMouse: true activeFocusOnTab: true maximumLength: field.maxLength clip: true Accessible.role: Accessible.EditableText Accessible.name: field.label.length > 0 ? field.label : field.placeholder Accessible.description: field.error onTextEdited: field.edited(text) Keys.onReturnPressed: event => { const consumed = field.returnConsumed; field.accepted(); event.accepted = consumed; } Keys.onEnterPressed: event => { const consumed = field.returnConsumed; field.accepted(); event.accepted = consumed; } Keys.onUpPressed: event => { event.accepted = true; field.keyUp(); } Keys.onDownPressed: event => { event.accepted = true; field.keyDown(); } Keys.onEscapePressed: event => { const consumed = field.escapeConsumed; field.keyEscape(); event.accepted = consumed; } Text { anchors.fill: parent verticalAlignment: Text.AlignVCenter text: field.placeholder color: Theme.muted font.family: Theme.family font.pixelSize: Theme.fontBody visible: input.text.length === 0 && !input.activeFocus } } // The show/hide control is a real focus stop, reachable with Tab and // operable with Space/Enter, so revealing a password never requires a // mouse. Item { id: reveal anchors.right: parent.right anchors.rightMargin: 10 anchors.verticalCenter: parent.verticalCenter width: 40 height: 26 visible: field.secret activeFocusOnTab: field.secret Accessible.role: Accessible.Button Accessible.name: field.showSecret ? "Hide " + field.label : "Show " + field.label Accessible.onPressAction: reveal.toggle() function toggle() { field.showSecret = !field.showSecret; } Keys.onReturnPressed: reveal.toggle() Keys.onEnterPressed: reveal.toggle() Keys.onSpacePressed: reveal.toggle() Rectangle { anchors.fill: parent radius: Theme.radiusSmall color: "transparent" border.width: 2 border.color: Theme.focusRing visible: reveal.activeFocus } Text { anchors.centerIn: parent text: field.showSecret ? "hide" : "show" color: Theme.amber font.family: Theme.family font.pixelSize: Theme.fontSmall } MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: reveal.toggle() } } } Text { width: parent.width text: field.error color: Theme.danger font.family: Theme.family font.pixelSize: Theme.fontSmall wrapMode: Text.WordWrap visible: field.error.length > 0 } }