Update libqmatrixclient.

Add author label.
Add time label.
Use Roboto font.
This commit is contained in:
Black Hat 2018-11-20 08:21:28 +08:00
parent f892236bfe
commit 6d17716e97
6 changed files with 177 additions and 142 deletions

View File

@ -9,7 +9,7 @@ import Spectral.Setting 0.1
import Spectral.Component 2.0 import Spectral.Component 2.0
import Spectral.Font 0.1 import Spectral.Font 0.1
RowLayout { ColumnLayout {
readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote" || aboveEventType === "other") readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote" || aboveEventType === "other")
readonly property bool highlighted: !(sentByMe || eventType === "notice" ) readonly property bool highlighted: !(sentByMe || eventType === "notice" )
readonly property bool sentByMe: author === currentRoom.localUser readonly property bool sentByMe: author === currentRoom.localUser
@ -18,191 +18,223 @@ RowLayout {
signal saveFileAs() signal saveFileAs()
signal openExternally() signal openExternally()
z: -5
id: messageRow
Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
spacing: 4 id: root
ImageItem { spacing: 0
Layout.preferredWidth: 32
Layout.preferredHeight: 32 Label {
Layout.alignment: Qt.AlignTop Layout.leftMargin: 48
text: author.displayName
visible: avatarVisible visible: avatarVisible
hint: author.displayName
source: author.paintable font.pixelSize: 13
font.weight: Font.Medium
verticalAlignment: Text.AlignVCenter
} }
Rectangle { RowLayout {
Layout.preferredWidth: 32 Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
color: "transparent" z: -5
visible: !(sentByMe || avatarVisible)
}
Control { id: messageRow
Layout.maximumWidth: messageListView.width - (!sentByMe ? 40 + messageRow.spacing : 0) - 48
topPadding: 8 spacing: 4
bottomPadding: 8
leftPadding: 16
rightPadding: 16
background: Rectangle { ImageItem {
color: sentByMe ? "#009DC2" : (highlighted || eventType) === "notice" ? "#4285F4" : "#673AB7" Layout.preferredWidth: 32
radius: 18 Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
AutoMouseArea { visible: avatarVisible
anchors.fill: parent hint: author.displayName
source: author.paintable
onSecondaryClicked: {
messageContextMenu.row = messageRow
messageContextMenu.model = model
messageContextMenu.selectedText = contentLabel.selectedText
messageContextMenu.popup()
}
}
} }
contentItem: ColumnLayout { Rectangle {
id: messageColumn Layout.preferredWidth: 32
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
spacing: 0 color: "transparent"
visible: !(sentByMe || avatarVisible)
}
TextEdit { Control {
Layout.fillWidth: true Layout.maximumWidth: messageListView.width - (!sentByMe ? 32 + messageRow.spacing : 0) - 48
id: contentLabel topPadding: 8
bottomPadding: 8
leftPadding: 16
rightPadding: 16
text: "<style>a{color: white;} .user-pill{color: white}</style>" + display background: Rectangle {
color: sentByMe ? "#009DC2" : eventType === "notice" ? "#4285F4" : "#673AB7"
radius: 18
visible: isText AutoMouseArea {
color: "white"
font.family: CommonFont.font.family
font.pixelSize: 14
selectByMouse: true
readOnly: true
wrapMode: Label.Wrap
selectedTextColor: highlighted ? Material.accent : "white"
selectionColor: highlighted ? "white" : Material.accent
textFormat: Text.RichText
onLinkActivated: Qt.openUrlExternally(link)
MouseArea {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor onSecondaryClicked: {
index === messageListView.currentIndex ? messageListView.currentIndex = -1 : messageListView.currentIndex = index
messageContextMenu.root = root
messageContextMenu.model = model
messageContextMenu.selectedText = contentLabel.selectedText
messageContextMenu.popup()
}
} }
} }
Loader { contentItem: ColumnLayout {
sourceComponent: { id: messageColumn
switch (eventType) {
case "image": spacing: 0
return imageComponent
case "file": TextEdit {
return fileComponent Layout.fillWidth: true
case "audio":
return audioComponent id: contentLabel
text: "<style>a{color: white;} .user-pill{color: white}</style>" + display
visible: isText
color: "white"
font.family: CommonFont.font.family
font.pixelSize: 14
selectByMouse: true
readOnly: true
wrapMode: Label.Wrap
selectedTextColor: highlighted ? Material.accent : "white"
selectionColor: highlighted ? "white" : Material.accent
textFormat: Text.RichText
onLinkActivated: Qt.openUrlExternally(link)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
} }
} }
active: eventType === "image" || eventType === "file" || eventType === "audio" Loader {
} sourceComponent: {
} switch (eventType) {
case "image":
return imageComponent
case "file":
return fileComponent
case "audio":
return audioComponent
}
}
Component { active: eventType === "image" || eventType === "file" || eventType === "audio"
id: imageComponent
DownloadableContent {
width: messageImage.width
height: messageImage.height
id: downloadable
TimelineImage {
z: -4
id: messageImage
sourceSize: 128
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
onClicked: downloadAndOpen()
}
Component.onCompleted: {
messageRow.saveFileAs.connect(saveFileAs)
messageRow.openExternally.connect(downloadAndOpen)
} }
} }
}
Component { Component {
id: fileComponent id: imageComponent
TimelineLabel { DownloadableContent {
Layout.fillWidth: true width: messageImage.width
height: messageImage.height
id: downloadDelegate
text: "<b>File: </b>" + content.body
coloredBackground: highlighted
background: DownloadableContent {
id: downloadable id: downloadable
TimelineImage {
z: -4
id: messageImage
sourceSize: 128
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
onClicked: downloadAndOpen()
}
Component.onCompleted: { Component.onCompleted: {
messageRow.saveFileAs.connect(saveFileAs) root.saveFileAs.connect(saveFileAs)
messageRow.openExternally.connect(downloadAndOpen) root.openExternally.connect(downloadAndOpen)
} }
} }
} }
}
Component { Component {
id: audioComponent id: fileComponent
TimelineLabel { TimelineLabel {
id: downloadDelegate Layout.fillWidth: true
text: content.info.duration / 1000 + '"' id: downloadDelegate
coloredBackground: highlighted
MouseArea { text: "<b>File: </b>" + content.body
anchors.fill: parent coloredBackground: highlighted
propagateComposedEvents: true background: DownloadableContent {
id: downloadable
onClicked: { Component.onCompleted: {
if (downloadable.downloaded) root.saveFileAs.connect(saveFileAs)
spectralController.playAudio(progressInfo.localPath) root.openExternally.connect(downloadAndOpen)
else
{
playOnFinished = true
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp")
} }
} }
} }
}
background: DownloadableContent { Component {
id: downloadable id: audioComponent
onDownloadedChanged: downloaded && playOnFinished ? spectralController.playAudio(progressInfo.localPath) : {} TimelineLabel {
id: downloadDelegate
Component.onCompleted: { text: content.info.duration / 1000 + '"'
messageRow.saveFileAs.connect(saveFileAs) coloredBackground: highlighted
messageRow.openExternally.connect(downloadAndOpen)
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
if (downloadable.downloaded)
spectralController.playAudio(progressInfo.localPath)
else
{
playOnFinished = true
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp")
}
}
}
background: DownloadableContent {
id: downloadable
onDownloadedChanged: downloaded && playOnFinished ? spectralController.playAudio(progressInfo.localPath) : {}
Component.onCompleted: {
root.saveFileAs.connect(saveFileAs)
root.openExternally.connect(downloadAndOpen)
}
} }
} }
} }
} }
} }
Label {
Layout.leftMargin: sentByMe ? 12 : 48
text: Qt.formatDateTime(time, "dd/MM/yyyy '-' hh:mm")
visible: index === messageListView.currentIndex
font.pixelSize: 13
verticalAlignment: Text.AlignVCenter
}
} }

View File

@ -2,7 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
Menu { Menu {
property var row: null property var root: null
property var model: null property var model: null
property string selectedText property string selectedText
@ -23,14 +23,14 @@ Menu {
height: visible ? undefined : 0 height: visible ? undefined : 0
text: "Open Externally" text: "Open Externally"
onTriggered: row.openExternally() onTriggered: root.openExternally()
} }
MenuItem { MenuItem {
visible: isFile visible: isFile
height: visible ? undefined : 0 height: visible ? undefined : 0
text: "Save As" text: "Save As"
onTriggered: row.saveFileAs() onTriggered: root.saveFileAs()
} }
MenuItem { MenuItem {
height: visible ? undefined : 0 height: visible ? undefined : 0

View File

@ -80,10 +80,12 @@ Item {
id: messageListView id: messageListView
spacing: 4
displayMarginBeginning: 100 displayMarginBeginning: 100
displayMarginEnd: 100 displayMarginEnd: 100
verticalLayoutDirection: ListView.BottomToTop verticalLayoutDirection: ListView.BottomToTop
spacing: 4 highlightMoveDuration: 500
boundsBehavior: Flickable.DragOverBounds boundsBehavior: Flickable.DragOverBounds

@ -1 +1 @@
Subproject commit 6f18091a48530399908fbc6ebcb0697bae970abb Subproject commit e1fdb33a4161b29d6df590ccea339d361d9fc4e8

View File

@ -11,3 +11,4 @@ Primary=#344955
Accent=#673AB7 Accent=#673AB7
;Foreground=#1D333E ;Foreground=#1D333E
;Background=#161616 ;Background=#161616
Font/Family=Roboto

View File

@ -75,11 +75,11 @@ void Controller::loginWithCredentials(QString serverAddr, QString user,
setConnection(conn); setConnection(conn);
}); });
connect(conn, &Connection::networkError, connect(conn, &Connection::networkError,
[=](QString error, QByteArray detail) { [=](QString error, QString, int, int) {
emit errorOccured("Network Error", error); emit errorOccured("Network Error", error);
}); });
connect(conn, &Connection::loginError, connect(conn, &Connection::loginError,
[=](QString error, QByteArray detail) { [=](QString error, QString) {
emit errorOccured("Login Failed", error); emit errorOccured("Login Failed", error);
}); });
} }
@ -150,11 +150,11 @@ void Controller::invokeLogin() {
addConnection(c); addConnection(c);
}); });
connect(c, &Connection::loginError, connect(c, &Connection::loginError,
[=](QString error, QByteArray detail) { [=](QString error, QString) {
emit errorOccured("Login Failed", error); emit errorOccured("Login Failed", error);
}); });
connect(c, &Connection::networkError, connect(c, &Connection::networkError,
[=](QString error, QByteArray detail) { [=](QString error, QString, int, int) {
emit errorOccured("Network Error", error); emit errorOccured("Network Error", error);
}); });
c->connectWithToken(account.userId(), accessToken, account.deviceId()); c->connectWithToken(account.userId(), accessToken, account.deviceId());