From 6a5a89313fe11147f7b282a71ca585f4f9433df3 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 1 Nov 2024 21:09:48 -0700 Subject: [PATCH] kcms/time: Fix layout of time dialog and port date dialog to DatePopup Some changes in Kirigami.Dialog recently completely broke the dialog, we apparently now have to manually set dimensions on children. Use DatePopup from Kirigami Addons in order to reduce the code needed here. --- kcms/time/ui/DatePicker.qml | 165 ----------------------------- kcms/time/ui/Digit.qml | 74 ------------- kcms/time/ui/TimePicker.qml | 6 +- kcms/time/ui/TimePickerSpinBox.qml | 4 +- kcms/time/ui/main.qml | 46 ++------ 5 files changed, 15 insertions(+), 280 deletions(-) delete mode 100644 kcms/time/ui/DatePicker.qml delete mode 100644 kcms/time/ui/Digit.qml diff --git a/kcms/time/ui/DatePicker.qml b/kcms/time/ui/DatePicker.qml deleted file mode 100644 index 315bb9bc..00000000 --- a/kcms/time/ui/DatePicker.qml +++ /dev/null @@ -1,165 +0,0 @@ -/* - SPDX-FileCopyrightText: 2011 Marco Martin - - SPDX-License-Identifier: LGPL-2.0-or-later -*/ - -import QtQuick -import QtQuick.Layouts -import org.kde.kirigami 2.5 as Kirigami - -Item { - id: root - - //////// API - property int day - property int month - property int year - - property bool userConfiguring: false - - property string isoDate: year + "-" + clockRow.twoDigitString(month) + "-" + clockRow.twoDigitString(day) - - property int fontSize: 14 - property int _margin: Kirigami.Units.gridUnit - - opacity: enabled ? 1.0 : 0.5 - - Rectangle { - color: "transparent" - border.width: 1 - border.color: Kirigami.Theme.textColor - anchors.fill: parent - opacity: 0.3 - } - - /////// Implementation - Connections { - target: root - function onDayChanged() { - clockRow.day = root.day; - } - function onMonthChanged() { - clockRow.month = root.month; - } - function onYearChanged() { - clockRow.year = root.year; - } - } - - Timer { - id: userConfiguringTimer - repeat: false - interval: 1500 - running: false - onTriggered: { - root.day = clockRow.day - root.month = clockRow.month - root.year = clockRow.year - userConfiguring = false - } - } - - RowLayout { - id: clockRow - anchors.margins: _margin - anchors.fill: parent - - property int day - property int month - property int year - - function twoDigitString(number) - { - return number < 10 ? "0"+number : number - } - - Digit { - id: dayDigit - Layout.fillWidth: true - model: { - var dd = new Date(year, month, 0); - return dd.getDate() - } - currentIndex: ((day - 1) < model) ? day-1 : 1 - onSelectedIndexChanged: { - if (selectedIndex > -1) { - day = selectedIndex+1 - } - } - delegate: Text { - horizontalAlignment: Text.AlignHCenter - width: dayDigit.width - property int ownIndex: index - text: index+1 - color: Kirigami.Theme.textColor - font.pointSize: root.fontSize - } - } - Item { - Layout.fillHeight: true - Kirigami.Separator { - anchors { - top: parent.top - bottom: parent.bottom - } - } - } - Digit { - id: monthDigit - Layout.fillWidth: true - model: 12 - currentIndex: month -1 - onSelectedIndexChanged: { - if (selectedIndex > -1) { - month = selectedIndex + 1 - } - } - delegate: Text { - horizontalAlignment: Text.AlignHCenter - width: monthDigit.width - property int ownIndex: index - property variant months: Array(i18n("Jan"), i18n("Feb"), i18n("Mar"), i18n("Apr"), i18n("May"), i18n("Jun"), i18n("Jul"), i18n("Aug"), i18n("Sep"), i18n("Oct"), i18n("Nov"), i18n("Dec")) - text: months[index] - font.pointSize: root.fontSize - color: Kirigami.Theme.textColor - opacity: PathView.itemOpacity - } - width: monthPlaceHolder.width - Text { - id: monthPlaceHolder - visible: false - font.pointSize: root.fontSize - text: "0000" - } - } - Item { - Layout.fillHeight: true - Kirigami.Separator { - anchors { - top: parent.top - bottom: parent.bottom - } - } - } - Digit { - id: yearDigit - Layout.fillWidth: true - //FIXME: yes, this is a tad lame ;) - model: 3000 - currentIndex: year - onSelectedIndexChanged: { - if (selectedIndex > -1) { - year = selectedIndex - } - } - width: yearPlaceHolder.width*1.3 - Text { - id: yearPlaceHolder - visible: false - font.pointSize: root.fontSize - text: "0000" - } - } - } -} diff --git a/kcms/time/ui/Digit.qml b/kcms/time/ui/Digit.qml deleted file mode 100644 index c7374cda..00000000 --- a/kcms/time/ui/Digit.qml +++ /dev/null @@ -1,74 +0,0 @@ -/* - SPDX-FileCopyrightText: 2011 Marco Martin - - SPDX-License-Identifier: LGPL-2.0-or-later -*/ - -import QtQuick 2.7 -import org.kde.kirigami 2.4 as Kirigami - - -Item { - id: root - - property alias model: spinnerView.model - property alias currentIndex: spinnerView.currentIndex - property alias delegate: spinnerView.delegate - property alias moving: spinnerView.moving - property int selectedIndex: -1 - property int fontSize: 14 - - width: placeHolder.width*1.3 - height: placeHolder.height*3 - - Text { - id: placeHolder - visible: false - font.pointSize: root.fontSize - text: "00" - } - - PathView { - id: spinnerView - anchors.fill: parent - model: 60 - clip: true - pathItemCount: 5 - dragMargin: 800 - preferredHighlightBegin: 0.5 - preferredHighlightEnd: 0.5 - delegate: Text { - horizontalAlignment: Text.AlignHCenter - width: spinnerView.width - property int ownIndex: index - text: index < 10 ? "0"+index : index - color: Kirigami.Theme.textColor - font.pointSize: root.fontSize - } - - onMovingChanged: { - userConfiguring = true - if (!moving) { - userConfiguringTimer.restart() - selectedIndex = childAt(width/2, height/2).ownIndex - } - } - - path: Path { - startX: spinnerView.width/2 - startY: spinnerView.height + 1.5*placeHolder.height - PathAttribute { name: "itemOpacity"; value: 0 } - PathLine { - x: spinnerView.width/2 - y: spinnerView.height/2 - } - PathAttribute { name: "itemOpacity"; value: 1 } - PathLine { - x: spinnerView.width/2 - y: -1.5*placeHolder.height - } - PathAttribute { name: "itemOpacity"; value: 0 } - } - } -} - diff --git a/kcms/time/ui/TimePicker.qml b/kcms/time/ui/TimePicker.qml index a25172ed..509b7593 100644 --- a/kcms/time/ui/TimePicker.qml +++ b/kcms/time/ui/TimePicker.qml @@ -8,8 +8,9 @@ import QtQuick.Layouts import org.kde.kcmutils import org.kde.kirigami as Kirigami -RowLayout { +Item { id: root + implicitHeight: row.implicitHeight + Kirigami.Units.largeSpacing * 2 property int hours: 0 property int minutes: 0 @@ -37,8 +38,9 @@ RowLayout { } RowLayout { + id: row + anchors.centerIn: parent spacing: Kirigami.Units.largeSpacing - Layout.alignment: Qt.AlignHCenter // note: for 12-hour time, we have hours from 1-12 (0'o clock displays as 12) // for 24-hour time, we have hours from 0-23 diff --git a/kcms/time/ui/TimePickerSpinBox.qml b/kcms/time/ui/TimePickerSpinBox.qml index 0657d5ad..54564601 100644 --- a/kcms/time/ui/TimePickerSpinBox.qml +++ b/kcms/time/ui/TimePickerSpinBox.qml @@ -55,7 +55,7 @@ Item { spinBox.increase(); spinBox.valueModified(); } - icon.name: 'list-add-symbolic' + icon.name: 'arrow-up-symbolic' isStart: true isEnd: false enabled: spinBox.value < spinBox.to @@ -149,7 +149,7 @@ Item { spinBox.decrease(); spinBox.valueModified(); } - icon.name: 'list-remove-symbolic' + icon.name: 'arrow-down-symbolic' isStart: false isEnd: true enabled: spinBox.value > spinBox.from diff --git a/kcms/time/ui/main.qml b/kcms/time/ui/main.qml index 57d14d30..be3444cd 100644 --- a/kcms/time/ui/main.qml +++ b/kcms/time/ui/main.qml @@ -15,6 +15,7 @@ import org.kde.kcmutils import org.kde.timesettings import org.kde.kirigamiaddons.formcard 1 as FormCard import org.kde.kirigamiaddons.delegates 1 as Delegates +import org.kde.kirigamiaddons.dateandtime as DateAndTime SimpleKCM { id: timeModule @@ -163,45 +164,18 @@ SimpleKCM { } }, - Kirigami.PromptDialog { + DateAndTime.DatePopup { id: datePickerDialog - title: i18n("Pick System Date") - topPadding: Kirigami.Units.largeSpacing - bottomPadding: Kirigami.Units.largeSpacing - preferredWidth: Kirigami.Units.gridUnit * 15 - preferredHeight: Kirigami.Units.gridUnit * 13 - - standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel - - onAccepted: { - kcm.currentDate = datePicker.isoDate; - kcm.saveTime(); - } + modal: true + parent: timeModule onOpened: { - let date = new Date(kcm.currentDate) - datePicker.day = date.getDate(); - datePicker.month = date.getMonth() + 1; - datePicker.year = date.getFullYear(); + value = kcm.currentDate; } - DatePicker { - id: datePicker - implicitHeight: Kirigami.Units.gridUnit * 6 - - Connections { - target: kcm - function onCurrentDateChanged() { - if (datePickerDialog.visible) { - return; - } - - let date = new Date(kcm.currentDate); - datePicker.day = date.getDate(); - datePicker.month = date.getMonth() + 1; - datePicker.year = date.getFullYear(); - } - } + onAccepted: { + kcm.currentDate = value; + kcm.saveTime(); } }, @@ -209,9 +183,6 @@ SimpleKCM { id: timePickerDialog title: i18n("Pick System Time") preferredWidth: Kirigami.Units.gridUnit * 15 - topPadding: Kirigami.Units.largeSpacing - bottomPadding: Kirigami.Units.largeSpacing - standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel onAccepted: { @@ -231,6 +202,7 @@ SimpleKCM { TimePicker { id: timePicker + width: timePickerDialog.width - timePickerDialog.leftPadding - timePickerDialog.rightPadding Connections { target: kcm