1/*
2 SPDX-FileCopyrightText: 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KDATEPICKERPOPUP_H
7#define KDATEPICKERPOPUP_H
8
9#include <kwidgetsaddons_export.h>
10
11#include <QDate>
12#include <QMenu>
13
14#include <memory>
15
16class KDatePicker;
17class KDatePickerPopupPrivate;
18
19/*!
20 * \class KDatePickerPopup
21 * \inmodule KWidgetsAddons
22 *
23 * \brief This menu helps the user to select a date quickly.
24 *
25 * This menu helps the user to select a date quickly. It offers various
26 * modes of selecting, e.g. with a KDatePicker or with words like "Tomorrow".
27 *
28 * The available modes are:
29 * \list
30 * \li NoDate: A menu-item with "No Date". If chosen, the datepicker will emit
31 * a null QDate.
32 * \li DatePicker: Shows a KDatePicker-widget.
33 * \li Words: Shows items like "Today", "Tomorrow" or "Next Week".
34 * \endlist
35 *
36 * \since 5.94
37 */
38class KWIDGETSADDONS_EXPORT KDatePickerPopup : public QMenu
39{
40 Q_OBJECT
41
42 /*!
43 * \property KDatePickerPopup::modes
44 */
45 Q_PROPERTY(Modes modes READ modes WRITE setModes)
46
47public:
48 /*!
49 * Describes the available selection modes.
50 *
51 * \value NoDate A menu-item with "No Date". Will always return an invalid date.
52 * \value DatePicker A menu-item with a KDatePicker.
53 * \value Words A menu-item with list of words that describe a date.
54 */
55 enum Mode {
56 NoDate = 1,
57 DatePicker = 2,
58 Words = 4
59 };
60 Q_DECLARE_FLAGS(Modes, Mode)
61
62 /*!
63 * Creates a new date picker popup.
64 *
65 * \a modes The selection modes that shall be offered
66 *
67 * \a date The initial date of date picker widget.
68 *
69 * \a parent The parent object.
70 */
71 explicit KDatePickerPopup(Modes modes = DatePicker, QDate date = QDate::currentDate(), QWidget *parent = nullptr);
72
73 ~KDatePickerPopup() override;
74
75 /*!
76 * Returns the currently used selection modes.
77 */
78 Modes modes() const;
79
80 /*!
81 * Set the selection modes to use.
82 */
83 void setModes(Modes modes);
84
85 /*!
86 * Sets the range of dates that can be accepted.
87 *
88 * Invalid dates can be used to define open-ended ranges.
89 * If both values are valid, the minimum date must be less than
90 * or equal to the maximum date, otherwise the date range will
91 * not be set.
92 *
93 * \a minDate the minimum date
94 *
95 * \a maxDate the maximum date
96 */
97 void setDateRange(const QDate &minDate, const QDate &maxDate);
98
99 /*!
100 * Return the map of dates listed in the drop-down and their displayed
101 * string forms.
102 *
103 * \sa setDateMap()
104 */
105 QMap<QDate, QString> dateMap() const;
106
107 /*!
108 * Sets the list of dates in the drop-down menu that the user can select from
109 * and the text string to display for each date, e.g. "2010-01-01" and "Yesterday".
110 *
111 * The list of date/string pairs is used as-is (invalid or duplicate dates aren't removed),
112 * and the order will not be changed (the map is sorted by key); also and the minimum and
113 * maximum dates will not be affected.
114 *
115 * The \a dateMap is keyed by the date to be listed and the value is the
116 * string to be displayed. If you want the date to be displayed in the
117 * default date format then the string should be null. If you want a
118 * separator to be displayed then set the string to "separator".
119 *
120 * \a dateMap the map of dates the user can select from
121 *
122 * \sa dateMap()
123 */
124 void setDateMap(const QMap<QDate, QString> &dateMap);
125
126 /*!
127 * Returns the used KDatePicker object.
128 */
129 Q_REQUIRED_RESULT KDatePicker *datePicker() const;
130
131public Q_SLOTS:
132 /*!
133 * Sets the current \a date.
134 */
135 void setDate(QDate date);
136
137Q_SIGNALS:
138 /*!
139 * This signal is emitted whenever the user has selected a new date.
140 *
141 * \a date The new date.
142 */
143 void dateChanged(const QDate &date);
144
145private:
146 std::unique_ptr<KDatePickerPopupPrivate> const d;
147};
148
149Q_DECLARE_OPERATORS_FOR_FLAGS(KDatePickerPopup::Modes)
150
151#endif
152

source code of kwidgetsaddons/src/kdatepickerpopup.h