From ef469ee347751a5f70fb7103a6d0a769868e55bd Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sat, 4 May 2019 21:05:59 +0800 Subject: [PATCH] Load fullscreenimage directly. Tweak reply UI. --- .../Spectral/Component/FullScreenImage.qml | 6 ++-- .../Component/Timeline/FileDelegate.qml | 4 +-- .../Component/Timeline/ImageDelegate.qml | 26 ++------------ .../Component/Timeline/MessageDelegate.qml | 34 +++++-------------- imports/Spectral/Dialog/UserDetailDialog.qml | 14 ++++++++ imports/Spectral/Panel/RoomListPanel.qml | 2 +- qml/main.qml | 2 +- src/spectralroom.cpp | 5 +++ src/spectralroom.h | 2 ++ 9 files changed, 40 insertions(+), 55 deletions(-) diff --git a/imports/Spectral/Component/FullScreenImage.qml b/imports/Spectral/Component/FullScreenImage.qml index 0fb9a31..0caf0a7 100644 --- a/imports/Spectral/Component/FullScreenImage.qml +++ b/imports/Spectral/Component/FullScreenImage.qml @@ -2,7 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 ApplicationWindow { - property string eventId + property string filename property url localPath id: root @@ -11,7 +11,7 @@ ApplicationWindow { visible: true visibility: Qt.WindowFullScreen - title: "Image View - " + eventId + title: "Image View - " + filename color: "#BB000000" @@ -26,8 +26,8 @@ ApplicationWindow { width: Math.min(sourceSize.width, root.width) height: Math.min(sourceSize.height, root.height) - fillMode: Image.PreserveAspectFit cache: false + fillMode: Image.PreserveAspectFit source: localPath } diff --git a/imports/Spectral/Component/Timeline/FileDelegate.qml b/imports/Spectral/Component/Timeline/FileDelegate.qml index 81cd8f5..81dc1b3 100644 --- a/imports/Spectral/Component/Timeline/FileDelegate.qml +++ b/imports/Spectral/Component/Timeline/FileDelegate.qml @@ -174,7 +174,7 @@ ColumnLayout { folderDialog.chosen.connect(function(path) { if (!path) return - currentRoom.downloadFile(eventId, path + "/" + (content.filename || content.body)) + currentRoom.downloadFile(eventId, path + "/" + currentRoom.fileNameToDownload(eventId)) }) folderDialog.open() @@ -186,7 +186,7 @@ ColumnLayout { else { openOnFinished = true - currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + (message || ".tmp")) + currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) } } diff --git a/imports/Spectral/Component/Timeline/ImageDelegate.qml b/imports/Spectral/Component/Timeline/ImageDelegate.qml index 708606d..3d4b67b 100644 --- a/imports/Spectral/Component/Timeline/ImageDelegate.qml +++ b/imports/Spectral/Component/Timeline/ImageDelegate.qml @@ -19,7 +19,6 @@ ColumnLayout { readonly property bool sentByMe: author === currentRoom.localUser property bool openOnFinished: false - property bool showOnFinished: false readonly property bool downloaded: progressInfo && progressInfo.completed id: root @@ -27,10 +26,6 @@ ColumnLayout { spacing: 0 onDownloadedChanged: { - if (downloaded && showOnFinished) { - showSavedFile() - showOnFinished = false - } if (downloaded && openOnFinished) { openSavedFile() openOnFinished = false @@ -160,7 +155,7 @@ ColumnLayout { id: messageMouseArea - onPrimaryClicked: downloadAndShow() + onPrimaryClicked: fullScreenImage.createObject(parent, {"filename": eventId, "localPath": currentRoom.urlToDownload(eventId)}).show() onSecondaryClicked: { var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay) @@ -215,34 +210,19 @@ ColumnLayout { folderDialog.chosen.connect(function(path) { if (!path) return - currentRoom.downloadFile(eventId, path + "/" + (content.filename || content.body)) + currentRoom.downloadFile(eventId, path + "/" + currentRoom.fileNameToDownload(eventId)) }) folderDialog.open() } - function downloadAndShow() - { - if (downloaded) showSavedFile() - else - { - showOnFinished = true - currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + (message || ".tmp")) - } - } - - function showSavedFile() - { - fullScreenImage.createObject(parent, {"eventId": eventId, "localPath": progressInfo.localPath}).show() - } - function downloadAndOpen() { if (downloaded) openSavedFile() else { openOnFinished = true - currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + (message || ".tmp")) + currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) } } diff --git a/imports/Spectral/Component/Timeline/MessageDelegate.qml b/imports/Spectral/Component/Timeline/MessageDelegate.qml index e9a949d..f6346c4 100644 --- a/imports/Spectral/Component/Timeline/MessageDelegate.qml +++ b/imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -136,7 +136,7 @@ ColumnLayout { visible: replyEventId || "" - padding: 8 + padding: 0 background: RippleEffect { anchors.fill: parent @@ -148,38 +148,22 @@ ColumnLayout { spacing: 8 Avatar { - Layout.preferredWidth: 36 - Layout.preferredHeight: 36 + Layout.preferredWidth: 28 + Layout.preferredHeight: 28 Layout.alignment: Qt.AlignTop source: replyAuthor ? replyAuthor.avatarMediaId : "" hint: replyAuthor ? replyAuthor.displayName : "H" } - ColumnLayout { + Label { Layout.fillWidth: true - spacing: 0 + color: "white" + text: "" + (replyDisplay || "") - Label { - Layout.fillWidth: true - - color: "white" - text: replyAuthor ? replyAuthor.displayName : "" - - font.pixelSize: 13 - font.weight: Font.Medium - } - - Label { - Layout.fillWidth: true - - color: "white" - text: "" + (replyDisplay || "") - - wrapMode: Label.Wrap - textFormat: Label.RichText - } + wrapMode: Label.Wrap + textFormat: Label.RichText } } } @@ -213,7 +197,7 @@ ColumnLayout { onLinkActivated: { if (link.startsWith("https://matrix.to/")) { var result = link.replace(/\?.*/, "").match("https://matrix.to/#/(!.*:.*)/(\\$.*:.*)") - if (result.length < 3) return + if (!result || result.length < 3) return if (result[1] != currentRoom.id) return if (!result[2]) return goToEvent(result[2]) diff --git a/imports/Spectral/Dialog/UserDetailDialog.qml b/imports/Spectral/Dialog/UserDetailDialog.qml index 7d5526f..373b1a1 100644 --- a/imports/Spectral/Dialog/UserDetailDialog.qml +++ b/imports/Spectral/Dialog/UserDetailDialog.qml @@ -29,6 +29,14 @@ Dialog { hint: user ? user.displayName : "No name" source: user ? user.avatarMediaId : null + + RippleEffect { + anchors.fill: parent + + circular: true + + onPrimaryClicked: fullScreenImage.createObject(parent, {"filename": user.diaplayName, "localPath": room.urlToMxcUrl(user.avatarUrl)}).show() + } } ColumnLayout { @@ -159,6 +167,12 @@ Dialog { } } + Component { + id: fullScreenImage + + FullScreenImage {} + } + onClosed: destroy() } diff --git a/imports/Spectral/Panel/RoomListPanel.qml b/imports/Spectral/Panel/RoomListPanel.qml index 2741537..003bf85 100644 --- a/imports/Spectral/Panel/RoomListPanel.qml +++ b/imports/Spectral/Panel/RoomListPanel.qml @@ -282,7 +282,7 @@ Item { Layout.fillWidth: true Layout.fillHeight: true - text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm,"") + text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ") color: MPalette.lighter font.pixelSize: 13 elide: Text.ElideRight diff --git a/qml/main.qml b/qml/main.qml index 44bf774..350b241 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -14,7 +14,7 @@ import Spectral 0.1 import Spectral.Setting 0.1 ApplicationWindow { - readonly property bool inPortrait: window.width < window.height + readonly property bool inPortrait: window.width < 640 Material.theme: MPalette.theme Material.background: MPalette.background diff --git a/src/spectralroom.cpp b/src/spectralroom.cpp index 259afaa..f50d73b 100644 --- a/src/spectralroom.cpp +++ b/src/spectralroom.cpp @@ -8,6 +8,7 @@ #include "csapi/typing.h" #include "events/accountdataevents.h" #include "events/typingevent.h" +#include "jobs/downloadfilejob.h" #include #include @@ -233,3 +234,7 @@ QString SpectralRoom::postMarkdownText(const QString& markdown) { return postHtmlText(markdown, result); } + +QUrl SpectralRoom::urlToMxcUrl(QUrl mxcUrl) { + return DownloadFileJob::makeRequestUrl(connection()->homeserver(), mxcUrl); +} diff --git a/src/spectralroom.h b/src/spectralroom.h index 29cea77..6b4908c 100644 --- a/src/spectralroom.h +++ b/src/spectralroom.h @@ -84,6 +84,8 @@ class SpectralRoom : public Room { Q_INVOKABLE QString postMarkdownText(const QString& markdown); + Q_INVOKABLE QUrl urlToMxcUrl(QUrl mxcUrl); + template QString eventToString(const BaseEventT& evt, Qt::TextFormat format = Qt::PlainText) {