mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-13 17:22:08 -04:00
time: add system default option to first day of week dropdown
This commit is contained in:
@@ -9,16 +9,22 @@ import qs.Modules.Settings.Widgets
|
|||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
readonly property string _systemDefaultLabel: I18n.tr("System Default")
|
||||||
|
|
||||||
function weekStartQt() {
|
function weekStartQt() {
|
||||||
if (SettingsData.firstDayOfWeek >= 7 || SettingsData.firstDayOfWeek < 0) {
|
if (SettingsData.firstDayOfWeek < 0 || SettingsData.firstDayOfWeek >= 7)
|
||||||
return Qt.locale().firstDayOfWeek;
|
return Qt.locale().firstDayOfWeek;
|
||||||
}
|
|
||||||
return SettingsData.firstDayOfWeek;
|
return SettingsData.firstDayOfWeek;
|
||||||
}
|
}
|
||||||
|
|
||||||
function weekStartJs() {
|
function weekStartJs() {
|
||||||
return weekStartQt() % 7;
|
return weekStartQt() % 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _dayNames() {
|
||||||
|
return Array(7).fill(0).map((_, i) => new Date(Date.UTC(2026, 2, 1 + i, 0, 0, 0)).toLocaleDateString(I18n.locale(), "dddd")).map(d => d[0].toUpperCase() + d.slice(1));
|
||||||
|
}
|
||||||
|
|
||||||
DankFlickable {
|
DankFlickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
clip: true
|
clip: true
|
||||||
@@ -84,20 +90,18 @@ Item {
|
|||||||
tags: ["first", "day", "week"]
|
tags: ["first", "day", "week"]
|
||||||
settingKey: "firstDayOfWeek"
|
settingKey: "firstDayOfWeek"
|
||||||
text: I18n.tr("First Day of Week")
|
text: I18n.tr("First Day of Week")
|
||||||
// Days from Sunday to Saturday in the selected language
|
options: [root._systemDefaultLabel].concat(root._dayNames())
|
||||||
// 1st of February 2026 is a Sunday, any Sunday works
|
currentValue: {
|
||||||
options: {
|
if (SettingsData.firstDayOfWeek < 0 || SettingsData.firstDayOfWeek >= 7)
|
||||||
return Array(7).fill(0).map(
|
return root._systemDefaultLabel;
|
||||||
(_, i) => new Date(Date.UTC(2026, 2, 1 + i, 0, 0, 0)).toLocaleDateString(
|
return root._dayNames()[root.weekStartJs()];
|
||||||
I18n.locale(), "dddd"
|
|
||||||
)
|
|
||||||
).map(
|
|
||||||
d => d[0].toUpperCase() + d.slice(1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
currentValue: options[root.weekStartJs()]
|
|
||||||
onValueChanged: value => {
|
onValueChanged: value => {
|
||||||
SettingsData.set("firstDayOfWeek", options.indexOf(value));
|
if (value === root._systemDefaultLabel) {
|
||||||
|
SettingsData.set("firstDayOfWeek", -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SettingsData.set("firstDayOfWeek", root._dayNames().indexOf(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user