hefty: bar: time widget

This commit is contained in:
end-4
2026-02-06 23:38:05 +01:00
parent 74368ad25a
commit 74c012c930
9 changed files with 177 additions and 18 deletions
@@ -95,4 +95,15 @@ Singleton {
}
}
}
function findParentWithProperty(obj, propertyName) {
let current = obj;
while (current) {
if (current.hasOwnProperty(propertyName)) {
return current;
}
current = current.parent;
}
return null;
}
}
@@ -1,5 +1,6 @@
pragma ComponentBehavior: Bound
import QtQuick
import qs.modules.common as C
Rectangle {
id: root
@@ -7,7 +8,7 @@ Rectangle {
property bool hover: false
property bool press: false
property bool drag: false
property color contentColor: Appearance.m3colors.m3onBackground
property color contentColor: C.Appearance.m3colors.m3onBackground
color: "transparent"
FadeLoader {
@@ -15,9 +16,12 @@ Rectangle {
anchors.fill: parent
shown: root.hover
sourceComponent: StateLayer {
radius: root.radius
state: StateLayer.State.Hover
color: root.contentColor
topLeftRadius: root.topLeftRadius
topRightRadius: root.topRightRadius
bottomLeftRadius: root.bottomLeftRadius
bottomRightRadius: root.bottomRightRadius
}
}
FadeLoader {
@@ -25,9 +29,12 @@ Rectangle {
anchors.fill: parent
shown: root.focus
sourceComponent: StateLayer {
radius: root.radius
state: StateLayer.State.Focus
color: root.contentColor
topLeftRadius: root.topLeftRadius
topRightRadius: root.topRightRadius
bottomLeftRadius: root.bottomLeftRadius
bottomRightRadius: root.bottomRightRadius
}
}
FadeLoader {
@@ -35,9 +42,12 @@ Rectangle {
anchors.fill: parent
shown: root.press
sourceComponent: StateLayer {
radius: root.radius
state: StateLayer.State.Press
color: root.contentColor
topLeftRadius: root.topLeftRadius
topRightRadius: root.topRightRadius
bottomLeftRadius: root.bottomLeftRadius
bottomRightRadius: root.bottomRightRadius
}
}
FadeLoader {
@@ -45,9 +55,12 @@ Rectangle {
anchors.fill: parent
shown: root.drag
sourceComponent: StateLayer {
radius: root.radius
state: StateLayer.State.Drag
color: root.contentColor
topLeftRadius: root.topLeftRadius
topRightRadius: root.topRightRadius
bottomLeftRadius: root.bottomLeftRadius
bottomRightRadius: root.bottomRightRadius
}
}
}
@@ -9,13 +9,19 @@ Item {
property bool vertical: C.Config.options.bar.vertical
property real spacing: 4
property list<var> leftWidgets: C.Config.options.hefty.bar.leftWidgets
property list<var> centerLeftWidgets: C.Config.options.hefty.bar.centerLeftWidgets
property list<var> centerWidgets: C.Config.options.hefty.bar.centerWidgets
property list<var> centerRightWidgets: C.Config.options.hefty.bar.centerRightWidgets
property list<var> rightWidgets: C.Config.options.hefty.bar.rightWidgets
Side {
id: leftSide
anchors.left: parent.left
anchors.top: parent.top
HBarUserFallbackComponentRepeater {
componentNames: C.Config.options.hefty.bar.leftWidgets
componentNames: root.leftWidgets
}
}
@@ -24,7 +30,16 @@ Item {
anchors.right: !root.vertical ? centerSide.left : parent.right
anchors.bottom: root.vertical ? parent.bottom : undefined
HBarUserFallbackComponentRepeater {
componentNames: C.Config.options.hefty.bar.centerLeftWidgets
componentNames: {
print(JSON.stringify([
...root.centerLeftWidgets,
...(root.centerLeftWidgets.length > 0 ? [invisibleItem] : []),
], null, 2));
return [
...root.centerLeftWidgets,
...(root.centerLeftWidgets.length > 0 ? [invisibleItem] : []),
];
}
}
}
@@ -33,7 +48,11 @@ Item {
anchors.verticalCenter: root.vertical ? parent.verticalCenter : undefined
anchors.horizontalCenter: !root.vertical ? parent.horizontalCenter : undefined
HBarUserFallbackComponentRepeater {
componentNames: C.Config.options.hefty.bar.centerWidgets
componentNames: [
...(root.centerLeftWidgets.length > 0 ? [invisibleItem] : []),
...root.centerWidgets,
...(root.centerRightWidgets.length > 0 ? [invisibleItem] : []),
]
}
}
@@ -42,7 +61,10 @@ Item {
anchors.left: !root.vertical ? centerSide.right : parent.left
anchors.top: root.vertical ? parent.top : undefined
HBarUserFallbackComponentRepeater {
componentNames: C.Config.options.hefty.bar.centerRightWidgets
componentNames: [
...(root.centerLeftWidgets.length > 0 ? [invisibleItem] : []),
...root.centerRightWidgets,
]
}
}
@@ -51,7 +73,7 @@ Item {
anchors.right: parent.right
anchors.bottom: parent.bottom
HBarUserFallbackComponentRepeater {
componentNames: C.Config.options.hefty.bar.rightWidgets
componentNames: root.rightWidgets
}
}
@@ -22,10 +22,17 @@ Item {
implicitWidth: vertical ? barUndirectionalWidth : layout.implicitWidth + padding * 2
implicitHeight: vertical ? layout.implicitHeight + padding * 2 : barUndirectionalWidth
property alias startRadius: bg.startRadius
property alias endRadius: bg.endRadius
property alias topLeftRadius: bg.topLeftRadius
property alias topRightRadius: bg.topRightRadius
property alias bottomLeftRadius: bg.bottomLeftRadius
property alias bottomRightRadius: bg.bottomRightRadius
W.AxisRectangle {
id: bg
anchors.centerIn: parent
contentLayer: W.StyledRectangle.ContentLayer.Pane
contentLayer: W.StyledRectangle.ContentLayer.Group
width: root.vertical ? root.backgroundUndirectionalWidth : root.width
height: root.vertical ? root.height : root.backgroundUndirectionalWidth
@@ -7,21 +7,25 @@ import qs.modules.common.widgets as W
Repeater {
id: root
readonly property string invisibleItem: "_invisible"
required property list<var> componentNames
property string context: Quickshell.shellPath("modules/hefty/topLayer/bar/widgets")
model: {
const m = componentNames.map(item => {
if (item instanceof Array)
return ({"type": "container", "value": item});
else if (item === root.invisibleItem)
return ({"type": "invisible", "value": item});
else
return ({"type": "component", "value": item});
});
for (var i = 0;i < m.length; i++) {
const item = m[i];
if (item.type === "container") {
item.startSide = (i === 0) || (m[i - 1].type !== "container");
item.endSide = (i + 1 >= m.length) || (m[i + 1].type !== "container");
item.startSide = (i === 0) || (m[i - 1].type === "component");
item.endSide = (i + 1 >= m.length) || (m[i + 1].type === "component");
}
}
// print(JSON.stringify(m, null, 2));
@@ -29,6 +33,11 @@ Repeater {
}
delegate: DelegateChooser {
role: "type"
DelegateChoice {
roleValue: root.invisibleItem
delegate: Item { visible: false }
}
DelegateChoice {
roleValue: "component"
@@ -0,0 +1,91 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import qs.modules.common as C
import qs.modules.common.functions as F
import qs.services as S
import qs.modules.common.widgets as W
W.ButtonMouseArea {
id: root
property bool vertical: C.Config.options.bar.vertical
property bool showPopup: false
property var layoutParent: F.ObjectUtils.findParentWithProperty(root, "startSide")
property real layoutParentTopLeftRadius: layoutParent.topLeftRadius
property real layoutParentTopRightRadius: layoutParent.topRightRadius
property real layoutParentBottomLeftRadius: layoutParent.bottomLeftRadius
property real layoutParentBottomRightRadius: layoutParent.bottomRightRadius
readonly property real barThickness: vertical ? C.Appearance.sizes.verticalBarWidth : C.Appearance.sizes.barHeight
property var activeContent: vertical ? verticalContent : horizontalContent
property real parentRadiusToPaddingRatio: 0.3
implicitWidth: vertical ? barThickness : (activeContent.implicitWidth + (layoutParentTopLeftRadius + layoutParentBottomRightRadius) * parentRadiusToPaddingRatio)
implicitHeight: !vertical ? barThickness : (activeContent.implicitHeight + (layoutParentTopLeftRadius + layoutParentBottomRightRadius) * parentRadiusToPaddingRatio)
Layout.alignment: vertical ? Qt.AlignHCenter : Qt.AlignVCenter
Layout.fillWidth: vertical
Layout.fillHeight: !vertical
onClicked: showPopup = !showPopup
W.StateOverlay {
id: hoverOverlay
anchors.fill: parent
property real parentMargins: 4
property real ownMargins: 2
property real edgeMargins: parentMargins + ownMargins
property real sideMargins: -2
anchors {
leftMargin: root.vertical ? edgeMargins : sideMargins
rightMargin: root.vertical ? edgeMargins : sideMargins
topMargin: root.vertical ? sideMargins : edgeMargins
bottomMargin: root.vertical ? sideMargins : edgeMargins
}
topLeftRadius: root.layoutParentTopLeftRadius - ownMargins
topRightRadius: root.layoutParentTopRightRadius - ownMargins
bottomLeftRadius: root.layoutParentBottomLeftRadius - ownMargins
bottomRightRadius: root.layoutParentBottomRightRadius - ownMargins
hover: root.containsMouse
press: root.containsPress
}
W.FadeLoader {
id: horizontalContent
anchors.fill: parent
shown: !root.vertical
sourceComponent: RowLayout {
anchors.fill: parent
W.StyledText {
Layout.leftMargin: root.layoutParentTopLeftRadius * root.parentRadiusToPaddingRatio
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: C.Appearance.font.pixelSize.large
color: C.Appearance.colors.colOnLayer1
text: S.DateTime.time
}
W.StyledText {
Layout.alignment: Qt.AlignVCenter
font.pixelSize: C.Appearance.font.pixelSize.small
color: C.Appearance.colors.colOnLayer1
text: "•"
}
W.StyledText {
Layout.alignment: Qt.AlignVCenter
font.pixelSize: C.Appearance.font.pixelSize.small
color: C.Appearance.colors.colOnLayer1
text: S.DateTime.longDate
}
}
}
W.FadeLoader {
id: verticalContent
anchors.fill: parent
}
}
@@ -36,8 +36,9 @@ Item {
Layout.alignment: vertical ? Qt.AlignHCenter : Qt.AlignVCenter
Layout.fillWidth: vertical
Layout.fillHeight: !vertical
implicitWidth: vertical ? Appearance.sizes.verticalBarWidth : occupiedIndicators.implicitWidth
implicitHeight: vertical ? occupiedIndicators.implicitHeight : Appearance.sizes.barHeight
readonly property real barThickness: vertical ? Appearance.sizes.verticalBarWidth : Appearance.sizes.barHeight
implicitWidth: vertical ? barThickness : occupiedIndicators.implicitWidth
implicitHeight: vertical ? occupiedIndicators.implicitHeight : barThickness
property real specialBlur: (wsModel.specialWorkspaceActive && !interactionMouseArea.containsMouse) ? 1 : 0
Behavior on specialBlur {
@@ -316,8 +317,8 @@ Item {
component WorkspaceItem: Item {
required property int index
readonly property int wsId: wsModel.getWorkspaceIdAt(index)
implicitWidth: root.vertical ? Appearance.sizes.verticalBarWidth : root.workspaceButtonWidth
implicitHeight: root.vertical ? root.workspaceButtonWidth : Appearance.sizes.barHeight
implicitWidth: root.vertical ? root.barThickness : root.workspaceButtonWidth
implicitHeight: root.vertical ? root.workspaceButtonWidth : root.barThickness
}
component NumberWorkspaceItem: WorkspaceItem {
@@ -0,0 +1,6 @@
pragma ComponentBehavior: Bound
import QtQuick
Item {
visible: false
}
@@ -6,7 +6,6 @@ import QtQuick.Layouts
Item {
id: root
property bool borderless: Config.options.bar.borderless
property bool showDate: Config.options.bar.verbose
implicitWidth: rowLayout.implicitWidth
implicitHeight: Appearance.sizes.barHeight