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        : 2004-04-21
0007  * Description : a menu widget to pick a date.
0008  *
0009  * SPDX-FileCopyrightText: 2004      by Bram Schoenmakers <bramschoenmakers at kde dot nl>
0010  * SPDX-FileCopyrightText: 2006      by Mikolaj Machowski <mikmach at wp dot pl>
0011  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_DDATE_PICKER_POP_UP_H
0018 #define DIGIKAM_DDATE_PICKER_POP_UP_H
0019 
0020 // Qt includes
0021 
0022 #include <QDateTime>
0023 #include <QMenu>
0024 
0025 // Local includes
0026 
0027 #include "ddatepicker.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 /**
0033  * @short This menu helps the user to select a date quickly.
0034  *
0035  * This menu helps the user to select a date quickly. It offers various ways of selecting, e.g. with a DDatePicker or with words like "Tomorrow".
0036  *
0037  * The available items are:
0038  *
0039  * @li NoDate: A menu-item with "No Date". If chosen, the datepicker will emit a null QDate.
0040  * @li DatePicker: Show a DDatePicker-widget.
0041  * @li Words: Show items like "Today", "Tomorrow" or "Next Week".
0042  *
0043  * When supplying multiple items, separate each item with a bitwise OR.
0044  */
0045 class DDatePickerPopup : public QMenu
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050 
0051     enum ItemFlag
0052     {
0053         NoDate     = 1,
0054         DatePicker = 2,
0055         Words      = 4
0056     };
0057 
0058     Q_DECLARE_FLAGS(Items, ItemFlag)
0059 
0060 public:
0061 
0062     /**
0063      * A constructor for the DDatePickerPopup.
0064      *
0065      * @param items List of all desirable items, separated with a bitwise OR.
0066      * @param date Initial date of datepicker-widget.
0067      * @param parent The object's parent.
0068      */
0069     explicit DDatePickerPopup(Items items,
0070                               const QDate& date = QDate::currentDate(),
0071                               QWidget* const parent = nullptr);
0072     ~DDatePickerPopup()             override;
0073 
0074     /**
0075      * @return A pointer to the private variable mDatePicker, an instance of
0076      * DDatePicker.
0077      */
0078     DDatePicker* datePicker() const;
0079 
0080     void setDate(const QDate& date);
0081 
0082 #if 0
0083     /**
0084      * Set items which should be shown and rebuilds the menu afterwards. Only if the menu is not visible.
0085      * @param items List of all desirable items, separated with a bitwise OR.
0086      */
0087     void setItems(int items = 1);
0088 #endif
0089 
0090     /**
0091      * @return Returns the bitwise result of the active items in the popup.
0092      */
0093     int items()               const;
0094 
0095 Q_SIGNALS:
0096 
0097     /**
0098      *  This signal emits the new date (selected with datepicker or other
0099      *  menu-items).
0100      */
0101     void dateChanged(const QDate&);
0102 
0103 protected Q_SLOTS:
0104 
0105     void slotDateChanged(const QDate&);
0106     void slotToday();
0107     void slotTomorrow();
0108     void slotNextWeek();
0109     void slotNextMonth();
0110 
0111     void slotYesterday();
0112     void slotPrevMonday();
0113     void slotPrevFriday();
0114     void slotPrevWeek();
0115     void slotPrevMonth();
0116 
0117     void slotNoDate();
0118 
0119 private:
0120 
0121     void buildMenu();
0122 
0123 private:
0124 
0125     // Disable
0126     DDatePickerPopup() = delete;
0127 
0128 private:
0129 
0130     class Private;
0131     Private* const d;
0132 };
0133 
0134 Q_DECLARE_OPERATORS_FOR_FLAGS(DDatePickerPopup::Items)
0135 
0136 } // namespace Digikam
0137 
0138 #endif // DIGIKAM_DDATE_PICKER_POP_UP_H