Add basic loading indicator to images

This commit is contained in:
miruka
2019-10-27 16:35:58 -04:00
parent a67d611958
commit fe4eff62c5
4 changed files with 25 additions and 4 deletions

View File

@@ -51,6 +51,7 @@ Rectangle {
fillMode: Image.PreserveAspectCrop
source: Qt.resolvedUrl(imageUrl)
animate: false
loadingLabel.font.pixelSize: theme.fontSize.small
HoverHandler { id: hoverHandler }

View File

@@ -14,6 +14,7 @@ Image {
property bool animate: true
readonly property bool animated: Utils.urlExtension(image.source) == "gif"
readonly property alias loadingLabel: loadingLabel
Component {
@@ -58,8 +59,19 @@ Image {
}
HLoader {
id: loader
anchors.fill: parent
sourceComponent: animate && animated ? animatedImageComponent : null
}
HLabel {
id: loadingLabel
anchors.centerIn: parent
visible: image.status === Image.Loading
text: qsTr("%1%").arg(progress)
property int progress: Math.round(image.progress * 100)
Behavior on progress { HNumberAnimation { factor: 2 } }
}
}