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

KDE's Doxygen guidelines are available online.