2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtGraphicalEffects 1.15
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2021-10-26 14:21:08 +00:00
|
|
|
import StatusQ.Components 0.1
|
2024-10-15 19:26:12 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-10-26 14:21:08 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-12-08 21:20:43 +00:00
|
|
|
import shared.stores 1.0
|
2020-09-23 08:18:23 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: root
|
2020-11-30 17:03:52 +00:00
|
|
|
property bool noHover: false
|
2021-02-17 16:31:59 +00:00
|
|
|
property bool noMouseArea: false
|
2021-09-24 09:55:48 +00:00
|
|
|
property bool showLoadingIndicator: true
|
|
|
|
|
2020-10-06 04:16:36 +00:00
|
|
|
property alias source: image.source
|
|
|
|
property alias fillMode: image.fillMode
|
2021-09-24 09:55:48 +00:00
|
|
|
|
2020-10-20 14:15:04 +00:00
|
|
|
signal loaded
|
2020-09-23 08:18:23 +00:00
|
|
|
signal clicked
|
2021-09-24 09:55:48 +00:00
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.backgroundHover
|
2020-09-23 08:18:23 +00:00
|
|
|
radius: width / 2
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "loading"
|
|
|
|
when: image.status === Image.Loading
|
|
|
|
PropertyChanges {
|
2021-09-24 09:55:48 +00:00
|
|
|
target: loader
|
|
|
|
sourceComponent: loadingIndicator
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "error"
|
|
|
|
when: image.status === Image.Error
|
|
|
|
PropertyChanges {
|
2021-09-24 09:55:48 +00:00
|
|
|
target: loader
|
|
|
|
sourceComponent: reload
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "ready"
|
|
|
|
when: image.status === Image.Ready
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.transparent
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
2021-09-24 09:55:48 +00:00
|
|
|
target: loader
|
|
|
|
sourceComponent: undefined
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-02-25 18:15:35 +00:00
|
|
|
Connections {
|
2022-03-07 22:59:38 +00:00
|
|
|
enabled: !!mainModule
|
|
|
|
target: enabled ? mainModule : undefined
|
2022-09-27 21:26:26 +00:00
|
|
|
function onOnlineStatusChanged(connected) {
|
2022-02-25 18:15:35 +00:00
|
|
|
if (connected && root.state !== "ready" &&
|
|
|
|
root.visible &&
|
|
|
|
root.source &&
|
|
|
|
root.source.startsWith("http")) {
|
|
|
|
root.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 05:50:47 +00:00
|
|
|
|
2020-09-23 08:18:23 +00:00
|
|
|
function reload() {
|
|
|
|
// From the documentation (https://doc.qt.io/qt-5/qml-qtquick-image.html#sourceSize-prop)
|
2021-09-24 09:55:48 +00:00
|
|
|
// Note: Changing this property dynamically causes the image source to
|
|
|
|
// be reloaded, potentially even from the network, if it is not in the
|
2020-09-23 08:18:23 +00:00
|
|
|
// disk cache.
|
2020-12-14 05:50:47 +00:00
|
|
|
const oldSource = image.source
|
|
|
|
image.cache = false
|
2020-09-23 08:18:23 +00:00
|
|
|
image.sourceSize.width += 1
|
|
|
|
image.sourceSize.width -= 1
|
2020-12-14 05:50:47 +00:00
|
|
|
image.cache = true
|
|
|
|
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 18:12:43 +00:00
|
|
|
Component {
|
|
|
|
id: loadingIndicator
|
2021-04-26 10:25:01 +00:00
|
|
|
StatusLoadingIndicator {
|
2020-10-07 18:12:43 +00:00
|
|
|
width: 23
|
|
|
|
height: 23
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.secondaryText
|
2020-10-07 18:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 09:55:48 +00:00
|
|
|
Component {
|
|
|
|
id: reload
|
|
|
|
SVGImage {
|
2024-10-15 19:26:12 +00:00
|
|
|
source: Theme.svg("reload")
|
2021-09-24 09:55:48 +00:00
|
|
|
mipmap: false
|
|
|
|
width: 15.5
|
|
|
|
height: 19.5
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.textColor
|
2021-09-24 09:55:48 +00:00
|
|
|
antialiasing: true
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
root.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 09:55:48 +00:00
|
|
|
Loader {
|
|
|
|
id: loader
|
2020-09-23 08:18:23 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: image
|
2021-09-24 09:55:48 +00:00
|
|
|
anchors.fill: parent
|
2020-09-23 08:18:23 +00:00
|
|
|
horizontalAlignment: Image.AlignHCenter
|
|
|
|
verticalAlignment: Image.AlignVCenter
|
|
|
|
cache: true
|
2020-10-20 14:15:04 +00:00
|
|
|
onStatusChanged: {
|
2021-09-24 09:55:48 +00:00
|
|
|
if (status === Image.Ready) {
|
2020-10-20 14:15:04 +00:00
|
|
|
loaded()
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 08:18:23 +00:00
|
|
|
MouseArea {
|
2021-02-17 16:31:59 +00:00
|
|
|
enabled: !noMouseArea
|
2020-11-30 17:03:52 +00:00
|
|
|
cursorShape: noHover ? Qt.ArrowCursor : Qt.PointingHandCursor
|
2020-09-23 08:18:23 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
root.clicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|