5import QtQuick.Layouts 1.15
6import QtQuick.Controls 2.15 as QQC2
7import org.kde.kirigami 2.20 as Kirigami
8import org.kde.kirigamiaddons.dateandtime 1.0 as DateTime
9import org.kde.kirigamiaddons.components 1.0 as Components
61 enum DateTimeDisplay {
73 property int dateTimeDisplay: FormDateTimeDelegate.DateTimeDisplay.DateTime
80 property date minimumDate
87 property date maximumDate
95 property date initialValue: new Date()
101 property bool readOnly: false
106 property date value: new Date()
128 property var status: Kirigami.MessageType.Information
136 property string statusMessage: ""
142 property var popupParent: QQC2.ApplicationWindow.window
146 focusPolicy: text.length > 0 ?
Qt.TabFocus :
Qt.NoFocus
149 topPadding: undefined
150 leftPadding: undefined
151 rightPadding: undefined
152 bottomPadding: undefined
153 verticalPadding: undefined
154 horizontalPadding: undefined
156 contentItem: ColumnLayout {
161 Layout.fillWidth:
true
163 bottomPadding:
Kirigami.Units.largeSpacing
164 topPadding:
Kirigami.Units.largeSpacing
166 Accessible.ignored:
true
172 Layout.fillWidth:
true
173 Layout.minimumWidth: parent.width
175 QQC2.AbstractButton {
178 property bool androidPickerActive:
false
180 horizontalPadding:
Kirigami.Units.gridUnit
183 Layout.fillWidth:
true
188 text:
if (!isNaN(root.value.valueOf())) {
189 const today =
new Date();
190 if (root.value.getFullYear() === today.getFullYear()
191 && root.value.getDate() === today.getDate()
192 && root.value.getMonth() == today.getMonth()) {
193 return i18ndc(
"kirigami-addons6",
"Displayed in place of the date if the selected day is today",
"Today");
195 const locale =
Qt.locale();
196 const weekDay = root.value.toLocaleDateString(locale,
"ddd, ");
197 if (root.value.getFullYear() == today.getFullYear()) {
198 return weekDay + root.value.toLocaleDateString(locale, Locale.ShortFormat);
201 const escapeRegExp = (strToEscape) => {
203 return strToEscape.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,
"\\$&");
206 const trimChar = (origString, charToTrim) => {
207 charToTrim = escapeRegExp(charToTrim);
208 const regEx =
new RegExp(
"^[" + charToTrim +
"]+|[" + charToTrim +
"]+$",
"g");
209 return origString.replace(regEx,
"");
212 let dateFormat = locale.dateFormat(Locale.ShortFormat)
213 .replace(root.value.getFullYear(),
'')
214 .replace(
'yyyy',
'');
216 dateFormat = trimChar(trimChar(trimChar(dateFormat,
'-'),
'.'),
'/')
218 return weekDay + root.value.toLocaleDateString(locale, dateFormat);
220 i18ndc(
"kirigami-addons6",
"Date is not set",
"Not set")
223 contentItem: RowLayout {
227 source:
"view-calendar"
228 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
229 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
230 Layout.rightMargin:
Kirigami.Units.largeSpacing +
Kirigami.Units.smallSpacing
239 Layout.fillWidth:
true
240 Accessible.ignored:
true
244 text: dateButton.text
246 Layout.fillWidth: !dateLabel.visible
247 Accessible.ignored:
true
255 let value = root.value;
257 if (isNaN(value.valueOf())) {
258 value = root.initialValue;
261 if (root.minimumDate) {
262 root.minimumDate.setHours(0, 0, 0, 0);
264 if (root.maximumDate) {
265 root.maximumDate.setHours(0, 0, 0, 0);
268 if (
Qt.platform.os ===
'android') {
269 androidPickerActive =
true;
270 DateTime.AndroidIntegration.showDatePicker(value.getTime());
272 const item = datePopup.createObject(root.popupParent, {
274 minimumDate: root.minimumDate,
275 maximumDate: root.maximumDate,
278 item.accepted.connect(() => {
279 if (isNaN(root.value.valueOf())) {
280 root.value = root.initialValue;
282 root.value.setFullYear(item.value.getFullYear());
283 root.value.setMonth(item.value.getMonth());
284 root.value.setDate(item.value.getDate());
292 visible: !root.readOnly
299 x: parent ? Math.round((parent.width - width) / 2) : 0
300 y: parent ? Math.round((parent.height - height) / 2) : 0
302 width: Math.min(
Kirigami.Units.gridUnit * 20, root.popupParent.width - 2 *
Kirigami.Units.gridUnit)
304 height:
Kirigami.Units.gridUnit * 20
313 enabled:
Qt.platform.os ===
'android' && dateButton.androidPickerActive
314 ignoreUnknownSignals: !enabled
315 target: enabled ? DateTime.AndroidIntegration : null
316 function onDatePickerFinished(accepted, newDate) {
317 dateButton.androidPickerActive =
false;
319 if (isNaN(root.value.valueOf())) {
320 root.value = root.initialValue;
322 root.value.setFullYear(newDate.getFullYear());
323 root.value.setMonth(newDate.getMonth());
324 root.value.setDate(newDate.getDate());
331 Layout.fillHeight:
true
332 Layout.preferredWidth: 1
333 Layout.topMargin:
Kirigami.Units.smallSpacing
334 Layout.bottomMargin:
Kirigami.Units.smallSpacing
335 opacity: dateButton.hovered || timeButton.hovered ? 0 : 0.5
338 QQC2.AbstractButton {
341 property bool androidPickerActive:
false
345 horizontalPadding:
Kirigami.Units.gridUnit
348 Layout.fillWidth:
true
351 text:
if (!isNaN(root.value.valueOf())) {
352 const locale =
Qt.locale();
353 const timeFormat = locale.timeFormat(Locale.ShortFormat)
355 return root.value.toLocaleTimeString(locale, timeFormat);
357 return i18ndc(
"kirigami-addons6",
"Date is not set",
"Not set");
365 let value = root.value;
366 if (isNaN(value.valueOf())) {
367 value = root.initialValue;
370 if (
Qt.platform.os ===
'android') {
371 androidPickerActive =
true;
372 DateTime.AndroidIntegration.showTimePicker(value.getTime());
374 const popup = timePopup.createObject(root.popupParent, {
386 x: parent ? Math.round((parent.width - width) / 2) : 0
387 y: parent ? Math.round((parent.height - height) / 2) : 0
389 onClosed: popup.destroy();
391 parent: root.popupParent.overlay
395 if (isNaN(root.value.valueOf())) {
396 root.value = root.initialValue;
398 root.value.setHours(popup.value.getHours(), popup.value.getMinutes());
404 enabled:
Qt.platform.os ===
'android' && timeButton.androidPickerActive
405 ignoreUnknownSignals: !enabled
406 target: enabled ? DateTime.AndroidIntegration : null
407 function onTimePickerFinished(accepted, newDate) {
408 timeButton.androidPickerActive =
false;
410 if (isNaN(root.value.valueOf())) {
411 root.value = root.initialValue;
413 root.value.setHours(newDate.getHours(), newDate.getMinutes());
418 contentItem: RowLayout {
424 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
425 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
426 Layout.rightMargin:
Kirigami.Units.largeSpacing +
Kirigami.Units.smallSpacing
434 Layout.fillWidth:
true
435 Accessible.ignored:
true
439 text: timeButton.text
440 Layout.fillWidth: !timeLabel.visible
441 Accessible.ignored:
true
447 visible: !root.readOnly
454 visible: root.statusMessage.length > 0
455 Layout.topMargin: visible ?
Kirigami.Units.smallSpacing : 0
456 Layout.bottomMargin: visible ?
Kirigami.Units.smallSpacing : 0
457 Layout.leftMargin:
Kirigami.Units.gridUnit
458 Layout.rightMargin:
Kirigami.Units.gridUnit
459 Layout.fillWidth:
true
460 text: root.statusMessage
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)