status-desktop/ui/shared/Input.qml

115 lines
3.8 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
2020-06-17 19:31:01 +00:00
import "../imports"
2020-05-29 17:42:25 +00:00
Item {
property alias textField: inputValue
2020-05-29 17:42:25 +00:00
property string placeholderText: "My placeholder"
property string placeholderTextColor: Style.current.secondaryText
2020-06-04 14:53:10 +00:00
property alias text: inputValue.text
property string validationError: ""
property alias validationErrorAlignment: validationErrorText.horizontalAlignment
property int validationErrorTopMargin: 1
2020-05-29 17:42:25 +00:00
property string label: ""
readonly property bool hasLabel: label !== ""
property color bgColor: Style.current.inputBackground
2020-05-29 17:42:25 +00:00
property url icon: ""
property int iconHeight: 24
property int iconWidth: 24
2020-05-29 17:42:25 +00:00
readonly property bool hasIcon: icon.toString() !== ""
readonly property var forceActiveFocus: function () {
inputValue.forceActiveFocus(Qt.MouseFocusReason)
}
readonly property int labelMargin: 7
property int customHeight: 44
property int fontPixelSize: 15
signal editingFinished(string inputValue)
signal textEdited(string inputValue)
2020-05-29 17:42:25 +00:00
id: inputBox
height: inputRectangle.height + (hasLabel ? inputLabel.height + labelMargin : 0) + (!!validationError ? (validationErrorText.height + validationErrorTopMargin) : 0)
2020-06-04 14:53:10 +00:00
anchors.right: parent.right
anchors.left: parent.left
2020-05-29 17:42:25 +00:00
StyledText {
2020-05-29 17:42:25 +00:00
id: inputLabel
text: inputBox.label
font.weight: Font.Medium
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
font.pixelSize: 13
color: Style.current.textColor
2020-05-29 17:42:25 +00:00
}
Rectangle {
id: inputRectangle
height: customHeight
2020-06-04 18:56:04 +00:00
color: bgColor
radius: Style.current.radius
2020-05-29 17:42:25 +00:00
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
anchors.right: parent.right
anchors.left: parent.left
border.width: !!validationError ? 1 : 0
border.color: Style.current.red
StyledTextField {
2020-05-29 17:42:25 +00:00
id: inputValue
visible: !inputBox.isTextArea && !inputBox.isSelect
2020-05-29 17:42:25 +00:00
placeholderText: inputBox.placeholderText
placeholderTextColor: inputBox.placeholderTextColor
2020-05-29 17:42:25 +00:00
text: inputBox.text
anchors.top: parent.top
anchors.topMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.right: parent.right
anchors.rightMargin: parent.rightMargin
2020-05-29 17:42:25 +00:00
anchors.left: parent.left
anchors.leftMargin: 0
leftPadding: inputBox.hasIcon ? iconWidth + 20 : Style.current.padding
selectByMouse: true
font.pixelSize: fontPixelSize
2020-05-29 17:42:25 +00:00
background: Rectangle {
color: Style.current.transparent
2020-05-29 17:42:25 +00:00
}
onEditingFinished: inputBox.editingFinished(inputBox.text)
onTextEdited: inputBox.textEdited(inputBox.text)
2020-05-29 17:42:25 +00:00
}
SVGImage {
2020-05-29 17:42:25 +00:00
id: iconImg
sourceSize.height: iconHeight
sourceSize.width: iconWidth
2020-05-29 17:42:25 +00:00
anchors.left: parent.left
anchors.leftMargin: Style.current.smallPadding
2020-05-29 17:42:25 +00:00
anchors.verticalCenter: parent.verticalCenter
fillMode: Image.PreserveAspectFit
source: inputBox.icon
}
}
TextEdit {
visible: !!validationError
id: validationErrorText
text: validationError
anchors.top: inputRectangle.bottom
anchors.topMargin: validationErrorTopMargin
selectByMouse: true
readOnly: true
font.pixelSize: 12
height: 16
color: Style.current.danger
width: parent.width
}
2020-05-29 17:42:25 +00:00
}
/*##^##
Designer {
D{i:0;formeditorColor:"#c0c0c0";formeditorZoom:1.25}
2020-05-29 17:42:25 +00:00
}
##^##*/