From 9a17c07fdd62de8c7a67ab9c430c1e2eaf9d73d9 Mon Sep 17 00:00:00 2001 From: Noah Davis Date: Mon, 4 Jan 2021 03:54:13 -0500 Subject: [PATCH] [ChatTextInput] support more image formats and use icons for non-image attached files --- imports/NeoChat/Component/ChatTextInput.qml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/imports/NeoChat/Component/ChatTextInput.qml b/imports/NeoChat/Component/ChatTextInput.qml index 621f4ddf5..2c371cd41 100644 --- a/imports/NeoChat/Component/ChatTextInput.qml +++ b/imports/NeoChat/Component/ChatTextInput.qml @@ -33,7 +33,10 @@ ToolBar { property int autoCompleteEndPosition property bool hasAttachment: false - property url attachmentPath + property url attachmentPath: "" + property var attachmentMimetype: FileType.mimeTypeForUrl(attachmentPath) + property bool hasImageAttachment: hasAttachment && attachmentMimetype.valid + && FileType.supportedImageFormats.includes(attachmentMimetype.preferredSuffix) position: ToolBar.Footer @@ -193,7 +196,7 @@ ToolBar { Image { Layout.preferredHeight: Kirigami.Units.gridUnit * 10 source: attachmentPath - visible: hasAttachment && (attachmentPath.toString().endsWith('.png') || attachmentPath.toString().endsWith('.jpg')) + visible: hasImageAttachment fillMode: Image.PreserveAspectFit Layout.preferredWidth: paintedWidth RowLayout { @@ -249,7 +252,7 @@ ToolBar { } RowLayout { - visible: hasAttachment && !(attachmentPath.toString().endsWith('.png') || attachmentPath.toString().endsWith('.jpg')) + visible: hasAttachment && !hasImageAttachment ToolButton { icon.name: "dialog-cancel" onClicked: { @@ -258,7 +261,15 @@ ToolBar { } } + Kirigami.Icon { + id: mimetypeIcon + implicitHeight: Kirigami.Units.fontMetrics.roundedIconSize(horizontalFileLabel.implicitHeight) + implicitWidth: implicitHeight + source: attachmentMimetype.iconName + } + Label { + id: horizontalFileLabel Layout.alignment: Qt.AlignVCenter text: attachmentPath !== "" ? attachmentPath.toString().substring(attachmentPath.toString().lastIndexOf('/') + 1, attachmentPath.length) : "" }