79 lines
2.2 KiB
QML
79 lines
2.2 KiB
QML
import QtQuick
|
|
import QtQuick.Effects
|
|
import Quickshell
|
|
import "." as M
|
|
|
|
Text {
|
|
id: root
|
|
property string icon: ""
|
|
property string tooltip: ""
|
|
property string minIcon: ""
|
|
property bool _hovered: false
|
|
property string _displayIcon: icon
|
|
property string _pendingIcon: ""
|
|
|
|
text: _displayIcon
|
|
|
|
onIconChanged: {
|
|
_pendingIcon = icon;
|
|
if (!_crossfade.running)
|
|
_crossfade.start();
|
|
}
|
|
|
|
SequentialAnimation {
|
|
id: _crossfade
|
|
NumberAnimation {
|
|
target: root
|
|
property: "opacity"
|
|
to: 0
|
|
duration: 60
|
|
easing.type: Easing.InQuad
|
|
}
|
|
ScriptAction {
|
|
script: root._displayIcon = root._pendingIcon
|
|
}
|
|
NumberAnimation {
|
|
target: root
|
|
property: "opacity"
|
|
to: 1
|
|
duration: 100
|
|
easing.type: Easing.OutQuad
|
|
}
|
|
}
|
|
width: minIcon ? Math.max(implicitWidth, _minIconMetrics.width) : implicitWidth
|
|
horizontalAlignment: minIcon ? Text.AlignHCenter : Text.AlignLeft
|
|
color: parent?.accentColor ?? M.Theme.base05
|
|
font.pixelSize: M.Theme.fontSize + 1
|
|
font.family: M.Theme.iconFontFamily
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
TextMetrics {
|
|
id: _minIconMetrics
|
|
text: root.minIcon
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|