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