From 23079277bd99e68faa7e5da14d188d61c752402c Mon Sep 17 00:00:00 2001 From: Reed Johns <115313701+vertumnal@users.noreply.github.com> Date: Mon, 24 Feb 2025 15:45:15 -0700 Subject: [PATCH] Write new settings for toggling background image, picking file, and adjusting tint. Also handles the opacity setting appropriately, taking control and disabling the slider when background image is used and returning control with the last stored value when the background image is toggled back off. Tint slider is disabled when background image is disabled. --- app/qml/SettingsGeneralTab.qml | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/app/qml/SettingsGeneralTab.qml b/app/qml/SettingsGeneralTab.qml index 40fbc0d..9037334 100644 --- a/app/qml/SettingsGeneralTab.qml +++ b/app/qml/SettingsGeneralTab.qml @@ -180,6 +180,66 @@ ColumnLayout { } } + GroupBox { + title: qsTr("Background Image") + signal opacity + ColumnLayout { + anchors.fill: parent + CheckBox { + id: useBackgroundImage + text: qsTr("Use background image instead of background color") + checked: appSettings.useBackgroundImage + + property real lastOpacity: 0.0 + property real thisOpacity: appSettings.windowOpacity + property real buffer: NaN + onCheckedChanged: appSettings.useBackgroundImage = checked, + buttonUseBackground.enabled = appSettings.useBackgroundImage, + sliderBackgroundTint.enabled = appSettings.useBackgroundImage, + sliderOpacity.enabled = !appSettings.useBackgroundImage, + + thisOpacity = appSettings.windowOpacity, + buffer = thisOpacity, + + thisOpacity = lastOpacity, + lastOpacity = buffer, + appSettings.windowOpacity = thisOpacity + + } + // Workaround for QTBUG-31627 for pre 5.3.0 + Binding { + target: useBackgroundImage + property: "checked" + value: appSettings.useBackgroundImage + } + Button { + Layout.fillWidth: true + id: buttonUseBackground + text: qsTr("Open") + enabled: useBackgroundImage + onClicked: { + fileDialogImage.callBack = function (url) { + loadFile(url) + } + fileDialogImage.open() + } + function loadFile(url) { + try { + if (appSettings.verbose) + console.log("Opening file: " + url) + + image.source = url + } catch (err) { + console.log(err) + messageDialog.text = qsTr( + "There has been an error opening the file.") + messageDialog.open() + } + } + } + } + } + GroupBox { title: qsTr("Screen") Layout.fillWidth: true @@ -219,10 +279,25 @@ ColumnLayout { visible: !appSettings.isMacOS } SimpleSlider { + id: sliderOpacity + enabled: !useBackgroundImage onValueChanged: appSettings.windowOpacity = value value: appSettings.windowOpacity visible: !appSettings.isMacOS } + Label { + text: qsTr("Background Tint") + } + SimpleSlider { + id: sliderBackgroundTint + enabled: useBackgroundImage + onValueChanged: appSettings.backgroundTint = value + value: appSettings.backgroundTint + } + function reload() { + active = false + active = true + } } } @@ -265,4 +340,21 @@ ColumnLayout { active = true } } + Loader { + property var callBack + id: fileDialogImage + + sourceComponent: FileDialog { + nameFilters: ["Image files (*.png *.jpeg *.jpg)"] + selectMultiple: false + selectFolder: false + selectExisting: true + folder: shortcuts.pictures + onAccepted: callBack(fileUrl) + } + + function open() { + item.open() + } + } }