quickshell/modules/wallpaper/WallpaperPicker.qml
2026-07-27 00:37:33 +02:00

138 lines
4.4 KiB
QML

pragma ComponentBehavior: Bound
import Quickshell
import Quickshell.Wayland
import Quickshell.Widgets
import Quickshell.Hyprland
import QtQuick
import Qt.labs.folderlistmodel 2.11
import QtQuick.Effects
import qs
import qs.settings
import qs.widgets
Rectangle {
id: main
required property real moduleHeight
required property int screenHeight
color: Colors.base02
radius: Config.rounding
implicitWidth: moduleHeight
implicitHeight: moduleHeight
MaterialIcon {
anchors.centerIn: main
text: "\ue1bc"
font.pixelSize: 16
font.bold: true
}
MouseArea {
id: clickHandler
anchors.fill: main
acceptedButtons: Qt.LeftButton
cursorShape: Qt.PointingHandCursor
onClicked: {
wallPicker.visible = !wallPicker.visible;
}
}
WlrLayershell {
id: wallPicker
visible: false
exclusionMode: ExclusionMode.Ignore
keyboardFocus: WlrKeyboardFocus.OnDemand
implicitHeight: 300
color: 'transparent'
anchors {
bottom: true
left: true
right: true
}
margins {
bottom: 20
left: 20
right: 20
}
HyprlandFocusGrab {
id: grabber
active: wallPicker.visible
windows: [wallPicker]
onCleared: wallPicker.visible = false
}
onVisibleChanged: {
if (wallPicker.visible)
container.forceActiveFocus();
}
ClippingRectangle {
id: container
focus: true
Keys.onEscapePressed: {
wallPicker.visible = false;
}
anchors.fill: parent
color: Colors.base01
radius: Config.rounding
border.width: 2
border.color: Colors.base0D
clip: true
GridView {
id: wallpaperLayout
clip: true
snapMode: GridView.SnapOneRow
anchors.fill: parent
flow: GridView.FlowTopToBottom
width: parent.width - 10
height: parent.height - 10
anchors.centerIn: parent
model: wallpaperList
cellWidth: ((wallPicker.width) / 5) - 2
cellHeight: wallPicker.height
delegate: ClippingWrapperRectangle {
id: wallTile
layer.enabled: true
layer.effect: MultiEffect {
id: dropShadow
source: wallTile
shadowEnabled: true
shadowHorizontalOffset: 10
shadowVerticalOffset: 10
shadowColor: "#020202"
}
margin: 10
required property var modelData
color: 'transparent'
radius: Config.rounding - 4
implicitWidth: (wallPicker.width - wallPicker.margins.left * 2) / 5
implicitHeight: wallPicker.height - wallPicker.margins.bottom / 2
child: ClippingRectangle {
id: wpRounder
color: 'transparent'
radius: Config.rounding
Image {
id: wallpaper
anchors.fill: parent
source: wallTile.modelData.filePath
sourceSize.width: 16 * 30
sourceSize.height: 9 * 30
asynchronous: true
cache: true
}
MouseArea {
id: wpClickHandler
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton
hoverEnabled: true
onClicked: {
Config.wallpaper = wallTile.modelData.filePath;
}
}
}
}
}
FolderListModel {
id: wallpaperList
folder: Config.wallDir
nameFilters: ["*.png"]
}
}
}
}