File indexing completed on 2025-02-16 13:11:40
0001 /* -*- C++ -*- 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1997 Tim D. Gilman <tdgilman@best.org> 0004 SPDX-FileCopyrightText: 1998-2001 Mirko Boehm <mirko@kde.org> 0005 SPDX-FileCopyrightText: 2007 John Layt <john@layt.net> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KDATEPICKER_H 0011 #define KDATEPICKER_H 0012 0013 #include <kwidgetsaddons_export.h> 0014 0015 #include <QFrame> 0016 #include <memory> 0017 0018 class QLineEdit; 0019 class KDateTable; 0020 0021 /** 0022 * @class KDatePicker kdatepicker.h KDatePicker 0023 * 0024 * @short A date selection widget. 0025 * 0026 * Provides a widget for calendar date input. 0027 * 0028 * Different from the previous versions, it now emits two types of signals, 0029 * either dateSelected() or dateEntered() (see documentation for both signals). 0030 * 0031 * A line edit has been added in the newer versions to allow the user 0032 * to select a date directly by entering numbers like 19990101 0033 * or 990101. 0034 * 0035 * \image html kdatepicker.png "KDatePicker Widget" 0036 * 0037 * @author Tim Gilman, Mirko Boehm 0038 */ 0039 class KWIDGETSADDONS_EXPORT KDatePicker : public QFrame 0040 { 0041 Q_OBJECT 0042 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged USER true) 0043 Q_PROPERTY(bool closeButton READ hasCloseButton WRITE setCloseButton) 0044 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize) 0045 0046 public: 0047 /** 0048 * The constructor. The current date will be displayed initially. 0049 */ 0050 explicit KDatePicker(QWidget *parent = nullptr); 0051 0052 /** 0053 * The constructor. The given date will be displayed initially. 0054 */ 0055 explicit KDatePicker(const QDate &dt, QWidget *parent = nullptr); 0056 0057 /** 0058 * The destructor. 0059 */ 0060 ~KDatePicker() override; 0061 0062 /** 0063 * The size hint for date pickers. The size hint recommends the 0064 * minimum size of the widget so that all elements may be placed 0065 * without clipping. This sometimes looks ugly, so when using the 0066 * size hint, try adding 28 to each of the reported numbers of 0067 * pixels. 0068 */ 0069 QSize sizeHint() const override; 0070 0071 /** 0072 * Sets the date. 0073 * 0074 * @returns @p false and does not change anything if the date given is invalid. 0075 */ 0076 bool setDate(const QDate &date); 0077 0078 /** 0079 * @returns the selected date. 0080 */ 0081 const QDate &date() const; 0082 0083 /** 0084 * Sets the font size of the widgets elements. 0085 */ 0086 void setFontSize(int); 0087 0088 /** 0089 * Returns the font size of the widget elements. 0090 */ 0091 int fontSize() const; 0092 0093 /** 0094 * By calling this method with @p enable = true, KDatePicker will show 0095 * a little close-button in the upper button-row. Clicking the 0096 * close-button will cause the KDatePicker's topLevelWidget()'s close() 0097 * method being called. This is mostly useful for toplevel datepickers 0098 * without a window manager decoration. 0099 * @see hasCloseButton 0100 */ 0101 void setCloseButton(bool enable); 0102 0103 /** 0104 * @returns true if a KDatePicker shows a close-button. 0105 * @see setCloseButton 0106 */ 0107 bool hasCloseButton() const; 0108 0109 protected: 0110 /// to catch move keyEvents when QLineEdit has keyFocus 0111 bool eventFilter(QObject *o, QEvent *e) override; 0112 /// the resize event 0113 void resizeEvent(QResizeEvent *) override; 0114 void changeEvent(QEvent *event) override; 0115 0116 protected Q_SLOTS: 0117 void dateChangedSlot(const QDate &date); 0118 void tableClickedSlot(); 0119 void monthForwardClicked(); 0120 void monthBackwardClicked(); 0121 void yearForwardClicked(); 0122 void yearBackwardClicked(); 0123 void selectMonthClicked(); 0124 void selectYearClicked(); 0125 void uncheckYearSelector(); 0126 void lineEnterPressed(); 0127 void todayButtonClicked(); 0128 void weekSelected(int); 0129 0130 Q_SIGNALS: 0131 /** 0132 * This signal is emitted each time the selected date is changed. 0133 * Usually, this does not mean that the date has been entered, 0134 * since the date also changes, for example, when another month is 0135 * selected. 0136 * @see dateSelected 0137 */ 0138 void dateChanged(const QDate &date); 0139 0140 /** 0141 * This signal is emitted each time a day has been selected by 0142 * clicking on the table (hitting a day in the current month). It 0143 * has the same meaning as dateSelected() in older versions of 0144 * KDatePicker. 0145 */ 0146 void dateSelected(const QDate &date); 0147 0148 /** 0149 * This signal is emitted when enter is pressed and a VALID date 0150 * has been entered before into the line edit. Connect to both 0151 * dateEntered() and dateSelected() to receive all events where the 0152 * user really enters a date. 0153 */ 0154 void dateEntered(const QDate &date); 0155 0156 /** 0157 * This signal is emitted when the day has been selected by 0158 * clicking on it in the table. 0159 */ 0160 void tableClicked(); 0161 0162 private: 0163 KWIDGETSADDONS_NO_EXPORT KDateTable *dateTable() const; 0164 KWIDGETSADDONS_NO_EXPORT void initWidget(const QDate &date); 0165 0166 private: 0167 friend class KDatePickerPrivate; 0168 std::unique_ptr<class KDatePickerPrivate> const d; 0169 }; 0170 0171 #endif // KDATEPICKER_H