Warning, /network/neochat/src/qml/AttachmentPane.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.de>
0002 // SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick
0006 import QtQuick.Layouts
0007 import QtQuick.Controls as QQC2
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 import org.kde.neochat
0012 
0013 ColumnLayout {
0014     id: root
0015 
0016     signal attachmentCancelled
0017 
0018     property string attachmentPath
0019 
0020     readonly property var attachmentMimetype: FileType.mimeTypeForUrl(attachmentPath)
0021     readonly property bool hasImage: attachmentMimetype.valid && FileType.supportedImageFormats.includes(attachmentMimetype.preferredSuffix)
0022     readonly property string baseFileName: attachmentPath.substring(attachmentPath.lastIndexOf('/') + 1, attachmentPath.length)
0023 
0024     RowLayout {
0025         spacing: Kirigami.Units.smallSpacing
0026 
0027         QQC2.Label {
0028             Layout.fillWidth: true
0029             Layout.alignment: Qt.AlignLeft
0030             text: i18n("Attachment:")
0031             horizontalAlignment: Text.AlignLeft
0032             verticalAlignment: Text.AlignVCenter
0033         }
0034         QQC2.ToolButton {
0035             id: editImageButton
0036             visible: hasImage
0037             icon.name: "document-edit"
0038             text: i18n("Edit")
0039             display: QQC2.AbstractButton.IconOnly
0040 
0041             Component {
0042                 id: imageEditorPage
0043                 ImageEditorPage {
0044                     imagePath: root.attachmentPath
0045                 }
0046             }
0047 
0048             onClicked: {
0049                 let imageEditor = applicationWindow().pageStack.layers.push(imageEditorPage);
0050                 imageEditor.newPathChanged.connect(function (newPath) {
0051                     applicationWindow().pageStack.layers.pop();
0052                     root.attachmentPath = newPath;
0053                 });
0054             }
0055             QQC2.ToolTip.text: text
0056             QQC2.ToolTip.visible: hovered
0057         }
0058         QQC2.ToolButton {
0059             id: cancelAttachmentButton
0060             display: QQC2.AbstractButton.IconOnly
0061             action: Kirigami.Action {
0062                 text: i18n("Cancel sending attachment")
0063                 icon.name: "dialog-close"
0064                 onTriggered: attachmentCancelled()
0065                 shortcut: "Escape"
0066             }
0067             QQC2.ToolTip.text: text
0068             QQC2.ToolTip.visible: hovered
0069         }
0070     }
0071 
0072     Image {
0073         id: image
0074         Layout.alignment: Qt.AlignHCenter
0075 
0076         asynchronous: true
0077         cache: false // Cache is not needed. Images will rarely be shown repeatedly.
0078         source: hasImage ? root.attachmentPath : ""
0079         visible: hasImage
0080         fillMode: Image.PreserveAspectFit
0081 
0082         onSourceChanged: {
0083             // Reset source size height, which affect implicitHeight
0084             sourceSize.height = -1;
0085         }
0086 
0087         onSourceSizeChanged: {
0088             if (implicitHeight > Kirigami.Units.gridUnit * 8) {
0089                 // This can save a lot of RAM when loading large images.
0090                 // It also improves visual quality for large images.
0091                 sourceSize.height = Kirigami.Units.gridUnit * 8;
0092             }
0093         }
0094 
0095         Behavior on height {
0096             NumberAnimation {
0097                 duration: Kirigami.Units.shortDuration
0098                 easing.type: Easing.OutCubic
0099             }
0100         }
0101     }
0102     QQC2.BusyIndicator {
0103         id: imageBusyIndicator
0104 
0105         visible: running
0106         running: image.visible && image.progress < 1
0107     }
0108     RowLayout {
0109         id: fileInfoLayout
0110         Layout.alignment: Qt.AlignHCenter
0111         spacing: parent.spacing
0112 
0113         Kirigami.Icon {
0114             id: mimetypeIcon
0115             implicitWidth: Kirigami.Units.iconSizes.smallMedium
0116             implicitHeight: Kirigami.Units.iconSizes.smallMedium
0117             source: attachmentMimetype.iconName
0118         }
0119         QQC2.Label {
0120             id: fileLabel
0121             text: baseFileName
0122         }
0123     }
0124 }