|
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 // |
|
27 // W A R N I N G |
|
28 // ------------- |
|
29 // |
|
30 // This file is not part of the Hb API. It exists purely as an |
|
31 // implementation detail. This file may change from version to |
|
32 // version without notice, or even be removed. |
|
33 // |
|
34 // We mean it. |
|
35 // |
|
36 |
|
37 #include <QtDebug> |
|
38 |
|
39 #include <QTextDocument> |
|
40 #include <QTextBlock> |
|
41 #include <QRegExp> |
|
42 |
|
43 #include "hbdatetimeedit_p.h" |
|
44 #include "hbdatetimeedit.h" |
|
45 #include "hbdatetimevalidator_p.h" |
|
46 #include "hbinputeditorinterface.h" |
|
47 |
|
48 HbDateTimeEditPrivate::HbDateTimeEditPrivate () : |
|
49 HbLineEditPrivate(), |
|
50 validator(new HbDateTimeValidator()), |
|
51 isSetDateTimeActive( false ) |
|
52 { |
|
53 } |
|
54 |
|
55 HbDateTimeEditPrivate::~HbDateTimeEditPrivate () |
|
56 { |
|
57 delete validator; |
|
58 } |
|
59 |
|
60 void HbDateTimeEditPrivate::init() |
|
61 { |
|
62 Q_Q(HbDateTimeEdit); |
|
63 |
|
64 QString defaultFormat = QLocale().dateFormat(QLocale::ShortFormat); |
|
65 validator->setDisplayFormat(defaultFormat); |
|
66 q->setValidator(validator); |
|
67 q->setDateTime(QDateTime::currentDateTime()); |
|
68 |
|
69 #if QT_VERSION >= 0x040600 |
|
70 q->setInputMethodHints(Qt::ImhDigitsOnly); |
|
71 #endif |
|
72 } |
|
73 |
|
74 void HbDateTimeEditPrivate::init(const QDate &date) |
|
75 { |
|
76 Q_Q(HbDateTimeEdit); |
|
77 |
|
78 QString defaultFormat = QLocale().dateFormat(QLocale::ShortFormat); |
|
79 validator->setDisplayFormat(defaultFormat); |
|
80 q->setValidator(validator); |
|
81 q->setDateTime(QDateTime(date)); |
|
82 |
|
83 #if QT_VERSION >= 0x040600 |
|
84 q->setInputMethodHints(Qt::ImhDigitsOnly); |
|
85 #endif |
|
86 } |
|
87 |
|
88 void HbDateTimeEditPrivate::init(const QTime &time) |
|
89 { |
|
90 Q_Q(HbDateTimeEdit); |
|
91 |
|
92 QString defaultFormat = QLocale().timeFormat(QLocale::ShortFormat); |
|
93 validator->setDisplayFormat(defaultFormat); |
|
94 q->setValidator(validator); |
|
95 q->setDateTime(QDateTime(QDate::currentDate(), time)); |
|
96 |
|
97 #if QT_VERSION >= 0x040600 |
|
98 q->setInputMethodHints(Qt::ImhDigitsOnly); |
|
99 #endif |
|
100 } |
|
101 |
|
102 void HbDateTimeEditPrivate::init(const QDateTime &dateTime) |
|
103 { |
|
104 Q_Q(HbDateTimeEdit); |
|
105 |
|
106 QString defaultFormat = QLocale().dateTimeFormat(QLocale::ShortFormat); |
|
107 validator->setDisplayFormat(defaultFormat); |
|
108 q->setValidator(validator); |
|
109 q->setDateTime(dateTime); |
|
110 |
|
111 #if QT_VERSION >= 0x040600 |
|
112 q->setInputMethodHints(Qt::ImhDigitsOnly); |
|
113 #endif |
|
114 } |
|
115 |
|
116 void HbDateTimeEditPrivate::_q_textChanged() |
|
117 { |
|
118 if(!isSetDateTimeActive) { |
|
119 QDateTime tmpDateTime = QDateTime::fromString(doc->toPlainText(), validator->displayFormat()); |
|
120 |
|
121 if( tmpDateTime.isValid() ) { |
|
122 dateTime = tmpDateTime; |
|
123 } |
|
124 } |
|
125 HbLineEditPrivate::_q_textChanged(); |
|
126 } |