Split out indicators

This commit is contained in:
David Heinemeier Hansson
2026-05-20 13:05:56 +02:00
parent 8476fa7d82
commit 3b9700682c
12 changed files with 527 additions and 162 deletions
+52
View File
@@ -0,0 +1,52 @@
import QtQuick
import qs.Commons
WidgetButton {
id: root
property string moduleName: ""
property var settings: ({})
property string activeText: ""
property string inactiveText: activeText
property string activeTooltipText: ""
property string inactiveTooltipText: activeTooltipText
property string indicatorBlock: "single"
readonly property bool belongsInBlock: indicatorBlock === "active" ? active : (indicatorBlock === "inactive" ? !active : true)
readonly property bool inactiveRevealed: !active && !!bar && bar.revealInactiveIndicators
function extractData(raw) {
var text = String(raw || "").trim()
if (text === "") return {}
var lines = text.split("\n")
try {
return JSON.parse(lines[lines.length - 1])
} catch (error) {
return { text: text }
}
}
function syncIndicatorOpacity() {
root.opacity = !belongsInBlock ? 0 : (active ? 1 : (inactiveRevealed ? 0.45 : 0))
}
Component.onCompleted: syncIndicatorOpacity()
onActiveChanged: syncIndicatorOpacity()
onBarChanged: syncIndicatorOpacity()
onBelongsInBlockChanged: syncIndicatorOpacity()
onInactiveRevealedChanged: syncIndicatorOpacity()
onIndicatorBlockChanged: syncIndicatorOpacity()
visible: belongsInBlock && (text !== "" || keepSpace)
text: active ? activeText : inactiveText
tooltipText: active ? activeTooltipText : inactiveTooltipText
keepSpace: true
dimmed: !active
concealed: !active && !inactiveRevealed
interactive: belongsInBlock && (active || indicatorBlock === "inactive" || inactiveRevealed)
useActiveColor: false
maintainIndicatorReveal: indicatorBlock === "inactive"
fontSize: Style.font.caption
horizontalMargin: 5
verticalPadding: 5
}
+22 -4
View File
@@ -18,6 +18,11 @@ Item {
property real fixedHeight: -1
property real textRotation: 0
property bool keepSpace: false
property bool dimmed: false
property bool concealed: false
property bool interactive: true
property bool useActiveColor: true
property bool maintainIndicatorReveal: false
property string tooltipText: ""
property var registeredBar: null
@@ -46,7 +51,7 @@ Item {
readonly property real scaledVerticalPadding: Style.spaceReal(verticalPadding)
visible: text !== "" || keepSpace
opacity: text === "" ? 0 : 1
opacity: text === "" || concealed ? 0 : (dimmed ? 0.45 : 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)
@@ -59,7 +64,7 @@ Item {
anchors.centerIn: parent
anchors.horizontalCenterOffset: root.vertical ? 0 : -root.scaledRightExtraMargin / 2
text: root.text
color: root.active ? root.activeColor : root.foreground
color: root.active && root.useActiveColor ? root.activeColor : root.foreground
font.family: root.fontFamily
font.pixelSize: root.fontSize
renderType: Text.NativeRendering
@@ -76,10 +81,23 @@ Item {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
enabled: root.interactive
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: if (root.bar) root.bar.showTooltip(root, root.tooltipText)
onExited: if (root.bar) root.bar.hideTooltip(root)
onEntered: {
if (root.bar) {
root.bar.showTooltip(root, root.tooltipText)
if (root.maintainIndicatorReveal && root.bar.setIndicatorItemHovered)
root.bar.setIndicatorItemHovered(true)
}
}
onExited: {
if (root.bar) {
root.bar.hideTooltip(root)
if (root.maintainIndicatorReveal && root.bar.setIndicatorItemHovered)
root.bar.setIndicatorItemHovered(false)
}
}
onClicked: function(mouse) { root.triggerPress(mouse.button) }
onWheel: function(wheel) { root.wheelMoved(wheel.angleDelta.y) }
}
+1
View File
@@ -1,5 +1,6 @@
module qs.Ui
BarIndicator 1.0 BarIndicator.qml
BarWidget 1.0 BarWidget.qml
Button 1.0 Button.qml
ButtonGroup 1.0 ButtonGroup.qml