Skip to content

Commit

Permalink
feat(@desktop/wallet): Make images match their aspect ratio but still…
Browse files Browse the repository at this point in the history
… have min width and height in collectible details

Also make images zoom to cropped when visible in the collectibles list view

fixes #14203
  • Loading branch information
Khushboo-dev-cpp committed May 6, 2024
1 parent 195cb55 commit 8d8268d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
57 changes: 47 additions & 10 deletions ui/StatusQ/src/StatusQ/Components/StatusRoundedMedia.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ StatusRoundedComponent {
*/
property url fallbackImageUrl

/*!
\qmlproperty url StatusRoundedMedia::fillMode
helps set fillModel for the Media file loaded
*/
property int fillMode: Image.PreserveAspectFit

/*!
\qmlproperty url StatusRoundedMedia::maxDimension
is used to set dimension for the image in case of portrait or landscape
when fillMode = Image.PreserveAspectFit
if not set the width/height of parent will be considered
*/
property int manualMaxDimension: 0

readonly property int componentMediaType: {
if (root.mediaType.startsWith("image")) {
return StatusRoundedMedia.MediaType.Image
Expand Down Expand Up @@ -112,31 +126,51 @@ StatusRoundedComponent {
}
}

Loader {
id: mediaLoader
anchors.fill: parent
asynchronous: true
visible: !root.isError && !root.isLoading
implicitWidth: {
// Use Painted width so that the rectangle follow width of the image actually painted
if(!!mediaLoader.item && (mediaLoader.item.paintedWidth > 0 || mediaLoader.item.paintedHeight > 0)) {
return mediaLoader.item.paintedWidth
}
else return root.manualMaxDimension
}
implicitHeight: {
// Use Painted height so that the rectangle follows height of the image actually painted
if(!!mediaLoader.item && (mediaLoader.item.paintedWidth > 0 || mediaLoader.item.paintedHeight > 0)) {
return mediaLoader.item.paintedHeight
}
else return root.manualMaxDimension
}

Component.onCompleted: updateMediaLoader()
onMediaUrlChanged: updateMediaLoader()
onComponentMediaTypeChanged: updateMediaLoader()
onFallbackImageUrlChanged: updateMediaLoader()

Loader {
id: mediaLoader
anchors.centerIn: parent
// In case manualMaxDimension is not defined then use parent width and height instead
width: root.manualMaxDimension === 0 ? parent.width : root.manualMaxDimension
height: root.manualMaxDimension === 0 ? parent.height : root.manualMaxDimension
asynchronous: true
visible: !root.isError && !root.isLoading
}

function updateMediaLoader() {
d.reset()
if (root.mediaUrl !== "") {
if (componentMediaType === StatusRoundedMedia.MediaType.Image) {
mediaLoader.setSource("StatusAnimatedImage.qml",
{
"source": root.mediaUrl
"source": root.mediaUrl,
"fillMode": root.fillMode
});
return
} else if (componentMediaType === StatusRoundedMedia.MediaType.Video) {
mediaLoader.setSource("StatusVideo.qml",
{
"player.source": root.mediaUrl
"player.source": root.mediaUrl,
"fillMode": root.fillMode
});
return
}
Expand All @@ -150,7 +184,8 @@ StatusRoundedComponent {
if (componentMediaType === StatusRoundedMedia.MediaType.Image && d.errorCounter <= 1) {
mediaLoader.setSource("StatusImage.qml",
{
"source": root.mediaUrl
"source": root.mediaUrl,
"fillMode": root.fillMode
})
return
} else if (root.fallbackImageUrl !== "") {
Expand All @@ -165,14 +200,16 @@ StatusRoundedComponent {
d.isFallback = true
mediaLoader.setSource("StatusImage.qml",
{
"source": root.fallbackImageUrl
"source": root.fallbackImageUrl,
"fillMode": root.fillMode
})
}

function setEmptyComponent() {
mediaLoader.setSource("StatusImage.qml",
{
"source": ""
"source": "",
"fillMode": root.fillMode
});
}
}
1 change: 1 addition & 0 deletions ui/StatusQ/src/StatusQ/Components/StatusVideo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Item {

property alias player: player
property alias output: output
property alias fillMode: output.fillMode

MediaPlayer {
id: player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Control {

property bool showTag: false
property int size: PrivilegedTokenArtworkPanel.Size.Small
property int fillMode: Image.PreserveAspectFit

property alias artwork: image.source
property alias color: icon.color
Expand Down Expand Up @@ -86,7 +87,7 @@ Control {
anchors.centerIn: parent
width: d.imageSize
height: width
fillMode: Image.PreserveAspectFit
fillMode: root.fillMode
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,12 @@ Item {
StatusRoundedMedia {
id: collectibleImage
readonly property bool isEmpty: !mediaUrl.toString() && !fallbackImageUrl.toString()
width: 248
height: width
radius: Style.current.radius
color: isError || isEmpty ? Theme.palette.baseColor5 : collectible.backgroundColor
border.color: Theme.palette.directColor8
border.width: 1
mediaUrl: collectible.mediaUrl ?? ""
mediaType: modelIndex === 0 && !!collectible ? collectible.mediaType : ""
mediaType: !!collectible ? (modelIndex > 0 && collectible.mediaType.startsWith("video")) ? "" : collectible.mediaType: ""
fallbackImageUrl: collectible.imageUrl
manualMaxDimension: 240

Column {
anchors.centerIn: parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Control {
fallbackImageUrl: root.fallbackImageUrl
showLoadingIndicator: true
color: root.isLoading ? "transparent" : root.backgroundColor
fillMode: Image.PreserveAspectCrop

Loader {
anchors.fill: parent
Expand Down Expand Up @@ -119,6 +120,7 @@ Control {
size: PrivilegedTokenArtworkPanel.Size.Medium
artwork: root.fallbackImageUrl
color: root.ornamentColor
fillMode: Image.PreserveAspectCrop
isOwner: root.privilegesLevel === Constants.TokenPrivilegesLevel.Owner

Loader {
Expand Down

0 comments on commit 8d8268d

Please sign in to comment.