Load fullscreenimage directly. Tweak reply UI.

This commit is contained in:
Black Hat 2019-05-04 21:05:59 +08:00
parent ce688e9756
commit ef469ee347
9 changed files with 40 additions and 55 deletions

View File

@ -2,7 +2,7 @@ import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
ApplicationWindow { ApplicationWindow {
property string eventId property string filename
property url localPath property url localPath
id: root id: root
@ -11,7 +11,7 @@ ApplicationWindow {
visible: true visible: true
visibility: Qt.WindowFullScreen visibility: Qt.WindowFullScreen
title: "Image View - " + eventId title: "Image View - " + filename
color: "#BB000000" color: "#BB000000"
@ -26,8 +26,8 @@ ApplicationWindow {
width: Math.min(sourceSize.width, root.width) width: Math.min(sourceSize.width, root.width)
height: Math.min(sourceSize.height, root.height) height: Math.min(sourceSize.height, root.height)
fillMode: Image.PreserveAspectFit
cache: false cache: false
fillMode: Image.PreserveAspectFit
source: localPath source: localPath
} }

View File

@ -174,7 +174,7 @@ ColumnLayout {
folderDialog.chosen.connect(function(path) { folderDialog.chosen.connect(function(path) {
if (!path) return if (!path) return
currentRoom.downloadFile(eventId, path + "/" + (content.filename || content.body)) currentRoom.downloadFile(eventId, path + "/" + currentRoom.fileNameToDownload(eventId))
}) })
folderDialog.open() folderDialog.open()
@ -186,7 +186,7 @@ ColumnLayout {
else else
{ {
openOnFinished = true 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))
} }
} }

View File

@ -19,7 +19,6 @@ ColumnLayout {
readonly property bool sentByMe: author === currentRoom.localUser readonly property bool sentByMe: author === currentRoom.localUser
property bool openOnFinished: false property bool openOnFinished: false
property bool showOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed readonly property bool downloaded: progressInfo && progressInfo.completed
id: root id: root
@ -27,10 +26,6 @@ ColumnLayout {
spacing: 0 spacing: 0
onDownloadedChanged: { onDownloadedChanged: {
if (downloaded && showOnFinished) {
showSavedFile()
showOnFinished = false
}
if (downloaded && openOnFinished) { if (downloaded && openOnFinished) {
openSavedFile() openSavedFile()
openOnFinished = false openOnFinished = false
@ -160,7 +155,7 @@ ColumnLayout {
id: messageMouseArea id: messageMouseArea
onPrimaryClicked: downloadAndShow() onPrimaryClicked: fullScreenImage.createObject(parent, {"filename": eventId, "localPath": currentRoom.urlToDownload(eventId)}).show()
onSecondaryClicked: { onSecondaryClicked: {
var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay) var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay)
@ -215,34 +210,19 @@ ColumnLayout {
folderDialog.chosen.connect(function(path) { folderDialog.chosen.connect(function(path) {
if (!path) return if (!path) return
currentRoom.downloadFile(eventId, path + "/" + (content.filename || content.body)) currentRoom.downloadFile(eventId, path + "/" + currentRoom.fileNameToDownload(eventId))
}) })
folderDialog.open() 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() function downloadAndOpen()
{ {
if (downloaded) openSavedFile() if (downloaded) openSavedFile()
else else
{ {
openOnFinished = true 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))
} }
} }

View File

@ -136,7 +136,7 @@ ColumnLayout {
visible: replyEventId || "" visible: replyEventId || ""
padding: 8 padding: 0
background: RippleEffect { background: RippleEffect {
anchors.fill: parent anchors.fill: parent
@ -148,29 +148,14 @@ ColumnLayout {
spacing: 8 spacing: 8
Avatar { Avatar {
Layout.preferredWidth: 36 Layout.preferredWidth: 28
Layout.preferredHeight: 36 Layout.preferredHeight: 28
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
source: replyAuthor ? replyAuthor.avatarMediaId : "" source: replyAuthor ? replyAuthor.avatarMediaId : ""
hint: replyAuthor ? replyAuthor.displayName : "H" hint: replyAuthor ? replyAuthor.displayName : "H"
} }
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Label {
Layout.fillWidth: true
color: "white"
text: replyAuthor ? replyAuthor.displayName : ""
font.pixelSize: 13
font.weight: Font.Medium
}
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
@ -182,7 +167,6 @@ ColumnLayout {
} }
} }
} }
}
Rectangle { Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
@ -213,7 +197,7 @@ ColumnLayout {
onLinkActivated: { onLinkActivated: {
if (link.startsWith("https://matrix.to/")) { if (link.startsWith("https://matrix.to/")) {
var result = link.replace(/\?.*/, "").match("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[1] != currentRoom.id) return
if (!result[2]) return if (!result[2]) return
goToEvent(result[2]) goToEvent(result[2])

View File

@ -29,6 +29,14 @@ Dialog {
hint: user ? user.displayName : "No name" hint: user ? user.displayName : "No name"
source: user ? user.avatarMediaId : null 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 { ColumnLayout {
@ -159,6 +167,12 @@ Dialog {
} }
} }
Component {
id: fullScreenImage
FullScreenImage {}
}
onClosed: destroy() onClosed: destroy()
} }

View File

@ -282,7 +282,7 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: 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 color: MPalette.lighter
font.pixelSize: 13 font.pixelSize: 13
elide: Text.ElideRight elide: Text.ElideRight

View File

@ -14,7 +14,7 @@ import Spectral 0.1
import Spectral.Setting 0.1 import Spectral.Setting 0.1
ApplicationWindow { ApplicationWindow {
readonly property bool inPortrait: window.width < window.height readonly property bool inPortrait: window.width < 640
Material.theme: MPalette.theme Material.theme: MPalette.theme
Material.background: MPalette.background Material.background: MPalette.background

View File

@ -8,6 +8,7 @@
#include "csapi/typing.h" #include "csapi/typing.h"
#include "events/accountdataevents.h" #include "events/accountdataevents.h"
#include "events/typingevent.h" #include "events/typingevent.h"
#include "jobs/downloadfilejob.h"
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
@ -233,3 +234,7 @@ QString SpectralRoom::postMarkdownText(const QString& markdown) {
return postHtmlText(markdown, result); return postHtmlText(markdown, result);
} }
QUrl SpectralRoom::urlToMxcUrl(QUrl mxcUrl) {
return DownloadFileJob::makeRequestUrl(connection()->homeserver(), mxcUrl);
}

View File

@ -84,6 +84,8 @@ class SpectralRoom : public Room {
Q_INVOKABLE QString postMarkdownText(const QString& markdown); Q_INVOKABLE QString postMarkdownText(const QString& markdown);
Q_INVOKABLE QUrl urlToMxcUrl(QUrl mxcUrl);
template <typename BaseEventT> template <typename BaseEventT>
QString eventToString(const BaseEventT& evt, QString eventToString(const BaseEventT& evt,
Qt::TextFormat format = Qt::PlainText) { Qt::TextFormat format = Qt::PlainText) {