diff --git a/kcms/nightcolor/package/contents/ui/LocationsAutoView.qml b/kcms/nightcolor/package/contents/ui/LocationsAutoView.qml deleted file mode 100644 index 5f9c6cb83..000000000 --- a/kcms/nightcolor/package/contents/ui/LocationsAutoView.qml +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************** -Copyright 2017 Roman Gilg - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*********************************************************************/ -import QtQuick 2.1 -import org.kde.kirigami 2.5 as Kirigami - -Kirigami.FormLayout { - twinFormLayouts: parentLayout - enabled: activator.checked - - property double latitude - property double longitude - - onLatitudeChanged: latitudeField.backend = latitude; - onLongitudeChanged: longitudeField.backend = longitude; - - NumberField { - id: latitudeField - Kirigami.FormData.label: i18n("Latitude:") - backend: locator.latitude - enabled: false - } - - NumberField { - id: longitudeField - Kirigami.FormData.label: i18n("Longitude:") - backend: locator.longitude - enabled: false - } -} diff --git a/kcms/nightcolor/package/contents/ui/LocationsFixedView.qml b/kcms/nightcolor/package/contents/ui/LocationsFixedView.qml index c1ec05e22..b55845124 100644 --- a/kcms/nightcolor/package/contents/ui/LocationsFixedView.qml +++ b/kcms/nightcolor/package/contents/ui/LocationsFixedView.qml @@ -1,68 +1,71 @@ /******************************************************************** Copyright 2017 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.1 -import org.kde.kirigami 2.5 as Kirigami +import QtQuick.Layouts 1.1 import QtQuick.Controls 2.5 as QQC2 +import org.kde.kirigami 2.5 as Kirigami Kirigami.FormLayout { twinFormLayouts: parentLayout - enabled: activator.checked Connections { target: root onReset: reset() } function reset() { latitudeFixedField.backend = cA.latitudeFixed; longitudeFixedField.backend = cA.longitudeFixed; } + QQC2.Button { + text: i18n("Detect Location") + // Match combobox width + Layout.minimumWidth: modeSwitcher.width + icon.name: "find-location" + onClicked: { + latitudeFixedField.backend = locator.latitude; + longitudeFixedField.backend = locator.longitude; + } + } + NumberField { id: latitudeFixedField + // Match combobox width + Layout.minimumWidth: modeSwitcher.width Kirigami.FormData.label: i18n("Latitude:") backend: cA.latitudeFixedStaged validator: DoubleValidator {bottom: -90; top: 90; decimals: 10} onBackendChanged: { cA.latitudeFixedStaged = backend; - manualLocationsViewRow.change(); calcNeedsSave(); } } NumberField { id: longitudeFixedField + // Match combobox width + Layout.minimumWidth: modeSwitcher.width Kirigami.FormData.label: i18n("Longitude:") backend: cA.longitudeFixedStaged validator: DoubleValidator {bottom: -180; top: 180; decimals: 10} onBackendChanged: { cA.longitudeFixedStaged = backend; - manualLocationsViewRow.change(); calcNeedsSave(); } } - - QQC2.Button { - text: i18n("Detect Location") - implicitWidth: longitudeFixedField.width // TODO: see if there is a smarter way for doing this - icon.name: "find-location" - onClicked: { - latitudeFixedField.backend = locator.latitude; - longitudeFixedField.backend = locator.longitude; - } - } } diff --git a/kcms/nightcolor/package/contents/ui/TimingsView.qml b/kcms/nightcolor/package/contents/ui/TimingsView.qml index bcb3e81b3..52ec8a143 100644 --- a/kcms/nightcolor/package/contents/ui/TimingsView.qml +++ b/kcms/nightcolor/package/contents/ui/TimingsView.qml @@ -1,63 +1,64 @@ /******************************************************************** Copyright 2017 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.1 import org.kde.kirigami 2.5 as Kirigami import QtQuick.Controls 2.5 as QQC2 Kirigami.FormLayout { twinFormLayouts: parentLayout - enabled: activator.checked property double latitude property double longitude property var morningTimings: sunCalc.getMorningTimings(latitude, longitude) property var eveningTimings: sunCalc.getEveningTimings(latitude, longitude) function reset() { morningTimings = sunCalc.getMorningTimings(latitude, longitude); eveningTimings = sunCalc.getEveningTimings(latitude, longitude); } - TimeField { - id: mornBeginField - Kirigami.FormData.label: i18n("Sunrise begins:") - backend: morningTimings.begin - enabled: false + function prettyTime(date) { + return date.toLocaleString(Qt.locale(), "h:m"); } - TimeField { - id: mornEndField - Kirigami.FormData.label: i18n("...and ends:") - backend: morningTimings.end - enabled: false + Kirigami.Separator { + Kirigami.FormData.isSection: true } - TimeField { - id: evenBeginField - Kirigami.FormData.label: i18n("Sunset begins:") - backend: eveningTimings.begin - enabled: false + QQC2.Label { + wrapMode: Text.Wrap + text: i18n("Night Color begins at %1", prettyTime(eveningTimings.begin)) + } + QQC2.Label { + wrapMode: Text.Wrap + text: i18n("Color fully changed at %1", prettyTime(eveningTimings.end)) + } + + Item { + Kirigami.FormData.isSection: true } - TimeField { - id: evenEndField - Kirigami.FormData.label: i18n("...and ends:") - backend: eveningTimings.end - enabled: false + QQC2.Label { + wrapMode: Text.Wrap + text: i18n("Night Color begins changing back at %1", prettyTime(morningTimings.begin)) + } + QQC2.Label { + wrapMode: Text.Wrap + text: i18n("Normal coloration restored by %1", prettyTime(morningTimings.end)) } } diff --git a/kcms/nightcolor/package/contents/ui/main.qml b/kcms/nightcolor/package/contents/ui/main.qml index e1f19db63..06c22fced 100644 --- a/kcms/nightcolor/package/contents/ui/main.qml +++ b/kcms/nightcolor/package/contents/ui/main.qml @@ -1,376 +1,314 @@ /******************************************************************** Copyright 2017 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.12 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.5 as QQC2 import org.kde.kirigami 2.5 as Kirigami import org.kde.kcm 1.2 as KCM import org.kde.colorcorrect 0.1 as CC KCM.SimpleKCM { id: root property int error: cA.error property bool defaultRequested: false implicitHeight: Kirigami.Units.gridUnit * 29 + implicitWidth: Kirigami.Units.gridUnit * 35 CC.CompositorAdaptor { id: cA } CC.Geolocator { id: locator } CC.SunCalc { id: sunCalc } function calcNeedsSave() { kcm.needsSave = cA.checkStaged(); // If the user changes something manually again after // Default was triggered, only allow a normal // configuration change again: defaultRequested = false; } Connections { target: kcm onLoadRelay: cA.reloadData() onSaveRelay: defaultRequested ? cA.sendConfigurationAll() : cA.sendConfiguration(); onDefaultsRelay: { if (!cA.nightColorAvailable) { return; } activator.checked = cA.activeDefault; tempSlider.value = cA.nightTemperatureDefault; modeSwitcher.currentIndex = cA.modeDefault; // set everything else to default as well cA.latitudeFixedStaged = cA.latitudeFixedDefault; cA.longitudeFixedStaged = cA.longitudeFixedDefault; cA.morningBeginFixedStaged = cA.morningBeginFixedDefault; cA.eveningBeginFixedStaged = cA.eveningBeginFixedDefault; cA.transitionTimeStaged = cA.transitionTimeDefault; kcm.needsSave = cA.checkStagedAll(); defaultRequested = true; } } Connections { target: cA onDataUpdated: calcNeedsSave() onStagedDataReset: { activator.checked = cA.active; tempSlider.value = cA.nightTemperature; modeSwitcher.currentIndex = cA.mode; reset(); calcNeedsSave(); } } signal reset() header: ColumnLayout{ Kirigami.InlineMessage { id: errorMessage Layout.fillWidth: true visible: error != CC.CompositorAdaptor.ErrorCodeSuccess type: Kirigami.MessageType.Error text: cA.errorText } } ColumnLayout { spacing: 0 QQC2.Label { Layout.topMargin: Kirigami.Units.largeSpacing * 2 Layout.bottomMargin: Kirigami.Units.largeSpacing * 4 Layout.leftMargin: Kirigami.Units.smallSpacing Layout.rightMargin: Kirigami.Units.smallSpacing Layout.alignment: Qt.AlignHCenter Layout.maximumWidth: Math.round(root.width * 0.5) - text: i18n("Night Color makes the colors on the screen warmer to reduce eye strain.") + text: i18n("Night Color makes the colors on the screen warmer to reduce eye strain at the time of your choosing.") wrapMode: Text.WordWrap } Kirigami.FormLayout { id: parentLayout + Connections { + target: root + onReset: { + mornBeginManField.backend = cA.morningBeginFixed; + evenBeginManField.backend = cA.eveningBeginFixed; + transTimeField.value = cA.transitionTime; + } + } + QQC2.CheckBox { id: activator text: i18n("Activate Night Color") enabled: cA.nightColorAvailable checked: cA.active onCheckedChanged: { cA.activeStaged = checked; calcNeedsSave(); } } Item { Kirigami.FormData.isSection: true } GridLayout { - Kirigami.FormData.label: i18n("Night Color temperature:") + Kirigami.FormData.label: i18n("Night Color Temperature:") Kirigami.FormData.buddyFor: tempSlider enabled: activator.checked columns: 4 QQC2.Slider { id: tempSlider + // Match combobox width + Layout.minimumWidth: modeSwitcher.width enabled: activator.checked from: cA.minimalTemperature - implicitWidth: modeSwitcher.width to: cA.neutralTemperature value: cA.nightTemperature stepSize: 100 Layout.columnSpan: 3 onValueChanged: { cA.nightTemperatureStaged = value; calcNeedsSave(); } } QQC2.Label { text: tempSlider.value + i18n(" K") } //row 2 QQC2.Label { text: i18nc("Night colour red-ish", "Warm") } Item { Layout.fillWidth: true } QQC2.Label { text: i18nc("Night colour blue-ish", "Cool") } Item {} } Item { Kirigami.FormData.isSection: true } QQC2.ComboBox { id: modeSwitcher - Kirigami.FormData.label: i18n("Operation mode:") + // Work around https://bugs.kde.org/show_bug.cgi?id=403153 + Layout.minimumWidth: Kirigami.Units.gridUnit * 17 + Kirigami.FormData.label: i18n("Activation time:") enabled: activator.checked model: [ - i18n("Automatic"), - i18n("Location"), - i18n("Times"), - i18n("Constant") + i18n("Sunset to sunrise at current location"), + i18n("Sunset to sunrise at manual location"), + i18n("Custom time"), + i18n("Always on") ] currentIndex: cA.mode onCurrentIndexChanged: { cA.modeStaged = currentIndex; - advancedControlLoader.updatePage(currentIndex); calcNeedsSave(); } } - } - Kirigami.FormLayout { + // Show current location in auto mode + QQC2.Label { + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeAutomatic + enabled: activator.checked + wrapMode: Text.Wrap + text: i18n("Latitude: %1 Longitude: %2", locator.latitude, locator.longitude) + } - Loader { - id: advancedControlLoader - - - function updatePage(index) { - switch (index) { - case CC.CompositorAdaptor.ModeAutomatic: - sourceComponent = automaticView; - break; - case CC.CompositorAdaptor.ModeLocation: - sourceComponent = manualLocationsView; - break; - case CC.CompositorAdaptor.ModeTimings: - sourceComponent = manualTimingsView; - break; - case CC.CompositorAdaptor.ModeConstant: - default: - sourceComponent = undefined; - break; - } + // Show time entry fields in manual timings mode + TimeField { + id: evenBeginManField + // Match combobox width + Layout.minimumWidth: modeSwitcher.width + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeTimings + Kirigami.FormData.label: i18n("Turn on at:") + backend: cA.eveningBeginFixedStaged + onBackendChanged: {cA.eveningBeginFixedStaged = backend; + calcNeedsSave(); } - } - Component { - id: automaticView + QQC2.ToolTip { + text: i18n("Input format: HH:MM") + } + } - ColumnLayout { + TimeField { + id: mornBeginManField + // Match combobox width + Layout.minimumWidth: modeSwitcher.width + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeTimings + Kirigami.FormData.label: i18n("Turn off at:") + backend: cA.morningBeginFixedStaged + onBackendChanged: {cA.morningBeginFixedStaged = backend; + calcNeedsSave(); + } - Loader { - sourceComponent: TimingsView { - latitude: locator.latitude - longitude: locator.longitude - } - } + QQC2.ToolTip { + text: i18n("Input format: HH:MM") + } + } - Kirigami.Separator { - Layout.fillWidth: true - Kirigami.FormData.isSection: true - } + QQC2.SpinBox { + id: transTimeField + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeTimings + // Match width of combobox and input fields + Layout.minimumWidth: modeSwitcher.width + Kirigami.FormData.label: i18n("Transition duration:") + from: 1 + to: 600 // less than 12 hours (in minutes: 720) + value: cA.transitionTimeStaged + editable: true + onValueModified: { + cA.transitionTimeStaged = value; + calcNeedsSave(); + } + textFromValue: function(value, locale) { + return i18np("%1 minute", "%1 minutes", value) + } + valueFromText: function(text, locale) { + return parseInt(text); + } - Loader { - sourceComponent: LocationsAutoView { - latitude: locator.latitude - longitude: locator.longitude - } - } + QQC2.ToolTip { + text: i18n("Input minutes - min. 1, max. 600") } } - Component { - id: manualLocationsView - - ColumnLayout { - id: manualLocationsViewRow - signal change() - - Loader { - sourceComponent: TimingsView { - latitude: cA.latitudeFixedStaged - longitude: cA.longitudeFixedStaged - - Connections { - target: manualLocationsViewRow - onChange: { - reset(); - } - } - } - } + QQC2.Label { + id: manualTimingsError1 + visible: evenBeginManField.getNormedDate() - mornBeginManField.getNormedDate() <= 0 + font.italic: true + text: i18n("Error: Morning is before evening.") + } - Kirigami.Separator { - Layout.fillWidth: true - Kirigami.FormData.isSection: true + QQC2.Label { + id: manualTimingsError2 + visible: { + if (manualTimingsError1.visible) { + return false; } + var trTime = transTimeField.backend * 60 * 1000; + var mor = mornBeginManField.getNormedDate(); + var eve = evenBeginManField.getNormedDate(); - Loader { - sourceComponent: LocationsFixedView {} - } + return eve - mor <= trTime || eve - mor >= 86400000 - trTime; } + font.italic: true + text: i18n("Error: Transition time overlaps.") } + } - Component { - id: manualTimingsView - - ColumnLayout { - Loader { - sourceComponent: Kirigami.FormLayout { - twinFormLayouts: parentLayout - enabled: activator.checked && cA.timingsEnabled - - Connections { - target: root - onReset: { - mornBeginManField.backend = cA.morningBeginFixed; - evenBeginManField.backend = cA.eveningBeginFixed; - transTimeField.backend = cA.transitionTime; - } - } - - TimeField { - id: mornBeginManField - Kirigami.FormData.label: i18n("Sunrise begins:") - backend: cA.morningBeginFixedStaged - onBackendChanged: {cA.morningBeginFixedStaged = backend; - calcNeedsSave(); - } - - QQC2.ToolTip { - text: i18n("(Input format: HH:MM)") - } - } - - TimeField { - id: evenBeginManField - Kirigami.FormData.label: i18n("Sunset begins:") - backend: cA.eveningBeginFixedStaged - onBackendChanged: {cA.eveningBeginFixedStaged = backend; - calcNeedsSave(); - } - - QQC2.ToolTip { - text: i18n("Input format: HH:MM") - } - } - - QQC2.SpinBox { - id: transTimeField - // Match width of other text fields - Layout.minimumWidth: 200 - Kirigami.FormData.label: i18n("Transition duration:") - from: 1 - to: 600 // less than 12 hours (in minutes: 720) - value: cA.transitionTimeStaged - editable: true - onValueModified: { - cA.transitionTimeStaged = value; - calcNeedsSave(); - } - textFromValue: function(value, locale) { - return i18np("%1 minute", "%1 minutes", value) - } - valueFromText: function(text, locale) { - return parseInt(text); - } - - QQC2.ToolTip { - text: i18n("Input minutes - min. 1, max. 600") - } - } - - QQC2.Label { - id: manualTimingsError1 - visible: evenBeginManField.getNormedDate() - mornBeginManField.getNormedDate() <= 0 - font.italic: true - text: i18n("Error: Morning is before evening.") - } - - QQC2.Label { - id: manualTimingsError2 - visible: { - if (manualTimingsError1.visible) { - return false; - } - var trTime = transTimeField.backend * 60 * 1000; - var mor = mornBeginManField.getNormedDate(); - var eve = evenBeginManField.getNormedDate(); - - return eve - mor <= trTime || eve - mor >= 86400000 - trTime; - } - font.italic: true - text: i18n("Error: Transition time overlaps.") - } - } - } - } - } + // Show location chooser in manual location mode + LocationsFixedView { + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeLocation + enabled: activator.checked + } + + // Show start/end times in automatic and manual location modes + TimingsView { + id: timings + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeAutomatic || + modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeLocation + enabled: activator.checked + latitude: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeAutomatic ? locator.latitude : cA.latitudeFixedStaged + longitude: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeAutomatic ? locator.longitude : cA.longitudeFixedStaged } } }