Added a Spacer widget so people can add spacing between other widgets
(as requested in ##226). Spacer: create variable width invisible rectangle BarWidgetSettingsDialog: add Spacer support BarWidgetRegistry: add Spacer
This commit is contained in:
parent
e76b2c5497
commit
977b2d9e7c
3 changed files with 91 additions and 0 deletions
56
Modules/Bar/Widgets/Spacer.qml
Normal file
56
Modules/Bar/Widgets/Spacer.qml
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
// Widget properties passed from Bar.qml
|
||||
property var screen
|
||||
property real scaling: 1.0
|
||||
|
||||
property string barSection: ""
|
||||
property int sectionWidgetIndex: -1
|
||||
property int sectionWidgetsCount: 0
|
||||
|
||||
// Get user settings from Settings data - make it reactive
|
||||
property var widgetSettings: {
|
||||
var section = barSection.replace("Section", "").toLowerCase()
|
||||
if (section && sectionWidgetIndex >= 0) {
|
||||
var widgets = Settings.data.bar.widgets[section]
|
||||
if (widgets && sectionWidgetIndex < widgets.length) {
|
||||
return widgets[sectionWidgetIndex]
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
// Use settings or defaults from BarWidgetRegistry
|
||||
readonly property int userWidth: {
|
||||
var section = barSection.replace("Section", "").toLowerCase()
|
||||
if (section && sectionWidgetIndex >= 0) {
|
||||
var widgets = Settings.data.bar.widgets[section]
|
||||
if (widgets && sectionWidgetIndex < widgets.length) {
|
||||
return widgets[sectionWidgetIndex].width || BarWidgetRegistry.widgetMetadata["Spacer"].width
|
||||
}
|
||||
}
|
||||
return BarWidgetRegistry.widgetMetadata["Spacer"].width
|
||||
}
|
||||
|
||||
// Set the width based on user settings
|
||||
implicitWidth: userWidth * scaling
|
||||
implicitHeight: Style.barHeight * scaling
|
||||
width: implicitWidth
|
||||
height: implicitHeight
|
||||
|
||||
// Optional: Add a subtle visual indicator in debug mode
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Qt.rgba(1, 0, 0, 0.1) // Very subtle red tint
|
||||
visible: Settings.data.general.debugMode || false
|
||||
radius: 2 * scaling
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,8 @@ Popup {
|
|||
sourceComponent: {
|
||||
if (settingsPopup.widgetId === "CustomButton") {
|
||||
return customButtonSettings
|
||||
} else if (settingsPopup.widgetId === "Spacer") {
|
||||
return spacerSettings
|
||||
}
|
||||
// Add more widget settings components here as needed
|
||||
return null
|
||||
|
|
@ -157,4 +159,28 @@ Popup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Spacer settings component
|
||||
Component {
|
||||
id: spacerSettings
|
||||
|
||||
ColumnLayout {
|
||||
spacing: Style.marginM * scaling
|
||||
|
||||
function saveSettings() {
|
||||
var settings = Object.assign({}, settingsPopup.widgetData)
|
||||
settings.width = parseInt(widthInput.text) || 20
|
||||
return settings
|
||||
}
|
||||
|
||||
NTextInput {
|
||||
id: widthInput
|
||||
Layout.fillWidth: true
|
||||
label: "Width (pixels)"
|
||||
description: "Width of the spacer in pixels."
|
||||
text: settingsPopup.widgetData.width || "20"
|
||||
placeholderText: "Enter width in pixels"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ Singleton {
|
|||
"PowerToggle": powerToggleComponent,
|
||||
"ScreenRecorderIndicator": screenRecorderIndicatorComponent,
|
||||
"SidePanelToggle": sidePanelToggleComponent,
|
||||
"Spacer": spacerComponent,
|
||||
"SystemMonitor": systemMonitorComponent,
|
||||
"Taskbar": taskbarComponent,
|
||||
"Tray": trayComponent,
|
||||
|
|
@ -43,6 +44,11 @@ Singleton {
|
|||
"leftClickExec": "",
|
||||
"rightClickExec": "",
|
||||
"middleClickExec": ""
|
||||
},
|
||||
"Spacer": {
|
||||
"allowUserSettings": true,
|
||||
"icon": "space_bar",
|
||||
"width": 20
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -101,6 +107,9 @@ Singleton {
|
|||
property Component sidePanelToggleComponent: Component {
|
||||
SidePanelToggle {}
|
||||
}
|
||||
property Component spacerComponent: Component {
|
||||
Spacer {}
|
||||
}
|
||||
property Component systemMonitorComponent: Component {
|
||||
SystemMonitor {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue