qml: preserve aspect ratio in `RoundImage.qml` and provide painted size
Turns out we can actually use fillMode
, at least PreserveAspectFit
and Stretch
. I'm not sure about tiling, it may not be supported so I put a note there.
I preferred to use PreserveAspectFit
instead of PreserveAspectCrop
for several reasons:
- We don't need clipping (
clip: true
) (https://doc.qt.io/qt-6/qml-qtquick-image.html#fillMode-prop). We can not use clipping here, that breaks batching. We could modify the shader and have a custom sub-rect, for that 1) we can not use custom vertex shader because it breaks batching inShaderEffect
2) we can do it in the fragment shader, but that needs multiple branches and would make it look ugly. SinceQQuickImage
also requires clipping forPreserveAspectCrop
, I have less desire to implement it. - We keep all the cover content. With
PreserveAspectCrop
, part of the cover would be cropped. - Playlist delegate also have been using
PreserveAspectFit
for a long time, for these reasons.
I have tested this with cover images that are not square.
The leftmost cover is thin (height > width), the center cover is fat (width > height), and the rightmost cover is square. All of their aspect ratio is preserved with PreserveAspectFit
. The shadow also stretches to the aspect ratio, in the future it can be generated with aspect ratio (which should be constant) pre-applied.
Request review @chub.