From 6e79bf6495983b8c6f58d7261215d0998ae665e2 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Fri, 17 Aug 2018 15:58:08 +0800 Subject: [PATCH] Working audio bubble. Also, fixes #2. --- matrique.pro | 2 +- qml/component/AudioBubble.qml | 53 +++++++++++++++++++++++++------ qml/component/FileBubble.qml | 2 ++ qml/component/MessageDelegate.qml | 3 +- qml/form/RoomListForm.qml | 17 +--------- src/messageeventmodel.cpp | 2 ++ 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/matrique.pro b/matrique.pro index 0f9b78b..7c9f0b1 100644 --- a/matrique.pro +++ b/matrique.pro @@ -1,4 +1,4 @@ -QT += quick widgets +QT += quick widgets multimedia CONFIG += c++14 CONFIG += object_parallel_to_source CONFIG += qtquickcompiler diff --git a/qml/component/AudioBubble.qml b/qml/component/AudioBubble.qml index c72728d..c5ec76b 100644 --- a/qml/component/AudioBubble.qml +++ b/qml/component/AudioBubble.qml @@ -1,19 +1,54 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 -import QtMultimedia 5.8 +import QtQuick.Controls.Material 2.2 +import QtMultimedia 5.9 +import Qt.labs.platform 1.0 AvatarContainer { - Button { - id: downloadButton + readonly property var downloadAndOpen: downloadable.downloadAndOpen + readonly property var saveFileAs: downloadable.saveFileAs - text: content.body - highlighted: !sentByMe - flat: true + property bool playOnFinished: false - onClicked: downloadable.downloadAndOpen() + id: messageRow - Audio { - audioRole: Audio.VoiceCommunicationRole + Audio { + id: audioPlayer + source: progressInfo.localPath + } + + DownloadableContent { + id: downloadable + + width: downloadDelegate.width + height: downloadDelegate.height + + TextDelegate { + id: downloadDelegate + + maximumWidth: messageListView.width + highlighted: !sentByMe + timeLabelVisible: false + authorLabelVisible: messageRow.avatarVisible + + displayText: content.info.duration / 1000 + '"' + + MouseArea { + anchors.fill: parent + + propagateComposedEvents: true + + onClicked: { + if (downloadable.downloaded) + audioPlayer.play() + else + { + playOnFinished = true + currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp") + } + } + } } + onDownloadedChanged: downloaded && playOnFinished ? audioPlayer.play() : {} } } diff --git a/qml/component/FileBubble.qml b/qml/component/FileBubble.qml index c73a5f8..aa3eff4 100644 --- a/qml/component/FileBubble.qml +++ b/qml/component/FileBubble.qml @@ -6,6 +6,8 @@ AvatarContainer { readonly property var downloadAndOpen: downloadable.downloadAndOpen readonly property var saveFileAs: downloadable.saveFileAs + id: messageRow + DownloadableContent { id: downloadable diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml index 65b37ef..6e52651 100644 --- a/qml/component/MessageDelegate.qml +++ b/qml/component/MessageDelegate.qml @@ -42,8 +42,9 @@ Item { return "MessageBubble.qml" case "image": return "ImageBubble.qml" - case "video": case "audio": + return "AudioBubble.qml" + case "video": case "file": return "FileBubble.qml" } diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index d2b3f24..b3f0cf4 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -103,22 +103,7 @@ Item { } sorters: [ - ExpressionSorter { - expression: { - var leftCategory = modelLeft.category - var rightCategory = modelRight.category - if (leftCategory === 1) return true - if (rightCategory === 1) return false - if (leftCategory === 2) return true - if (rightCategory === 2) return false - if (leftCategory === 5) return false - if (rightCategory === 5) return true - if (leftCategory === 4) return false - if (rightCategory === 4) return true - return true - } - }, - + RoleSorter { roleName: "category" }, StringSorter { roleName: "name" } ] } diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index 4536883..238629b 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -519,6 +519,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { return "notice"; case MessageEventType::Image: return "image"; + case MessageEventType::Audio: + return "audio"; default: return e->hasFileContent() ? "file" : "message"; }