File indexing completed on 2024-05-12 05:14:40

0001 /*
0002  *  datepicker.h  -  date chooser widget
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2021-2023 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "editdlg.h"
0012 
0013 #include <QWidget>
0014 #include <QDate>
0015 
0016 class DPToolButton;
0017 class QLabel;
0018 class DayMatrix;
0019 
0020 
0021 /**
0022  *  Displays the calendar for a month, to allow the user to select days.
0023  *  Dates before today are disabled.
0024  */
0025 class DatePicker : public QWidget
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit DatePicker(QWidget* parent = nullptr);
0030     ~DatePicker() override;
0031 
0032     /** Return the currently selected dates, if any. */
0033     QList<QDate> selectedDates() const;
0034 
0035     /** Deselect all dates. */
0036     void clearSelection();
0037 
0038 Q_SIGNALS:
0039      /** Emitted when the user selects or deselects dates.
0040       *
0041      *  @param dates       The dates selected, in date order, or empty if none.
0042      *  @param workChange  The holiday region or work days have changed.
0043      */
0044     void datesSelected(const QList<QDate>& dates, bool workChange);
0045 
0046 protected:
0047     void showEvent(QShowEvent*) override;
0048     bool eventFilter(QObject*, QEvent*) override;
0049 
0050 private Q_SLOTS:
0051     void prevYearClicked();
0052     void prevMonthClicked();
0053     void nextYearClicked();
0054     void nextMonthClicked();
0055     void todayClicked();
0056     void updateToday();
0057     void slotNewAlarm(EditAlarmDlg::Type);
0058     void slotNewAlarmFromTemplate(const KAEvent&);
0059 
0060 private:
0061     void newMonthShown();
0062     void updateDisplay();
0063     DPToolButton* createArrowButton(bool useArrows, const QString& iconId, const QString& arrowIconId = {});
0064     DPToolButton* createArrowButton(const QString& iconId);
0065 
0066     DPToolButton* mPrevYear;
0067     DPToolButton* mPrevMonth;
0068     DPToolButton* mNextYear;
0069     DPToolButton* mNextMonth;
0070     DPToolButton* mToday;
0071     QLabel*       mMonthYear;
0072     QLabel*       mDayNames;
0073     DayMatrix*    mDayMatrix;
0074     QDate         mMonthShown;     // 1st of month currently displayed
0075     QDate         mStartDate;      // earliest date currently displayed
0076 };
0077 
0078 // vim: et sw=4: