|
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 "hbinputdialog_p.h" |
|
27 #include "hbinputdialogcontent_p.h" |
|
28 #include "hbstyleoptioninputdialog.h" |
|
29 |
|
30 #include <hblineedit.h> |
|
31 #include <hbaction.h> |
|
32 #include <hbvalidator.h> |
|
33 #include <hbstyle.h> |
|
34 #include <hbinputeditorinterface.h> |
|
35 #include <hbinputsettingproxy.h> |
|
36 #include <hbmainwindow.h> |
|
37 |
|
38 //#define HBINPUTDIALOG_DEBUG |
|
39 #ifdef HBINPUTDIALOG_DEBUG |
|
40 #include <QtDebug> |
|
41 #endif |
|
42 |
|
43 HbInputDialogContentWidget::HbInputDialogContentWidget(HbInputDialogPrivate* priv,QGraphicsItem* parent) : |
|
44 HbWidget(parent), |
|
45 d(priv), |
|
46 mLabel1(0), |
|
47 mLabel2(0), |
|
48 mEdit2(0), |
|
49 mAdditionalRowVisible(false) |
|
50 { |
|
51 mLabel1 = style()->createPrimitive(HbStyle::P_InputDialog_text,this); |
|
52 mEdit1 = new HbLineEdit(this); |
|
53 HbStyle::setItemName(mEdit1, "text-1"); |
|
54 |
|
55 this->setProperty("additionalRowVisible",QVariant(false)); |
|
56 } |
|
57 |
|
58 |
|
59 void HbInputDialogContentWidget::setAdditionalRowVisible(bool visible) |
|
60 { |
|
61 mAdditionalRowVisible = visible; |
|
62 |
|
63 if(!mLabel2 && visible) { |
|
64 mLabel2 = style()->createPrimitive(HbStyle::P_InputDialog_additional_text,this); |
|
65 } |
|
66 |
|
67 if(!mEdit2 && visible) { |
|
68 //Retrieve the cached data here and assign// |
|
69 mEdit2 = new HbLineEdit(this); |
|
70 mEdit2->setText(d->mText); |
|
71 mEdit2->setEchoMode(d->mEchoMode); |
|
72 //Retrieve the cached data here// |
|
73 d->setInputMode(mEdit2, d->mSecondaryMode); |
|
74 HbStyle::setItemName(mEdit2, "text-2"); |
|
75 this->setProperty("additionalRowVisible",QVariant(true)); |
|
76 } |
|
77 if(!visible) { |
|
78 if(mEdit2) { |
|
79 delete mEdit2; |
|
80 mEdit2 = 0; |
|
81 } |
|
82 this->setProperty("additionalRowVisible",QVariant(false)); |
|
83 } |
|
84 repolish(); |
|
85 } |
|
86 |
|
87 |
|
88 HbInputDialogPrivate::HbInputDialogPrivate() : |
|
89 mCustomButtonBank(0), |
|
90 mDotButton(0), |
|
91 mDashButton(0), |
|
92 mValid(0), |
|
93 mSecondaryMode(HbInputDialog::TextInput), |
|
94 mEchoMode(HbLineEdit::Normal), |
|
95 mPromptText(), |
|
96 mPromptAdditionalText(), |
|
97 mText() |
|
98 { |
|
99 } |
|
100 |
|
101 |
|
102 HbInputDialogPrivate::~HbInputDialogPrivate() |
|
103 { |
|
104 if(primaryAction){ |
|
105 delete primaryAction; |
|
106 } |
|
107 if(secondaryAction){ |
|
108 delete secondaryAction; |
|
109 } |
|
110 } |
|
111 |
|
112 |
|
113 void HbInputDialogPrivate::init() |
|
114 { |
|
115 #ifdef HBINPUTDIALOG_DEBUG |
|
116 qDebug()<<" Entering init()"; |
|
117 #endif |
|
118 Q_Q(HbInputDialog); |
|
119 |
|
120 mPrimaryMode = HbInputDialog::TextInput; //Default input mode is text input |
|
121 |
|
122 //Populate the widget |
|
123 mContentWidget = new HbInputDialogContentWidget(this); |
|
124 |
|
125 q->setContentWidget(mContentWidget); |
|
126 primaryAction = new HbAction(QString(q->tr("Ok"))); |
|
127 q->setPrimaryAction(primaryAction); |
|
128 |
|
129 secondaryAction = new HbAction(QString(q->tr("Cancel"))); |
|
130 q->setSecondaryAction(secondaryAction); |
|
131 |
|
132 q->setTimeout(HbPopup::NoTimeout); |
|
133 q->setModal(true); // Dialog is modal |
|
134 q->setDismissPolicy(HbPopup::NoDismiss); |
|
135 |
|
136 QObject::connect( q->mainWindow(), |
|
137 SIGNAL( orientationChanged(Qt::Orientation )), |
|
138 q, |
|
139 SLOT( _q_notesOrientationChanged(Qt::Orientation) ) ); |
|
140 } |
|
141 |
|
142 |
|
143 void HbInputDialogPrivate::setInputMode(HbLineEdit *pEdit, HbInputDialog::InputMode mode) |
|
144 { |
|
145 Q_Q(HbInputDialog); |
|
146 #ifdef HBINPUTDIALOG_DEBUG |
|
147 qDebug()<<"Entering setInputMode"; |
|
148 #endif |
|
149 HbEditorInterface eInt(pEdit); |
|
150 switch(mode) { |
|
151 case HbInputDialog::TextInput: |
|
152 #ifdef HBINPUTDIALOG_DEBUG |
|
153 qDebug()<<"TextInputMode"; |
|
154 #endif |
|
155 eInt.setConstraints(HbEditorConstraintNone); |
|
156 break; |
|
157 case HbInputDialog::IntInput: |
|
158 { |
|
159 #ifdef HBINPUTDIALOG_DEBUG |
|
160 qDebug()<<"IntInputMode"; |
|
161 #endif |
|
162 //set the validator |
|
163 if(mValid) { |
|
164 // NOTE:This validation is for readability. mValid is being deleted |
|
165 // when setValidator is called on editor. |
|
166 mValid = 0; |
|
167 } |
|
168 mValid = new HbValidator(); |
|
169 QValidator *intValidator = new QIntValidator(q); |
|
170 mValid->addField(intValidator, "0"); |
|
171 pEdit->setValidator(mValid); |
|
172 |
|
173 eInt.setConstraints(HbEditorConstraintFixedInputMode); |
|
174 eInt.setInputMode(HbInputModeNumeric); |
|
175 //eInt.setFilter(HbConverterNumberFilter::instance()); |
|
176 /* Old custom button API has been deprecated for some time now. Commented out to prevent a build break. |
|
177 customButtonBank = HbInputCustomButtonStore::instance()->newBank(); |
|
178 1, intValidator->locale().negativeSign(), intValidator->locale().negativeSign()); |
|
179 mCustomButtonBank->addButton(mDashButton); |
|
180 dashButton = new HbInputCustomButton(HbInputCustomButton::HbCustomButtonShortcut, |
|
181 1, intValidator->locale().negativeSign(), intValidator->locale().negativeSign()); |
|
182 customButtonBank->addButton(dashButton); |
|
183 eInt.setCustomButtonBank(customButtonBank->id()); */ |
|
184 |
|
185 break; |
|
186 } |
|
187 case HbInputDialog::RealInput: |
|
188 { |
|
189 #ifdef HBINPUTDIALOG_DEBUG |
|
190 qDebug()<<"RealInputMode"; |
|
191 #endif |
|
192 //set the validator |
|
193 if(mValid) { |
|
194 mValid = 0; |
|
195 } |
|
196 |
|
197 mValid = new HbValidator(); |
|
198 QValidator *doubleValidator = new QDoubleValidator(q); |
|
199 mValid->addField(doubleValidator, "0"); |
|
200 pEdit->setValidator(mValid); |
|
201 |
|
202 eInt.setConstraints(HbEditorConstraintFixedInputMode); |
|
203 eInt.setInputMode(HbInputModeNumeric); |
|
204 //eInt.setFilter(HbConverterNumberFilter::instance()); |
|
205 /* Old custom button API has been deprecated for some time now. Commented out to prevent a build break. |
|
206 customButtonBank = HbInputCustomButtonStore::instance()->newBank(); |
|
207 dotButton = new HbInputCustomButton(HbInputCustomButton::HbCustomButtonShortcut, |
|
208 0, doubleValidator->locale().decimalPoint(), doubleValidator->locale().decimalPoint()); |
|
209 customButtonBank->addButton(dotButton); |
|
210 dashButton = new HbInputCustomButton(HbInputCustomButton::HbCustomButtonShortcut, |
|
211 1, doubleValidator->locale().negativeSign(), doubleValidator->locale().negativeSign()); |
|
212 customButtonBank->addButton(dashButton); |
|
213 eInt.setCustomButtonBank(customButtonBank->id()); */ |
|
214 |
|
215 break; |
|
216 } |
|
217 case HbInputDialog::IpInput: |
|
218 { |
|
219 mValid = new HbValidator; |
|
220 QRegExp r("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); |
|
221 mValid->setMasterValidator(new QRegExpValidator(r,0)); |
|
222 mValid->addField(new QIntValidator(0,255,0),"127"); |
|
223 mValid->addSeparator(QString(".")); |
|
224 mValid->addField(new QIntValidator(0,255,0),"0"); |
|
225 mValid->addSeparator(QString(".")); |
|
226 mValid->addField(new QIntValidator(0,255,0),"0"); |
|
227 mValid->addSeparator(QString(".")); |
|
228 mValid->addField(new QIntValidator(0,255,0),"1"); |
|
229 |
|
230 pEdit->setValidator(mValid); |
|
231 eInt.setInputMode(HbInputModeNumeric); |
|
232 |
|
233 break; |
|
234 } |
|
235 default: |
|
236 break; |
|
237 } |
|
238 } |
|
239 |
|
240 |
|
241 void HbInputDialogPrivate::setInputMode(HbInputDialog::InputMode mode,int row) |
|
242 { |
|
243 if(row > 1) { |
|
244 return; |
|
245 } |
|
246 if(row == 0) { |
|
247 mPrimaryMode = mode; |
|
248 setInputMode(mContentWidget->mEdit1, mode); |
|
249 } else { |
|
250 mSecondaryMode = mode; |
|
251 if(mContentWidget->mAdditionalRowVisible) { |
|
252 setInputMode(mContentWidget->mEdit2,mode); |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 void HbInputDialogPrivate::setPromptText(const QString& text,int row) |
|
259 { |
|
260 Q_Q(HbInputDialog); |
|
261 if(row > 1) { |
|
262 return; |
|
263 } |
|
264 HbStyleOptionInputDialog option; |
|
265 if(row == 0) { |
|
266 mPromptText = text; |
|
267 q->initStyleOption(&option); |
|
268 q->style()->updatePrimitive(mContentWidget->mLabel1,HbStyle::P_InputDialog_text,&option); |
|
269 } else { |
|
270 mPromptAdditionalText = text; |
|
271 q->initStyleOption(&option); |
|
272 if(mContentWidget->mAdditionalRowVisible) { |
|
273 q->style()->updatePrimitive(mContentWidget->mLabel2,HbStyle::P_InputDialog_additional_text,&option); |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 |
|
279 QString HbInputDialogPrivate::promptText(int row) const |
|
280 { |
|
281 if( row > 1 ) { |
|
282 return QString(); |
|
283 } |
|
284 if(row == 0) { |
|
285 return mPromptText; |
|
286 } else { |
|
287 return mPromptAdditionalText; |
|
288 } |
|
289 } |
|
290 |
|
291 |
|
292 void HbInputDialogPrivate::setText(const QString& text,int row) |
|
293 { |
|
294 if(row > 1) { |
|
295 return; |
|
296 } |
|
297 if(row == 0) { |
|
298 mContentWidget->mEdit1->setText(text); |
|
299 } else { |
|
300 mText = text; |
|
301 if(mContentWidget->mAdditionalRowVisible) { |
|
302 mContentWidget->mEdit2->setText(mText); |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 |
|
308 QString HbInputDialogPrivate::text(int row) const |
|
309 { |
|
310 if(row > 1) { |
|
311 return QString(); |
|
312 } |
|
313 if(row == 0) { |
|
314 return mContentWidget->mEdit1->text(); |
|
315 } else { |
|
316 if(mContentWidget->mEdit2) { |
|
317 return mContentWidget->mEdit2->text(); |
|
318 } else { |
|
319 return mText; |
|
320 } |
|
321 } |
|
322 } |
|
323 |
|
324 |
|
325 void HbInputDialogPrivate::setAdditionalRowVisible(bool visible) |
|
326 { |
|
327 mContentWidget->setAdditionalRowVisible(visible); |
|
328 } |
|
329 |
|
330 |
|
331 bool HbInputDialogPrivate::isAdditionalRowVisible()const |
|
332 { |
|
333 return mContentWidget->mAdditionalRowVisible; |
|
334 } |
|
335 |
|
336 void HbInputDialogPrivate::_q_notesOrientationChanged(Qt::Orientation) |
|
337 { |
|
338 Q_Q(HbInputDialog); |
|
339 q->repolish(); |
|
340 } |