booru: put context menu in loader, add tooltip for tags

This commit is contained in:
end-4
2025-05-16 14:56:14 +02:00
parent 3b764ca70e
commit 9a68f80ffa
2 changed files with 98 additions and 67 deletions
@@ -92,3 +92,20 @@ function splitMarkdownBlocks(markdown) {
function escapeBackslashes(str) { function escapeBackslashes(str) {
return str.replace(/\\/g, '\\\\'); return str.replace(/\\/g, '\\\\');
} }
function wordWrap(str, maxLen) {
if (!str) return "";
let words = str.split(" ");
let lines = [];
let current = "";
for (let i = 0; i < words.length; ++i) {
if ((current + (current.length > 0 ? " " : "") + words[i]).length > maxLen) {
if (current.length > 0) lines.push(current);
current = words[i];
} else {
current += (current.length > 0 ? " " : "") + words[i];
}
}
if (current.length > 0) lines.push(current);
return lines.join("\n");
}
@@ -7,6 +7,7 @@ import Qt.labs.platform
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Hyprland import Quickshell.Hyprland
import Qt5Compat.GraphicalEffects import Qt5Compat.GraphicalEffects
@@ -21,9 +22,9 @@ Button {
property string nsfwPath property string nsfwPath
property string fileName: decodeURIComponent((imageData.file_url).substring((imageData.file_url).lastIndexOf('/') + 1)) property string fileName: decodeURIComponent((imageData.file_url).substring((imageData.file_url).lastIndexOf('/') + 1))
property string filePath: `${root.previewDownloadPath}/${root.fileName}` property string filePath: `${root.previewDownloadPath}/${root.fileName}`
property int maxTagStringLineLength: 50
property bool showActions: false property bool showActions: false
Process { Process {
id: downloadProcess id: downloadProcess
running: false running: false
@@ -95,6 +96,10 @@ Button {
PointingHandInteraction {} PointingHandInteraction {}
StyledToolTip {
content: StringUtils.wordWrap(root.imageData.tags, root.maxTagStringLineLength)
}
background: Rectangle { background: Rectangle {
color: menuButton.down ? Appearance.transparentize(Appearance.mix(Appearance.m3colors.m3surface, Appearance.m3colors.m3onSurface, 0.6), 0.1) : color: menuButton.down ? Appearance.transparentize(Appearance.mix(Appearance.m3colors.m3surface, Appearance.m3colors.m3onSurface, 0.6), 0.1) :
menuButton.hovered ? Appearance.transparentize(Appearance.mix(Appearance.m3colors.m3surface, Appearance.m3colors.m3onSurface, 0.8), 0.2) : menuButton.hovered ? Appearance.transparentize(Appearance.mix(Appearance.m3colors.m3surface, Appearance.m3colors.m3onSurface, 0.8), 0.2) :
@@ -114,15 +119,24 @@ Button {
} }
} }
Loader {
id: contextMenuLoader
active: root.showActions
anchors.top: menuButton.bottom
anchors.right: parent.right
anchors.margins: 8
sourceComponent: Item {
width: contextMenu.width
height: contextMenu.height
Rectangle { Rectangle {
id: contextMenu id: contextMenu
anchors.centerIn: parent
opacity: root.showActions ? 1 : 0 opacity: root.showActions ? 1 : 0
visible: opacity > 0 visible: opacity > 0
radius: Appearance.rounding.small radius: Appearance.rounding.small
color: Appearance.m3colors.m3surfaceContainer color: Appearance.m3colors.m3surfaceContainer
anchors.top: menuButton.bottom
anchors.right: parent.right
anchors.margins: 8
implicitHeight: contextMenuColumnLayout.implicitHeight + radius * 2 implicitHeight: contextMenuColumnLayout.implicitHeight + radius * 2
implicitWidth: contextMenuColumnLayout.implicitWidth implicitWidth: contextMenuColumnLayout.implicitWidth
@@ -156,7 +170,6 @@ Button {
enabled: root.imageData.source && root.imageData.source.length > 0 enabled: root.imageData.source && root.imageData.source.length > 0
onClicked: { onClicked: {
root.showActions = false root.showActions = false
Hyprland.dispatch("global quickshell:sidebarLeftClose")
Qt.openUrlExternally(root.imageData.source) Qt.openUrlExternally(root.imageData.source)
} }
} }
@@ -191,6 +204,7 @@ Button {
} }
} }
} }
}
}
} }
} }