Formatting

This commit is contained in:
Ly-sec 2025-08-22 19:57:29 +02:00
parent 566e3e2aa7
commit ce9ab7f90f
8 changed files with 73 additions and 86 deletions

View file

@ -47,7 +47,8 @@ Singleton {
// ----------- // -----------
function applyOpacity(color, opacity) { function applyOpacity(color, opacity) {
// Convert color to string and apply opacity // Convert color to string and apply opacity
if (!color) return "transparent" if (!color)
return "transparent"
return color.toString().replace("#", "#" + opacity) return color.toString().replace("#", "#" + opacity)
} }

View file

@ -133,7 +133,7 @@ Singleton {
// Widget configuration for modular bar system // Widget configuration for modular bar system
property JsonObject widgets property JsonObject widgets
widgets: JsonObject { widgets: JsonObject {
property list<string> left: ["SystemMonitor", "ActiveWindow", "MediaMini"] property list<string> left: ["SystemMonitor", "ActiveWindow", "MediaMini"]
property list<string> center: ["Workspace"] property list<string> center: ["Workspace"]

View file

@ -19,16 +19,17 @@ QtObject {
if (!widgetName || widgetName.trim() === "") { if (!widgetName || widgetName.trim() === "") {
return null return null
} }
const widgetPath = `../Modules/Bar/Widgets/${widgetName}.qml` const widgetPath = `../Modules/Bar/Widgets/${widgetName}.qml`
// Try to load the widget directly from file // Try to load the widget directly from file
const component = Qt.createComponent(widgetPath) const component = Qt.createComponent(widgetPath)
if (component.status === Component.Ready) { if (component.status === Component.Ready) {
return component return component
} }
const errorMsg = `Failed to load ${widgetName}.qml widget, status: ${component.status}, error: ${component.errorString()}` const errorMsg = `Failed to load ${widgetName}.qml widget, status: ${component.status}, error: ${component.errorString(
)}`
Logger.error("WidgetLoader", errorMsg) Logger.error("WidgetLoader", errorMsg)
return null return null
} }
@ -44,7 +45,7 @@ QtObject {
function onWidgetLoaded(widgetName) { function onWidgetLoaded(widgetName) {
loadedWidgets++ loadedWidgets++
widgetLoaded(widgetName) widgetLoaded(widgetName)
if (loadedWidgets + failedWidgets === totalWidgets) { if (loadedWidgets + failedWidgets === totalWidgets) {
Logger.log("WidgetLoader", `Loaded ${loadedWidgets} widgets`) Logger.log("WidgetLoader", `Loaded ${loadedWidgets} widgets`)
loadingComplete(totalWidgets, loadedWidgets, failedWidgets) loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
@ -55,7 +56,7 @@ QtObject {
function onWidgetFailed(widgetName, error) { function onWidgetFailed(widgetName, error) {
failedWidgets++ failedWidgets++
widgetFailed(widgetName, error) widgetFailed(widgetName, error)
if (loadedWidgets + failedWidgets === totalWidgets) { if (loadedWidgets + failedWidgets === totalWidgets) {
loadingComplete(totalWidgets, loadedWidgets, failedWidgets) loadingComplete(totalWidgets, loadedWidgets, failedWidgets)
} }
@ -64,28 +65,24 @@ QtObject {
// This is where you should add your Modules/Bar/Widgets/ // This is where you should add your Modules/Bar/Widgets/
// so it gets registered in the BarTab // so it gets registered in the BarTab
function discoverAvailableWidgets() { function discoverAvailableWidgets() {
const widgetFiles = [ const widgetFiles = ["ActiveWindow", "Battery", "Bluetooth", "Brightness", "Clock", "MediaMini", "NotificationHistory", "ScreenRecorderIndicator", "SidePanelToggle", "SystemMonitor", "Tray", "Volume", "WiFi", "Workspace"]
"ActiveWindow", "Battery", "Bluetooth", "Brightness", "Clock",
"MediaMini", "NotificationHistory", "ScreenRecorderIndicator",
"SidePanelToggle", "SystemMonitor", "Tray", "Volume", "WiFi", "Workspace"
]
const availableWidgets = [] const availableWidgets = []
widgetFiles.forEach(widgetName => { widgetFiles.forEach(widgetName => {
// Test if the widget can be loaded // Test if the widget can be loaded
const component = getWidgetComponent(widgetName) const component = getWidgetComponent(widgetName)
if (component) { if (component) {
availableWidgets.push({ availableWidgets.push({
key: widgetName, "key": widgetName,
name: widgetName "name": widgetName
}) })
} }
}) })
// Sort alphabetically // Sort alphabetically
availableWidgets.sort((a, b) => a.name.localeCompare(b.name)) availableWidgets.sort((a, b) => a.name.localeCompare(b.name))
return availableWidgets return availableWidgets
} }
} }

View file

@ -23,8 +23,6 @@ Variants {
implicitHeight: Style.barHeight * scaling implicitHeight: Style.barHeight * scaling
color: Color.transparent color: Color.transparent
// If no bar activated in settings, then show them all // If no bar activated in settings, then show them all
visible: modelData ? (Settings.data.bar.monitors.includes(modelData.name) visible: modelData ? (Settings.data.bar.monitors.includes(modelData.name)
|| (Settings.data.bar.monitors.length === 0)) : false || (Settings.data.bar.monitors.length === 0)) : false
@ -136,24 +134,16 @@ Variants {
// Widget loader instance // Widget loader instance
WidgetLoader { WidgetLoader {
id: widgetLoader id: widgetLoader
onWidgetFailed: function(widgetName, error) { onWidgetFailed: function (widgetName, error) {
Logger.error("Bar", `Widget failed: ${widgetName} - ${error}`) Logger.error("Bar", `Widget failed: ${widgetName} - ${error}`)
} }
} }
// Initialize widget loading tracking // Initialize widget loading tracking
Component.onCompleted: { Component.onCompleted: {
const allWidgets = [ const allWidgets = [...Settings.data.bar.widgets.left, ...Settings.data.bar.widgets.center, ...Settings.data.bar.widgets.right]
...Settings.data.bar.widgets.left,
...Settings.data.bar.widgets.center,
...Settings.data.bar.widgets.right
]
widgetLoader.initializeLoading(allWidgets) widgetLoader.initializeLoading(allWidgets)
} }
} }
} }

View file

@ -7,7 +7,6 @@ import qs.Commons
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
NIconButton { NIconButton {
id: root id: root

View file

@ -9,13 +9,10 @@ import qs.Commons
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
Rectangle { Rectangle {
readonly property real itemSize: 24 * scaling readonly property real itemSize: 24 * scaling
visible: Settings.data.bar.showTray && (SystemTray.items.values.length > 0) visible: Settings.data.bar.showTray && (SystemTray.items.values.length > 0)
width: tray.width + Style.marginM * scaling * 2 width: tray.width + Style.marginM * scaling * 2

View file

@ -166,13 +166,14 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: { Layout.minimumHeight: {
var widgetCount = Settings.data.bar.widgets.left.length var widgetCount = Settings.data.bar.widgets.left.length
if (widgetCount === 0) return 140 * scaling if (widgetCount === 0)
return 140 * scaling
var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins
var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing
var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth)) var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth))
var rows = Math.ceil(widgetCount / widgetsPerRow) var rows = Math.ceil(widgetCount / widgetsPerRow)
// Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20) // Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20)
return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling
} }
@ -192,7 +193,9 @@ ColumnLayout {
color: Color.mOnSurface color: Color.mOnSurface
} }
Item { Layout.fillWidth: true } Item {
Layout.fillWidth: true
}
NComboBox { NComboBox {
id: leftComboBox id: leftComboBox
@ -202,8 +205,8 @@ ColumnLayout {
description: "" description: ""
placeholder: "Add widget to left section" placeholder: "Add widget to left section"
onSelected: key => { onSelected: key => {
addWidgetToSection(key, "left") addWidgetToSection(key, "left")
} }
} }
} }
@ -290,13 +293,14 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: { Layout.minimumHeight: {
var widgetCount = Settings.data.bar.widgets.center.length var widgetCount = Settings.data.bar.widgets.center.length
if (widgetCount === 0) return 140 * scaling if (widgetCount === 0)
return 140 * scaling
var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins
var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing
var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth)) var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth))
var rows = Math.ceil(widgetCount / widgetsPerRow) var rows = Math.ceil(widgetCount / widgetsPerRow)
// Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20) // Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20)
return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling
} }
@ -316,7 +320,9 @@ ColumnLayout {
color: Color.mOnSurface color: Color.mOnSurface
} }
Item { Layout.fillWidth: true } Item {
Layout.fillWidth: true
}
NComboBox { NComboBox {
id: centerComboBox id: centerComboBox
@ -326,9 +332,9 @@ ColumnLayout {
description: "" description: ""
placeholder: "Add widget to center section" placeholder: "Add widget to center section"
onSelected: key => { onSelected: key => {
addWidgetToSection(key, "center") addWidgetToSection(key, "center")
reset() // Reset selection reset() // Reset selection
} }
} }
} }
@ -415,13 +421,14 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: { Layout.minimumHeight: {
var widgetCount = Settings.data.bar.widgets.right.length var widgetCount = Settings.data.bar.widgets.right.length
if (widgetCount === 0) return 140 * scaling if (widgetCount === 0)
return 140 * scaling
var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins var availableWidth = scrollView.availableWidth - (Style.marginM * scaling * 2) // Card margins
var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing var avgWidgetWidth = 150 * scaling // Estimated widget width including spacing
var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth)) var widgetsPerRow = Math.max(1, Math.floor(availableWidth / avgWidgetWidth))
var rows = Math.ceil(widgetCount / widgetsPerRow) var rows = Math.ceil(widgetCount / widgetsPerRow)
// Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20) // Header (50) + spacing (20) + (rows * widget height) + (rows-1 * spacing) + bottom margin (20)
return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling return (50 + 20 + (rows * 48) + ((rows - 1) * Style.marginS) + 20) * scaling
} }
@ -441,7 +448,9 @@ ColumnLayout {
color: Color.mOnSurface color: Color.mOnSurface
} }
Item { Layout.fillWidth: true } Item {
Layout.fillWidth: true
}
NComboBox { NComboBox {
id: rightComboBox id: rightComboBox
@ -451,9 +460,9 @@ ColumnLayout {
description: "" description: ""
placeholder: "Add widget to right section" placeholder: "Add widget to right section"
onSelected: key => { onSelected: key => {
addWidgetToSection(key, "right") addWidgetToSection(key, "right")
reset() // Reset selection reset() // Reset selection
} }
} }
} }
@ -540,8 +549,6 @@ ColumnLayout {
} }
} }
// Helper functions // Helper functions
function addWidgetToSection(widgetName, section) { function addWidgetToSection(widgetName, section) {
console.log("Adding widget", widgetName, "to section", section) console.log("Adding widget", widgetName, "to section", section)
@ -551,7 +558,7 @@ ColumnLayout {
var newArray = sectionArray.slice() var newArray = sectionArray.slice()
newArray.push(widgetName) newArray.push(widgetName)
console.log("Widget added. New array:", JSON.stringify(newArray)) console.log("Widget added. New array:", JSON.stringify(newArray))
// Assign the new array // Assign the new array
Settings.data.bar.widgets[section] = newArray Settings.data.bar.widgets[section] = newArray
} }
@ -565,7 +572,7 @@ ColumnLayout {
var newArray = sectionArray.slice() var newArray = sectionArray.slice()
newArray.splice(index, 1) newArray.splice(index, 1)
console.log("Widget removed. New array:", JSON.stringify(newArray)) console.log("Widget removed. New array:", JSON.stringify(newArray))
// Assign the new array // Assign the new array
Settings.data.bar.widgets[section] = newArray Settings.data.bar.widgets[section] = newArray
} }
@ -574,16 +581,16 @@ ColumnLayout {
function reorderWidgetInSection(section, fromIndex, toIndex) { function reorderWidgetInSection(section, fromIndex, toIndex) {
console.log("Reordering widget in section", section, "from", fromIndex, "to", toIndex) console.log("Reordering widget in section", section, "from", fromIndex, "to", toIndex)
var sectionArray = Settings.data.bar.widgets[section] var sectionArray = Settings.data.bar.widgets[section]
if (sectionArray && fromIndex >= 0 && fromIndex < sectionArray.length && if (sectionArray && fromIndex >= 0 && fromIndex < sectionArray.length && toIndex >= 0
toIndex >= 0 && toIndex < sectionArray.length) { && toIndex < sectionArray.length) {
// Create a new array to avoid modifying the original // Create a new array to avoid modifying the original
var newArray = sectionArray.slice() var newArray = sectionArray.slice()
var item = newArray[fromIndex] var item = newArray[fromIndex]
newArray.splice(fromIndex, 1) newArray.splice(fromIndex, 1)
newArray.splice(toIndex, 0, item) newArray.splice(toIndex, 0, item)
console.log("Widget reordered. New array:", JSON.stringify(newArray)) console.log("Widget reordered. New array:", JSON.stringify(newArray))
// Assign the new array // Assign the new array
Settings.data.bar.widgets[section] = newArray Settings.data.bar.widgets[section] = newArray
} }
@ -593,28 +600,25 @@ ColumnLayout {
WidgetLoader { WidgetLoader {
id: widgetLoader id: widgetLoader
} }
ListModel { ListModel {
id: availableWidgets id: availableWidgets
} }
Component.onCompleted: { Component.onCompleted: {
discoverWidgets() discoverWidgets()
} }
// Automatically discover available widgets using WidgetLoader // Automatically discover available widgets using WidgetLoader
function discoverWidgets() { function discoverWidgets() {
availableWidgets.clear() availableWidgets.clear()
// Use WidgetLoader to discover available widgets // Use WidgetLoader to discover available widgets
const discoveredWidgets = widgetLoader.discoverAvailableWidgets() const discoveredWidgets = widgetLoader.discoverAvailableWidgets()
// Add discovered widgets to the ListModel // Add discovered widgets to the ListModel
discoveredWidgets.forEach(widget => { discoveredWidgets.forEach(widget => {
availableWidgets.append(widget) availableWidgets.append(widget)
}) })
} }
} }

View file

@ -37,8 +37,6 @@ ColumnLayout {
return -1 return -1
} }
ComboBox { ComboBox {
id: combo id: combo
Layout.fillWidth: true Layout.fillWidth: true
@ -64,9 +62,10 @@ ColumnLayout {
font.pointSize: Style.fontSizeM * scaling font.pointSize: Style.fontSizeM * scaling
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight elide: Text.ElideRight
color: (combo.currentIndex >= 0 && combo.currentIndex < root.model.count) ? Color.mOnSurface : Color.mOnSurfaceVariant color: (combo.currentIndex >= 0
text: (combo.currentIndex >= 0 && combo.currentIndex < root.model.count) ? root.model.get( && combo.currentIndex < root.model.count) ? Color.mOnSurface : Color.mOnSurfaceVariant
combo.currentIndex).name : root.placeholder text: (combo.currentIndex >= 0
&& combo.currentIndex < root.model.count) ? root.model.get(combo.currentIndex).name : root.placeholder
} }
indicator: NIcon { indicator: NIcon {