2020-06-10 14:11:06 +00:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtGraphicalEffects 1.12
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2020-06-10 14:11:06 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
property alias textField: textArea
|
|
|
|
property string placeholderText: "My placeholder"
|
|
|
|
property alias text: textArea.text
|
2020-06-22 17:26:47 +00:00
|
|
|
property string validationError: ""
|
2020-06-10 14:11:06 +00:00
|
|
|
property string label: ""
|
|
|
|
readonly property bool hasLabel: label !== ""
|
2020-07-22 20:16:06 +00:00
|
|
|
property color bgColor: Style.current.inputBackground
|
2020-06-10 14:11:06 +00:00
|
|
|
readonly property var forceActiveFocus: function () {
|
|
|
|
textArea.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
readonly property int labelMargin: 7
|
|
|
|
property int customHeight: 44
|
2021-04-14 20:50:09 +00:00
|
|
|
property bool hideRectangle: false
|
|
|
|
signal keyPressed(var event)
|
2020-06-10 14:11:06 +00:00
|
|
|
|
|
|
|
id: inputBox
|
2020-06-22 17:26:47 +00:00
|
|
|
height: inputRectangle.height + (hasLabel ? inputLabel.height + labelMargin : 0) + (!!validationError ? validationErrorText.height : 0)
|
2020-06-10 14:11:06 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-10 14:11:06 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: inputRectangle
|
|
|
|
height: customHeight
|
2021-04-14 20:50:09 +00:00
|
|
|
color: hideRectangle ? Style.current.transparent : bgColor
|
2020-07-22 20:16:06 +00:00
|
|
|
radius: Style.current.radius
|
2020-06-10 14:11:06 +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
|
2021-04-14 20:50:09 +00:00
|
|
|
border.width: !!validationError && !hideRectangle ? 1 : 0
|
2020-07-02 15:14:31 +00:00
|
|
|
border.color: Style.current.red
|
2020-06-10 14:11:06 +00:00
|
|
|
|
|
|
|
TextArea {
|
|
|
|
id: textArea
|
|
|
|
text: ""
|
|
|
|
font.pixelSize: 15
|
2021-04-28 19:34:16 +00:00
|
|
|
selectByMouse: true
|
2020-12-11 20:29:46 +00:00
|
|
|
wrapMode: Text.WrapAnywhere
|
2020-06-10 14:11:06 +00:00
|
|
|
placeholderText: inputBox.placeholderText
|
2020-12-11 20:29:46 +00:00
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
anchors.leftMargin: inputBox.hasIcon ? 36 : Style.current.smallPadding
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.bottomMargin: Style.current.smallPadding
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
2020-06-10 14:11:06 +00:00
|
|
|
anchors.fill: parent
|
2020-07-02 15:14:31 +00:00
|
|
|
font.family: Style.current.fontRegular.name
|
2020-10-03 13:53:46 +00:00
|
|
|
color: Style.current.textColor
|
2021-04-28 19:34:16 +00:00
|
|
|
placeholderTextColor: Style.current.secondaryText
|
2021-01-14 15:11:10 +00:00
|
|
|
selectionColor: Style.current.primarySelectionColor
|
2021-04-14 20:50:09 +00:00
|
|
|
|
|
|
|
Keys.onPressed: inputBox.keyPressed(event)
|
2020-06-10 14:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-22 17:26:47 +00:00
|
|
|
|
|
|
|
TextEdit {
|
|
|
|
visible: !!validationError
|
|
|
|
id: validationErrorText
|
|
|
|
text: validationError
|
|
|
|
anchors.top: inputRectangle.bottom
|
|
|
|
anchors.topMargin: 1
|
|
|
|
selectByMouse: true
|
|
|
|
readOnly: true
|
|
|
|
font.pixelSize: 12
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.red
|
2021-01-14 15:11:10 +00:00
|
|
|
selectedTextColor: Style.current.textColor
|
|
|
|
selectionColor: Style.current.primarySelectionColor
|
2020-06-22 17:26:47 +00:00
|
|
|
}
|
2020-06-10 14:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;formeditorColor:"#ffffff";formeditorZoom:1.25}
|
|
|
|
}
|
|
|
|
##^##*/
|
|
|
|
|