wallpaper selector: freedesktop spec-compliant thumbnail generation

This commit is contained in:
end-4
2025-08-27 21:51:15 +07:00
parent eb2c9f2fe1
commit 1c1a141701
9 changed files with 211 additions and 31 deletions
@@ -19,19 +19,19 @@ MouseArea {
property alias colBackground: background.color
property alias colText: wallpaperItemName.color
property alias radius: background.radius
property alias padding: background.anchors.margins
property alias margins: background.anchors.margins
property alias padding: wallpaperItemColumnLayout.anchors.margins
margins: Appearance.sizes.wallpaperSelectorItemMargins
padding: Appearance.sizes.wallpaperSelectorItemPadding
signal activated
signal activated()
hoverEnabled: true
onClicked: root.activated()
Rectangle {
id: background
anchors {
fill: parent
margins: 8
}
anchors.fill: parent
radius: Appearance.rounding.normal
Behavior on color {
animation: Appearance.animation.elementMoveFast.colorAnimation.createObject(this)
@@ -39,10 +39,7 @@ MouseArea {
ColumnLayout {
id: wallpaperItemColumnLayout
anchors {
fill: parent
margins: 6
}
anchors.fill: parent
spacing: 4
Item {
@@ -67,6 +64,7 @@ MouseArea {
active: root.useThumbnail
sourceComponent: ThumbnailImage {
id: thumbnailImage
generateThumbnail: false
sourcePath: fileModelData.filePath
fillMode: Image.PreserveAspectCrop
@@ -74,6 +72,16 @@ MouseArea {
sourceSize.width: wallpaperItemColumnLayout.width
sourceSize.height: wallpaperItemColumnLayout.height - wallpaperItemColumnLayout.spacing - wallpaperItemName.height
Connections {
target: Wallpapers
function onThumbnailGenerated(directory) {
if (thumbnailImage.status !== Image.Error) return;
if (FileUtils.parentDirectory(thumbnailImage.sourcePath) !== directory) return;
thumbnailImage.source = "";
thumbnailImage.source = thumbnailImage.thumbnailPath;
}
}
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
@@ -16,6 +16,19 @@ Item {
property real previewCellAspectRatio: 4 / 3
property bool useDarkMode: Appearance.m3colors.darkmode
function updateThumbnails() {
const totalImageMargin = (Appearance.sizes.wallpaperSelectorItemMargins + Appearance.sizes.wallpaperSelectorItemPadding) * 2
const thumbnailSizeName = Images.thumbnailSizeNameForDimensions(grid.cellWidth - totalImageMargin, grid.cellHeight - totalImageMargin)
Wallpapers.generateThumbnail(thumbnailSizeName)
}
Connections {
target: Wallpapers
function onDirectoryChanged() {
root.updateThumbnails()
}
}
Keys.onPressed: event => {
if (event.key === Qt.Key_Escape) {
GlobalStates.wallpaperSelectorOpen = false;
@@ -203,9 +216,12 @@ Item {
keyNavigationWraps: true
boundsBehavior: Flickable.StopAtBounds
bottomMargin: extraOptions.implicitHeight
ScrollBar.vertical: StyledScrollBar {}
Component.onCompleted: {
root.updateThumbnails()
}
function moveSelection(delta) {
currentIndex = Math.max(0, Math.min(grid.model.count - 1, currentIndex + delta));
positionViewAtIndex(currentIndex, GridView.Contain);
@@ -219,7 +235,6 @@ Item {
model: Wallpapers.folderModel
onModelChanged: currentIndex = 0
delegate: WallpaperDirectoryItem {
required property var modelData
required property int index