KWidgetsAddons

kdatepicker.h
1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1997 Tim D. Gilman <tdgilman@best.org>
4 SPDX-FileCopyrightText: 1998-2001 Mirko Boehm <mirko@kde.org>
5 SPDX-FileCopyrightText: 2007 John Layt <john@layt.net>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KDATEPICKER_H
11#define KDATEPICKER_H
12
13#include <kwidgetsaddons_export.h>
14
15#include <QDate>
16#include <QFrame>
17#include <memory>
18
19class QLineEdit;
20class KDateTable;
21
22/**
23 * @class KDatePicker kdatepicker.h KDatePicker
24 *
25 * @short A date selection widget.
26 *
27 * Provides a widget for calendar date input.
28 *
29 * Different from the previous versions, it now emits two types of signals,
30 * either dateSelected() or dateEntered() (see documentation for both signals).
31 *
32 * A line edit has been added in the newer versions to allow the user
33 * to select a date directly by entering numbers like 19990101
34 * or 990101.
35 *
36 * \image html kdatepicker.png "KDatePicker Widget"
37 *
38 * @author Tim Gilman, Mirko Boehm
39 */
40class KWIDGETSADDONS_EXPORT KDatePicker : public QFrame
41{
43 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged USER true)
44 Q_PROPERTY(bool closeButton READ hasCloseButton WRITE setCloseButton)
45 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize)
46
47public:
48 /**
49 * The constructor. The current date will be displayed initially.
50 */
51 explicit KDatePicker(QWidget *parent = nullptr);
52
53 /**
54 * The constructor. The given date will be displayed initially.
55 */
56 explicit KDatePicker(const QDate &dt, QWidget *parent = nullptr);
57
58 /**
59 * The destructor.
60 */
61 ~KDatePicker() override;
62
63 /**
64 * The size hint for date pickers. The size hint recommends the
65 * minimum size of the widget so that all elements may be placed
66 * without clipping. This sometimes looks ugly, so when using the
67 * size hint, try adding 28 to each of the reported numbers of
68 * pixels.
69 */
70 QSize sizeHint() const override;
71
72 /**
73 * Sets the date.
74 *
75 * @returns @p false and does not change anything if the date given is invalid.
76 */
77 bool setDate(const QDate &date);
78
79 /**
80 * @returns the selected date.
81 */
82 const QDate &date() const;
83
84 /**
85 * Sets the font size of the widgets elements.
86 */
87 void setFontSize(int);
88
89 /**
90 * Returns the font size of the widget elements.
91 */
92 int fontSize() const;
93
94 /**
95 * By calling this method with @p enable = true, KDatePicker will show
96 * a little close-button in the upper button-row. Clicking the
97 * close-button will cause the KDatePicker's topLevelWidget()'s close()
98 * method being called. This is mostly useful for toplevel datepickers
99 * without a window manager decoration.
100 * @see hasCloseButton
101 */
102 void setCloseButton(bool enable);
103
104 /**
105 * @returns true if a KDatePicker shows a close-button.
106 * @see setCloseButton
107 */
108 bool hasCloseButton() const;
109
110 /**
111 * Sets the range of dates that can be accepted.
112 *
113 * Invalid dates can be used to define open-ended ranges.
114 * If both values are valid, the minimum date must be less than
115 * or equal to the maximum date, otherwise the date range will
116 * not be set.
117 *
118 * @param minDate the minimum date
119 * @param maxDate the maximum date
120 *
121 * @since 6.12
122 */
123 void setDateRange(const QDate &minDate, const QDate &maxDate = QDate());
124
125protected:
126 /// to catch move keyEvents when QLineEdit has keyFocus
127 bool eventFilter(QObject *o, QEvent *e) override;
128 /// the resize event
129 void resizeEvent(QResizeEvent *) override;
130 void changeEvent(QEvent *event) override;
131
132protected Q_SLOTS:
133 void dateChangedSlot(const QDate &date);
134 void tableClickedSlot();
135 void monthForwardClicked();
136 void monthBackwardClicked();
137 void yearForwardClicked();
138 void yearBackwardClicked();
139 void selectMonthClicked();
140 void selectYearClicked();
141 void uncheckYearSelector();
142 void lineEnterPressed();
143 void todayButtonClicked();
144 void weekSelected(int);
145
147 /**
148 * This signal is emitted each time the selected date is changed.
149 * Usually, this does not mean that the date has been entered,
150 * since the date also changes, for example, when another month is
151 * selected.
152 * @see dateSelected
153 */
154 void dateChanged(const QDate &date);
155
156 /**
157 * This signal is emitted each time a day has been selected by
158 * clicking on the table (hitting a day in the current month). It
159 * has the same meaning as dateSelected() in older versions of
160 * KDatePicker.
161 */
162 void dateSelected(const QDate &date);
163
164 /**
165 * This signal is emitted when enter is pressed and a VALID date
166 * has been entered before into the line edit. Connect to both
167 * dateEntered() and dateSelected() to receive all events where the
168 * user really enters a date.
169 */
170 void dateEntered(const QDate &date);
171
172 /**
173 * This signal is emitted when the day has been selected by
174 * clicking on it in the table.
175 */
177
178private:
179 KWIDGETSADDONS_NO_EXPORT KDateTable *dateTable() const;
180 KWIDGETSADDONS_NO_EXPORT void initWidget(const QDate &date);
181
182private:
183 friend class KDatePickerPrivate;
184 std::unique_ptr<class KDatePickerPrivate> const d;
185};
186
187#endif // KDATEPICKER_H
KDatePicker(QWidget *parent=nullptr)
The constructor.
bool setDate(const QDate &date)
Sets the date.
void setDateRange(const QDate &minDate, const QDate &maxDate=QDate())
Sets the range of dates that can be accepted.
void dateEntered(const QDate &date)
This signal is emitted when enter is pressed and a VALID date has been entered before into the line e...
bool hasCloseButton() const
void dateSelected(const QDate &date)
This signal is emitted each time a day has been selected by clicking on the table (hitting a day in t...
void setFontSize(int)
Sets the font size of the widgets elements.
~KDatePicker() override
The destructor.
void dateChanged(const QDate &date)
This signal is emitted each time the selected date is changed.
void setCloseButton(bool enable)
By calling this method with enable = true, KDatePicker will show a little close-button in the upper b...
void tableClicked()
This signal is emitted when the day has been selected by clicking on it in the table.
QFrame(QWidget *parent, Qt::WindowFlags f)
virtual void changeEvent(QEvent *ev) override
virtual bool event(QEvent *e) override
virtual QSize sizeHint() const const override
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
virtual bool eventFilter(QObject *watched, QEvent *event)
QObject * parent() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
virtual void resizeEvent(QResizeEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:54:47 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.