Click to play/pause animated image

This commit is contained in:
miruka 2019-09-12 16:23:30 -04:00
parent 125d1e24aa
commit 5192fe8b55
3 changed files with 16 additions and 9 deletions

View File

@ -7,13 +7,18 @@ Image {
asynchronous: true asynchronous: true
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
cache: ! loader.sourceComponent && cache: ! (animate && animated) &&
(sourceSize.width + sourceSize.height) <= 512 (sourceSize.width + sourceSize.height) <= 512
property bool animate: true property bool animate: true
property color colorize: "transparent" property color colorize: "transparent"
readonly property bool animated:
image.source.toString()
.split("/").splice(-1)[0].split("?")[0].toLowerCase()
.endsWith(".gif")
layer.enabled: ! Qt.colorEqual(colorize, "transparent") layer.enabled: ! Qt.colorEqual(colorize, "transparent")
layer.effect: ColorOverlay { layer.effect: ColorOverlay {
@ -37,17 +42,19 @@ Image {
verticalAlignment: image.verticalAlignment verticalAlignment: image.verticalAlignment
cache: true // Needed to allow GIFs to loop cache: true // Needed to allow GIFs to loop
paused: ! visible || window.hidden paused: ! visible || window.hidden || userPaused
property bool userPaused: false
TapHandler {
onTapped: parent.userPaused = ! parent.userPaused
}
} }
} }
HLoader { HLoader {
id: loader id: loader
anchors.fill: parent anchors.fill: parent
sourceComponent: sourceComponent: animate && animated ? animatedImage : null
animate &&
image.source.toString()
.split("/").splice(-1)[0].split("?")[0].toLowerCase()
.endsWith(".gif") ? animatedImage : null
} }
} }

View File

@ -13,7 +13,8 @@ HImage {
) )
TapHandler { TapHandler {
onTapped: Qt.openUrlExternally(image.source) onTapped: if (! image.animated) Qt.openUrlExternally(image.source)
onDoubleTapped: Qt.openUrlExternally(image.source)
} }
HoverHandler { HoverHandler {

View File

@ -61,7 +61,6 @@ HGridLayout {
avatarUrl: accountInfo.avatar_url avatarUrl: accountInfo.avatar_url
imageUrl: fileDialog.selectedFile || fileDialog.file || defaultImageUrl imageUrl: fileDialog.selectedFile || fileDialog.file || defaultImageUrl
toolTipImageUrl: "" toolTipImageUrl: ""
animate: true // note: matrix doesn't actually support gif avatars
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter