File indexing completed on 2024-04-21 14:47:02

0001 /*
0002     SPDX-FileCopyrightText: 2010 Akarsh Simha <akarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ui_genericcalendarwidget.h"
0010 
0011 #include <QDate>
0012 
0013 /**
0014  *@class GenericCalendarWidget
0015  *@author Akarsh Simha
0016  *@version 1.0
0017  *@short Uses any KDateTable subclass for the date table and provides a calendar with options to choose a month / year.
0018  *@note This supports only the Gregorian calendar system for simplicity.
0019  *@note This shouldn't be the way to do things in the first place, but
0020  *      this is until KDatePicker starts supporting overridden
0021  *      KDateTables and the like
0022  */
0023 
0024 class GenericCalendarWidget : public QWidget, public Ui::GenericCalendarWidgetUi
0025 {
0026     Q_OBJECT
0027 
0028   public:
0029     /** @short Constructor. Sets up the Ui, connects signals to slots etc. */
0030     explicit GenericCalendarWidget(KDateTable &dateTable, QWidget *parent = nullptr);
0031 
0032     /** @short Empty destructor */
0033     virtual ~GenericCalendarWidget() override = default;
0034 
0035     /** @short Returns the selected date */
0036     const QDate &date() const;
0037 
0038   public slots:
0039     /**
0040      * @short Set the month
0041      * @param month  The month to choose
0042      */
0043     bool setMonth(int month);
0044 
0045     /**
0046      * @short Set the year
0047      * @param year  The year to choose
0048      */
0049     bool setYear(int year);
0050 
0051     /**
0052      * @short Set the selected day of month
0053      * @param date_ The date of the month to choose
0054      */
0055     bool setDate(int date_);
0056 
0057     /**
0058      * @short Set the selected date
0059      * @param date_ The date to set
0060      */
0061     bool setDate(const QDate &date_);
0062 
0063   signals:
0064     /**
0065      * @short Emitted when the date has been changed
0066      * @note Emitted by dateTableDateChanged() which subscribes to KDateTable::dateChanged()
0067      */
0068     void dateChanged(const QDate &date_);
0069 
0070   private slots:
0071 
0072     /** @short Called when the previous / next year / month buttons are clicked */
0073     void previousYearClicked();
0074     void nextYearClicked();
0075     void previousMonthClicked();
0076     void nextMonthClicked();
0077 
0078     /** @short Called when the year changes through the spin box */
0079     void yearChanged(int year);
0080 
0081     /** @short Called when the month changes through the combo box */
0082     void monthChanged(int month);
0083 
0084     /**
0085      * @short Subscribes to KDateTable::dateChanged() and echoes it by emitting this widget's dateChanged signals
0086      * @note For details on parameters, see KDateTable::dateChanged()
0087      */
0088     void dateChangedSlot(const QDate &date_);
0089 
0090   private:
0091     /** @short Fills the month combo box with month names */
0092     void populateMonthNames();
0093 
0094     /** @short Returns a link to the KCalendarSystem in use */
0095     const KCalendarSystem *calendar() const;
0096 
0097     QDate m_Date;
0098 };