mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
locale-aware clock and date formatting
This commit is contained in:
@@ -50,8 +50,8 @@ Singleton {
|
||||
property bool focusedWindowCompactMode: false
|
||||
property bool runningAppsCompactMode: true
|
||||
property bool runningAppsCurrentWorkspace: false
|
||||
property string clockDateFormat: "ddd d"
|
||||
property string lockDateFormat: "dddd, MMMM d"
|
||||
property string clockDateFormat: ""
|
||||
property string lockDateFormat: ""
|
||||
property int mediaSize: 1
|
||||
property var topBarLeftWidgets: ["launcherButton", "workspaceSwitcher", "focusedWindow"]
|
||||
property var topBarCenterWidgets: ["music", "clock", "weather"]
|
||||
@@ -108,6 +108,22 @@ Singleton {
|
||||
signal widgetDataChanged
|
||||
signal workspaceIconsUpdated
|
||||
|
||||
function getEffectiveTimeFormat() {
|
||||
if (use24HourClock) {
|
||||
return Locale.ShortFormat
|
||||
} else {
|
||||
return "h:mm AP"
|
||||
}
|
||||
}
|
||||
|
||||
function getEffectiveClockDateFormat() {
|
||||
return clockDateFormat && clockDateFormat.length > 0 ? clockDateFormat : "ddd d"
|
||||
}
|
||||
|
||||
function getEffectiveLockDateFormat() {
|
||||
return lockDateFormat && lockDateFormat.length > 0 ? lockDateFormat : Locale.LongFormat
|
||||
}
|
||||
|
||||
function initializeListModels() {
|
||||
// ! Hack-ish to add all properties to the listmodel once
|
||||
// ! allows the properties to be bound on new widget addtions
|
||||
@@ -224,9 +240,9 @@ Singleton {
|
||||
runningAppsCurrentWorkspace = settings.runningAppsCurrentWorkspace
|
||||
!== undefined ? settings.runningAppsCurrentWorkspace : false
|
||||
clockDateFormat = settings.clockDateFormat
|
||||
!== undefined ? settings.clockDateFormat : "ddd d"
|
||||
!== undefined ? settings.clockDateFormat : ""
|
||||
lockDateFormat = settings.lockDateFormat
|
||||
!== undefined ? settings.lockDateFormat : "dddd, MMMM d"
|
||||
!== undefined ? settings.lockDateFormat : ""
|
||||
mediaSize = settings.mediaSize !== undefined ? settings.mediaSize : (settings.mediaCompactMode !== undefined ? (settings.mediaCompactMode ? 0 : 1) : 1)
|
||||
if (settings.topBarWidgetOrder) {
|
||||
topBarLeftWidgets = settings.topBarWidgetOrder.filter(w => {
|
||||
@@ -474,12 +490,12 @@ Singleton {
|
||||
}
|
||||
|
||||
function setClockDateFormat(format) {
|
||||
clockDateFormat = format
|
||||
clockDateFormat = format || ""
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
function setLockDateFormat(format) {
|
||||
lockDateFormat = format
|
||||
lockDateFormat = format || ""
|
||||
saveSettings()
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ Column {
|
||||
StyledText {
|
||||
width: parent.width - 80
|
||||
height: 40
|
||||
text: Qt.formatDate(displayDate, "MMMM yyyy")
|
||||
text: displayDate.toLocaleDateString(Qt.locale(), "MMMM yyyy")
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
@@ -128,7 +128,15 @@ Column {
|
||||
height: 32
|
||||
|
||||
Repeater {
|
||||
model: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
||||
model: {
|
||||
var days = []
|
||||
var locale = Qt.locale()
|
||||
for (var i = 0; i < 7; i++) {
|
||||
var date = new Date(2024, 0, 7 + i)
|
||||
days.push(locale.dayName(i, Locale.ShortFormat))
|
||||
}
|
||||
return days
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: parent.width / 7
|
||||
|
||||
@@ -84,7 +84,7 @@ Item {
|
||||
SystemClock {
|
||||
id: systemClock
|
||||
|
||||
precision: SystemClock.Seconds
|
||||
precision: SystemClock.Minutes
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@@ -102,11 +102,13 @@ Item {
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
text: SettingsData.use24HourClock ? Qt.formatTime(
|
||||
systemClock.date,
|
||||
"HH:mm") : Qt.formatTime(
|
||||
systemClock.date,
|
||||
"h:mm AP")
|
||||
text: {
|
||||
if (SettingsData.use24HourClock) {
|
||||
return systemClock.date.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
|
||||
} else {
|
||||
return systemClock.date.toLocaleTimeString(Qt.locale(), "h:mm AP")
|
||||
}
|
||||
}
|
||||
font.pixelSize: 120
|
||||
font.weight: Font.Light
|
||||
color: "white"
|
||||
@@ -117,8 +119,12 @@ Item {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: clockText.bottom
|
||||
anchors.topMargin: -20
|
||||
text: Qt.formatDate(systemClock.date,
|
||||
SettingsData.lockDateFormat)
|
||||
text: {
|
||||
if (SettingsData.lockDateFormat && SettingsData.lockDateFormat.length > 0) {
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), SettingsData.lockDateFormat)
|
||||
}
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), Locale.LongFormat)
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeXLarge
|
||||
color: "white"
|
||||
opacity: 0.9
|
||||
|
||||
@@ -126,10 +126,11 @@ Item {
|
||||
width: parent.width
|
||||
height: 50
|
||||
text: "Top Bar Format"
|
||||
description: "Preview: " + Qt.formatDate(
|
||||
new Date(),
|
||||
SettingsData.clockDateFormat)
|
||||
description: "Preview: " + (SettingsData.clockDateFormat ? new Date().toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat) : new Date().toLocaleDateString(Qt.locale(), "ddd d"))
|
||||
currentValue: {
|
||||
if (!SettingsData.clockDateFormat || SettingsData.clockDateFormat.length === 0) {
|
||||
return "System Default"
|
||||
}
|
||||
// Find matching preset or show "Custom"
|
||||
const presets = [{
|
||||
"format": "ddd d",
|
||||
@@ -162,9 +163,10 @@ Item {
|
||||
})
|
||||
return match ? match.label : "Custom: " + SettingsData.clockDateFormat
|
||||
}
|
||||
options: ["Day Date", "Day Month Date", "Month Date", "Numeric (M/D)", "Numeric (D/M)", "Full with Year", "ISO Date", "Full Day & Month", "Custom..."]
|
||||
options: ["System Default", "Day Date", "Day Month Date", "Month Date", "Numeric (M/D)", "Numeric (D/M)", "Full with Year", "ISO Date", "Full Day & Month", "Custom..."]
|
||||
onValueChanged: value => {
|
||||
const formatMap = {
|
||||
"System Default": "",
|
||||
"Day Date": "ddd d",
|
||||
"Day Month Date": "ddd MMM d",
|
||||
"Month Date": "MMM d",
|
||||
@@ -188,10 +190,11 @@ Item {
|
||||
width: parent.width
|
||||
height: 50
|
||||
text: "Lock Screen Format"
|
||||
description: "Preview: " + Qt.formatDate(
|
||||
new Date(),
|
||||
SettingsData.lockDateFormat)
|
||||
description: "Preview: " + (SettingsData.lockDateFormat ? new Date().toLocaleDateString(Qt.locale(), SettingsData.lockDateFormat) : new Date().toLocaleDateString(Qt.locale(), Locale.LongFormat))
|
||||
currentValue: {
|
||||
if (!SettingsData.lockDateFormat || SettingsData.lockDateFormat.length === 0) {
|
||||
return "System Default"
|
||||
}
|
||||
// Find matching preset or show "Custom"
|
||||
const presets = [{
|
||||
"format": "ddd d",
|
||||
@@ -224,9 +227,10 @@ Item {
|
||||
})
|
||||
return match ? match.label : "Custom: " + SettingsData.lockDateFormat
|
||||
}
|
||||
options: ["Day Date", "Day Month Date", "Month Date", "Numeric (M/D)", "Numeric (D/M)", "Full with Year", "ISO Date", "Full Day & Month", "Custom..."]
|
||||
options: ["System Default", "Day Date", "Day Month Date", "Month Date", "Numeric (M/D)", "Numeric (D/M)", "Full with Year", "ISO Date", "Full Day & Month", "Custom..."]
|
||||
onValueChanged: value => {
|
||||
const formatMap = {
|
||||
"System Default": "",
|
||||
"Day Date": "ddd d",
|
||||
"Day Month Date": "ddd MMM d",
|
||||
"Month Date": "MMM d",
|
||||
|
||||
@@ -37,10 +37,13 @@ Rectangle {
|
||||
spacing: Theme.spacingS
|
||||
|
||||
StyledText {
|
||||
text: SettingsData.use24HourClock ? Qt.formatTime(
|
||||
root.currentDate,
|
||||
"HH:mm") : Qt.formatTime(
|
||||
root.currentDate, "h:mm AP")
|
||||
text: {
|
||||
if (SettingsData.use24HourClock) {
|
||||
return root.currentDate.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
|
||||
} else {
|
||||
return root.currentDate.toLocaleTimeString(Qt.locale(), "h:mm AP")
|
||||
}
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeMedium - 1
|
||||
color: Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
@@ -55,7 +58,12 @@ Rectangle {
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: Qt.formatDate(root.currentDate, SettingsData.clockDateFormat)
|
||||
text: {
|
||||
if (SettingsData.clockDateFormat && SettingsData.clockDateFormat.length > 0) {
|
||||
return root.currentDate.toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat)
|
||||
}
|
||||
return root.currentDate.toLocaleDateString(Qt.locale(), "ddd d")
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeMedium - 1
|
||||
color: Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Reference in New Issue
Block a user