Page MenuHomePhorge

Image.qml
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

Image.qml

/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import moe.kazv.mxc.kazv 0.0 as MK
import Qt.labs.platform 1.1 as Platform
import org.kde.kirigami 2.13 as Kirigami
import '..' as Kazv
Simple {
id: upper
property var gender: 'neutral'
property var body: event.content.body
property var mxcUri: event.content.url
property var imageUri: matrixSdk.mxcUriToHttp(mxcUri)
property var imageInfo: event.content.info || {}
property var imageWidth: image.implicitWidth || imageInfo.w || 1 // lest we divide by 0
property var imageHeight: image.implicitHeight || imageInfo.h || 1
property var innerContentWidth: upper.contentMaxWidth - bubble.bubbleSpacing
property var kazvIO: MK.KazvIO {
onResult: {
progressBarLayout.visible = false
}
}
Kazv.Bubble {
id: bubble
ColumnLayout {
id: layout
Label {
Layout.fillWidth: false
Layout.maximumWidth: innerContentWidth
wrapMode: Text.Wrap
text: l10n.get('event-message-image-sent', { gender, body })
}
Image {
id: image
source: imageUri
Layout.maximumWidth: innerContentWidth
Layout.preferredWidth: imageWidth
Layout.preferredHeight: imageHeight / imageWidth * width
fillMode: Image.PreserveAspectFit
TapHandler {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onSingleTapped: {
if (eventPoint.event.button === Qt.RightButton) {
optionMenu.popup()
}
if (eventPoint.event.button === Qt.LeftButton) {
// TODO: Open with default program
}
}
onLongPressed: {
optionMenu.popup()
}
}
Menu {
id: optionMenu
Kirigami.Action {
text: l10n.get('menu-option-view')
// shortcut: StandardKey.Open
// TODO: open with default program
}
Kirigami.Action {
text: l10n.get('menu-option-save-as')
// Can't think of a suitable shortcut key
// shortcut: StandardKey.Save
onTriggered: {
fileDialog.open()
}
}
}
}
RowLayout {
id: progressBarLayout
// visible: false
Layout.preferredWidth: image.width
ProgressBar {
id: progressBar
Layout.fillWidth: true
value: kazvIO.progress
}
RoundButton {
/* In the best case this should be an icon */
text: l10n.get('button-download-suspend')
property var suspended: false
onClicked: {
if (suspended) {
kazvIO.resume()
console.log("resume")
} else {
kazvIO.suspend()
suspended = true
console.log("suspend")
}
}
}
RoundButton {
/* In the best case this should be an icon */
text: l10n.get('button-download-cancel')
onClicked: {
kazvIO.cancel()
console.log("cancel")
}
}
}
Platform.FileDialog {
id: fileDialog
acceptLabel: l10n.get('menu-option-save-as')
fileMode: Platform.FileDialog.SaveFile
onAccepted: {
kazvIO.fileUrl = file
kazvIO.download(imageUri)
progressBarLayout.visible = true
}
}
}
}
}

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 2, 2:58 AM (17 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
487027
Default Alt Text
Image.qml (3 KB)

Event Timeline