File indexing completed on 2024-04-21 14:55:51

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2001 Waldo Bastian (bastian@kde.org)
0003     Copyright (c) 2007 John Layt <john@layt.net>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Library General Public
0007     License version 2 as published by the Free Software Foundation.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDATEWIDGET_H
0021 #define KDATEWIDGET_H
0022 
0023 #include <kdelibs4support_export.h>
0024 
0025 #include <QWidget>
0026 
0027 #include "klocale.h"
0028 
0029 class KCalendarSystem;
0030 
0031 class QDate;
0032 
0033 /**
0034  * @short A date selection widget.
0035  *
0036  * This widget can be used to display or allow user selection of a date.
0037  *
0038  * \image html kdatewidget.png "KDE Date Widget"
0039  *
0040  * @see KDatePicker
0041  *
0042  * @author Waldo Bastian <bastian@kde.org>, John Layt <john@layt.net>
0043  */
0044 class KDELIBS4SUPPORT_EXPORT KDateWidget : public QWidget
0045 {
0046     Q_OBJECT
0047     Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY changed USER true)
0048 //FIXME    Q_PROPERTY( KCalendarSystem calendar READ calendar WRITE setCalendar USER true )
0049 
0050 public:
0051     /**
0052      * Constructs a date selection widget.
0053      */
0054     KDELIBS4SUPPORT_DEPRECATED explicit KDateWidget(QWidget *parent = nullptr);
0055 
0056     /**
0057      * Constructs a date selection widget with the initial date set to @p date.
0058      */
0059     KDELIBS4SUPPORT_DEPRECATED explicit KDateWidget(const QDate &date, QWidget *parent = nullptr);
0060 
0061     /**
0062      * Destructs the date selection widget.
0063      */
0064     ~KDateWidget() override;
0065 
0066     // KDE5 remove const &
0067     /**
0068      * Returns the currently selected date.
0069      */
0070     const QDate &date() const;
0071 
0072     /**
0073      * Changes the selected date to @p date.
0074      *
0075      * @return @c true if the date was successfully set, @c false otherwise
0076      */
0077     bool setDate(const QDate &date);
0078 
0079     /**
0080      * Returns the currently selected calendar system.
0081      *
0082      * @return a KCalendarSystem object
0083      */
0084     const KCalendarSystem *calendar() const;
0085 
0086     /**
0087      * Changes the calendar system to use.  Can use its own local locale if set.
0088      *
0089      * @param calendar the calendar system object to use, defaults to global
0090      *
0091      * @return @c true if the calendar system was successfully set, @c false otherwise
0092      */
0093     bool setCalendar(KCalendarSystem *calendar = nullptr);
0094 
0095     /**
0096      * @since 4.6
0097      *
0098      * Changes the calendar system to use.  Will always use global locale.
0099      *
0100      * @param calendarSystem the calendar system to use
0101      * @return @c true if the calendar system was successfully set, @c false otherwise
0102      */
0103     bool setCalendarSystem(KLocale::CalendarSystem calendarSystem);
0104 
0105 Q_SIGNALS:
0106     /**
0107      * Emitted whenever the date of the widget
0108      * is changed, either with setDate() or via user selection.
0109      */
0110     void changed(const QDate &date);
0111 
0112 protected:
0113     void initWidget(const QDate &date);
0114 
0115 protected Q_SLOTS:
0116     void slotDateChanged();
0117 
0118 private:
0119     class KDateWidgetPrivate;
0120     KDateWidgetPrivate *const d;
0121 };
0122 
0123 #endif // KDATEWIDGET_H
0124