ControlCenterTab: if weather is disabled, disable weather card

This commit is contained in:
Ly-sec
2025-11-04 08:24:00 +01:00
parent dac6c0c539
commit a48e789e2e
4 changed files with 65 additions and 15 deletions
+1 -1
View File
@@ -58,8 +58,8 @@ NPanel {
// Use implicitHeight from content + margins to avoid binding loops
property real contentPreferredHeight: mainColumn.implicitHeight + Style.marginL * 2
// property real contentPreferredHeight: Math.min(screen.height * 0.42, mainColumn.implicitHeight) + Style.marginL * 2
// property real contentPreferredHeight: Math.min(screen.height * 0.42, mainColumn.implicitHeight) + Style.marginL * 2
ColumnLayout {
id: mainColumn
anchors.fill: parent
+36 -1
View File
@@ -86,6 +86,10 @@ ColumnLayout {
if (settingCard.id === cardsDefault[j].id) {
var card = cardsDefault[j]
card.enabled = settingCard.enabled
// Auto-disable weather card if weather is disabled
if (card.id === "weather-card" && !Settings.data.location.weatherEnabled) {
card.enabled = false
}
cardsModel.push(card)
}
}
@@ -102,7 +106,12 @@ ColumnLayout {
}
if (!found) {
cardsModel.push(cardsDefault[i])
var card = cardsDefault[i]
// Auto-disable weather card if weather is disabled
if (card.id === "weather-card" && !Settings.data.location.weatherEnabled) {
card.enabled = false
}
cardsModel.push(card)
}
}
@@ -171,6 +180,24 @@ ColumnLayout {
description: I18n.tr("settings.control-center.cards.section.description")
}
Connections {
target: Settings.data.location
function onWeatherEnabledChanged() {
// Auto-disable weather card when weather is disabled
var newModel = cardsModel.slice()
for (var i = 0; i < newModel.length; i++) {
if (newModel[i].id === "weather-card") {
newModel[i] = Object.assign({}, newModel[i], {
"enabled": Settings.data.location.weatherEnabled
})
cardsModel = newModel
saveCards()
break
}
}
}
}
NReorderCheckboxes {
Layout.fillWidth: true
model: cardsModel
@@ -181,6 +208,10 @@ ColumnLayout {
root.handleDragEnd()
}
onItemToggled: function (index, enabled) {
// Prevent toggling weather card when weather is disabled
if (cardsModel[index].id === "weather-card" && !Settings.data.location.weatherEnabled) {
return
}
//Logger.i("ControlCenterTab", "Item", index, "toggled to", enabled)
var newModel = cardsModel.slice()
newModel[index] = Object.assign({}, newModel[index], {
@@ -190,6 +221,10 @@ ColumnLayout {
saveCards()
}
onItemsReordered: function (fromIndex, toIndex) {
// Prevent reordering weather card when weather is disabled
if (cardsModel[fromIndex].id === "weather-card" && !Settings.data.location.weatherEnabled) {
return
}
//Logger.i("ControlCenterTab", "Item moved from", fromIndex, "to", toIndex)
var newModel = cardsModel.slice()
var item = newModel.splice(fromIndex, 1)[0]
+8 -8
View File
@@ -242,14 +242,14 @@ Item {
// If touching screen edges, fall through to the distance-based calculation below
// var touchingAnyScreenEdge = touchingLeftEdge || touchingRightEdge || touchingTopEdge || touchingBottomEdge
// if (!touchingAnyScreenEdge) {
if (touchingTopBar && root.barPosition === "top")
return "top"
if (touchingBottomBar && root.barPosition === "bottom")
return "bottom"
if (touchingLeftBar && root.barPosition === "left")
return "left"
if (touchingRightBar && root.barPosition === "right")
return "right"
if (touchingTopBar && root.barPosition === "top")
return "top"
if (touchingBottomBar && root.barPosition === "bottom")
return "bottom"
if (touchingLeftBar && root.barPosition === "left")
return "left"
if (touchingRightBar && root.barPosition === "right")
return "right"
//}
// Use panel's center point (barycenter) as reference
+20 -5
View File
@@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import qs.Commons
import qs.Services
Item {
id: root
@@ -75,8 +76,15 @@ Item {
required property var modelData
property string text: modelData.text || ""
property bool enabled: modelData.enabled || false
property bool enabled: {
// Override enabled for weather card based on weatherEnabled setting
if (modelData.id === "weather-card") {
return (modelData.enabled || false) && Settings.data.location.weatherEnabled
}
return modelData.enabled || false
}
property bool required: modelData.required || false
readonly property bool isWeatherCardDisabled: modelData.id === "weather-card" && !Settings.data.location.weatherEnabled
property bool dragging: false
property int dragStartY: 0
property int dragStartIndex: -1
@@ -88,6 +96,7 @@ Item {
width: parent.width
spacing: Style.marginS
opacity: (modelData.id === "weather-card" && !Settings.data.location.weatherEnabled) ? 0.5 : 1.0
// Drag handle
Rectangle {
@@ -123,12 +132,16 @@ Item {
id: dragHandleMouseArea
anchors.fill: parent
cursorShape: Qt.SizeVerCursor
cursorShape: (delegateItem.required || delegateItem.isWeatherCardDisabled) ? Qt.ForbiddenCursor : Qt.SizeVerCursor
hoverEnabled: true
preventStealing: false
enabled: !delegateItem.required && !delegateItem.isWeatherCardDisabled
z: 1000
onPressed: mouse => {
if (delegateItem.required || delegateItem.isWeatherCardDisabled) {
return
}
delegateItem.dragStartIndex = delegateItem.index
delegateItem.dragTargetIndex = delegateItem.index
delegateItem.dragStartY = delegateItem.y
@@ -221,11 +234,13 @@ Item {
MouseArea {
anchors.fill: parent
cursorShape: delegateItem.required ? Qt.ForbiddenCursor : Qt.PointingHandCursor
enabled: !delegateItem.required
cursorShape: (delegateItem.required || delegateItem.isWeatherCardDisabled) ? Qt.ForbiddenCursor : Qt.PointingHandCursor
enabled: !delegateItem.required && !delegateItem.isWeatherCardDisabled
onClicked: {
root.toggleItem(delegateItem.index)
if (!delegateItem.required && !delegateItem.isWeatherCardDisabled) {
root.toggleItem(delegateItem.index)
}
}
}
}