2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2021-08-25 08:52:39 +00:00
|
|
|
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
2020-06-17 19:31:01 +00:00
|
|
|
import "../imports"
|
2021-01-28 11:04:10 +00:00
|
|
|
import "../shared/status"
|
2020-08-14 19:19:08 +00:00
|
|
|
import "."
|
2020-05-29 17:42:25 +00:00
|
|
|
|
|
|
|
Item {
|
2020-05-29 19:54:06 +00:00
|
|
|
property alias textField: inputValue
|
2021-07-05 12:34:56 +00:00
|
|
|
property alias inputLabel: inputLabel
|
|
|
|
|
2020-05-29 17:42:25 +00:00
|
|
|
property string placeholderText: "My placeholder"
|
2020-08-06 07:25:53 +00:00
|
|
|
property string placeholderTextColor: Style.current.secondaryText
|
2020-06-04 14:53:10 +00:00
|
|
|
property alias text: inputValue.text
|
2021-06-29 12:47:28 +00:00
|
|
|
property alias maxLength: inputValue.maximumLength
|
2020-06-22 15:51:15 +00:00
|
|
|
property string validationError: ""
|
2020-08-06 07:25:53 +00:00
|
|
|
property alias validationErrorAlignment: validationErrorText.horizontalAlignment
|
|
|
|
property int validationErrorTopMargin: 1
|
2021-07-07 18:37:49 +00:00
|
|
|
property color validationErrorColor: Style.current.danger
|
2020-05-29 17:42:25 +00:00
|
|
|
property string label: ""
|
2020-06-10 14:11:06 +00:00
|
|
|
readonly property bool hasLabel: label !== ""
|
2020-07-22 20:16:06 +00:00
|
|
|
property color bgColor: Style.current.inputBackground
|
2020-05-29 17:42:25 +00:00
|
|
|
property url icon: ""
|
2020-06-15 16:24:21 +00:00
|
|
|
property int iconHeight: 24
|
|
|
|
property int iconWidth: 24
|
2020-08-14 19:19:08 +00:00
|
|
|
property bool copyToClipboard: false
|
2021-04-30 15:05:35 +00:00
|
|
|
property string textToCopy
|
2020-10-29 15:18:36 +00:00
|
|
|
property bool pasteFromClipboard: false
|
2020-09-03 20:43:08 +00:00
|
|
|
property bool readOnly: false
|
2020-06-15 16:24:21 +00:00
|
|
|
|
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
|
2020-06-08 19:30:22 +00:00
|
|
|
property int customHeight: 44
|
2020-06-15 16:24:21 +00:00
|
|
|
property int fontPixelSize: 15
|
2021-01-20 20:56:38 +00:00
|
|
|
property alias validator: inputValue.validator
|
2020-07-24 11:27:26 +00:00
|
|
|
signal editingFinished(string inputValue)
|
2020-08-06 07:25:53 +00:00
|
|
|
signal textEdited(string inputValue)
|
2020-05-29 17:42:25 +00:00
|
|
|
|
|
|
|
id: inputBox
|
2020-12-28 20:03:57 +00:00
|
|
|
implicitHeight: inputRectangle.height + (hasLabel ? inputLabel.height + labelMargin : 0) + (!!validationError ? (validationErrorText.height + validationErrorTopMargin) : 0)
|
|
|
|
height: implicitHeight
|
2020-06-04 14:53:10 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
2020-05-29 17:42:25 +00:00
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
function resetInternal() {
|
|
|
|
inputValue.text = ""
|
|
|
|
validationError = ""
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +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
|
2020-07-13 18:45:54 +00:00
|
|
|
color: Style.current.textColor
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-15 10:35:15 +00:00
|
|
|
Item {
|
|
|
|
id: inputField
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
2020-06-08 19:30:22 +00:00
|
|
|
height: customHeight
|
2020-05-29 17:42:25 +00:00
|
|
|
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
|
|
|
|
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
|
2020-06-22 15:51:15 +00:00
|
|
|
|
2020-06-19 18:21:02 +00:00
|
|
|
StyledTextField {
|
2020-05-29 17:42:25 +00:00
|
|
|
id: inputValue
|
2020-06-08 19:30:22 +00:00
|
|
|
visible: !inputBox.isTextArea && !inputBox.isSelect
|
2020-05-29 17:42:25 +00:00
|
|
|
placeholderText: inputBox.placeholderText
|
2020-08-06 07:25:53 +00:00
|
|
|
placeholderTextColor: inputBox.placeholderTextColor
|
2020-06-15 16:24:21 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 0
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: 0
|
2021-01-28 11:04:10 +00:00
|
|
|
anchors.right: clipboardButtonLoader.active ? clipboardButtonLoader.left : parent.right
|
2020-06-15 16:24:21 +00:00
|
|
|
anchors.rightMargin: parent.rightMargin
|
2020-05-29 17:42:25 +00:00
|
|
|
anchors.left: parent.left
|
2020-06-15 16:24:21 +00:00
|
|
|
anchors.leftMargin: 0
|
2020-07-02 15:14:31 +00:00
|
|
|
leftPadding: inputBox.hasIcon ? iconWidth + 20 : Style.current.padding
|
2020-06-15 16:24:21 +00:00
|
|
|
selectByMouse: true
|
|
|
|
font.pixelSize: fontPixelSize
|
2020-09-03 20:43:08 +00:00
|
|
|
readOnly: inputBox.readOnly
|
2020-05-29 17:42:25 +00:00
|
|
|
background: Rectangle {
|
2021-07-15 10:35:15 +00:00
|
|
|
id: inputRectangle
|
|
|
|
anchors.fill: parent
|
|
|
|
color: bgColor
|
|
|
|
radius: Style.current.radius
|
|
|
|
border.width: (!!validationError || inputValue.focus) ? 1 : 0
|
|
|
|
border.color: {
|
|
|
|
if (!!validationError) {
|
|
|
|
return validationErrorColor
|
|
|
|
}
|
|
|
|
if (!inputBox.readOnly && inputValue.focus) {
|
|
|
|
return Style.current.inputBorderFocus
|
|
|
|
}
|
|
|
|
return Style.current.transparent
|
|
|
|
}
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
2020-07-24 11:27:26 +00:00
|
|
|
onEditingFinished: inputBox.editingFinished(inputBox.text)
|
2020-08-06 07:25:53 +00:00
|
|
|
onTextEdited: inputBox.textEdited(inputBox.text)
|
2021-08-25 08:52:39 +00:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.RightButton | Qt.LeftButton
|
|
|
|
onClicked: {
|
|
|
|
if((mouse.button === Qt.RightButton) && inputValue.canPaste) {
|
|
|
|
rightClickContextMenu.popup()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inputValue.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 13:23:17 +00:00
|
|
|
SVGImage {
|
2020-05-29 17:42:25 +00:00
|
|
|
id: iconImg
|
2020-06-15 16:24:21 +00:00
|
|
|
sourceSize.height: iconHeight
|
|
|
|
sourceSize.width: iconWidth
|
2020-05-29 17:42:25 +00:00
|
|
|
anchors.left: parent.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
2020-05-29 17:42:25 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: inputBox.icon
|
|
|
|
}
|
2020-08-14 19:19:08 +00:00
|
|
|
|
|
|
|
Loader {
|
2021-01-28 11:04:10 +00:00
|
|
|
id: clipboardButtonLoader
|
2020-10-29 15:18:36 +00:00
|
|
|
active: inputBox.copyToClipboard || inputBox.pasteFromClipboard
|
2020-08-14 19:19:08 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 8
|
2020-10-29 15:18:36 +00:00
|
|
|
sourceComponent: Component {
|
|
|
|
Item {
|
|
|
|
width: copyBtn.width
|
|
|
|
height: copyBtn.height
|
2020-08-14 19:19:08 +00:00
|
|
|
|
2020-10-29 15:18:36 +00:00
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
}
|
2020-08-14 19:19:08 +00:00
|
|
|
|
2021-01-28 11:04:10 +00:00
|
|
|
StatusButton {
|
2020-10-29 15:18:36 +00:00
|
|
|
property bool copied: false
|
|
|
|
id: copyBtn
|
2021-01-28 11:04:10 +00:00
|
|
|
text: {
|
2020-10-29 15:18:36 +00:00
|
|
|
if (copied) {
|
|
|
|
return inputBox.copyToClipboard ?
|
|
|
|
//% "Copied"
|
|
|
|
qsTrId("sharing-copied-to-clipboard") :
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Pasted"
|
|
|
|
qsTrId("pasted")
|
2020-10-29 15:18:36 +00:00
|
|
|
}
|
|
|
|
return inputBox.copyToClipboard ?
|
|
|
|
//% "Copy"
|
|
|
|
qsTrId("copy-to-clipboard") :
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Paste"
|
|
|
|
qsTrId("paste")
|
2020-10-29 15:18:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
height: 28
|
2021-01-28 11:04:10 +00:00
|
|
|
font.pixelSize: 12
|
|
|
|
borderColor: Style.current.blue
|
|
|
|
showBorder: true
|
2020-10-29 15:18:36 +00:00
|
|
|
onClicked: {
|
|
|
|
if (inputBox.copyToClipboard) {
|
2021-04-30 15:05:35 +00:00
|
|
|
chatsModel.copyToClipboard(inputBox.textToCopy ? inputBox.textToCopy : inputValue.text)
|
2020-10-29 15:18:36 +00:00
|
|
|
} else {
|
|
|
|
if (inputValue.canPaste) {
|
|
|
|
inputValue.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
copyBtn.copied = true
|
|
|
|
timer.setTimeout(function() {
|
|
|
|
copyBtn.copied = false
|
|
|
|
}, 2000);
|
|
|
|
}
|
2020-08-14 19:19:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
2020-06-22 15:51:15 +00:00
|
|
|
|
|
|
|
TextEdit {
|
|
|
|
visible: !!validationError
|
|
|
|
id: validationErrorText
|
|
|
|
text: validationError
|
2021-07-20 04:37:57 +00:00
|
|
|
anchors.top: inputField.bottom
|
2020-08-06 07:25:53 +00:00
|
|
|
anchors.topMargin: validationErrorTopMargin
|
2021-07-21 10:16:07 +00:00
|
|
|
anchors.right: inputField.right
|
2020-06-22 15:51:15 +00:00
|
|
|
selectByMouse: true
|
|
|
|
readOnly: true
|
|
|
|
font.pixelSize: 12
|
2020-08-06 07:25:53 +00:00
|
|
|
height: 16
|
2021-07-07 18:37:49 +00:00
|
|
|
color: validationErrorColor
|
2021-03-25 06:19:05 +00:00
|
|
|
wrapMode: TextEdit.Wrap
|
2020-06-22 15:51:15 +00:00
|
|
|
}
|
2021-08-25 08:52:39 +00:00
|
|
|
|
|
|
|
StatusPopupMenu {
|
|
|
|
id: rightClickContextMenu
|
|
|
|
|
|
|
|
StatusMenuItem {
|
|
|
|
enabled: inputValue.canPaste
|
|
|
|
text: qsTrId("Paste")
|
|
|
|
onTriggered: {
|
|
|
|
inputValue.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
inputValue.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
2020-06-22 15:51:15 +00:00
|
|
|
D{i:0;formeditorColor:"#c0c0c0";formeditorZoom:1.25}
|
2020-05-29 17:42:25 +00:00
|
|
|
}
|
|
|
|
##^##*/
|