2024-08-27 16:35:52 +02:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2021-08-25 10:52:39 +02:00
|
|
|
|
2024-08-27 16:35:52 +02:00
|
|
|
import StatusQ 0.1
|
2021-10-21 17:07:13 +02:00
|
|
|
import StatusQ.Controls 0.1
|
2021-08-25 10:52:39 +02:00
|
|
|
import StatusQ.Popups 0.1
|
2022-03-28 14:27:46 +03:00
|
|
|
import StatusQ.Core 0.1
|
2024-10-15 21:26:12 +02:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-08-25 10:52:39 +02:00
|
|
|
|
2021-09-28 18:04:06 +03:00
|
|
|
import utils 1.0
|
2021-10-21 17:07:13 +02:00
|
|
|
|
2021-10-14 14:14:11 +02:00
|
|
|
import "../panels"
|
2021-10-14 15:23:03 +02:00
|
|
|
import "../controls"
|
2020-05-29 13:42:25 -04:00
|
|
|
|
|
|
|
Item {
|
2022-01-11 00:30:39 +01:00
|
|
|
id: inputBox
|
|
|
|
|
2020-05-29 15:54:06 -04:00
|
|
|
property alias textField: inputValue
|
2021-07-05 08:34:56 -04:00
|
|
|
property alias inputLabel: inputLabel
|
2022-01-11 00:30:39 +01:00
|
|
|
|
2020-05-29 13:42:25 -04:00
|
|
|
property string placeholderText: "My placeholder"
|
2024-10-15 21:26:12 +02:00
|
|
|
property string placeholderTextColor: Theme.palette.secondaryText
|
2020-06-04 10:53:10 -04:00
|
|
|
property alias text: inputValue.text
|
2021-06-29 14:47:28 +02:00
|
|
|
property alias maxLength: inputValue.maximumLength
|
2020-06-22 11:51:15 -04:00
|
|
|
property string validationError: ""
|
2022-08-03 13:31:59 -04:00
|
|
|
property alias validationErrorObjectName: validationErrorText.objectName
|
2020-08-06 17:25:53 +10:00
|
|
|
property alias validationErrorAlignment: validationErrorText.horizontalAlignment
|
|
|
|
property int validationErrorTopMargin: 1
|
2024-10-15 21:26:12 +02:00
|
|
|
property color validationErrorColor: Theme.palette.dangerColor1
|
2020-05-29 13:42:25 -04:00
|
|
|
property string label: ""
|
2020-06-10 10:11:06 -04:00
|
|
|
readonly property bool hasLabel: label !== ""
|
2024-10-15 21:26:12 +02:00
|
|
|
property color bgColor: Theme.palette.baseColor2
|
2020-05-29 13:42:25 -04:00
|
|
|
property url icon: ""
|
2020-06-15 12:24:21 -04:00
|
|
|
property int iconHeight: 24
|
|
|
|
property int iconWidth: 24
|
2020-08-14 15:19:08 -04:00
|
|
|
property bool copyToClipboard: false
|
2021-04-30 11:05:35 -04:00
|
|
|
property string textToCopy
|
2020-10-29 11:18:36 -04:00
|
|
|
property bool pasteFromClipboard: false
|
2020-09-03 16:43:08 -04:00
|
|
|
property bool readOnly: false
|
2022-01-11 00:30:39 +01:00
|
|
|
property bool keepHeight: false // determine whether validationError should affect item's height
|
2020-06-15 12:24:21 -04:00
|
|
|
|
2020-05-29 13:42:25 -04:00
|
|
|
readonly property bool hasIcon: icon.toString() !== ""
|
|
|
|
readonly property var forceActiveFocus: function () {
|
|
|
|
inputValue.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
readonly property int labelMargin: 7
|
2020-06-08 15:30:22 -04:00
|
|
|
property int customHeight: 44
|
2020-06-15 12:24:21 -04:00
|
|
|
property int fontPixelSize: 15
|
2021-01-21 00:56:38 +04:00
|
|
|
property alias validator: inputValue.validator
|
2020-07-24 13:27:26 +02:00
|
|
|
signal editingFinished(string inputValue)
|
2020-08-06 17:25:53 +10:00
|
|
|
signal textEdited(string inputValue)
|
2022-05-10 11:42:35 -04:00
|
|
|
signal keyPressed(var event)
|
2020-05-29 13:42:25 -04:00
|
|
|
|
2022-01-11 00:30:39 +01:00
|
|
|
implicitHeight: inputRectangle.height +
|
|
|
|
(hasLabel ? inputLabel.height + labelMargin : 0) +
|
|
|
|
(!keepHeight &&!!validationError ? (validationErrorText.height + validationErrorTopMargin) : 0)
|
2020-12-28 15:03:57 -05:00
|
|
|
height: implicitHeight
|
2020-05-29 13:42:25 -04:00
|
|
|
|
2020-08-20 14:45:29 +10:00
|
|
|
function resetInternal() {
|
|
|
|
inputValue.text = ""
|
|
|
|
validationError = ""
|
|
|
|
}
|
|
|
|
|
2023-03-23 11:54:16 +02:00
|
|
|
onFocusChanged: {
|
|
|
|
if(focus) inputField.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
2020-06-19 14:06:58 -04:00
|
|
|
StyledText {
|
2020-05-29 13:42:25 -04:00
|
|
|
id: inputLabel
|
|
|
|
text: inputBox.label
|
|
|
|
font.weight: Font.Medium
|
|
|
|
font.pixelSize: 13
|
2024-10-15 21:26:12 +02:00
|
|
|
color: Theme.palette.textColor
|
2020-05-29 13:42:25 -04:00
|
|
|
}
|
|
|
|
|
2021-07-15 13:35:15 +03:00
|
|
|
Item {
|
|
|
|
id: inputField
|
|
|
|
anchors.left: parent.left
|
2022-07-25 18:16:22 +03:00
|
|
|
anchors.right: parent.right
|
2020-06-08 15:30:22 -04:00
|
|
|
height: customHeight
|
2020-05-29 13:42:25 -04:00
|
|
|
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
|
|
|
|
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
|
2024-09-11 13:49:20 +02:00
|
|
|
StatusTextField {
|
2020-05-29 13:42:25 -04:00
|
|
|
id: inputValue
|
2020-06-08 15:30:22 -04:00
|
|
|
visible: !inputBox.isTextArea && !inputBox.isSelect
|
2020-05-29 13:42:25 -04:00
|
|
|
placeholderText: inputBox.placeholderText
|
2020-08-06 17:25:53 +10:00
|
|
|
placeholderTextColor: inputBox.placeholderTextColor
|
2022-07-25 18:16:22 +03:00
|
|
|
anchors.fill: parent
|
2021-01-28 12:04:10 +01:00
|
|
|
anchors.right: clipboardButtonLoader.active ? clipboardButtonLoader.left : parent.right
|
2024-10-15 21:26:12 +02:00
|
|
|
anchors.rightMargin: clipboardButtonLoader.active ? Theme.padding : 0
|
|
|
|
leftPadding: inputBox.hasIcon ? iconWidth + 20 : Theme.padding
|
2020-06-15 12:24:21 -04:00
|
|
|
font.pixelSize: fontPixelSize
|
2020-09-03 16:43:08 -04:00
|
|
|
readOnly: inputBox.readOnly
|
2020-05-29 13:42:25 -04:00
|
|
|
background: Rectangle {
|
2021-07-15 13:35:15 +03:00
|
|
|
id: inputRectangle
|
|
|
|
anchors.fill: parent
|
|
|
|
color: bgColor
|
2024-10-15 21:26:12 +02:00
|
|
|
radius: Theme.radius
|
2021-07-15 13:35:15 +03:00
|
|
|
border.width: (!!validationError || inputValue.focus) ? 1 : 0
|
|
|
|
border.color: {
|
|
|
|
if (!!validationError) {
|
|
|
|
return validationErrorColor
|
|
|
|
}
|
|
|
|
if (!inputBox.readOnly && inputValue.focus) {
|
2024-10-15 21:26:12 +02:00
|
|
|
return Theme.palette.primaryColor1
|
2021-07-15 13:35:15 +03:00
|
|
|
}
|
2024-10-15 21:26:12 +02:00
|
|
|
return Theme.palette.transparent
|
2021-07-15 13:35:15 +03:00
|
|
|
}
|
2020-05-29 13:42:25 -04:00
|
|
|
}
|
2020-07-24 13:27:26 +02:00
|
|
|
onEditingFinished: inputBox.editingFinished(inputBox.text)
|
2020-08-06 17:25:53 +10:00
|
|
|
onTextEdited: inputBox.textEdited(inputBox.text)
|
2021-08-25 10:52:39 +02:00
|
|
|
|
2022-05-10 11:42:35 -04:00
|
|
|
Keys.onPressed: {
|
|
|
|
inputBox.keyPressed(event);
|
|
|
|
}
|
2020-05-29 13:42:25 -04:00
|
|
|
}
|
|
|
|
|
2020-06-25 09:23:17 -04:00
|
|
|
SVGImage {
|
2020-05-29 13:42:25 -04:00
|
|
|
id: iconImg
|
2020-06-15 12:24:21 -04:00
|
|
|
sourceSize.height: iconHeight
|
|
|
|
sourceSize.width: iconWidth
|
2020-05-29 13:42:25 -04:00
|
|
|
anchors.left: parent.left
|
2024-10-15 21:26:12 +02:00
|
|
|
anchors.leftMargin: Theme.smallPadding
|
2020-05-29 13:42:25 -04:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: inputBox.icon
|
|
|
|
}
|
2020-08-14 15:19:08 -04:00
|
|
|
|
|
|
|
Loader {
|
2021-01-28 12:04:10 +01:00
|
|
|
id: clipboardButtonLoader
|
2020-10-29 11:18:36 -04:00
|
|
|
active: inputBox.copyToClipboard || inputBox.pasteFromClipboard
|
2020-08-14 15:19:08 -04:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
2024-10-15 21:26:12 +02:00
|
|
|
anchors.rightMargin: Theme.padding
|
2020-10-29 11:18:36 -04:00
|
|
|
sourceComponent: Component {
|
|
|
|
Item {
|
|
|
|
width: copyBtn.width
|
|
|
|
height: copyBtn.height
|
2020-08-14 15:19:08 -04:00
|
|
|
|
2020-10-29 11:18:36 -04:00
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
}
|
2020-08-14 15:19:08 -04:00
|
|
|
|
2021-01-28 12:04:10 +01:00
|
|
|
StatusButton {
|
2020-10-29 11:18:36 -04:00
|
|
|
property bool copied: false
|
|
|
|
id: copyBtn
|
2021-01-28 12:04:10 +01:00
|
|
|
text: {
|
2020-10-29 11:18:36 -04:00
|
|
|
if (copied) {
|
|
|
|
return inputBox.copyToClipboard ?
|
2022-04-04 13:26:30 +02:00
|
|
|
qsTr("Copied") :
|
|
|
|
qsTr("Pasted")
|
2020-10-29 11:18:36 -04:00
|
|
|
}
|
|
|
|
return inputBox.copyToClipboard ?
|
2022-04-04 13:26:30 +02:00
|
|
|
qsTr("Copy") :
|
|
|
|
qsTr("Paste")
|
2020-10-29 11:18:36 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
onClicked: {
|
2022-01-24 12:41:55 +01:00
|
|
|
if (inputBox.copyToClipboard) {
|
2024-08-27 16:35:52 +02:00
|
|
|
ClipboardUtils.setText(inputBox.textToCopy ? inputBox.textToCopy : inputValue.text)
|
2022-01-24 12:41:55 +01:00
|
|
|
} else {
|
2024-09-11 13:49:20 +02:00
|
|
|
inputValue.paste()
|
2022-01-24 12:41:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
copyBtn.copied = true
|
|
|
|
timer.setTimeout(function() {
|
|
|
|
copyBtn.copied = false
|
|
|
|
}, 2000);
|
2020-10-29 11:18:36 -04:00
|
|
|
}
|
2020-08-14 15:19:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 13:42:25 -04:00
|
|
|
}
|
2020-06-22 11:51:15 -04:00
|
|
|
|
2022-03-28 14:27:46 +03:00
|
|
|
StatusBaseText {
|
2020-06-22 11:51:15 -04:00
|
|
|
id: validationErrorText
|
2022-07-26 17:17:53 +03:00
|
|
|
visible: !!validationError
|
2020-06-22 11:51:15 -04:00
|
|
|
text: validationError
|
2024-03-05 18:12:03 +04:00
|
|
|
anchors.left: inputField.left
|
|
|
|
anchors.leftMargin: 2
|
2021-07-20 07:37:57 +03:00
|
|
|
anchors.top: inputField.bottom
|
2020-08-06 17:25:53 +10:00
|
|
|
anchors.topMargin: validationErrorTopMargin
|
2022-07-26 17:17:53 +03:00
|
|
|
horizontalAlignment: Text.AlignRight
|
2020-06-22 11:51:15 -04:00
|
|
|
font.pixelSize: 12
|
2020-08-06 17:25:53 +10:00
|
|
|
height: 16
|
2024-10-25 15:22:34 +03:00
|
|
|
width: inputField.width
|
2021-07-07 14:37:49 -04:00
|
|
|
color: validationErrorColor
|
2021-03-25 17:19:05 +11:00
|
|
|
wrapMode: TextEdit.Wrap
|
2020-06-22 11:51:15 -04:00
|
|
|
}
|
2020-05-29 13:42:25 -04:00
|
|
|
}
|