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