forked from Shinonome/dots-hyprland
wallpaper selector: not reinvent MouseArea containsMouse
This commit is contained in:
@@ -10,12 +10,11 @@ import Qt5Compat.GraphicalEffects
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
||||||
Item {
|
MouseArea {
|
||||||
id: root
|
id: root
|
||||||
required property var fileModelData
|
required property var fileModelData
|
||||||
property bool isDirectory: fileModelData.fileIsDir
|
property bool isDirectory: fileModelData.fileIsDir
|
||||||
property bool useThumbnail: Images.isValidImageByName(fileModelData.fileName)
|
property bool useThumbnail: Images.isValidImageByName(fileModelData.fileName)
|
||||||
property bool isHovered: false
|
|
||||||
|
|
||||||
property alias colBackground: background.color
|
property alias colBackground: background.color
|
||||||
property alias colText: wallpaperItemName.color
|
property alias colText: wallpaperItemName.color
|
||||||
@@ -24,6 +23,9 @@ Item {
|
|||||||
|
|
||||||
signal activated
|
signal activated
|
||||||
|
|
||||||
|
hoverEnabled: true
|
||||||
|
onClicked: root.activated()
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: background
|
id: background
|
||||||
anchors {
|
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) {
|
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));
|
currentIndex = Math.max(0, Math.min(grid.model.count - 1, currentIndex + delta));
|
||||||
positionViewAtIndex(currentIndex, GridView.Contain);
|
positionViewAtIndex(currentIndex, GridView.Contain);
|
||||||
}
|
}
|
||||||
@@ -234,11 +228,15 @@ Item {
|
|||||||
fileModelData: modelData
|
fileModelData: modelData
|
||||||
width: grid.cellWidth
|
width: grid.cellWidth
|
||||||
height: grid.cellHeight
|
height: grid.cellHeight
|
||||||
colBackground: (index === grid?.currentIndex || parent?.isHovered) ? Appearance.colors.colPrimaryContainer : ColorUtils.transparentize(Appearance.colors.colPrimaryContainer)
|
colBackground: (index === grid?.currentIndex || containsMouse) ? Appearance.colors.colPrimaryContainer : ColorUtils.transparentize(Appearance.colors.colPrimaryContainer)
|
||||||
colText: (index === grid.currentIndex || parent.isHovered) ? Appearance.colors.colPrimary : Appearance.colors.colOnLayer0
|
colText: (index === grid.currentIndex || containsMouse) ? Appearance.colors.colPrimary : Appearance.colors.colOnLayer0
|
||||||
|
|
||||||
|
onEntered: {
|
||||||
|
grid.currentIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
onActivated: {
|
onActivated: {
|
||||||
Wallpapers.select(fileModelData.filePath, root.useDarkMode);
|
Wallpapers.select(fileModelData.filePath, root.useDarkMode);
|
||||||
|
|
||||||
filterField.text = "";
|
filterField.text = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user