148 lines
4.7 KiB
QML
148 lines
4.7 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
|
|
Rectangle {
|
|
id: root
|
|
|
|
required property Theme theme
|
|
required property string title
|
|
required property string app
|
|
required property bool selected
|
|
required property bool current
|
|
// 0 at the front of the loop, 1 at the very back.
|
|
required property real shade
|
|
// Live capture source on Hyprland, null elsewhere.
|
|
required property Toplevel toplevel
|
|
// Screenshot file on niri, "" elsewhere.
|
|
required property string previewFile
|
|
// Changes whenever the screenshot files are rewritten.
|
|
required property int previewVersion
|
|
|
|
signal activated
|
|
|
|
readonly property string iconSource: Quickshell.iconPath(root.app, "application-x-executable")
|
|
|
|
width: root.theme.cardWidth
|
|
height: root.theme.cardHeight
|
|
radius: root.theme.cardRadius
|
|
color: root.theme.cardBg
|
|
border.width: root.selected ? 3 : 1
|
|
border.color: root.selected ? root.theme.accent : root.theme.cardBorder
|
|
antialiasing: true
|
|
|
|
Rectangle {
|
|
id: previewArea
|
|
anchors.top: parent.top
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: infoRow.top
|
|
anchors.margins: root.theme.cardPadding
|
|
radius: root.theme.previewRadius
|
|
color: root.theme.previewBg
|
|
clip: true
|
|
|
|
ScreencopyView {
|
|
id: liveView
|
|
|
|
// Keeps the window's own shape inside the preview area.
|
|
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
|
|
|
|
anchors.centerIn: parent
|
|
width: Math.min(parent.width, parent.height * liveView.aspect)
|
|
height: liveView.width / liveView.aspect
|
|
captureSource: root.toplevel
|
|
live: true
|
|
visible: root.toplevel !== null && liveView.hasContent
|
|
}
|
|
|
|
Image {
|
|
id: shotView
|
|
anchors.fill: parent
|
|
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
|
|
// The file is rewritten in place, so never reuse an old copy.
|
|
cache: false
|
|
asynchronous: true
|
|
sourceSize.width: root.theme.cardWidth * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
visible: shotView.status === Image.Ready
|
|
}
|
|
|
|
Image {
|
|
anchors.centerIn: parent
|
|
width: root.theme.iconSize
|
|
height: root.theme.iconSize
|
|
source: root.iconSource
|
|
sourceSize.width: root.theme.iconSize * 2
|
|
sourceSize.height: root.theme.iconSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
visible: !liveView.visible && !shotView.visible
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: infoRow
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
anchors.leftMargin: root.theme.cardPadding
|
|
anchors.rightMargin: root.theme.cardPadding
|
|
anchors.bottomMargin: root.theme.cardPadding
|
|
height: root.theme.rowHeight
|
|
spacing: 10
|
|
|
|
Image {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: root.theme.rowIconSize
|
|
height: root.theme.rowIconSize
|
|
source: root.iconSource
|
|
sourceSize.width: root.theme.rowIconSize * 2
|
|
sourceSize.height: root.theme.rowIconSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
}
|
|
|
|
Column {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: parent.width - root.theme.rowIconSize - parent.spacing
|
|
|
|
Text {
|
|
width: parent.width
|
|
elide: Text.ElideRight
|
|
color: root.theme.textColor
|
|
font.pixelSize: root.theme.titleSize
|
|
text: root.title.length > 0 ? root.title : "Untitled"
|
|
}
|
|
|
|
Text {
|
|
width: parent.width
|
|
elide: Text.ElideRight
|
|
color: root.current ? root.theme.accent : root.theme.labelColor
|
|
font.pixelSize: root.theme.appSize
|
|
text: {
|
|
const name = root.app.length > 0 ? root.app : "unknown app";
|
|
return root.current ? name + " · focused" : name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Darkens cards toward the back of the loop.
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
radius: parent.radius
|
|
color: "black"
|
|
opacity: root.shade * root.theme.backShade
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: root.activated()
|
|
}
|
|
}
|