Kirigami-addons

DatePopup.qml
1// SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
2// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
3// SPDX-License-Identifier: LGPL-2.0-or-later
4
5import QtQuick
6import QtQuick.Window
7import QtQuick.Layouts
8import QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
10import org.kde.kirigamiaddons.components as Components
11import './private/' as P
12
13/**
14 * A popup that prompts the user to select a date
15 */
16QQC2.Dialog {
17 id: root
18
19 /**
20 * @brief The current date and time selected by the user.
21 */
22 property date value: new Date()
23
24 /**
25 * Emitted when the user cancells the popup
26 * @deprecated Use rejected instead.
27 */
28 signal cancelled()
29
30 /**
31 * This property holds the minimum date (inclusive) that the user can select.
32 *
33 * By default, no limit is applied to the date selection.
34 */
35 property date minimumDate
37 /**
38 * This property holds the maximum date (inclusive) that the user can select.
39 *
40 * By default, no limit is applied to the date selection.
41 */
42 property date maximumDate
44 /**
45 * This property holds whether the date popup will automatically select a date
46 * on selection or has a "Select" button.
47 *
48 * By default, this is false.
49 */
50 property bool autoAccept: false
51
52 padding: 0
53 topPadding: undefined
54 leftPadding: undefined
55 rightPadding: undefined
56 bottomPadding: undefined
57 verticalPadding: undefined
58 horizontalPadding: undefined
59
60 header: null
61
62 contentItem: P.DatePicker {
63 id: datePicker
64 selectedDate: root.value
65 minimumDate: root.minimumDate
66 maximumDate: root.maximumDate
67 focus: true
68
69 onDatePicked: (pickedDate) => {
70 if (autoAccept) {
71 root.value = pickedDate;
72 root.accepted();
73 }
74 }
75 }
76
77 footer: QQC2.DialogButtonBox {
78 id: box
79
80 visible: !autoAccept
81
82 leftPadding: Kirigami.Units.mediumSpacing
83 rightPadding: Kirigami.Units.mediumSpacing
84 bottomPadding: Kirigami.Units.mediumSpacing
85
86 QQC2.Button {
87 text: i18ndc("kirigami-addons6", "@action:button", "Cancel")
88 icon.name: "dialog-cancel"
89 onClicked: {
90 root.cancelled()
91 root.rejected()
92 root.close()
93 }
94
95 QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole
96 }
97
98 QQC2.Button {
99 text: i18ndc("kirigami-addons6", "@action:button", "Select")
100 icon.name: "dialog-ok-apply"
101
102 onClicked: {
103 root.value = datePicker.selectedDate;
104 root.accepted()
105 root.close()
106 }
107
108 QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
109 }
110 }
111
112 background: Components.DialogRoundedBackground {}
113
114 // black background, fades in and out
115 QQC2.Overlay.modal: Rectangle {
116 color: Qt.rgba(0, 0, 0, 0.3)
117
118 // the opacity of the item is changed internally by QQuickPopup on open/close
119 Behavior on opacity {
120 OpacityAnimator {
121 duration: Kirigami.Units.longDuration
122 easing.type: Easing.InOutQuad
123 }
124 }
125 }
126}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.