mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
time-kcm: Port to FormCard
This commit is contained in:
parent
8030c73c67
commit
37b9fad3b1
4 changed files with 130 additions and 145 deletions
|
|
@ -12,7 +12,7 @@
|
|||
class TimeZoneData
|
||||
{
|
||||
public:
|
||||
QString id;
|
||||
QByteArray id;
|
||||
QString region;
|
||||
QString city;
|
||||
QString comment;
|
||||
|
|
|
|||
|
|
@ -58,30 +58,32 @@ TimeZoneModel::~TimeZoneModel()
|
|||
|
||||
int TimeZoneModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return m_data.count();
|
||||
return parent.isValid() ? 0 : m_data.count();
|
||||
}
|
||||
|
||||
QVariant TimeZoneModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.isValid()) {
|
||||
TimeZoneData currentData = m_data.at(index.row());
|
||||
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
|
||||
|
||||
switch (role) {
|
||||
case TimeZoneIdRole:
|
||||
const TimeZoneData ¤tData = m_data.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case TimeZoneIdRole:
|
||||
return currentData.id;
|
||||
case RegionRole: {
|
||||
return currentData.region;
|
||||
case CityRole:
|
||||
if (currentData.city.isEmpty())
|
||||
return currentData.id;
|
||||
case RegionRole:
|
||||
return currentData.region;
|
||||
case CityRole:
|
||||
return currentData.city;
|
||||
case CommentRole:
|
||||
return currentData.comment;
|
||||
case CheckedRole:
|
||||
return currentData.checked;
|
||||
}
|
||||
return currentData.city;
|
||||
case CommentRole:
|
||||
return currentData.comment;
|
||||
case CheckedRole:
|
||||
return currentData.checked;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
return {};
|
||||
}
|
||||
|
||||
bool TimeZoneModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
|
|
@ -120,7 +122,7 @@ void TimeZoneModel::update()
|
|||
const QStringList data = QString::fromUtf8(localZone.id()).split(QLatin1Char('/'));
|
||||
|
||||
TimeZoneData local;
|
||||
local.id = QStringLiteral("Local");
|
||||
local.id = "Local";
|
||||
local.region = i18nc("This means \"Local Timezone\"", "Local");
|
||||
local.city = m_timezonesI18n->i18nCity(data.last());
|
||||
local.comment = i18n("Your system time zone");
|
||||
|
|
@ -131,21 +133,22 @@ void TimeZoneModel::update()
|
|||
QStringList cities;
|
||||
QHash<QString, QTimeZone> zonesByCity;
|
||||
|
||||
const QList<QByteArray> systemTimeZones = QTimeZone::availableTimeZoneIds();
|
||||
const auto systemTimeZones = QTimeZone::availableTimeZoneIds();
|
||||
|
||||
for (auto it = systemTimeZones.constBegin(); it != systemTimeZones.constEnd(); ++it) {
|
||||
const QTimeZone zone(*it);
|
||||
const QStringList splitted = QString::fromUtf8(zone.id()).split(QStringLiteral("/"));
|
||||
for (const auto &id : systemTimeZones) {
|
||||
const QTimeZone zone(id);
|
||||
|
||||
const QStringList splitted = QString::fromUtf8(id).split(QStringLiteral("/"));
|
||||
|
||||
// CITY | COUNTRY | CONTINENT
|
||||
const QString key = QStringLiteral("%1|%2|%3").arg(splitted.last(), QLocale::countryToString(zone.country()), splitted.first());
|
||||
const QString key = QStringLiteral("%1|%2|%3").arg(splitted.last(), QLocale::territoryToString(zone.territory()), splitted.first());
|
||||
|
||||
cities.append(key);
|
||||
zonesByCity.insert(key, zone);
|
||||
}
|
||||
cities.sort(Qt::CaseInsensitive);
|
||||
|
||||
Q_FOREACH (const QString &key, cities) {
|
||||
for (const QString &key : std::as_const(cities)) {
|
||||
const QTimeZone timeZone = zonesByCity.value(key);
|
||||
QString comment = timeZone.comment();
|
||||
|
||||
|
|
@ -157,10 +160,10 @@ void TimeZoneModel::update()
|
|||
const QStringList cityCountryContinent = key.split(QLatin1Char('|'));
|
||||
|
||||
TimeZoneData newData;
|
||||
newData.id = QString::fromUtf8(timeZone.id());
|
||||
newData.region = timeZone.country() == QLocale::AnyCountry
|
||||
newData.id = timeZone.id();
|
||||
newData.region = timeZone.territory() == QLocale::AnyCountry
|
||||
? QString()
|
||||
: m_timezonesI18n->i18nContinents(cityCountryContinent.at(2)) + QLatin1Char('/') + m_timezonesI18n->i18nCountry(timeZone.country());
|
||||
: m_timezonesI18n->i18nContinents(cityCountryContinent.at(2)) + QLatin1Char('/') + m_timezonesI18n->i18nCountry(timeZone.territory());
|
||||
newData.city = m_timezonesI18n->i18nCity(cityCountryContinent.at(0));
|
||||
newData.comment = comment;
|
||||
newData.checked = false;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef TIMEZONEMODEL_H
|
||||
#define TIMEZONEMODEL_H
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTimeZone>
|
||||
|
||||
#include "timezonedata.h"
|
||||
|
||||
|
|
@ -76,5 +76,3 @@ private:
|
|||
QStringList m_selectedTimeZones;
|
||||
TimezonesI18n *m_timezonesI18n;
|
||||
};
|
||||
|
||||
#endif // TIMEZONEMODEL_H
|
||||
|
|
|
|||
|
|
@ -5,141 +5,107 @@
|
|||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.3 as Controls
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls as Controls
|
||||
|
||||
import org.kde.kirigami 2.10 as Kirigami
|
||||
import org.kde.kirigami as Kirigami
|
||||
import org.kde.kcmutils
|
||||
import org.kde.timesettings 1.0
|
||||
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
|
||||
import org.kde.timesettings
|
||||
import org.kde.kirigamiaddons.formcard 1 as FormCard
|
||||
import org.kde.kirigamiaddons.delegates 1 as Delegates
|
||||
|
||||
SimpleKCM {
|
||||
id: timeModule
|
||||
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
topPadding: Kirigami.Units.gridUnit
|
||||
bottomPadding: Kirigami.Units.gridUnit
|
||||
|
||||
Component {
|
||||
id: listDelegateComponent
|
||||
|
||||
Kirigami.BasicListItem {
|
||||
text: {
|
||||
if (model) {
|
||||
if (model.region) {
|
||||
return "%1 / %2".arg(model.region).arg(model.city)
|
||||
} else {
|
||||
return model.city
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
onClicked: {
|
||||
timeZonePickerSheet.close()
|
||||
kcm.saveTimeZone(model.timeZoneId)
|
||||
}
|
||||
}
|
||||
}
|
||||
topPadding: 0
|
||||
bottomPadding: 0
|
||||
|
||||
ColumnLayout {
|
||||
spacing: 0
|
||||
width: parent.width
|
||||
|
||||
MobileForm.FormCard {
|
||||
Layout.fillWidth: true
|
||||
FormCard.FormHeader {
|
||||
title: i18n("Display")
|
||||
}
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
|
||||
MobileForm.FormCardHeader {
|
||||
title: i18n("Display")
|
||||
FormCard.FormCard {
|
||||
FormCard.FormSwitchDelegate {
|
||||
id: hourFormatSwitch
|
||||
text: i18n("24-Hour Format")
|
||||
description: i18n("Whether to use a 24-hour format for clocks.")
|
||||
checked: kcm.twentyFour
|
||||
onCheckedChanged: {
|
||||
kcm.twentyFour = checked
|
||||
}
|
||||
}
|
||||
|
||||
MobileForm.FormSwitchDelegate {
|
||||
id: hourFormatSwitch
|
||||
text: i18n("24-Hour Format")
|
||||
description: i18n("Whether to use a 24-hour format for clocks.")
|
||||
checked: kcm.twentyFour
|
||||
onCheckedChanged: {
|
||||
kcm.twentyFour = checked
|
||||
}
|
||||
}
|
||||
FormCard.FormDelegateSeparator { above: hourFormatSwitch; below: timeZoneSelect }
|
||||
|
||||
MobileForm.FormDelegateSeparator { above: hourFormatSwitch; below: timeZoneSelect }
|
||||
|
||||
MobileForm.FormButtonDelegate {
|
||||
id: timeZoneSelect
|
||||
text: i18n("Timezone")
|
||||
description: kcm.timeZone
|
||||
onClicked: timeZonePickerSheet.open()
|
||||
}
|
||||
FormCard.FormButtonDelegate {
|
||||
id: timeZoneSelect
|
||||
text: i18n("Timezone")
|
||||
description: kcm.timeZone
|
||||
onClicked: timeZonePickerSheet.open()
|
||||
}
|
||||
}
|
||||
|
||||
MobileForm.FormCard {
|
||||
Layout.topMargin: Kirigami.Units.gridUnit
|
||||
Layout.fillWidth: true
|
||||
FormCard.FormHeader {
|
||||
title: i18n("Time and Date")
|
||||
}
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
|
||||
MobileForm.FormCardHeader {
|
||||
title: i18n("Time and Date")
|
||||
}
|
||||
|
||||
MobileForm.FormSwitchDelegate {
|
||||
id: ntpCheckBox
|
||||
text: i18n("Automatic Time Synchronization")
|
||||
description: i18n("Whether to set the time automatically.")
|
||||
checked: kcm.useNtp
|
||||
onCheckedChanged: {
|
||||
kcm.useNtp = checked
|
||||
if (!checked) {
|
||||
kcm.ntpServer = ""
|
||||
kcm.saveTime()
|
||||
}
|
||||
FormCard.FormCard {
|
||||
FormCard.FormSwitchDelegate {
|
||||
id: ntpCheckBox
|
||||
text: i18n("Automatic Time Synchronization")
|
||||
description: i18n("Whether to set the time automatically.")
|
||||
checked: kcm.useNtp
|
||||
onCheckedChanged: {
|
||||
kcm.useNtp = checked
|
||||
if (!checked) {
|
||||
kcm.ntpServer = ""
|
||||
kcm.saveTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MobileForm.FormDelegateSeparator { above: ntpCheckBox; below: timeSelect }
|
||||
FormCard.FormDelegateSeparator { above: ntpCheckBox; below: timeSelect }
|
||||
|
||||
MobileForm.FormButtonDelegate {
|
||||
id: timeSelect
|
||||
enabled: !ntpCheckBox.checked
|
||||
icon.name: "clock"
|
||||
text: i18n("Current Time")
|
||||
description: Qt.formatTime(kcm.currentTime, Locale.LongFormat)
|
||||
onClicked: timePickerSheet.open()
|
||||
}
|
||||
FormCard.FormButtonDelegate {
|
||||
id: timeSelect
|
||||
enabled: !ntpCheckBox.checked
|
||||
icon.name: "clock"
|
||||
text: i18n("Current Time")
|
||||
description: Qt.formatTime(kcm.currentTime, Locale.LongFormat)
|
||||
onClicked: timePickerSheet.open()
|
||||
}
|
||||
|
||||
MobileForm.FormDelegateSeparator { above: timeSelect; below: dateSelect }
|
||||
FormCard.FormDelegateSeparator { above: timeSelect; below: dateSelect }
|
||||
|
||||
MobileForm.FormButtonDelegate {
|
||||
id: dateSelect
|
||||
enabled: !ntpCheckBox.checked
|
||||
icon.name: "view-calendar"
|
||||
text: i18n("Date")
|
||||
description: Qt.formatDate(kcm.currentDate, Locale.LongFormat)
|
||||
onClicked: datePickerSheet.open()
|
||||
}
|
||||
FormCard.FormButtonDelegate {
|
||||
id: dateSelect
|
||||
enabled: !ntpCheckBox.checked
|
||||
icon.name: "view-calendar"
|
||||
text: i18n("Date")
|
||||
description: Qt.formatDate(kcm.currentDate, Locale.LongFormat)
|
||||
onClicked: datePickerSheet.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.OverlaySheet {
|
||||
data: Kirigami.OverlaySheet {
|
||||
id: timeZonePickerSheet
|
||||
|
||||
header: ColumnLayout {
|
||||
Kirigami.Heading {
|
||||
text: i18nc("@title:window", "Pick Timezone")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Kirigami.SearchField {
|
||||
Layout.fillWidth: true
|
||||
width: parent.width
|
||||
onTextChanged: {
|
||||
kcm.timeZonesModel.filterString = text
|
||||
}
|
||||
onTextChanged: kcm.timeZonesModel.filterString = text
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,17 +118,35 @@ SimpleKCM {
|
|||
onClicked: timeZonePickerSheet.close()
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
clip: true
|
||||
anchors.fill: parent
|
||||
implicitWidth: 18 * Kirigami.Units.gridUnit
|
||||
model: kcm.timeZonesModel
|
||||
delegate: Kirigami.DelegateRecycler {
|
||||
width: listView.width
|
||||
|
||||
sourceComponent: listDelegateComponent
|
||||
topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
|
||||
bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
|
||||
|
||||
model: kcm.timeZonesModel
|
||||
delegate: Delegates.RoundedItemDelegate {
|
||||
required property string region
|
||||
required property string city
|
||||
|
||||
width: ListView.view.width
|
||||
|
||||
text: {
|
||||
if (region) {
|
||||
return "%1 / %2".arg(region).arg(city)
|
||||
} else {
|
||||
return city
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
timeZonePickerSheet.close()
|
||||
kcm.saveTimeZone(model.timeZoneId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +159,7 @@ SimpleKCM {
|
|||
enabled: !ntpCheckBox.checked
|
||||
twentyFour: hourFormatSwitch.checked
|
||||
|
||||
implicitWidth: width > Kirigami.Units.gridUnit * 15 ? width : Kirigami.Units.gridUnit * 15
|
||||
implicitWidth: Kirigami.Units.gridUnit * 15
|
||||
|
||||
Component.onCompleted: {
|
||||
var date = new Date(kcm.currentTime);
|
||||
|
|
@ -185,7 +169,7 @@ SimpleKCM {
|
|||
}
|
||||
Connections {
|
||||
target: kcm
|
||||
onCurrentTimeChanged: {
|
||||
function onCurrentTimeChanged() {
|
||||
if (timePicker.userConfiguring) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -229,7 +213,7 @@ SimpleKCM {
|
|||
}
|
||||
Connections {
|
||||
target: kcm
|
||||
onCurrentDateChanged: {
|
||||
function onCurrentDateChanged() {
|
||||
if (datePicker.userConfiguring) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue