2020-07-23 18:20:57 +00:00
|
|
|
import QtQuick 2.3
|
2020-11-12 14:08:40 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2020-07-23 18:20:57 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
property int verticalPadding: 0
|
|
|
|
property int imageWidth: 350
|
2020-11-12 14:08:40 +00:00
|
|
|
property bool isCurrentUser: false
|
2020-07-23 18:20:57 +00:00
|
|
|
property url source
|
2021-12-08 21:20:43 +00:00
|
|
|
property bool playing: Global.applicationWindow.active
|
2021-01-13 20:27:56 +00:00
|
|
|
property bool isAnimated: !!source && source.toString().endsWith('.gif')
|
2021-08-25 20:31:00 +00:00
|
|
|
signal clicked(var image, var mouse)
|
2020-12-07 23:38:53 +00:00
|
|
|
property var container
|
2021-01-13 20:27:56 +00:00
|
|
|
property alias imageAlias: imageMessage
|
2021-04-23 15:49:05 +00:00
|
|
|
property bool allCornersRounded: false
|
2020-07-23 18:20:57 +00:00
|
|
|
|
|
|
|
id: imageContainer
|
|
|
|
width: loadingImage.visible ? loadingImage.width : imageMessage.width
|
|
|
|
height: loadingImage.visible ? loadingImage.height : imageMessage.paintedHeight
|
|
|
|
|
2020-11-17 19:43:52 +00:00
|
|
|
Connections {
|
2021-12-08 21:20:43 +00:00
|
|
|
target: Global.applicationWindow
|
2020-11-17 19:43:52 +00:00
|
|
|
onActiveChanged: {
|
2021-12-08 21:20:43 +00:00
|
|
|
if (Global.applicationWindow.active === false) {
|
2020-11-17 19:43:52 +00:00
|
|
|
imageMessage.playing = false
|
|
|
|
} else {
|
|
|
|
imageMessage.playing = Qt.binding(function () {return imageContainer.playing})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimatedImage {
|
2020-07-23 18:20:57 +00:00
|
|
|
id: imageMessage
|
|
|
|
width: sourceSize.width > imageWidth ? imageWidth : sourceSize.width
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: imageContainer.source
|
2021-09-23 12:27:05 +00:00
|
|
|
playing: isAnimated
|
2020-09-30 14:01:08 +00:00
|
|
|
|
2020-11-12 14:08:40 +00:00
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: OpacityMask {
|
|
|
|
maskSource: Item {
|
|
|
|
width: imageMessage.width
|
|
|
|
height: imageMessage.height
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: imageMessage.width
|
|
|
|
height: imageMessage.height
|
|
|
|
radius: 16
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: 32
|
|
|
|
height: 32
|
|
|
|
radius: 4
|
2021-04-23 15:49:05 +00:00
|
|
|
visible: !imageContainer.isCurrentUser && !allCornersRounded
|
2020-11-12 14:08:40 +00:00
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: 32
|
|
|
|
height: 32
|
|
|
|
radius: 4
|
2021-04-23 15:49:05 +00:00
|
|
|
visible: imageContainer.isCurrentUser && !allCornersRounded
|
2020-11-12 14:08:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:01:08 +00:00
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
2021-08-16 09:11:43 +00:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
2020-09-30 14:01:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2020-11-17 19:43:52 +00:00
|
|
|
if (imageContainer.isAnimated) {
|
|
|
|
// FIXME the ListView completely removes Items that scroll out of view
|
|
|
|
// so when we scroll backto the image, it gets reloaded and playing is reset
|
|
|
|
imageContainer.playing = !imageContainer.playing
|
|
|
|
return
|
|
|
|
}
|
2021-08-25 20:31:00 +00:00
|
|
|
imageContainer.clicked(imageMessage, mouse)
|
2020-09-30 14:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-23 18:20:57 +00:00
|
|
|
}
|
2021-09-23 12:27:05 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: loadingImage
|
|
|
|
visible: imageMessage.status === Image.Loading
|
|
|
|
|| imageMessage.status === Image.Error
|
|
|
|
width: parent.width
|
|
|
|
height: width
|
|
|
|
border.width: 1
|
|
|
|
border.color: Style.current.border
|
|
|
|
radius: Style.current.radius
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: imageMessage.status === Image.Error?
|
|
|
|
//% "Error loading the image"
|
|
|
|
qsTrId("error-loading-the-image") :
|
|
|
|
//% "Loading image..."
|
|
|
|
qsTrId("loading-image---")
|
|
|
|
color: imageMessage.status === Image.Error?
|
|
|
|
Style.current.red :
|
|
|
|
Style.current.textColor
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 18:20:57 +00:00
|
|
|
}
|