import QtQuick import qs.Commons Item { id: root property var bar: null property string text: "" property string fontFamily: bar ? bar.fontFamily : Style.font.family property real fontSize: Style.font.body property color foreground: bar ? bar.foreground : Color.foreground property color activeColor: bar ? bar.urgent : Color.urgent property bool active: false property real horizontalMargin: 8.5 property real rightExtraMargin: 0 property real verticalPadding: 6 property real fixedWidth: -1 property real fixedHeight: -1 property real textRotation: 0 property bool keepSpace: false property string tooltipText: "" property var registeredBar: null signal pressed(int button) signal wheelMoved(int delta) function triggerPress(button) { if (root.bar) root.bar.hideTooltip(root) root.pressed(button) } function syncClickRegistration() { if (registeredBar && registeredBar.unregisterClickTarget) registeredBar.unregisterClickTarget(root) registeredBar = root.bar if (registeredBar && registeredBar.registerClickTarget) registeredBar.registerClickTarget(root) } onBarChanged: syncClickRegistration() Component.onCompleted: syncClickRegistration() Component.onDestruction: if (registeredBar && registeredBar.unregisterClickTarget) registeredBar.unregisterClickTarget(root) readonly property bool vertical: bar ? bar.vertical : false readonly property int barSize: bar ? bar.barSize : Style.bar.sizeHorizontal readonly property real scaledHorizontalMargin: Style.spaceReal(horizontalMargin) readonly property real scaledRightExtraMargin: Style.spaceReal(rightExtraMargin) readonly property real scaledVerticalPadding: Style.spaceReal(verticalPadding) visible: text !== "" || keepSpace opacity: text === "" ? 0 : 1 implicitWidth: fixedWidth > 0 ? fixedWidth : (vertical ? barSize : Math.max(12, label.implicitWidth + scaledHorizontalMargin * 2 + scaledRightExtraMargin)) implicitHeight: fixedHeight > 0 ? fixedHeight : (vertical ? Math.max(12, label.implicitHeight + scaledVerticalPadding * 2) : barSize) Behavior on opacity { NumberAnimation { duration: 140; easing.type: Easing.OutCubic } } Text { id: label anchors.centerIn: parent anchors.horizontalCenterOffset: root.vertical ? 0 : -root.scaledRightExtraMargin / 2 text: root.text color: root.active ? root.activeColor : root.foreground font.family: root.fontFamily font.pixelSize: root.fontSize renderType: Text.NativeRendering rotation: root.textRotation horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter Behavior on color { ColorAnimation { duration: 160 } } } MouseArea { id: mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton hoverEnabled: true cursorShape: Qt.PointingHandCursor onEntered: if (root.bar) root.bar.showTooltip(root, root.tooltipText) onExited: if (root.bar) root.bar.hideTooltip(root) onClicked: function(mouse) { root.triggerPress(mouse.button) } onWheel: function(wheel) { root.wheelMoved(wheel.angleDelta.y) } } }