From ef4ae4480f66be85fb11a803a0c8ee5d7431af19 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 24 Aug 2025 16:12:37 +0700 Subject: [PATCH] wallpaper selector: not reinvent MouseArea containsMouse --- .../WallpaperDirectoryItem.qml | 25 +++---------------- .../WallpaperSelectorContent.qml | 16 ++++++------ 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperDirectoryItem.qml b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperDirectoryItem.qml index 66f3f9e24..382880df4 100644 --- a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperDirectoryItem.qml +++ b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperDirectoryItem.qml @@ -10,12 +10,11 @@ import Qt5Compat.GraphicalEffects import Quickshell import Quickshell.Io -Item { +MouseArea { id: root required property var fileModelData property bool isDirectory: fileModelData.fileIsDir property bool useThumbnail: Images.isValidImageByName(fileModelData.fileName) - property bool isHovered: false property alias colBackground: background.color property alias colText: wallpaperItemName.color @@ -24,6 +23,9 @@ Item { signal activated + hoverEnabled: true + onClicked: root.activated() + Rectangle { id: background anchors { @@ -130,23 +132,4 @@ Item { } } } - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onEntered: { - for (let i = 0; i < grid.count; i++) { - const item = grid.itemAtIndex(i); - if (item && item !== parent) { - item.isHovered = false; - } - } - parent.isHovered = true; - grid.currentIndex = index; - } - onExited: { - parent.isHovered = false; - } - onClicked: root.activated() - } } diff --git a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml index 8a985bfb0..bc6d3408a 100644 --- a/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml +++ b/.config/quickshell/ii/modules/wallpaperSelector/WallpaperSelectorContent.qml @@ -209,12 +209,6 @@ Item { } function moveSelection(delta) { - for (let i = 0; i < count; i++) { - const item = itemAtIndex(i); - if (item) { - item.isHovered = false; - } - } currentIndex = Math.max(0, Math.min(grid.model.count - 1, currentIndex + delta)); positionViewAtIndex(currentIndex, GridView.Contain); } @@ -234,11 +228,15 @@ Item { fileModelData: modelData width: grid.cellWidth height: grid.cellHeight - colBackground: (index === grid?.currentIndex || parent?.isHovered) ? Appearance.colors.colPrimaryContainer : ColorUtils.transparentize(Appearance.colors.colPrimaryContainer) - colText: (index === grid.currentIndex || parent.isHovered) ? Appearance.colors.colPrimary : Appearance.colors.colOnLayer0 + colBackground: (index === grid?.currentIndex || containsMouse) ? Appearance.colors.colPrimaryContainer : ColorUtils.transparentize(Appearance.colors.colPrimaryContainer) + colText: (index === grid.currentIndex || containsMouse) ? Appearance.colors.colPrimary : Appearance.colors.colOnLayer0 + + onEntered: { + grid.currentIndex = index; + } + onActivated: { Wallpapers.select(fileModelData.filePath, root.useDarkMode); - filterField.text = ""; } }