diff options
| author | Petri Hienonen <petri.hienonen@gmail.com> | 2024-05-23 13:56:00 +0300 |
|---|---|---|
| committer | Petri Hienonen <petri.hienonen@gmail.com> | 2025-11-30 12:29:57 +0200 |
| commit | 08297376a85a1719518507e54fca9de954d2376a (patch) | |
| tree | 3b9c58304b40248533bbb2bb5b7bad2da9da1ff0 /home/quickshell/bar/Tooltip.qml | |
| parent | 75c2af4aedd2ac5c2cfc74b346625fa4b265541d (diff) | |
| download | nixos-08297376a85a1719518507e54fca9de954d2376a.tar.zst | |
Agenix configuration
Diffstat (limited to 'home/quickshell/bar/Tooltip.qml')
| -rw-r--r-- | home/quickshell/bar/Tooltip.qml | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/home/quickshell/bar/Tooltip.qml b/home/quickshell/bar/Tooltip.qml new file mode 100644 index 0000000..7ab247d --- /dev/null +++ b/home/quickshell/bar/Tooltip.qml @@ -0,0 +1,89 @@ +import QtQuick +import Quickshell +import "root:/" // for Globals + +LazyLoader { + id: root + + // The item to display the tooltip at. If set to null the tooltip will be hidden. + property Item relativeItem: null + + // Tracks the item after relativeItem is unset. + property Item displayItem: null + + property PopupContext popupContext: Globals.popupContext + + property bool hoverable: false; + readonly property bool hovered: item?.hovered ?? false + + // The content to show in the tooltip. + required default property Component contentDelegate + + active: displayItem != null && popupContext.popup == this + + onRelativeItemChanged: { + if (relativeItem == null) { + if (item != null) item.hideTimer.start(); + } else { + if (item != null) item.hideTimer.stop(); + displayItem = relativeItem; + popupContext.popup = this; + } + } + + PopupWindow { + anchor { + window: root.displayItem.QsWindow.window + rect.y: anchor.window.height + 3 + rect.x: anchor.window.contentItem.mapFromItem(root.displayItem, root.displayItem.width / 2, 0).x + edges: Edges.Top + gravity: Edges.Bottom + } + + visible: true + + property alias hovered: body.containsMouse; + + property Timer hideTimer: Timer { + interval: 250 + + // unloads the popup by causing active to become false + onTriggered: root.popupContext.popup = null; + } + + color: "transparent" + + // don't accept mouse input if !hoverable + Region { id: emptyRegion } + mask: root.hoverable ? null : emptyRegion + + width: body.implicitWidth + height: body.implicitHeight + + MouseArea { + id: body + + anchors.fill: parent + implicitWidth: content.implicitWidth + 10 + implicitHeight: content.implicitHeight + 10 + + hoverEnabled: root.hoverable + + Rectangle { + anchors.fill: parent + + radius: 5 + border.width: 1 + color: palette.active.toolTipBase + border.color: palette.active.light + + Loader { + id: content + anchors.centerIn: parent + sourceComponent: contentDelegate + active: true + } + } + } + } +} |
