Separate different delegates.

This commit is contained in:
Black Hat
2018-11-22 17:15:14 +08:00
parent 1248b6f334
commit 58593015c1
5 changed files with 147 additions and 154 deletions

View File

@@ -10,16 +10,14 @@ import Spectral.Component 2.0
import Spectral.Font 0.1
ColumnLayout {
readonly property int alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
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 sentByMe: author === currentRoom.localUser
readonly property bool isText: eventType === "notice" || eventType === "message"
signal saveFileAs()
signal openExternally()
Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
id: root
spacing: 0
@@ -95,139 +93,30 @@ ColumnLayout {
}
}
contentItem: ColumnLayout {
id: messageColumn
contentItem: TextEdit {
Layout.fillWidth: true
spacing: 0
id: contentLabel
TextEdit {
Layout.fillWidth: true
text: "<style>a{color: white;} .user-pill{color: white}</style>" + display
id: contentLabel
color: "white"
text: "<style>a{color: white;} .user-pill{color: white}</style>" + display
font.family: CommonFont.font.family
font.pixelSize: 14
selectByMouse: true
readOnly: true
wrapMode: Label.Wrap
selectedTextColor: "white"
selectionColor: Material.accent
textFormat: Text.RichText
visible: isText
color: "white"
onLinkActivated: Qt.openUrlExternally(link)
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
}
}
Loader {
sourceComponent: {
switch (eventType) {
case "image":
return imageComponent
case "file":
return fileComponent
case "audio":
return audioComponent
}
}
active: eventType === "image" || eventType === "file" || eventType === "audio"
}
}
Component {
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: {
root.saveFileAs.connect(saveFileAs)
root.openExternally.connect(downloadAndOpen)
}
}
}
Component {
id: fileComponent
TimelineLabel {
Layout.fillWidth: true
id: downloadDelegate
text: "<b>File: </b>" + content.body
coloredBackground: highlighted
background: DownloadableContent {
id: downloadable
Component.onCompleted: {
root.saveFileAs.connect(saveFileAs)
root.openExternally.connect(downloadAndOpen)
}
}
}
}
Component {
id: audioComponent
TimelineLabel {
id: downloadDelegate
text: content.info.duration / 1000 + '"'
coloredBackground: highlighted
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)
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
}