6import QtQuick.Controls as QQC2
7import org.kde.kirigami as Kirigami
8import org.kde.kirigamiaddons.dateandtime as DateTime
9import org.kde.kirigamiaddons.components as Components
11import "private" as Private
82 property date minimumDate
89 property date maximumDate
97 property date initialValue:
new Date()
103 property
bool readOnly: false
108 property date value: new Date()
138 property
string statusMessage: ""
144 property var popupParent: QQC2.ApplicationWindow.window
148 focusPolicy: text.length > 0 ?
Qt.TabFocus :
Qt.NoFocus
151 topPadding: undefined
152 leftPadding: undefined
153 rightPadding: undefined
154 bottomPadding: undefined
155 verticalPadding: undefined
156 horizontalPadding: undefined
158 contentItem: ColumnLayout {
163 Layout.fillWidth:
true
165 bottomPadding:
Kirigami.Units.largeSpacing
166 topPadding:
Kirigami.Units.largeSpacing
168 Accessible.ignored:
true
174 Layout.fillWidth:
true
175 Layout.minimumWidth: parent.width
177 QQC2.AbstractButton {
180 property bool androidPickerActive:
false
182 horizontalPadding: Private.FormCardUnits.horizontalPadding
183 verticalPadding: Private.FormCardUnits.verticalPadding
185 Layout.fillWidth:
true
190 text:
if (!isNaN(root.value.valueOf())) {
191 const today =
new Date();
192 if (root.value.getFullYear() === today.getFullYear()
193 && root.value.getDate() === today.getDate()
194 && root.value.getMonth() == today.getMonth()) {
195 return i18ndc(
"kirigami-addons6",
"Displayed in place of the date if the selected day is today",
"Today");
197 const locale =
Qt.locale();
198 const weekDay = root.value.toLocaleDateString(locale,
"ddd, ");
199 if (root.value.getFullYear() == today.getFullYear()) {
200 return weekDay + root.value.toLocaleDateString(locale, Locale.ShortFormat);
203 const escapeRegExp = (strToEscape) => {
205 return strToEscape.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,
"\\$&");
208 const trimChar = (origString, charToTrim) => {
209 charToTrim = escapeRegExp(charToTrim);
210 const regEx =
new RegExp(
"^[" + charToTrim +
"]+|[" + charToTrim +
"]+$",
"g");
211 return origString.replace(regEx,
"");
214 let dateFormat = locale.dateFormat(Locale.ShortFormat)
215 .replace(root.value.getFullYear(),
'')
216 .replace(
'yyyy',
'');
218 dateFormat = trimChar(trimChar(trimChar(dateFormat,
'-'),
'.'),
'/')
220 return weekDay + root.value.toLocaleDateString(locale, dateFormat);
222 i18ndc(
"kirigami-addons6",
"Date is not set",
"Not set")
225 contentItem: RowLayout {
229 source:
"view-calendar"
230 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
231 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
232 Layout.rightMargin: Private.FormCardUnits.horizontalSpacing
241 Layout.fillWidth:
true
242 Accessible.ignored:
true
246 text: dateButton.text
248 Layout.fillWidth: !dateLabel.visible
249 Accessible.ignored:
true
257 let value = root.value;
259 if (isNaN(value.valueOf())) {
260 value = root.initialValue;
263 if (root.minimumDate) {
264 root.minimumDate.setHours(0, 0, 0, 0);
266 if (root.maximumDate) {
267 root.maximumDate.setHours(0, 0, 0, 0);
270 if (
Qt.platform.os ===
'android') {
271 androidPickerActive =
true;
272 DateTime.AndroidIntegration.showDatePicker(value.getTime());
274 const item = datePopup.createObject(root.popupParent, {
276 minimumDate: root.minimumDate,
277 maximumDate: root.maximumDate,
280 item.accepted.connect(() => {
281 if (isNaN(root.value.valueOf())) {
282 root.value = root.initialValue;
284 root.value.setFullYear(item.value.getFullYear());
285 root.value.setMonth(item.value.getMonth());
286 root.value.setDate(item.value.getDate());
294 visible: !root.readOnly
301 x: parent ? Math.round((parent.width - width) / 2) : 0
302 y: parent ? Math.round((parent.height - height) / 2) : 0
304 width: Math.min(
Kirigami.Units.gridUnit * 20, root.popupParent.width - 2 *
Kirigami.Units.gridUnit)
306 height:
Kirigami.Units.gridUnit * 20
315 enabled:
Qt.platform.os ===
'android' && dateButton.androidPickerActive
316 ignoreUnknownSignals: !enabled
317 target: enabled ? DateTime.AndroidIntegration : null
318 function onDatePickerFinished(accepted, newDate) {
319 dateButton.androidPickerActive =
false;
321 if (isNaN(root.value.valueOf())) {
322 root.value = root.initialValue;
324 root.value.setFullYear(newDate.getFullYear());
325 root.value.setMonth(newDate.getMonth());
326 root.value.setDate(newDate.getDate());
333 Layout.fillHeight:
true
334 Layout.preferredWidth: 1
335 Layout.topMargin:
Kirigami.Units.smallSpacing
336 Layout.bottomMargin:
Kirigami.Units.smallSpacing
337 opacity: dateButton.hovered || timeButton.hovered || !timeButton.visible || !dateButton.visible ? 0 : 0.5
340 QQC2.AbstractButton {
343 property bool androidPickerActive:
false
347 horizontalPadding: Private.FormCardUnits.horizontalPadding
348 verticalPadding: Private.FormCardUnits.verticalPadding
350 Layout.fillWidth:
true
353 text:
if (!isNaN(root.value.valueOf())) {
354 const locale =
Qt.locale();
355 const timeFormat = locale.timeFormat(Locale.ShortFormat)
357 return root.value.toLocaleTimeString(locale, timeFormat);
359 return i18ndc(
"kirigami-addons6",
"Date is not set",
"Not set");
367 let value = root.value;
368 if (isNaN(value.valueOf())) {
369 value = root.initialValue;
372 if (
Qt.platform.os ===
'android') {
373 androidPickerActive =
true;
374 DateTime.AndroidIntegration.showTimePicker(value.getTime());
376 const popup = timePopup.createObject(root.popupParent, {
388 x: parent ? Math.round((parent.width - width) / 2) : 0
389 y: parent ? Math.round((parent.height - height) / 2) : 0
391 onClosed: popup.destroy();
393 parent: root.popupParent.overlay
397 if (isNaN(root.value.valueOf())) {
398 root.value = root.initialValue;
400 root.value.setHours(popup.value.getHours(), popup.value.getMinutes());
406 enabled:
Qt.platform.os ===
'android' && timeButton.androidPickerActive
407 ignoreUnknownSignals: !enabled
408 target: enabled ? DateTime.AndroidIntegration : null
409 function onTimePickerFinished(accepted, newDate) {
410 timeButton.androidPickerActive =
false;
412 if (isNaN(root.value.valueOf())) {
413 root.value = root.initialValue;
415 root.value.setHours(newDate.getHours(), newDate.getMinutes());
420 contentItem: RowLayout {
426 Layout.preferredWidth:
Kirigami.Units.iconSizes.smallMedium
427 Layout.preferredHeight:
Kirigami.Units.iconSizes.smallMedium
428 Layout.rightMargin: Private.FormCardUnits.horizontalSpacing
436 Layout.fillWidth:
true
437 Accessible.ignored:
true
441 text: timeButton.text
442 Layout.fillWidth: !timeLabel.visible
443 Accessible.ignored:
true
449 visible: !root.readOnly
456 visible: root.statusMessage.length > 0
457 Layout.topMargin: visible ?
Kirigami.Units.smallSpacing : 0
458 Layout.bottomMargin: visible ?
Kirigami.Units.smallSpacing : 0
459 Layout.leftMargin:
Kirigami.Units.gridUnit
460 Layout.rightMargin:
Kirigami.Units.gridUnit
461 Layout.fillWidth:
true
462 text: root.statusMessage
Q_SCRIPTABLE CaptureState status()
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)