2024-02-14 12:52:54 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQml.Models 2.15
|
2021-10-19 09:17:20 +00:00
|
|
|
|
2023-02-06 13:37:25 +00:00
|
|
|
import StatusQ 0.1
|
2021-10-19 09:17:20 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2022-03-10 19:41:59 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
2024-02-14 12:52:54 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
2022-07-20 10:48:44 +00:00
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
import shared.controls 1.0
|
2022-09-27 21:26:26 +00:00
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
CommonContactDialog {
|
|
|
|
id: root
|
2020-09-16 16:00:21 +00:00
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
readonly property string nickname: contactDetails.localNickname
|
2022-07-20 10:48:44 +00:00
|
|
|
|
2022-03-08 11:01:57 +00:00
|
|
|
signal editDone(string newNickname)
|
2024-02-14 12:52:54 +00:00
|
|
|
signal removeNicknameRequested()
|
|
|
|
|
|
|
|
title: d.editMode ? qsTr("Edit nickname") : qsTr("Add nickname")
|
2021-10-22 20:49:47 +00:00
|
|
|
|
|
|
|
onOpened: {
|
2022-09-27 21:26:26 +00:00
|
|
|
nicknameInput.input.edit.forceActiveFocus()
|
2021-10-22 20:49:47 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
readonly property var d: QtObject {
|
|
|
|
id: d
|
|
|
|
readonly property bool editMode: root.nickname !== ""
|
|
|
|
readonly property int maxNicknameLength: 32
|
|
|
|
}
|
2021-01-12 20:51:00 +00:00
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
StatusInput {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
id: nicknameInput
|
|
|
|
label: qsTr("Nickname")
|
|
|
|
input.clearable: true
|
|
|
|
text: root.nickname
|
|
|
|
charLimit: d.maxNicknameLength
|
|
|
|
validationMode: StatusInput.ValidationMode.IgnoreInvalidInput
|
|
|
|
validators: [
|
|
|
|
StatusValidator {
|
|
|
|
validatorObj: RXValidator { regularExpression: /^[\w\d_ -]*$/u }
|
|
|
|
validate: (value) => validatorObj.test(value)
|
2021-10-19 09:17:20 +00:00
|
|
|
}
|
2024-02-14 12:52:54 +00:00
|
|
|
]
|
|
|
|
Keys.onReleased: {
|
|
|
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
|
|
|
root.editDone(nicknameInput.text)
|
2021-01-13 00:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-16 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("Nicknames help you identify others and are only visible to you")
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:56:29 +00:00
|
|
|
rightButtons: ObjectModel {
|
|
|
|
StatusFlatButton {
|
|
|
|
visible: !d.editMode
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
onClicked: root.close()
|
|
|
|
}
|
|
|
|
StatusFlatButton {
|
|
|
|
visible: d.editMode
|
|
|
|
borderColor: "transparent"
|
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
text: qsTr("Remove nickname")
|
|
|
|
onClicked: root.removeNicknameRequested()
|
|
|
|
}
|
|
|
|
StatusButton {
|
|
|
|
enabled: root.nickname !== nicknameInput.text && nicknameInput.valid
|
|
|
|
text: d.editMode ? qsTr("Change nickname") : qsTr("Add nickname")
|
|
|
|
onClicked: root.editDone(nicknameInput.text)
|
2020-09-16 16:00:21 +00:00
|
|
|
}
|
2024-02-14 12:52:54 +00:00
|
|
|
}
|
2020-09-16 16:00:21 +00:00
|
|
|
}
|