1 | /* -*- C++ -*- |
2 | This file is part of the KDE libraries |
3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) |
4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) |
5 | (C) 2007 John Layt <john@layt.net> |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef KDATEPICKER_H |
23 | #define KDATEPICKER_H |
24 | |
25 | #include <kdeui_export.h> |
26 | |
27 | #include <QtCore/QDateTime> |
28 | #include <QtGui/QFrame> |
29 | |
30 | #include <klocale.h> |
31 | |
32 | class QLineEdit; |
33 | class KDateTable; |
34 | class KCalendarSystem; |
35 | |
36 | /** |
37 | * @short A date selection widget. |
38 | * |
39 | * Provides a widget for calendar date input. |
40 | * |
41 | * Different from the |
42 | * previous versions, it now emits two types of signals, either |
43 | * dateSelected() or dateEntered() (see documentation for both |
44 | * signals). |
45 | * |
46 | * A line edit has been added in the newer versions to allow the user |
47 | * to select a date directly by entering numbers like 19990101 |
48 | * or 990101. |
49 | * |
50 | * \image html kdatepicker.png "KDE Date Widget" |
51 | * |
52 | * @author Tim Gilman, Mirko Boehm |
53 | * |
54 | **/ |
55 | class KDEUI_EXPORT KDatePicker: public QFrame |
56 | { |
57 | Q_OBJECT |
58 | Q_PROPERTY( QDate date READ date WRITE setDate NOTIFY dateChanged USER true ) |
59 | //FIXME Q_PROPERTY( KCalendarSystem calendar READ calendar WRITE setCalendar USER true ) |
60 | Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton ) |
61 | Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize ) |
62 | |
63 | public: |
64 | /** |
65 | * The constructor. The current date will be displayed initially. |
66 | **/ |
67 | explicit KDatePicker( QWidget *parent = 0 ); |
68 | |
69 | /** |
70 | * The constructor. The given date will be displayed initially. |
71 | **/ |
72 | explicit KDatePicker( const QDate &dt, QWidget *parent = 0 ); |
73 | |
74 | /** |
75 | * The destructor. |
76 | **/ |
77 | virtual ~KDatePicker(); |
78 | |
79 | /** The size hint for date pickers. The size hint recommends the |
80 | * minimum size of the widget so that all elements may be placed |
81 | * without clipping. This sometimes looks ugly, so when using the |
82 | * size hint, try adding 28 to each of the reported numbers of |
83 | * pixels. |
84 | **/ |
85 | QSize sizeHint() const; |
86 | |
87 | /** |
88 | * Sets the date. |
89 | * |
90 | * @returns @p false and does not change anything if the date given is invalid. |
91 | **/ |
92 | bool setDate( const QDate& date ); |
93 | |
94 | /** |
95 | * @returns the selected date. |
96 | */ |
97 | const QDate &date() const; |
98 | |
99 | /** |
100 | * Returns the currently selected calendar system. |
101 | * |
102 | * @returns a KCalendarSystem object |
103 | */ |
104 | const KCalendarSystem *calendar() const; |
105 | |
106 | /** |
107 | * Changes the calendar system to use. Can use its own local locale if set. |
108 | * |
109 | * @param calendar the calendar system object to use, defaults to global |
110 | * |
111 | * @return @c true if the calendar system was successfully set, @c false otherwise |
112 | */ |
113 | bool setCalendar( KCalendarSystem *calendar = 0 ); |
114 | |
115 | /** |
116 | * Changes the calendar system to use. Will always use global locale. |
117 | * |
118 | * @param calendarType the calendar system type to use |
119 | * |
120 | * @return @c true if the calendar system was successfully set, @c false otherwise |
121 | */ |
122 | bool setCalendar( const QString &calendarType ); |
123 | |
124 | /** |
125 | * @since 4.6 |
126 | * |
127 | * Changes the calendar system to use. Will always use global locale. |
128 | * |
129 | * @param calendarSystem the calendar system to use |
130 | * @return @c true if the calendar system was successfully set, @c false otherwise |
131 | */ |
132 | bool setCalendarSystem( KLocale::CalendarSystem calendarSystem ); |
133 | |
134 | /** |
135 | * Enables or disables the widget. |
136 | **/ |
137 | void setEnabled( bool enable ); |
138 | |
139 | /** |
140 | * @returns the KDateTable widget child of this KDatePicker |
141 | * widget. |
142 | */ |
143 | KDateTable *dateTable() const; |
144 | |
145 | /** |
146 | * Sets the font size of the widgets elements. |
147 | **/ |
148 | void setFontSize( int ); |
149 | |
150 | /** |
151 | * Returns the font size of the widget elements. |
152 | */ |
153 | int fontSize() const; |
154 | |
155 | /** |
156 | * By calling this method with @p enable = true, KDatePicker will show |
157 | * a little close-button in the upper button-row. Clicking the |
158 | * close-button will cause the KDatePicker's topLevelWidget()'s close() |
159 | * method being called. This is mostly useful for toplevel datepickers |
160 | * without a window manager decoration. |
161 | * @see hasCloseButton |
162 | */ |
163 | void setCloseButton( bool enable ); |
164 | |
165 | /** |
166 | * @returns true if a KDatePicker shows a close-button. |
167 | * @see setCloseButton |
168 | */ |
169 | bool hasCloseButton() const; |
170 | |
171 | protected: |
172 | /// to catch move keyEvents when QLineEdit has keyFocus |
173 | virtual bool eventFilter( QObject *o, QEvent *e ); |
174 | /// the resize event |
175 | virtual void resizeEvent( QResizeEvent* ); |
176 | |
177 | protected Q_SLOTS: |
178 | void dateChangedSlot( const QDate& date ); |
179 | void tableClickedSlot(); |
180 | void monthForwardClicked(); |
181 | void monthBackwardClicked(); |
182 | void yearForwardClicked(); |
183 | void yearBackwardClicked(); |
184 | void selectMonthClicked(); |
185 | void selectYearClicked(); |
186 | void uncheckYearSelector(); |
187 | void lineEnterPressed(); |
188 | void todayButtonClicked(); |
189 | void weekSelected( int ); |
190 | |
191 | Q_SIGNALS: |
192 | /** This signal is emitted each time the selected date is changed. |
193 | * Usually, this does not mean that the date has been entered, |
194 | * since the date also changes, for example, when another month is |
195 | * selected. |
196 | * @see dateSelected |
197 | */ |
198 | void dateChanged( const QDate &date ); |
199 | |
200 | /** This signal is emitted each time a day has been selected by |
201 | * clicking on the table (hitting a day in the current month). It |
202 | * has the same meaning as dateSelected() in older versions of |
203 | * KDatePicker. |
204 | */ |
205 | void dateSelected( const QDate &date ); |
206 | |
207 | /** This signal is emitted when enter is pressed and a VALID date |
208 | * has been entered before into the line edit. Connect to both |
209 | * dateEntered() and dateSelected() to receive all events where the |
210 | * user really enters a date. |
211 | */ |
212 | void dateEntered( const QDate &date ); |
213 | |
214 | /** This signal is emitted when the day has been selected by |
215 | * clicking on it in the table. |
216 | */ |
217 | void tableClicked(); |
218 | |
219 | private: |
220 | void init( const QDate &date ); |
221 | class KDatePickerPrivate; |
222 | friend class KDatePickerPrivate; |
223 | KDatePickerPrivate *const d; |
224 | }; |
225 | |
226 | #endif // KDATEPICKER_H |
227 | |