diff --git a/kcms/nightcolor/package/contents/ui/LocationsAutoView.qml b/kcms/nightcolor/package/contents/ui/LocationsAutoView.qml deleted file mode 100644 --- 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/TimingsView.qml b/kcms/nightcolor/package/contents/ui/TimingsView.qml --- a/kcms/nightcolor/package/contents/ui/TimingsView.qml +++ b/kcms/nightcolor/package/contents/ui/TimingsView.qml @@ -19,8 +19,6 @@ import QtQuick.Controls 2.5 as QQC2 Kirigami.FormLayout { - twinFormLayouts: parentLayout - enabled: activator.checked property double latitude property double longitude @@ -33,31 +31,37 @@ 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 { + elide: Text.ElideMiddle + Kirigami.FormData.label: i18n("Color change begins at:") + text: prettyTime(eveningTimings.begin) + } + QQC2.Label { + elide: Text.ElideMiddle + Kirigami.FormData.label: i18n("Color fully changed at:") + text: prettyTime(eveningTimings.end) + } + + Item { + Kirigami.FormData.isSection: true } - TimeField { - id: evenEndField - Kirigami.FormData.label: i18n("...and ends:") - backend: eveningTimings.end - enabled: false + QQC2.Label { + elide: Text.ElideMiddle + Kirigami.FormData.label: i18n("Color begins changing back at:") + text: prettyTime(morningTimings.begin) + } + QQC2.Label { + elide: Text.ElideMiddle + Kirigami.FormData.label: i18n("Normal coloration restored by:") + text: prettyTime(morningTimings.end) } } diff --git a/kcms/nightcolor/package/contents/ui/main.qml b/kcms/nightcolor/package/contents/ui/main.qml --- a/kcms/nightcolor/package/contents/ui/main.qml +++ b/kcms/nightcolor/package/contents/ui/main.qml @@ -27,7 +27,8 @@ id: root property int error: cA.error property bool defaultRequested: false - implicitHeight: Kirigami.Units.gridUnit * 29 + implicitHeight: Kirigami.Units.gridUnit * 30 + implicitWidth: Kirigami.Units.gridUnit * 35 CC.CompositorAdaptor { id: cA @@ -108,7 +109,7 @@ 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("To reduce eye strain, Night Color makes the colors on the screen warmer at the time of your choosing.") wrapMode: Text.WordWrap } @@ -176,200 +177,137 @@ 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:") enabled: activator.checked model: [ - i18n("Automatic"), - i18n("Location"), - i18n("Times"), - i18n("Constant") + i18n("Sunset/sunrise at current location"), + i18n("Sunset/sunrise at manual location"), + i18n("Manual times"), + i18n("Always on") ] currentIndex: cA.mode onCurrentIndexChanged: { cA.modeStaged = currentIndex; - advancedControlLoader.updatePage(currentIndex); calcNeedsSave(); } } } - Kirigami.FormLayout { + // Show current location in auto mode + QQC2.Label { + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeAutomatic + enabled: activator.checked + elide: Text.elideMiddle + 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 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 + } + + // Show time entry fields in manual timings mode + Kirigami.FormLayout { + visible: modeSwitcher.currentIndex === CC.CompositorAdaptor.ModeTimings + twinFormLayouts: parentLayout + enabled: activator.checked && cA.timingsEnabled + + Connections { + target: root + onReset: { + mornBeginManField.backend = cA.morningBeginFixed; + evenBeginManField.backend = cA.eveningBeginFixed; + transTimeField.backend = cA.transitionTime; } } - Component { - id: automaticView - - ColumnLayout { + TimeField { + id: evenBeginManField + Kirigami.FormData.label: i18n("Turn on at:") + backend: cA.eveningBeginFixedStaged + onBackendChanged: {cA.eveningBeginFixedStaged = 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 - } + TimeField { + id: mornBeginManField + Kirigami.FormData.label: i18n("Turn off at:") + backend: cA.morningBeginFixedStaged + onBackendChanged: {cA.morningBeginFixedStaged = backend; + calcNeedsSave(); + } - Loader { - sourceComponent: LocationsAutoView { - latitude: locator.latitude - longitude: locator.longitude - } - } + QQC2.ToolTip { + text: i18n("Input format: HH:MM") } } - Component { - id: manualLocationsView - - ColumnLayout { - id: manualLocationsViewRow - signal change() - - Loader { - sourceComponent: TimingsView { - latitude: cA.latitudeFixedStaged - longitude: cA.longitudeFixedStaged - - Connections { - target: manualLocationsViewRow - onChange: { - reset(); - } - } - } - } - - Kirigami.Separator { - Layout.fillWidth: true - Kirigami.FormData.isSection: true - } + 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); + } - Loader { - sourceComponent: LocationsFixedView {} - } + QQC2.ToolTip { + text: i18n("Input minutes - min. 1, max. 600") } } - 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.") - } - } + 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.") } } }