2020-09-23 08:18:23 +00:00
|
|
|
import QtQuick 2.3
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import "../imports"
|
|
|
|
|
|
|
|
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
|
2020-10-06 04:16:36 +00:00
|
|
|
property alias source: image.source
|
|
|
|
property alias fillMode: image.fillMode
|
2021-01-28 20:13:20 +00:00
|
|
|
property bool showLoadingIndicator: true
|
2020-10-20 14:15:04 +00:00
|
|
|
signal loaded
|
2020-09-23 08:18:23 +00:00
|
|
|
signal clicked
|
|
|
|
color: Style.current.backgroundHover
|
2021-01-28 20:13:20 +00:00
|
|
|
state: showLoadingIndicator ? "loading" : "ready"
|
2020-09-23 08:18:23 +00:00
|
|
|
radius: width / 2
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "loading"
|
|
|
|
when: image.status === Image.Loading
|
|
|
|
PropertyChanges {
|
|
|
|
target: loading
|
2020-10-07 18:12:43 +00:00
|
|
|
active: true
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: reload
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: image
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "error"
|
|
|
|
when: image.status === Image.Error
|
|
|
|
PropertyChanges {
|
|
|
|
target: loading
|
2020-10-07 18:12:43 +00:00
|
|
|
active: false
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: reload
|
|
|
|
visible: true
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: image
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "ready"
|
|
|
|
when: image.status === Image.Ready
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
|
|
|
color: Style.current.transparent
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: loading
|
2020-10-07 18:12:43 +00:00
|
|
|
active: false
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: reload
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: image
|
|
|
|
visible: true
|
|
|
|
height: root.height
|
|
|
|
width: root.width
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2020-12-14 05:50:47 +00:00
|
|
|
Connections {
|
|
|
|
target: chatsModel
|
|
|
|
onOnlineStatusChanged: {
|
|
|
|
if (connected && root.state !== "ready" &&
|
|
|
|
root.visible &&
|
|
|
|
root.source &&
|
|
|
|
root.source.startsWith("http")) {
|
|
|
|
root.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
// Note: Changing this property dynamically causes the image source to
|
|
|
|
// be reloaded, potentially even from the network, if it is not in the
|
|
|
|
// 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
|
|
|
|
LoadingImage {
|
|
|
|
width: 23
|
|
|
|
height: 23
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
antialiasing: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
2020-09-23 08:18:23 +00:00
|
|
|
id: loading
|
2020-10-07 18:12:43 +00:00
|
|
|
sourceComponent: loadingIndicator
|
2020-09-23 08:18:23 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-10-07 18:12:43 +00:00
|
|
|
active: false
|
2020-09-23 08:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: reload
|
|
|
|
source: "../app/img/reload.svg"
|
|
|
|
width: 15.5
|
|
|
|
height: 19.5
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
|
|
|
color: Style.current.textColor
|
|
|
|
antialiasing: true
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
root.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: image
|
|
|
|
width: 0
|
|
|
|
height: 0
|
|
|
|
sourceSize.width: root.width * 2
|
|
|
|
sourceSize.height: root.height * 2
|
|
|
|
source: root.source
|
|
|
|
horizontalAlignment: Image.AlignHCenter
|
|
|
|
verticalAlignment: Image.AlignVCenter
|
|
|
|
cache: true
|
2020-10-20 14:15:04 +00:00
|
|
|
onStatusChanged: {
|
|
|
|
if (image.status === Image.Ready) {
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|