File indexing completed on 2025-01-19 03:50:32
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2002-01-10 0007 * Description : a combo box to list date. 0008 * this widget come from libkdepim. 0009 * 0010 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2002 by Cornelius Schumacher <schumacher at kde dot org> 0012 * SPDX-FileCopyrightText: 2003-2004 by Reinhold Kainhofer <reinhold at kainhofer dot com> 0013 * SPDX-FileCopyrightText: 2004 by Tobias Koenig <tokoe at kde dot org> 0014 * 0015 * SPDX-License-Identifier: GPL-2.0-or-later 0016 * 0017 * ============================================================ */ 0018 0019 #ifndef DIGIKAM_DDATE_EDIT_H 0020 #define DIGIKAM_DDATE_EDIT_H 0021 0022 // Qt includes 0023 0024 #include <QMouseEvent> 0025 #include <QEvent> 0026 #include <QComboBox> 0027 0028 namespace Digikam 0029 { 0030 0031 /** 0032 * A date editing widget that consists of an editable combo box. 0033 * The combo box contains the date in text form, and clicking the combo 0034 * box arrow will display a 'popup' style date picker. 0035 * 0036 * This widget also supports advanced features like allowing the user 0037 * to type in the day name to get the date. The following keywords 0038 * are supported (in the native language): tomorrow, yesterday, today, 0039 * Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. 0040 * 0041 */ 0042 class DDateEdit : public QComboBox 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 0048 explicit DDateEdit(QWidget* const parent = nullptr, const QString& name = QString()); 0049 ~DDateEdit() override; 0050 0051 /** 0052 * @return The date entered. This date could be invalid, 0053 * you have to check validity yourself. 0054 */ 0055 QDate date() const; 0056 0057 /** 0058 * Sets whether the widget is read-only for the user. If read-only, 0059 * the date picker pop-up is inactive, and the displayed date cannot be edited. 0060 * 0061 * @param readOnly True to set the widget read-only, false to set it read-write. 0062 */ 0063 void setReadOnly(bool readOnly); 0064 0065 /** 0066 * @return True if the widget is read-only, false if read-write. 0067 */ 0068 bool isReadOnly() const; 0069 0070 void showPopup() override; 0071 0072 Q_SIGNALS: 0073 0074 /** 0075 * This signal is emitted whenever the user modifies the date. 0076 * The passed date can be invalid. 0077 */ 0078 void dateChanged(const QDate& date); 0079 0080 public Q_SLOTS: 0081 0082 /** 0083 * Sets the date. 0084 * 0085 * @param date The new date to display. This date must be valid or 0086 * it will not be set 0087 */ 0088 void setDate(const QDate& date); 0089 0090 protected Q_SLOTS: 0091 0092 void lineEnterPressed(); 0093 void slotTextChanged(const QString&); 0094 void dateEntered(const QDate&); 0095 void dateSelected(const QDate&); 0096 0097 protected: 0098 0099 bool eventFilter(QObject*, QEvent*) override; 0100 void mousePressEvent(QMouseEvent*) override; 0101 0102 /** 0103 * Sets the date, without altering the display. 0104 * This method is used internally to set the widget's date value. 0105 * As a virtual method, it allows derived classes to perform additional validation 0106 * on the date value before it is set. Derived classes should return true if 0107 * QDate::isValid(@p date) returns false. 0108 * 0109 * @param date The new date to set. 0110 * @return True if the date was set, false if it was considered invalid and 0111 * remains unchanged. 0112 */ 0113 virtual bool assignDate(const QDate& date); 0114 0115 /** 0116 * Fills the keyword map. Re-implement it if you want additional 0117 * keywords. 0118 */ 0119 void setupKeywords(); 0120 0121 private: 0122 0123 QDate parseDate(bool* = nullptr) const; 0124 void updateView(); 0125 0126 private: 0127 0128 class Private; 0129 Private* const d; 0130 }; 0131 0132 } // namespace Digikam 0133 0134 #endif // DIGIKAM_DDATE_EDIT_H