moment/src/qml/Base/HImage.qml

66 lines
1.8 KiB
QML
Raw Normal View History

import QtQuick 2.12
import "../utils.js" as Utils
Image {
id: image
autoTransform: true
asynchronous: true
fillMode: Image.PreserveAspectFit
2019-09-13 06:23:30 +10:00
cache: ! (animate && animated) &&
2019-09-13 06:16:35 +10:00
(sourceSize.width + sourceSize.height) <= 512
property bool animate: true
readonly property bool animated: Utils.urlExtension(image.source) == "gif"
2019-09-13 06:23:30 +10:00
2019-09-13 06:16:35 +10:00
Component {
2019-09-13 07:27:26 +10:00
id: animatedImageComponent
2019-09-13 06:16:35 +10:00
AnimatedImage {
2019-09-13 07:27:26 +10:00
id: animatedImage
2019-09-13 06:16:35 +10:00
source: image.source
autoTransform: image.autoTransform
asynchronous: image.asynchronous
fillMode: image.fillMode
mirror: image.mirror
mipmap: image.mipmap
smooth: image.smooth
horizontalAlignment: image.horizontalAlignment
verticalAlignment: image.verticalAlignment
cache: true // Needed to allow GIFs to loop
2019-09-13 06:23:30 +10:00
paused: ! visible || window.hidden || userPaused
2019-09-13 07:32:48 +10:00
property bool userPaused: ! window.settings.autoPlayGIF
2019-09-13 06:23:30 +10:00
TapHandler {
onTapped: parent.userPaused = ! parent.userPaused
}
2019-09-13 07:27:26 +10:00
HIcon {
2019-09-13 07:32:48 +10:00
anchors.centerIn: parent
2019-09-13 07:27:26 +10:00
svgName: "play"
colorize: "transparent"
dimension: Math.min(
parent.width - theme.spacing * 2,
parent.height - theme.spacing * 2,
theme.controls.image.maxPauseIndicatorSize,
)
2019-09-13 07:32:48 +10:00
scale: parent.status == Image.Ready && parent.paused ? 1 : 0
2019-09-13 07:27:26 +10:00
visible: scale > 0
Behavior on scale { HNumberAnimation { overshoot: 4 } }
}
2019-09-13 06:16:35 +10:00
}
}
HLoader {
id: loader
anchors.fill: parent
2019-09-13 07:27:26 +10:00
sourceComponent: animate && animated ? animatedImageComponent : null
2019-09-13 06:16:35 +10:00
}
}