2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
2019-04-27 06:02:20 +10:00
|
|
|
|
|
|
|
TextField {
|
2019-07-18 15:53:28 +10:00
|
|
|
id: field
|
2019-12-14 00:56:52 +11:00
|
|
|
text: defaultText
|
2019-12-13 21:29:58 +11:00
|
|
|
opacity: enabled ? 1 : theme.disabledElementsOpacity
|
2019-12-11 06:32:42 +11:00
|
|
|
selectByMouse: true
|
2019-08-31 08:10:25 +10:00
|
|
|
leftPadding: theme.spacing
|
|
|
|
rightPadding: leftPadding
|
|
|
|
topPadding: theme.spacing / 1.5
|
|
|
|
bottomPadding: topPadding
|
|
|
|
|
2019-07-07 07:50:55 +10:00
|
|
|
font.family: theme.fontFamily.sans
|
|
|
|
font.pixelSize: theme.fontSize.normal
|
2019-08-31 07:04:42 +10:00
|
|
|
font.pointSize: -1
|
2019-04-29 05:13:18 +10:00
|
|
|
|
2019-09-08 07:02:09 +10:00
|
|
|
placeholderTextColor: theme.controls.textField.placeholderText
|
|
|
|
color: activeFocus ?
|
|
|
|
theme.controls.textField.focusedText :
|
|
|
|
theme.controls.textField.text
|
|
|
|
|
2019-04-29 05:13:18 +10:00
|
|
|
background: Rectangle {
|
|
|
|
id: textFieldBackground
|
2019-07-18 15:53:28 +10:00
|
|
|
color: field.activeFocus ? focusedBackgroundColor : backgroundColor
|
2019-08-28 12:25:13 +10:00
|
|
|
border.color: error ? errorBorder :
|
|
|
|
field.activeFocus ? focusedBorderColor : borderColor
|
2019-07-14 10:15:20 +10:00
|
|
|
border.width: bordered ? theme.controls.textField.borderWidth : 0
|
2020-03-16 05:29:20 +11:00
|
|
|
radius: bordered ? theme.radius : 0
|
2019-04-29 05:13:18 +10:00
|
|
|
}
|
2019-04-27 06:02:20 +10:00
|
|
|
|
2019-12-11 06:32:42 +11:00
|
|
|
// Set it only on component creation to avoid binding loops
|
2019-12-11 08:04:03 +11:00
|
|
|
Component.onCompleted: if (! text) {
|
|
|
|
text = window.getState(this, "text", "")
|
|
|
|
cursorPosition = text.length
|
|
|
|
}
|
2019-12-11 06:32:42 +11:00
|
|
|
|
2019-12-11 07:29:49 +11:00
|
|
|
onTextChanged: window.saveState(this)
|
2019-08-23 04:23:33 +10:00
|
|
|
|
|
|
|
Keys.onPressed: if (
|
|
|
|
event.modifiers & Qt.AltModifier ||
|
|
|
|
event.modifiers & Qt.MetaModifier
|
2019-12-11 06:32:42 +11:00
|
|
|
) event.accepted = true // XXX Still needed?
|
|
|
|
|
|
|
|
|
2019-12-11 07:29:49 +11:00
|
|
|
property string saveName: ""
|
2019-12-11 08:04:03 +11:00
|
|
|
property var saveId: "ALL"
|
2019-12-11 07:29:49 +11:00
|
|
|
property var saveProperties: ["text"]
|
|
|
|
|
2019-12-11 06:32:42 +11:00
|
|
|
property bool error: false
|
|
|
|
|
|
|
|
property alias radius: textFieldBackground.radius
|
|
|
|
property bool bordered: true
|
|
|
|
|
|
|
|
property color backgroundColor: theme.controls.textField.background
|
|
|
|
property color borderColor: theme.controls.textField.border
|
|
|
|
property color errorBorder: theme.controls.textField.errorBorder
|
|
|
|
|
|
|
|
property color focusedBackgroundColor:
|
|
|
|
theme.controls.textField.focusedBackground
|
|
|
|
property color focusedBorderColor: theme.controls.textField.focusedBorder
|
2019-12-13 21:29:58 +11:00
|
|
|
|
|
|
|
property var disabledText: null
|
2019-12-14 00:56:52 +11:00
|
|
|
property string defaultText: ""
|
|
|
|
readonly property bool changed: text !== defaultText
|
|
|
|
|
|
|
|
|
|
|
|
function reset() { clear(); text = defaultText }
|
2019-12-13 21:29:58 +11:00
|
|
|
|
|
|
|
|
|
|
|
Binding on color {
|
|
|
|
value: "transparent"
|
|
|
|
when: disabledText !== null && ! field.enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
Binding on placeholderTextColor {
|
|
|
|
value: "transparent"
|
|
|
|
when: disabledText !== null && ! field.enabled
|
|
|
|
}
|
|
|
|
|
2020-03-18 08:41:15 +11:00
|
|
|
Binding on implicitHeight {
|
|
|
|
value: disabledTextLabel.implicitHeight
|
2020-05-30 04:43:30 +10:00
|
|
|
when: disabledText !== null && ! field.enabled
|
2020-03-18 08:41:15 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-12-13 21:29:58 +11:00
|
|
|
Behavior on color { HColorAnimation {} }
|
|
|
|
Behavior on placeholderTextColor { HColorAnimation {} }
|
|
|
|
|
|
|
|
HLabel {
|
2020-03-18 08:41:15 +11:00
|
|
|
id: disabledTextLabel
|
2019-12-13 21:29:58 +11:00
|
|
|
anchors.fill: parent
|
|
|
|
visible: opacity > 0
|
|
|
|
opacity: disabledText !== null && parent.enabled ? 0 : 1
|
|
|
|
text: disabledText || ""
|
|
|
|
|
|
|
|
leftPadding: parent.leftPadding
|
|
|
|
rightPadding: parent.rightPadding
|
|
|
|
topPadding: parent.topPadding
|
|
|
|
bottomPadding: parent.bottomPadding
|
|
|
|
|
2020-03-18 08:41:15 +11:00
|
|
|
wrapMode:
|
|
|
|
parent.wrapMode === TextField.Wrap ? Text.Wrap :
|
|
|
|
parent.wrapMode === TextField.WordWrap ? Text.WordWrap :
|
|
|
|
parent.wrapMode === TextField.WrapAnywhere ? Text.WrapAnywhere :
|
|
|
|
Text.NoWrap
|
|
|
|
|
2019-12-13 21:29:58 +11:00
|
|
|
font.family: parent.font.family
|
|
|
|
font.pixelSize: parent.font.pixelSize
|
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-12-13 21:29:58 +11:00
|
|
|
}
|
2019-04-27 06:02:20 +10:00
|
|
|
}
|