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 {
|
2022-10-07 12:17:09 +00:00
|
|
|
id: root
|
|
|
|
|
2020-07-23 18:20:57 +00:00
|
|
|
property int verticalPadding: 0
|
|
|
|
property int imageWidth: 350
|
|
|
|
property url source
|
2022-06-29 16:50:10 +00:00
|
|
|
property bool isActiveChannel: false
|
2023-02-01 16:20:42 +00:00
|
|
|
property bool playing: Global.applicationWindow.active
|
2021-01-13 20:27:56 +00:00
|
|
|
property bool isAnimated: !!source && source.toString().endsWith('.gif')
|
|
|
|
property alias imageAlias: imageMessage
|
2021-04-23 15:49:05 +00:00
|
|
|
property bool allCornersRounded: false
|
2022-10-07 12:17:09 +00:00
|
|
|
property bool isOnline: true // TODO: mark as required when migrating to 5.15 or above
|
2023-02-01 16:20:42 +00:00
|
|
|
property bool imageLoaded: (imageMessage.status === Image.Ready)
|
2023-02-03 13:05:32 +00:00
|
|
|
property alias asynchronous: imageMessage.asynchronous
|
2023-11-01 11:19:18 +00:00
|
|
|
property bool leftTail: true
|
2022-10-07 12:17:09 +00:00
|
|
|
|
|
|
|
signal clicked(var image, var mouse)
|
2020-07-23 18:20:57 +00:00
|
|
|
|
2022-02-10 20:02:02 +00:00
|
|
|
width: loadingImageLoader.active ? loadingImageLoader.width : imageMessage.width
|
|
|
|
height: loadingImageLoader.active ? loadingImageLoader.height : imageMessage.paintedHeight
|
2020-07-23 18:20:57 +00:00
|
|
|
|
2022-10-07 12:17:09 +00:00
|
|
|
onIsOnlineChanged: {
|
|
|
|
if (!isOnline)
|
|
|
|
return
|
|
|
|
|
|
|
|
if (imageMessage.status === Image.Error) {
|
|
|
|
imageMessage.reloadImage()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: retryTimer
|
|
|
|
|
|
|
|
readonly property int initialInterval: 10 * 1000 // 10s
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
if (imageMessage.status === Image.Error && root.isOnline) {
|
|
|
|
imageMessage.reloadImage()
|
|
|
|
interval *= 2
|
|
|
|
restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 19:43:52 +00:00
|
|
|
AnimatedImage {
|
2020-07-23 18:20:57 +00:00
|
|
|
id: imageMessage
|
|
|
|
width: sourceSize.width > imageWidth ? imageWidth : sourceSize.width
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2022-10-07 12:17:09 +00:00
|
|
|
source: root.source
|
|
|
|
playing: root.isAnimated && root.playing
|
2022-09-30 09:26:01 +00:00
|
|
|
mipmap: true
|
2023-04-26 15:33:24 +00:00
|
|
|
cache: false
|
2020-09-30 14:01:08 +00:00
|
|
|
|
2022-10-07 12:17:09 +00:00
|
|
|
onStatusChanged: {
|
|
|
|
if (imageMessage.status === Image.Error && !retryTimer.running) {
|
|
|
|
retryTimer.interval = retryTimer.initialInterval
|
|
|
|
retryTimer.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reloadImage() {
|
|
|
|
imageMessage.source = ""
|
|
|
|
imageMessage.source = Qt.binding(() => root.source)
|
|
|
|
}
|
|
|
|
|
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
|
2023-11-01 11:19:18 +00:00
|
|
|
visible: root.leftTail && !allCornersRounded
|
2020-11-12 14:08:40 +00:00
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: 32
|
|
|
|
height: 32
|
|
|
|
radius: 4
|
2023-11-01 11:19:18 +00:00
|
|
|
visible: !root.leftTail && !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: {
|
2022-10-07 12:17:09 +00:00
|
|
|
root.clicked(imageMessage, mouse)
|
2020-09-30 14:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-04 11:32:46 +00:00
|
|
|
|
|
|
|
Component.onDestruction: imageMessage.source = ""
|
2020-07-23 18:20:57 +00:00
|
|
|
}
|
2021-09-23 12:27:05 +00:00
|
|
|
|
2022-02-10 20:02:02 +00:00
|
|
|
Loader {
|
|
|
|
id: loadingImageLoader
|
|
|
|
active: imageMessage.status === Image.Loading
|
2023-02-01 16:20:42 +00:00
|
|
|
|| imageMessage.status === Image.Error
|
|
|
|
visible: active
|
|
|
|
width: active ? 300 : 0
|
2021-09-23 12:27:05 +00:00
|
|
|
height: width
|
2023-02-01 16:20:42 +00:00
|
|
|
|
2022-02-10 20:02:02 +00:00
|
|
|
sourceComponent: Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
border.width: 1
|
|
|
|
border.color: Style.current.border
|
|
|
|
radius: Style.current.radius
|
2021-09-23 12:27:05 +00:00
|
|
|
|
2022-02-10 20:02:02 +00:00
|
|
|
StyledText {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: imageMessage.status === Image.Error?
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("Error loading the image") :
|
|
|
|
qsTr("Loading image...")
|
2022-02-10 20:02:02 +00:00
|
|
|
color: imageMessage.status === Image.Error?
|
|
|
|
Style.current.red :
|
|
|
|
Style.current.textColor
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
2021-09-23 12:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-23 18:20:57 +00:00
|
|
|
}
|