smsapp: revert the custom style of compose message area to default kirigami TextArea

This commit is contained in:
Darshan Phaldesai 2024-10-05 18:27:25 +00:00 committed by Albert Vaca Cintora
parent 251ea971c5
commit 22a9571cfb

View file

@ -40,171 +40,164 @@ ColumnLayout {
} }
} }
Kirigami.ShadowedRectangle { Controls.Pane {
implicitHeight: sendingArea.height id: sendingArea
implicitWidth: sendingArea.width enabled: page.deviceConnected
color: "transparent" implicitWidth: root.width
shadow { padding: Kirigami.Units.gridUnit * 0.5
size: Math.round(Kirigami.Units.largeSpacing*1.5) wheelEnabled: true
color: Kirigami.Theme.disabledTextColor
}
Controls.Pane { RowLayout {
id: sendingArea anchors.fill: parent
enabled: page.deviceConnected
implicitWidth: root.width
padding: 0
wheelEnabled: true
RowLayout { Controls.ScrollView {
anchors.fill: parent Layout.fillWidth: true
Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3
contentWidth: page.width - sendButtonArea.width
clip: true
Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff
Controls.ScrollView { Controls.TextArea {
Layout.fillWidth: true width: parent.width
Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3 id: messageField
contentWidth: page.width - sendButtonArea.width placeholderText: i18nd("kdeconnect-sms", "Compose message")
clip: true wrapMode: TextEdit.Wrap
Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff topPadding: Kirigami.Units.gridUnit * 0.5
bottomPadding: topPadding
selectByMouse: true
hoverEnabled: true
Controls.TextArea { Keys.onReturnPressed: event => {
width: parent.width if (event.key === Qt.Key_Return) {
id: messageField if (event.modifiers & Qt.ShiftModifier) {
placeholderText: i18nd("kdeconnect-sms", "Compose message") //remove any selected text and insert new line at cursor position
wrapMode: TextEdit.Wrap messageField.cursorSelection.text = ""
topPadding: Kirigami.Units.gridUnit * 0.5 messageField.insert(messageField.cursorPosition,"\n")
bottomPadding: topPadding } else {
selectByMouse: true sendButton.clicked()
event.accepted = true
}
}
}
MouseArea {
anchors.fill : parent
hoverEnabled: true hoverEnabled: true
background: MouseArea { acceptedButtons: Qt.NoButton
hoverEnabled: true cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.NoButton z: 1
cursorShape: Qt.IBeamCursor
z: 1
}
Keys.onReturnPressed: event => {
if (event.key === Qt.Key_Return) {
if (event.modifiers & Qt.ShiftModifier) {
//remove any selected text and insert new line at cursor position
messageField.cursorSelection.text = ""
messageField.insert(messageField.cursorPosition,"\n")
} else {
sendButton.clicked()
event.accepted = true
}
}
}
}
}
ColumnLayout {
id: sendButtonArea
Layout.alignment: Qt.AlignBottom
RowLayout {
Controls.ToolButton {
id: attachFilesButton
enabled: true
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Text {
id: attachedFilesCount
text: selectedFileUrls.length
color: "red"
visible: selectedFileUrls.length > 0
}
Kirigami.Icon {
source: "insert-image"
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
onClicked: {
fileDialog.open()
}
}
Controls.ToolButton {
id: clearAttachmentButton
visible: selectedFileUrls.length > 0
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Kirigami.Icon {
id: cancelIcon
source: "edit-clear"
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
onClicked: {
selectedFileUrls = []
}
}
Controls.ToolButton {
property bool isSendingInProcess: false
id: sendButton
enabled: (messageField.text.length || selectedFileUrls.length) && !isSendingInProcess
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Kirigami.Icon {
source: "document-send"
enabled: sendButton.enabled
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
property bool messageSent: false
onClicked: {
// prevent sending the same message several times
// and don't touch enabled property
if (isSendingInProcess){
return;
}
isSendingInProcess = true
if (SmsHelper.totalMessageSize(selectedFileUrls, messageField.text) > maxMessageSize) {
messageDialog.visible = true
} else if (page.conversationId === page.invalidId) {
messageSent = conversationModel.startNewConversation(messageField.text, addresses, selectedFileUrls)
} else {
messageSent = conversationModel.sendReplyToConversation(messageField.text, selectedFileUrls)
}
if (messageSent) {
messageField.text = ""
selectedFileUrls = []
}
isSendingInProcess = false
}
}
}
Controls.Label {
id: charCount
text: conversationModel.getCharCountInfo(messageField.text)
visible: text.length > 0
Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink
} }
} }
} }
ColumnLayout {
id: sendButtonArea
Layout.alignment: Qt.AlignBottom
RowLayout {
Controls.ToolButton {
id: attachFilesButton
enabled: true
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Text {
id: attachedFilesCount
text: selectedFileUrls.length
color: "red"
visible: selectedFileUrls.length > 0
}
Kirigami.Icon {
source: "insert-image"
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
onClicked: {
fileDialog.open()
}
}
Controls.ToolButton {
id: clearAttachmentButton
visible: selectedFileUrls.length > 0
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Kirigami.Icon {
id: cancelIcon
source: "edit-clear"
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
onClicked: {
selectedFileUrls = []
}
}
Controls.ToolButton {
property bool isSendingInProcess: false
id: sendButton
enabled: (messageField.text.length || selectedFileUrls.length) && !isSendingInProcess
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0
Kirigami.Icon {
source: "document-send"
enabled: sendButton.enabled
isMask: true
smooth: true
anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
height: width
}
property bool messageSent: false
onClicked: {
// prevent sending the same message several times
// and don't touch enabled property
if (isSendingInProcess){
return;
}
isSendingInProcess = true
if (SmsHelper.totalMessageSize(selectedFileUrls, messageField.text) > maxMessageSize) {
messageDialog.visible = true
} else if (page.conversationId === page.invalidId) {
messageSent = conversationModel.startNewConversation(messageField.text, addresses, selectedFileUrls)
} else {
messageSent = conversationModel.sendReplyToConversation(messageField.text, selectedFileUrls)
}
if (messageSent) {
messageField.text = ""
selectedFileUrls = []
}
isSendingInProcess = false
}
}
}
Controls.Label {
id: charCount
text: conversationModel.getCharCountInfo(messageField.text)
visible: text.length > 0
Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink
}
}
} }
} }
} }