moment/src/qml/Base/HImage.qml

61 lines
1.5 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtGraphicalEffects 1.12
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
property color colorize: "transparent"
2019-09-13 06:23:30 +10:00
readonly property bool animated:
image.source.toString()
.split("/").splice(-1)[0].split("?")[0].toLowerCase()
.endsWith(".gif")
2019-09-13 06:16:35 +10:00
layer.enabled: ! Qt.colorEqual(colorize, "transparent")
layer.effect: ColorOverlay {
color: image.colorize
cached: image.cache
}
2019-09-13 06:16:35 +10:00
Component {
id: animatedImage
AnimatedImage {
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
property bool userPaused: false
TapHandler {
onTapped: parent.userPaused = ! parent.userPaused
}
2019-09-13 06:16:35 +10:00
}
}
HLoader {
id: loader
anchors.fill: parent
2019-09-13 06:23:30 +10:00
sourceComponent: animate && animated ? animatedImage : null
2019-09-13 06:16:35 +10:00
}
}