wallpaper selector: not reinvent MouseArea containsMouse

This commit is contained in:
end-4
2025-08-24 16:12:37 +07:00
parent 8277a2d942
commit ef4ae4480f
2 changed files with 11 additions and 30 deletions
@@ -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()
}
}
@@ -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 = "";
}
}