moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / libkdeedu / extdate / extdatepicker.h
blob03fe749e7eb3533a310a80e4ae93df68cfd1817a
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) 2004 Jason Harris (jharris@30doradus.org)
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 #ifndef EXTDATEPICKER_H
23 #define EXTDATEPICKER_H
26 #include "extdatetime.h"
28 class QLineEdit;
29 class QToolButton;
30 class ExtDateValidator;
31 class ExtDateTable;
33 /**
34 * Provides a widget for calendar date input.
36 * Different from the
37 * previous versions, it now emits two types of signals, either
38 * dateSelected() or dateEntered() (see documentation for both
39 * signals).
41 * A line edit has been added in the newer versions to allow the user
42 * to select a date directly by entering numbers like 19990101
43 * or 990101.
45 * \image html kdatepicker.png "KDE Date Widget"
47 * @version $Id$
48 * @author Tim Gilman, Mirko Boehm
50 * @short A date selection widget.
51 **/
52 class KDE_EXPORT ExtDatePicker: public QFrame
54 Q_OBJECT
55 // Q_PROPERTY( ExtDate date READ date WRITE setDate)
56 Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton )
57 Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
59 public:
60 /** The usual constructor. The given date will be displayed
61 * initially.
62 **/
63 ExtDatePicker(QWidget *parent=0,
64 ExtDate=ExtDate::currentDate(),
65 const char *name=0);
67 /** The usual constructor. The given date will be displayed
68 * initially.
69 * @since 3.1
70 **/
71 ExtDatePicker(QWidget *parent,
72 ExtDate,
73 const char *name,
74 WFlags f); // ### KDE 4.0: Merge
76 /**
77 * Standard qt widget constructor. The initial date will be the
78 * current date.
79 * @since 3.1
81 ExtDatePicker( QWidget *parent, const char *name );
83 /**
84 * The destructor.
85 **/
86 virtual ~ExtDatePicker();
88 /** The size hint for date pickers. The size hint recommends the
89 * minimum size of the widget so that all elements may be placed
90 * without clipping. This sometimes looks ugly, so when using the
91 * size hint, try adding 28 to each of the reported numbers of
92 * pixels.
93 **/
94 QSize sizeHint() const;
96 /**
97 * Sets the date.
99 * @returns @p false and does not change anything
100 * if the date given is invalid.
102 bool setDate(const ExtDate&);
105 * Returns the selected date.
106 * @deprecated
108 const ExtDate& getDate() const KDE_DEPRECATED;
111 * @returns the selected date.
113 const ExtDate &date() const;
116 * Enables or disables the widget.
118 void setEnabled(bool);
121 * @returns the ExtDateTable widget child of this ExtDatePicker
122 * widget.
123 * @since 3.2
125 ExtDateTable *dateTable() const { return table; };
128 * Sets the font size of the widgets elements.
130 void setFontSize(int);
132 * Returns the font size of the widget elements.
134 int fontSize() const
135 { return fontsize; }
138 * By calling this method with @p enable = true, ExtDatePicker will show
139 * a little close-button in the upper button-row. Clicking the
140 * close-button will cause the ExtDatePicker's topLevelWidget()'s close()
141 * method being called. This is mostly useful for toplevel datepickers
142 * without a window manager decoration.
143 * @see hasCloseButton
144 * @since 3.1
146 void setCloseButton( bool enable );
149 * @returns true if a ExtDatePicker shows a close-button.
150 * @see setCloseButton
151 * @since 3.1
153 bool hasCloseButton() const;
155 protected:
156 /// to catch move keyEvents when QLineEdit has keyFocus
157 virtual bool eventFilter(QObject *o, QEvent *e );
158 /// the resize event
159 virtual void resizeEvent(QResizeEvent*);
160 /// the year forward button
161 QToolButton *yearForward;
162 /// the year backward button
163 QToolButton *yearBackward;
164 /// the month forward button
165 QToolButton *monthForward;
166 /// the month backward button
167 QToolButton *monthBackward;
168 /// the button for selecting the month directly
169 QToolButton *selectMonth;
170 /// the button for selecting the year directly
171 QToolButton *selectYear;
172 /// the line edit to enter the date directly
173 QLineEdit *line;
174 /// the validator for the line edit:
175 ExtDateValidator *val;
176 /// the date table
177 ExtDateTable *table;
178 /// the size calculated during resize events
179 // QSize sizehint;
180 /// the widest month string in pixels:
181 QSize maxMonthRect;
182 protected slots:
183 void dateChangedSlot(const ExtDate&);
184 void tableClickedSlot();
185 void monthForwardClicked();
186 void monthBackwardClicked();
187 void yearForwardClicked();
188 void yearBackwardClicked();
190 * @since 3.1
191 * @deprecated in 3.2
193 void selectWeekClicked();
195 * @since 3.1
197 void selectMonthClicked();
199 * @since 3.1
201 void selectYearClicked();
203 * @since 3.1
205 void lineEnterPressed();
207 * @since 3.2
209 void todayButtonClicked();
211 * @since 3.2
213 void weekSelected(int);
215 signals:
216 /** This signal is emitted each time the selected date is changed.
217 * Usually, this does not mean that the date has been entered,
218 * since the date also changes, for example, when another month is
219 * selected.
220 * @see dateSelected
222 void dateChanged(const ExtDate&);
223 /** This signal is emitted each time a day has been selected by
224 * clicking on the table (hitting a day in the current month). It
225 * has the same meaning as dateSelected() in older versions of
226 * ExtDatePicker.
228 void dateSelected(const ExtDate&);
229 /** This signal is emitted when enter is pressed and a VALID date
230 * has been entered before into the line edit. Connect to both
231 * dateEntered() and dateSelected() to receive all events where the
232 * user really enters a date.
234 void dateEntered(const ExtDate&);
235 /** This signal is emitted when the day has been selected by
236 * clicking on it in the table.
238 void tableClicked();
240 private:
241 /// the font size for the widget
242 int fontsize;
244 protected:
245 virtual void virtual_hook( int id, void* data );
246 private:
247 void init( const ExtDate &dt );
248 void fillWeeksCombo(const ExtDate &date);
249 class ExtDatePickerPrivate;
250 ExtDatePickerPrivate *d;
253 #endif // EXTDATEPICKER_H