|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbdatetimepicker_p.h" |
|
27 #include "hbdatetimepicker.h" |
|
28 #include "hbstyleoption.h" |
|
29 |
|
30 /*! |
|
31 @alpha |
|
32 @hbwidgets |
|
33 \class HbDateTimePicker |
|
34 \brief HbDateTimePicker class provides a widget for picking the date, time, date and time. |
|
35 By default datetime picker will be created, with date functionality only. |
|
36 For exclusive time or date picker creation, use QTime or QDate variable as parameter for the constructor. |
|
37 \li Date and Time |
|
38 \li Date |
|
39 \li Time |
|
40 |
|
41 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,51} |
|
42 |
|
43 By default, display format is from HbExtendedLocale. User can set the format using \sa setDisplayFormat. |
|
44 Based on the display format the tumblers or sections will be rearranged. |
|
45 |
|
46 HbDateTimePicker provides various date and time range functionalities. |
|
47 currently the date range is independent of the time range. |
|
48 \sa setDateRange \sa setTimeRange \sa setDateTimeRange |
|
49 \sa setMinimumTime \sa setMaximumTime \sa setMinimumDate \sa setMaximumDate |
|
50 \sa setMinimumDateTime \sa setMaximumDateTime |
|
51 */ |
|
52 |
|
53 /*! |
|
54 \fn void dateChanged(const QDate &date) |
|
55 |
|
56 This signal is emitted when item selection changes in any of the date pickers in the datetimepicker widget. |
|
57 \a date selected by the user. |
|
58 |
|
59 */ |
|
60 |
|
61 /*! |
|
62 \fn void timeChanged(const QTime &time) |
|
63 |
|
64 This signal is emitted when item selection changes in any of the time pickers in the datetimepicker widget. |
|
65 \a time selected by the user. |
|
66 |
|
67 */ |
|
68 |
|
69 /*! |
|
70 \fn void dateTimeChanged(const QDateTime &datetime) |
|
71 |
|
72 This signal is emitted when item selection changes in any of the pickers in the datetimepicker widget. |
|
73 \a datetime selected by the user. |
|
74 |
|
75 */ |
|
76 |
|
77 /*! |
|
78 Constructs date picker widget by default. |
|
79 */ |
|
80 HbDateTimePicker::HbDateTimePicker( QGraphicsItem *parent ): |
|
81 HbWidget(*new HbDateTimePickerPrivate, parent) |
|
82 { |
|
83 Q_D(HbDateTimePicker); |
|
84 |
|
85 //no mode passed so it should take date as mode by default |
|
86 d->init(QVariant::Date); |
|
87 |
|
88 setDateTime(QDateTime::currentDateTime()); |
|
89 } |
|
90 |
|
91 /*! |
|
92 Constructs datetime picker widget. |
|
93 */ |
|
94 HbDateTimePicker::HbDateTimePicker(const QDateTime &datetime, QGraphicsItem *parent ): |
|
95 HbWidget(*new HbDateTimePickerPrivate, parent) |
|
96 { |
|
97 Q_D(HbDateTimePicker); |
|
98 |
|
99 d->init(QVariant::DateTime); |
|
100 setDateTime(datetime); |
|
101 } |
|
102 |
|
103 /*! |
|
104 Constructs date picker widget with default locale's date format. |
|
105 */ |
|
106 HbDateTimePicker::HbDateTimePicker(const QDate &date, QGraphicsItem *parent ): |
|
107 HbWidget(*new HbDateTimePickerPrivate, parent) |
|
108 { |
|
109 Q_D(HbDateTimePicker); |
|
110 |
|
111 d->init(QVariant::Date); |
|
112 setDate(date); |
|
113 } |
|
114 |
|
115 /*! |
|
116 Constructs time picker widget with default locale's time format. |
|
117 */ |
|
118 HbDateTimePicker::HbDateTimePicker(const QTime &time, QGraphicsItem *pParent ): |
|
119 HbWidget(*new HbDateTimePickerPrivate, pParent) |
|
120 { |
|
121 Q_D(HbDateTimePicker); |
|
122 |
|
123 d->init(QVariant::Time); |
|
124 setTime(time); |
|
125 } |
|
126 |
|
127 /*! |
|
128 Internal. Protected constructor for derivations. |
|
129 the default mode is DateTimeMode, if other mode is required, set the mDateTimeMode variable. |
|
130 this does not set any default datetime, needs to be explicitly done in the derived constructor. |
|
131 |
|
132 \sa setDateTime, setTime, setDate |
|
133 */ |
|
134 HbDateTimePicker::HbDateTimePicker(HbDateTimePickerPrivate &dd, QGraphicsItem *parent): |
|
135 HbWidget(dd, parent) |
|
136 { |
|
137 Q_D(HbDateTimePicker); |
|
138 |
|
139 d->init(QVariant::DateTime); |
|
140 } |
|
141 |
|
142 bool HbDateTimePicker::event(QEvent *e) |
|
143 { |
|
144 Q_D(HbDateTimePicker); |
|
145 bool result = HbWidget::event(e); |
|
146 if (e->type()==QEvent::LayoutRequest) { |
|
147 updatePrimitives(); |
|
148 d->updateDividers(); |
|
149 } |
|
150 return result; |
|
151 } |
|
152 |
|
153 /*! |
|
154 Destructor. |
|
155 */ |
|
156 HbDateTimePicker::~HbDateTimePicker() |
|
157 { |
|
158 } |
|
159 |
|
160 /*! |
|
161 Returns current display format as QString value. |
|
162 |
|
163 \sa setDisplayFormat() |
|
164 */ |
|
165 QString HbDateTimePicker::displayFormat() const |
|
166 { |
|
167 Q_D(const HbDateTimePicker); |
|
168 return d->mFormat; |
|
169 } |
|
170 |
|
171 /*! |
|
172 Sets the display \a format . eg: DDMMYY, MMDDYY |
|
173 |
|
174 These expressions may be used for the format: |
|
175 |
|
176 <TABLE> |
|
177 <TR><TD><b><i> Expression </TD><TD> Output </TD></i></b></TR> |
|
178 <TR><TD> d </TD><TD><i> The day as a number without a leading zero (1 to 31)</i></TD></TR> |
|
179 <TR><TD> dd </TD><TD><i> The day as a number with a leading zero (01 to 31) </i></TD></TR> |
|
180 <TR><TD> ddd </TD><TD><i> |
|
181 The abbreviated localized day name (e.g. 'Mon' to 'Sun'). |
|
182 Uses QDate::shortDayName().</i></TD></TR> |
|
183 <TR><TD> dddd </TD><TD><i> |
|
184 The long localized day name (e.g. 'Monday' to 'Sunday'). |
|
185 Uses QDate::longDayName().</i></TD></TR> |
|
186 <TR><TD> M </TD><TD><i> The month as a number without a leading zero (1 to 12)</i></TD></TR> |
|
187 <TR><TD> MM </TD><TD><i> The month as a number with a leading zero (01 to 12)</i></TD></TR> |
|
188 <TR><TD> MMM </TD><TD><i> |
|
189 The abbreviated localized month name (e.g. 'Jan' to 'Dec'). |
|
190 Uses QDate::shortMonthName().</i></TD></TR> |
|
191 <TR><TD> MMMM </TD><TD><i> |
|
192 The long localized month name (e.g. 'January' to 'December'). |
|
193 Uses QDate::longMonthName().</i></TD></TR> |
|
194 <TR><TD> yy </TD><TD><i> The year as two digit number (00 to 99)</i></TD></TR> |
|
195 <TR><TD> yyyy </TD><TD><i> The year as four digit number. If the year is negative, |
|
196 a minus sign is prepended in addition.</i></TD></TR> |
|
197 </TABLE> |
|
198 |
|
199 NOTE:setDisplayFormat works only when the seperators are mentioned in the format like 'dd.mm.yy' or 'dd mm yy', this |
|
200 will be fixed in the future versions. |
|
201 |
|
202 \sa displayFormat() |
|
203 */ |
|
204 void HbDateTimePicker::setDisplayFormat(const QString &format) |
|
205 { |
|
206 Q_D(HbDateTimePicker); |
|
207 |
|
208 if(d->isFormatValid(format)){ |
|
209 d->mFormat = format; |
|
210 d->parseDisplayFormat(format); |
|
211 d->rearrangeTumbleViews(); |
|
212 d->emitDateTimeChange(); |
|
213 }//End If format is valid |
|
214 } |
|
215 |
|
216 /*! |
|
217 Returns the current date in QDate format. |
|
218 |
|
219 \sa setDate |
|
220 */ |
|
221 QDate HbDateTimePicker::date() const |
|
222 { |
|
223 Q_D(const HbDateTimePicker); |
|
224 |
|
225 return d->mDateTime.date(); |
|
226 } |
|
227 |
|
228 /*! |
|
229 Sets the current \a date in the form of QDate. |
|
230 |
|
231 \sa date |
|
232 */ |
|
233 void HbDateTimePicker::setDate(const QDate& date) |
|
234 { |
|
235 Q_D(HbDateTimePicker); |
|
236 setDateTime(QDateTime(date,d->mDateTime.time())); |
|
237 } |
|
238 |
|
239 /*! |
|
240 Returns minimum date in QDate format. |
|
241 |
|
242 \sa setMinimumDate |
|
243 */ |
|
244 QDate HbDateTimePicker::minimumDate()const |
|
245 { |
|
246 Q_D(const HbDateTimePicker); |
|
247 return d->mMinimumDate.date(); |
|
248 } |
|
249 |
|
250 /*! |
|
251 Sets minimum \a date in QDate format. |
|
252 |
|
253 \sa minimumDate |
|
254 */ |
|
255 void HbDateTimePicker::setMinimumDate(const QDate& date) |
|
256 { |
|
257 Q_D(HbDateTimePicker); |
|
258 setMinimumDateTime(QDateTime(date, d->mMinimumDate.time())); |
|
259 } |
|
260 |
|
261 /*! |
|
262 Returns maximum date in QDate format. |
|
263 |
|
264 \sa setMaximumDate |
|
265 */ |
|
266 QDate HbDateTimePicker::maximumDate()const |
|
267 { |
|
268 Q_D(const HbDateTimePicker); |
|
269 return d->mMaximumDate.date(); |
|
270 } |
|
271 |
|
272 /*! |
|
273 Sets maximum \a date in QDate format. |
|
274 |
|
275 \sa maximumDate |
|
276 */ |
|
277 void HbDateTimePicker::setMaximumDate(const QDate& date) |
|
278 { |
|
279 Q_D(HbDateTimePicker); |
|
280 setMaximumDateTime(QDateTime(date, d->mMaximumDate.time())); |
|
281 } |
|
282 |
|
283 /*! |
|
284 Sets minimum \a minDate and maximum \a maxDate dates in QDate format. |
|
285 |
|
286 \sa setMinimumDate \sa setMaximumDate |
|
287 */ |
|
288 void HbDateTimePicker::setDateRange(const QDate &minDate, const QDate &maxDate) |
|
289 { |
|
290 Q_D(HbDateTimePicker); |
|
291 setDateTimeRange(QDateTime(minDate, d->mMinimumDate.time()), |
|
292 QDateTime(maxDate, d->mMaximumDate.time())); |
|
293 } |
|
294 |
|
295 /*! |
|
296 Returns the current datetime in QDateTime format. |
|
297 |
|
298 \sa setDateTime |
|
299 */ |
|
300 QDateTime HbDateTimePicker::dateTime()const |
|
301 { |
|
302 Q_D(const HbDateTimePicker); |
|
303 return d->mDateTime; |
|
304 } |
|
305 |
|
306 /*! |
|
307 Sets the current \a datetime in the form of QDateTime. |
|
308 |
|
309 \sa dateTime |
|
310 */ |
|
311 void HbDateTimePicker::setDateTime(const QDateTime &datetime) |
|
312 { |
|
313 Q_D(HbDateTimePicker); |
|
314 d->setDateTime(datetime); |
|
315 } |
|
316 |
|
317 /*! |
|
318 Returns minimum date time in QDateTime format. |
|
319 |
|
320 \sa setMinimumDateTime |
|
321 */ |
|
322 QDateTime HbDateTimePicker::minimumDateTime()const |
|
323 { |
|
324 Q_D(const HbDateTimePicker); |
|
325 return d->mMinimumDate; |
|
326 } |
|
327 |
|
328 /*! |
|
329 Sets minimum \a datetime in QDateTime format. |
|
330 <b><i>Note:</i></b> There's no link between Date and time in this API, using this API as of now |
|
331 would be similar to using combination of \sa setMinimumDate and \sa setMinimumTime |
|
332 |
|
333 \sa minimumDateTime \sa setMinimumDate \sa setMinimumTime |
|
334 */ |
|
335 void HbDateTimePicker::setMinimumDateTime(const QDateTime& datetime) |
|
336 { |
|
337 Q_D(HbDateTimePicker); |
|
338 d->setMinimumDateTime(datetime); |
|
339 } |
|
340 |
|
341 /*! |
|
342 Returns maximum date time in QDateTime format. |
|
343 |
|
344 \sa setMaximumDate |
|
345 */ |
|
346 QDateTime HbDateTimePicker::maximumDateTime()const |
|
347 { |
|
348 Q_D(const HbDateTimePicker); |
|
349 return d->mMaximumDate; |
|
350 } |
|
351 |
|
352 /*! |
|
353 Sets maximum \a datetime in QDateTime format. |
|
354 |
|
355 <b><i>Note:</i></b> There's no link between Date and time in this API, using this API as of now |
|
356 would be similar to using combination of \sa setMaximumDate and \sa setMaximumTime |
|
357 |
|
358 \sa maximumDateTime \sa setMaximumDate \sa setMaximumTime |
|
359 */ |
|
360 void HbDateTimePicker::setMaximumDateTime(const QDateTime& date) |
|
361 { |
|
362 Q_D(HbDateTimePicker); |
|
363 d->setMaximumDateTime(date); |
|
364 } |
|
365 |
|
366 /*! |
|
367 Sets minimum \a minDatetime and maximum \a maxDatetime datetimes in QDateTime format. |
|
368 |
|
369 <b><i>Note:</i></b> There's no link between Date and time in this API, using this API as of now |
|
370 would be similar to using combination of \sa setMinimumDate \sa setMaximumTime and |
|
371 \sa setMinimumTime, \sa setMaximumTime |
|
372 |
|
373 \sa setMinimumDateTime \sa setMaximumDateTime \sa setMinimumDate \sa setMaximumDate |
|
374 \sa setMinimumTime \sa setMaximumTime |
|
375 */ |
|
376 void HbDateTimePicker::setDateTimeRange(const QDateTime &minDateTime, const QDateTime &maxDateTime) |
|
377 { |
|
378 Q_D(HbDateTimePicker); |
|
379 d->setDateTimeRange(minDateTime, maxDateTime); |
|
380 } |
|
381 |
|
382 /*! |
|
383 Returns the current time in QTime format. |
|
384 |
|
385 \sa setTime |
|
386 */ |
|
387 QTime HbDateTimePicker::time() const |
|
388 { |
|
389 Q_D(const HbDateTimePicker); |
|
390 return d->mDateTime.time(); |
|
391 } |
|
392 |
|
393 /*! |
|
394 Sets the current \a time in the form of QTime. |
|
395 |
|
396 \sa time |
|
397 */ |
|
398 void HbDateTimePicker::setTime(const QTime &time) |
|
399 { |
|
400 Q_D(HbDateTimePicker); |
|
401 setDateTime(QDateTime(d->mDateTime.date(), time)); |
|
402 } |
|
403 |
|
404 /*! |
|
405 Returns minimum time in QTime format. |
|
406 |
|
407 \sa setMinimumTime |
|
408 */ |
|
409 QTime HbDateTimePicker::minimumTime()const |
|
410 { |
|
411 Q_D(const HbDateTimePicker); |
|
412 return d->mMinimumDate.time(); |
|
413 } |
|
414 |
|
415 /*! |
|
416 Sets minimum \a time in QTime format. |
|
417 |
|
418 \sa minimumTime |
|
419 */ |
|
420 void HbDateTimePicker::setMinimumTime(const QTime& time) |
|
421 { |
|
422 Q_D(HbDateTimePicker); |
|
423 setMinimumDateTime(QDateTime(d->mDateTime.date(),time)); |
|
424 } |
|
425 |
|
426 /*! |
|
427 Returns maximum time in QTime format. |
|
428 |
|
429 \sa setMaximumTime |
|
430 */ |
|
431 QTime HbDateTimePicker::maximumTime()const |
|
432 { |
|
433 Q_D(const HbDateTimePicker); |
|
434 return d->mMaximumDate.time(); |
|
435 } |
|
436 |
|
437 /*! |
|
438 Sets maximum \a time in QTime format. |
|
439 |
|
440 \sa maximumTime |
|
441 */ |
|
442 void HbDateTimePicker::setMaximumTime(const QTime& time) |
|
443 { |
|
444 Q_D(HbDateTimePicker); |
|
445 setMaximumDateTime(QDateTime(d->mMaximumDate.date(), time)); |
|
446 } |
|
447 |
|
448 /*! |
|
449 Sets minimum \a minTime and maximum \a maxTime in QTime format. |
|
450 |
|
451 \sa setMinimumTime \sa setMaximumTime |
|
452 */ |
|
453 void HbDateTimePicker::setTimeRange(const QTime &minTime, const QTime &maxTime) |
|
454 { |
|
455 Q_D(HbDateTimePicker); |
|
456 setDateTimeRange(QDateTime(d->mMinimumDate.date(), minTime), |
|
457 QDateTime(d->mMinimumDate.date(), maxTime)); |
|
458 } |
|
459 |
|
460 QGraphicsItem *HbDateTimePicker::primitive(HbStyle::Primitive primitive) const |
|
461 { |
|
462 Q_D(const HbDateTimePicker); |
|
463 switch(primitive) { |
|
464 case HbStyle::P_DateTimePicker_background: |
|
465 return d->mBackground; |
|
466 case HbStyle::P_DateTimePicker_frame: |
|
467 return d->mFrame; |
|
468 default: |
|
469 return HbWidget::primitive(primitive); |
|
470 } |
|
471 } |
|
472 |
|
473 void HbDateTimePicker::setGeometry(const QRectF &rect) |
|
474 { |
|
475 HbWidget::setGeometry(rect); |
|
476 updatePrimitives(); |
|
477 } |
|
478 |
|
479 void HbDateTimePicker::updatePrimitives() |
|
480 { |
|
481 Q_D(HbDateTimePicker); |
|
482 HbStyleOption option; |
|
483 initStyleOption(&option); |
|
484 if(d->mBackground) { |
|
485 style()->updatePrimitive(d->mBackground,HbStyle::P_DateTimePicker_background,&option); |
|
486 } |
|
487 if(d->mFrame) { |
|
488 style()->updatePrimitive(d->mFrame,HbStyle::P_DateTimePicker_frame,&option); |
|
489 } |
|
490 } |
|
491 |
|
492 #include "moc_hbdatetimepicker.cpp" |