NightLight: refactored the code to make simpler
- using intensity instead of warmth - animated color transition - removed unecessary bindings and double properties - using better icons to avoid confusion with brightness - polished settings UI
This commit is contained in:
parent
76f0368a64
commit
4cd94f0426
6 changed files with 113 additions and 216 deletions
|
|
@ -15,33 +15,24 @@ Item {
|
|||
implicitHeight: pill.height
|
||||
visible: true
|
||||
|
||||
function getIcon() {
|
||||
if (!NightLightService.enabled) {
|
||||
return "light_mode"
|
||||
}
|
||||
return NightLightService.isActive ? "dark_mode" : "light_mode"
|
||||
}
|
||||
|
||||
function getTooltipText() {
|
||||
if (!NightLightService.enabled) {
|
||||
return "Night Light: Disabled\nLeft click to open settings.\nRight click to enable."
|
||||
}
|
||||
|
||||
var status = NightLightService.isActive ? "Active" : "Inactive (outside schedule)"
|
||||
var warmth = Math.round(NightLightService.warmth * 10)
|
||||
var schedule = NightLightService.autoSchedule ? `Schedule: ${NightLightService.startTime} - ${NightLightService.stopTime}` : "Manual mode"
|
||||
|
||||
return `Night Light: ${status}\nWarmth: ${warmth}/10\n${schedule}\nLeft click to open settings.\nRight click to toggle.`
|
||||
}
|
||||
|
||||
NPill {
|
||||
id: pill
|
||||
icon: getIcon()
|
||||
icon: NightLightService.isActive ? "bedtime" : "bedtime_off"
|
||||
iconCircleColor: NightLightService.isActive ? Color.mSecondary : Color.mOnSurfaceVariant
|
||||
collapsedIconColor: NightLightService.isActive ? Color.mOnSecondary : Color.mOnSurface
|
||||
autoHide: false
|
||||
text: NightLightService.enabled ? (NightLightService.isActive ? "ON" : "OFF") : "OFF"
|
||||
tooltipText: getTooltipText()
|
||||
text: NightLightService.isActive ? "On" : "Off"
|
||||
tooltipText: {
|
||||
if (!Settings.isLoaded || !Settings.data.nightLight.enabled) {
|
||||
return "Night Light: Disabled\nLeft click to open settings.\nRight click to enable."
|
||||
}
|
||||
|
||||
var status = NightLightService.isActive ? "Active" : "Inactive (outside schedule)"
|
||||
var intensity = Math.round(Settings.data.nightLight.intensity * 100)
|
||||
var schedule = Settings.data.nightLight.autoSchedule ? `Schedule: ${Settings.data.nightLight.startTime} - ${Settings.data.nightLight.stopTime}` : "Manual mode"
|
||||
|
||||
return `Intensity: ${intensity}%\n${schedule}\nLeft click to open settings.\nRight click to toggle.`
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
// Left click - open settings
|
||||
|
|
@ -52,34 +43,13 @@ Item {
|
|||
|
||||
onRightClicked: {
|
||||
// Right click - toggle night light
|
||||
NightLightService.toggle()
|
||||
Settings.data.nightLight.enabled = !Settings.data.nightLight.enabled
|
||||
}
|
||||
}
|
||||
|
||||
// Update when service state changes
|
||||
Connections {
|
||||
target: NightLightService
|
||||
function onEnabledChanged() {
|
||||
pill.icon = getIcon()
|
||||
pill.text = NightLightService.enabled ? (NightLightService.isActive ? "ON" : "OFF") : "OFF"
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
function onIsActiveChanged() {
|
||||
pill.icon = getIcon()
|
||||
pill.text = NightLightService.enabled ? (NightLightService.isActive ? "ON" : "OFF") : "OFF"
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
function onWarmthChanged() {
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
function onStartTimeChanged() {
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
function onStopTimeChanged() {
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
function onAutoScheduleChanged() {
|
||||
pill.tooltipText = getTooltipText()
|
||||
}
|
||||
onWheel: delta => {
|
||||
var diff = delta > 0 ? 0.05 : -0.05
|
||||
Settings.data.nightLight.intensity = Math.max(0, Math.min(1.0,
|
||||
Settings.data.nightLight.intensity + diff))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue