Settings: reworked modular bar settings

- deleted NCard, we already have NBox
- assign a color to each widget for better overview when moving stuff
around
- minor QOL improvements to NComboBox
This commit is contained in:
LemmyCook 2025-08-22 18:37:48 -04:00
parent 6a159a390a
commit 1b77f4882d
4 changed files with 46 additions and 31 deletions

View file

@ -141,9 +141,10 @@ ColumnLayout {
NText { NText {
text: "Widgets Positioning" text: "Widgets Positioning"
font.pointSize: Style.fontSizeL * scaling font.pointSize: Style.fontSizeXXL * scaling
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
color: Color.mOnSurface color: Color.mOnSurface
Layout.bottomMargin: Style.marginS * scaling
} }
NText { NText {

View file

@ -1,16 +0,0 @@
import QtQuick
import qs.Commons
import qs.Services
// Generic card container
Rectangle {
id: root
implicitWidth: childrenRect.width
implicitHeight: childrenRect.height
color: Color.mSurface
radius: Style.radiusM * scaling
border.color: Color.mOutline
border.width: Math.max(1, Style.borderS * scaling)
}

View file

@ -8,7 +8,7 @@ import qs.Widgets
ColumnLayout { ColumnLayout {
id: root id: root
readonly property real preferredHeight: Style.baseWidgetSize * 1.25 * scaling readonly property real preferredHeight: Style.baseWidgetSize * 1.35 * scaling
property string label: "" property string label: ""
property string description: "" property string description: ""
@ -39,7 +39,8 @@ ColumnLayout {
ComboBox { ComboBox {
id: combo id: combo
Layout.fillWidth: true
Layout.preferredWidth: 320 * scaling
Layout.preferredHeight: height Layout.preferredHeight: height
model: model model: model
currentIndex: findIndexByKey(currentKey) currentIndex: findIndexByKey(currentKey)
@ -128,5 +129,13 @@ ColumnLayout {
radius: Style.radiusM * scaling radius: Style.radiusM * scaling
} }
} }
// Update the currentIndex if the currentKey is changed externalyu
Connections {
target: root
function onCurrentKeyChanged() {
combo.currentIndex = root.findIndexByKey(currentKey)
}
}
} }
} }

View file

@ -4,7 +4,7 @@ import QtQuick.Layouts
import qs.Commons import qs.Commons
import qs.Widgets import qs.Widgets
NCard { NBox {
id: root id: root
property string sectionName: "" property string sectionName: ""
@ -16,6 +16,7 @@ NCard {
signal removeWidget(string section, int index) signal removeWidget(string section, int index)
signal reorderWidget(string section, int fromIndex, int toIndex) signal reorderWidget(string section, int fromIndex, int toIndex)
color: Color.mSurface
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: { Layout.minimumHeight: {
var widgetCount = widgetModel.length var widgetCount = widgetModel.length
@ -30,6 +31,25 @@ NCard {
return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling
} }
// Generate widget color from name checksum
function getWidgetColor(name) {
const totalSum = name.split('').reduce((acc, character) => {
return acc + character.charCodeAt(0)
}, 0)
switch (totalSum % 5) {
case 0:
return Color.mPrimary
case 1:
return Color.mSecondary
case 2:
return Color.mTertiary
case 3:
return Color.mError
case 4:
return Color.mOnSurface
}
}
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
anchors.margins: Style.marginM * scaling anchors.margins: Style.marginM * scaling
@ -42,21 +62,19 @@ NCard {
text: sectionName + " Section" text: sectionName + " Section"
font.pointSize: Style.fontSizeL * scaling font.pointSize: Style.fontSizeL * scaling
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
color: Color.mOnSurface color: Color.mSecondary
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
Item { Item {
Layout.fillWidth: true Layout.fillWidth: true
} }
NComboBox { NComboBox {
id: comboBox id: comboBox
width: 120 * scaling
model: availableWidgets model: availableWidgets
label: "" label: ""
description: "" description: ""
placeholder: "Add widget to " + sectionName.toLowerCase() + " section" placeholder: "Add widget to the " + sectionName.toLowerCase() + " section..."
onSelected: key => { onSelected: key => {
comboBox.currentKey = key comboBox.currentKey = key
} }
@ -75,7 +93,7 @@ NCard {
onClicked: { onClicked: {
if (comboBox.currentKey !== "") { if (comboBox.currentKey !== "") {
addWidget(comboBox.currentKey, sectionName.toLowerCase()) addWidget(comboBox.currentKey, sectionName.toLowerCase())
comboBox.currentKey = "" comboBox.currentKey = "battery"
} }
} }
} }
@ -92,9 +110,9 @@ NCard {
model: widgetModel model: widgetModel
delegate: Rectangle { delegate: Rectangle {
width: widgetContent.implicitWidth + 16 * scaling width: widgetContent.implicitWidth + 16 * scaling
height: 48 * scaling height: 40 * scaling
radius: Style.radiusS * scaling radius: Style.radiusL * scaling
color: Color.mPrimary color: root.getWidgetColor(modelData)
border.color: Color.mOutline border.color: Color.mOutline
border.width: Math.max(1, Style.borderS * scaling) border.width: Math.max(1, Style.borderS * scaling)
@ -106,7 +124,8 @@ NCard {
NIconButton { NIconButton {
icon: "chevron_left" icon: "chevron_left"
size: 20 * scaling size: 20 * scaling
colorBg: Color.applyOpacity(Color.mOnPrimary, "20") colorBorder: Color.applyOpacity(Color.mOutline, "40")
colorBg: Color.mOnSurface
colorFg: Color.mOnPrimary colorFg: Color.mOnPrimary
colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40") colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40")
colorFgHover: Color.mOnPrimary colorFgHover: Color.mOnPrimary
@ -128,7 +147,8 @@ NCard {
NIconButton { NIconButton {
icon: "chevron_right" icon: "chevron_right"
size: 20 * scaling size: 20 * scaling
colorBg: Color.applyOpacity(Color.mOnPrimary, "20") colorBorder: Color.applyOpacity(Color.mOutline, "40")
colorBg: Color.mOnSurface
colorFg: Color.mOnPrimary colorFg: Color.mOnPrimary
colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40") colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40")
colorFgHover: Color.mOnPrimary colorFgHover: Color.mOnPrimary
@ -143,7 +163,8 @@ NCard {
NIconButton { NIconButton {
icon: "close" icon: "close"
size: 20 * scaling size: 20 * scaling
colorBg: Color.applyOpacity(Color.mOnPrimary, "20") colorBorder: Color.applyOpacity(Color.mOutline, "40")
colorBg: Color.mOnSurface
colorFg: Color.mOnPrimary colorFg: Color.mOnPrimary
colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40") colorBgHover: Color.applyOpacity(Color.mOnPrimary, "40")
colorFgHover: Color.mOnPrimary colorFgHover: Color.mOnPrimary