50 lines
1.5 KiB
QML
50 lines
1.5 KiB
QML
import QtQuick
|
|
import QtQuick.Effects
|
|
import Quickshell
|
|
import "." as M
|
|
|
|
Text {
|
|
id: root
|
|
property string label: ""
|
|
property string tooltip: ""
|
|
property string minText: ""
|
|
property bool _hovered: false
|
|
|
|
text: label
|
|
width: minText ? Math.max(implicitWidth, _minMetrics.width) : implicitWidth
|
|
horizontalAlignment: minText ? Text.AlignHCenter : Text.AlignLeft
|
|
color: parent?.accentColor ?? M.Theme.base05
|
|
font.pixelSize: M.Theme.fontSize
|
|
font.family: M.Theme.fontFamily
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
TextMetrics {
|
|
id: _minMetrics
|
|
text: root.minText
|
|
font.pixelSize: root.font.pixelSize
|
|
font.family: root.font.family
|
|
}
|
|
|
|
layer.enabled: _hovered && !(parent && parent._hovered === true)
|
|
layer.effect: MultiEffect {
|
|
shadowEnabled: true
|
|
shadowColor: M.Theme.base05
|
|
shadowBlur: 0.5
|
|
shadowVerticalOffset: 0
|
|
shadowHorizontalOffset: 0
|
|
}
|
|
|
|
HoverHandler {
|
|
onHoveredChanged: {
|
|
root._hovered = hovered;
|
|
if (hovered && root.tooltip !== "") {
|
|
M.FlyoutState.text = root.tooltip;
|
|
M.FlyoutState.itemX = root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0);
|
|
M.FlyoutState.screen = QsWindow.window?.screen ?? null;
|
|
M.FlyoutState.visible = true;
|
|
} else if (!hovered && root.tooltip !== "") {
|
|
M.FlyoutState.visible = false;
|
|
}
|
|
}
|
|
}
|
|
}
|