smsapp: Use Kirigami.ShadowedRectangle instead of DropShadow

Deprecated, allows to remove Qt5Compat import.
This commit is contained in:
Mike Noe 2024-03-14 18:57:54 -04:00
parent c469cdee88
commit 8b65e48b7f

View file

@ -9,7 +9,6 @@ import QtCore
import QtQuick.Controls as Controls import QtQuick.Controls as Controls
import QtQuick.Layouts import QtQuick.Layouts
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import Qt5Compat.GraphicalEffects
import QtQuick.Dialogs import QtQuick.Dialogs
import org.kde.kdeconnect.sms import org.kde.kdeconnect.sms
@ -41,166 +40,169 @@ ColumnLayout {
} }
} }
Controls.Pane { Kirigami.ShadowedRectangle {
id: sendingArea implicitHeight: sendingArea.height
enabled: page.deviceConnected implicitWidth: sendingArea.width
layer.enabled: sendingArea.enabled color: "transparent"
layer.effect: DropShadow { shadow {
verticalOffset: 1 size: Math.round(Kirigami.Units.largeSpacing*1.5)
color: Kirigami.Theme.disabledTextColor color: Kirigami.Theme.disabledTextColor
samples: 20
spread: 0.3
}
Layout.fillWidth: true
padding: 0
wheelEnabled: true
background: Rectangle {
color: Kirigami.Theme.backgroundColor
} }
RowLayout { Controls.Pane {
anchors.fill: parent id: sendingArea
enabled: page.deviceConnected
implicitWidth: root.width
padding: 0
wheelEnabled: true
Controls.ScrollView { RowLayout {
Layout.fillWidth: true anchors.fill: parent
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.TextArea { Controls.ScrollView {
width: parent.width Layout.fillWidth: true
id: messageField Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3
placeholderText: i18nd("kdeconnect-sms", "Compose message") contentWidth: page.width - sendButtonArea.width
wrapMode: TextEdit.Wrap clip: true
topPadding: Kirigami.Units.gridUnit * 0.5 Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff
bottomPadding: topPadding
selectByMouse: true Controls.TextArea {
hoverEnabled: true width: parent.width
background: MouseArea { id: messageField
placeholderText: i18nd("kdeconnect-sms", "Compose message")
wrapMode: TextEdit.Wrap
topPadding: Kirigami.Units.gridUnit * 0.5
bottomPadding: topPadding
selectByMouse: true
hoverEnabled: true hoverEnabled: true
acceptedButtons: Qt.NoButton background: MouseArea {
cursorShape: Qt.IBeamCursor hoverEnabled: true
z: 1 acceptedButtons: Qt.NoButton
} cursorShape: Qt.IBeamCursor
Keys.onReturnPressed: event => { z: 1
if (event.key === Qt.Key_Return) { }
if (event.modifiers & Qt.ShiftModifier) { Keys.onReturnPressed: event => {
messageField.append("") if (event.key === Qt.Key_Return) {
} else { if (event.modifiers & Qt.ShiftModifier) {
sendButton.clicked() messageField.append("")
event.accepted = true } else {
sendButton.clicked()
event.accepted = true
}
} }
} }
} }
} }
}
ColumnLayout { ColumnLayout {
id: sendButtonArea id: sendButtonArea
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
RowLayout { RowLayout {
Controls.ToolButton { Controls.ToolButton {
id: attachFilesButton id: attachFilesButton
enabled: true enabled: true
Layout.preferredWidth: Kirigami.Units.gridUnit * 2 Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
padding: 0 padding: 0
Text { Text {
id: attachedFilesCount id: attachedFilesCount
text: selectedFileUrls.length text: selectedFileUrls.length
color: "red" 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 visible: selectedFileUrls.length > 0
} Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Kirigami.Icon { Layout.preferredHeight: Kirigami.Units.gridUnit * 2
source: "insert-image" padding: 0
isMask: true Kirigami.Icon {
smooth: true id: cancelIcon
anchors.centerIn: parent source: "edit-clear"
width: Kirigami.Units.gridUnit * 1.5 isMask: true
height: width smooth: true
} anchors.centerIn: parent
width: Kirigami.Units.gridUnit * 1.5
onClicked: { height: width
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) { onClicked: {
messageField.text = ""
selectedFileUrls = [] selectedFileUrls = []
} }
isSendingInProcess = false }
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 { Controls.Label {
id: charCount id: charCount
text: conversationModel.getCharCountInfo(messageField.text) text: conversationModel.getCharCountInfo(messageField.text)
visible: text.length > 0 visible: text.length > 0
Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink
}
} }
} }
} }
} }
} }