repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nuguland/ClipboardPanel.qml
Rawpragma ComponentBehavior: Bound
import QtQuick
import "Util.js" as Util
Column {
id: root
required property Theme theme
required property Clipboard clipboardService
property string query: ""
property var panelState: clipboardService ? Util.parseJson(clipboardService.stateJson(), {
"rows": [],
"privateMode": false,
"privateRole": "ui.accent",
"lastAction": {}
}) : ({
"rows": [],
"privateMode": false,
"privateRole": "ui.accent",
"lastAction": {}
})
readonly property var rows: panelState.rows || []
function refreshFrom(text) {
panelState = Util.parseJson(text, panelState);
}
function search(text) {
query = String(text);
if (clipboardService)
refreshFrom(clipboardService.search(query));
}
function copy(id) {
if (clipboardService)
refreshFrom(clipboardService.copy(id));
}
function paste(id) {
if (clipboardService)
refreshFrom(clipboardService.paste(id));
}
function togglePin(id) {
if (clipboardService)
refreshFrom(clipboardService.togglePin(id));
}
function deleteRow(id) {
if (clipboardService)
refreshFrom(clipboardService.deleteRow(id));
}
function setPrivateMode(enabled) {
if (clipboardService)
refreshFrom(clipboardService.setPrivateMode(enabled));
}
spacing: 10
width: parent ? parent.width : 0
Row {
width: parent.width
spacing: 8
PopupTextField {
objectName: "searchField"
theme: root.theme
width: parent.width - 108
height: 32
icon: ""
placeholderText: "search clipboard"
text: root.query
onEdited: text => root.search(text)
}
PopupButton {
objectName: "privateModeChip"
theme: root.theme
width: 100
height: 32
icon: root.panelState.privateMode ? "" : ""
text: root.panelState.privateMode ? "private" : "normal"
checked: root.panelState.privateMode
onClicked: root.setPrivateMode(!root.panelState.privateMode)
}
}
PopupCard {
objectName: "clipboardHistoryPanel"
theme: root.theme
padding: 0
width: parent.width
height: Math.min(440, Math.max(120, rowColumn.implicitHeight + 16))
Flickable {
id: list
anchors.fill: parent
anchors.margins: 8
contentHeight: rowColumn.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
Column {
id: rowColumn
width: list.width
spacing: 6
Repeater {
model: root.rows
delegate: PopupCard {
id: clipRow
theme: root.theme
padding: 0
active: modelData.pinned
required property var modelData
objectName: "clipRow"
width: rowColumn.width
height: 56
// Single hover detector covering the whole card. NoButton
// lets clicks fall through to the action buttons (later
// siblings); the buttons keep hoverEnabled off so they
// never steal containsMouse from this detector.
MouseArea {
id: rowHover
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
}
Item {
id: leadingSlot
anchors.left: parent.left
anchors.leftMargin: 9
anchors.verticalCenter: parent.verticalCenter
width: 36
height: 36
Image {
id: thumb
anchors.fill: parent
visible: clipRow.modelData.isImage && thumb.status !== Image.Error
// encodeURI keeps "/" but escapes spaces/specials so screenshot
// paths ("/tmp/Screenshot from ….png") resolve as valid file:// URLs
source: clipRow.modelData.isImage ? "file://" + encodeURI(clipRow.modelData.imagePath || "") : ""
sourceSize.width: 36
sourceSize.height: 36
fillMode: Image.PreserveAspectCrop
asynchronous: true
clip: true
smooth: true
}
Rectangle {
id: swatch
anchors.fill: parent
visible: !clipRow.modelData.isImage && !!clipRow.modelData.swatch
radius: 9
color: clipRow.modelData.swatch ? clipRow.modelData.swatch : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.normal, 0.25) : "transparent"
}
// Type-icon fallback: shown for non-image/non-color
// rows, and when the image thumbnail fails to load.
Text {
anchors.centerIn: parent
visible: !swatch.visible && !thumb.visible
text: clipRow.modelData.icon
color: root.theme ? root.theme.ui.accent : "white"
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 18
}
}
Column {
anchors.left: leadingSlot.right
anchors.right: actionRail.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 11
anchors.rightMargin: 8
spacing: 3
NuguText {
theme: root.theme
text: clipRow.modelData.title
width: parent.width
elide: Text.ElideRight
}
NuguText {
theme: root.theme
variant: "meta"
text: clipRow.modelData.kind + " · " + clipRow.modelData.age
width: parent.width
elide: Text.ElideRight
}
}
// Pin badge, hidden while the action rail is revealed.
Text {
id: pinBadge
anchors.right: parent.right
anchors.rightMargin: 11
anchors.top: parent.top
anchors.topMargin: 8
visible: clipRow.modelData.pinned && !rowHover.containsMouse
text: ""
color: root.theme ? root.theme.ui.focus : "white"
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 11
}
Row {
id: actionRail
anchors.right: parent.right
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 5
opacity: rowHover.containsMouse ? 1 : 0
enabled: rowHover.containsMouse
Behavior on opacity {
NumberAnimation {
duration: root.theme && root.theme.lowPowerMode ? 0 : 120
easing.type: Easing.OutCubic
}
}
Repeater {
model: ["copy", "paste", "pin", "delete"]
delegate: PopupButton {
id: actionButton
required property string modelData
readonly property bool isDelete: modelData === "delete"
readonly property bool isPin: modelData === "pin"
theme: root.theme
width: 64
height: 30
text: modelData
role: isDelete ? "destructive" : "normal"
checked: isPin && clipRow.modelData.pinned
onClicked: {
if (modelData === "copy")
root.copy(clipRow.modelData.id);
else if (modelData === "paste")
root.paste(clipRow.modelData.id);
else if (isPin)
root.togglePin(clipRow.modelData.id);
else
root.deleteRow(clipRow.modelData.id);
}
}
}
}
}
}
}
}
}
}