40 |
40 |
41 |
41 |
42 /*! |
42 /*! |
43 @beta |
43 @beta |
44 @hbwidgets |
44 @hbwidgets |
45 |
|
46 \class HbInputDialog |
45 \class HbInputDialog |
47 \brief HbInputDialog creates a modal dialog for the user to get some information in the form of text or numbers. |
46 \brief HbInputDialog is a convenient class for getting user inputs. |
48 |
|
49 Based on the \InputMode user can enter text, int, double or an IP address. InputDialog can have one or two line edit input fields. |
47 Based on the \InputMode user can enter text, int, double or an IP address. InputDialog can have one or two line edit input fields. |
50 |
48 |
51 HbInputDialog by default will have a label to display a descriptive text for the line edit input field and, |
49 \image html inputdialog.png "An Input dialog with prompt text and a user input field." |
52 OK and Cancel buttons. |
50 |
|
51 HbInputDialog by default will have a label to display a descriptive text which gives information on the user input field, |
|
52 an edit field for entering text and,two action buttons. |
53 |
53 |
54 example code example: |
54 example code example: |
55 \code |
55 \code |
|
56 HbInputDialog *object = new HbInputDialog(); |
|
57 \endcode |
|
58 |
|
59 The HbDialog::open( QObject* receiver, const char* member ) method from the HbDialog is used to show the HbInputDialog. |
|
60 |
|
61 The open method can be attached with a SLOT of the format finished(HbAction*). When the open is used with a slot then the slot |
|
62 will be invoked once the user does any action such as accept or reject (The Ok or Cancel press). |
|
63 |
|
64 |
|
65 below is the declaration of the slot. |
|
66 \code |
|
67 public slots : |
|
68 void dialogClosed(HbAction *action); |
|
69 \endcode |
|
70 |
|
71 below code shows how the open method can be called using this slot. |
|
72 |
|
73 \code |
56 HbInputDialog *object = new HbInputDialog(parent); |
74 HbInputDialog *object = new HbInputDialog(parent); |
57 object->show(); |
75 object->open(this,SLOT(dialogClosed(HbAction*))); |
58 \endcode |
76 \endcode |
59 |
77 |
60 Four static convenience API's are provided: getText(), getInteger(), getDouble(), and getIp() |
78 A sample slot definition is shown below |
|
79 |
|
80 \code |
|
81 void dialogClosed(HbAction *action) |
|
82 { |
|
83 HbInputDialog *dlg=static_cast<HbInputDialog*>(sender()); |
|
84 if(dlg->actions().first() == action) { // user is clicked OK |
|
85 //Get the string enter by user |
|
86 QString myString = dlg->value().toString(); |
|
87 //Do the action here |
|
88 } |
|
89 else if(dlg->actions().at(1) == action) { |
|
90 // user is clicked CANCEL |
|
91 } |
|
92 } |
|
93 \endcode |
|
94 |
|
95 |
|
96 In HbInputDialog four static convenience API's are provided: getText(), getInteger(), getDouble(), and getIp() |
61 static API's can be used to quickly get an input from user. |
97 static API's can be used to quickly get an input from user. |
62 |
98 |
63 \enum HbInputDialog::InputMode |
99 \enum HbInputDialog::InputMode |
64 |
100 |
65 \value \b TextInput When this value is set as Input mode, input dialog accepts text input in its |
101 \value \b TextInput When this value is set as Input mode, Input Dialog accepts text input in its |
66 correspoinding line edit field. |
102 correspoinding line edit field. |
67 |
103 |
68 \value \b IntInput When this value is set as Input mode, input dialog accepts Integer input in its |
104 \value \b IntInput When this value is set as Input mode, Input Dialog accepts Integer input in its |
69 correspoinding line edit field. |
105 correspoinding line edit field. |
70 |
106 |
71 \value \b RealInput When this value is set as Input mode, input dialog accepts double or float input in its |
107 \value \b RealInput When this value is set as Input mode, Input Dialog accepts double or float input in its |
72 correspoinding line edit field. |
108 correspoinding line edit field. |
73 |
109 |
74 \value \b IpInput When this value is set as Input mode, input dialog accepts Ip address as input in its |
110 \value \b IpInput When this value is set as Input mode, Input Dialog accepts Ip address as input in its |
75 correspoinding line edit field. |
111 correspoinding line edit field. |
76 |
112 |
77 */ |
113 */ |
78 |
114 |
79 |
115 |
105 HbInputDialog::~HbInputDialog() |
141 HbInputDialog::~HbInputDialog() |
106 { |
142 { |
107 } |
143 } |
108 |
144 |
109 /*! |
145 /*! |
110 Sets the input mode of the primary(Top/default)line edit in the query widget. |
146 Sets the input mode of the user field. The default InputMode is TextInput. |
111 |
147 The other available modes are IntInput,RealInput and IpInput. |
112 The default InputMode is TextInput |
|
113 |
148 |
114 \param mode. InputMode can be TextMode, IntMode, RealMode and Ip address mode. |
149 \param mode. InputMode can be TextMode, IntMode, RealMode and Ip address mode. |
115 each mode will affect how the line edit filters its input. |
150 each mode will affect how the line edit filters its input. |
116 |
151 |
117 \param row. value 0 or 1 |
152 \param row. This parameter indicates which row of the field.0 (by default) means the |
118 |
153 the first user field and 1 means second user field. |
|
154 |
119 \sa inputMode() |
155 \sa inputMode() |
120 */ |
156 */ |
121 void HbInputDialog::setInputMode(InputMode mode ,int row) |
157 void HbInputDialog::setInputMode(InputMode mode ,int row) |
122 { |
158 { |
123 Q_D(HbInputDialog); |
159 Q_D(HbInputDialog); |
124 d->setInputMode(mode,row); |
160 d->setInputMode(mode,row); |
125 } |
161 } |
126 |
162 |
127 /*! |
163 /*! |
128 Returns input mode for top/default line edit. |
164 Returns input mode of the user field.The default InputMode is TextInput. |
129 |
165 |
130 The default InputMode is TextInput |
166 \param row This parameter indicates which row of the field.0 means the |
131 |
167 the first user field and 1 means second user field. |
132 \param row. value 0 or 1 |
|
133 |
168 |
134 \sa setInputMode() |
169 \sa setInputMode() |
135 */ |
170 */ |
136 HbInputDialog::InputMode HbInputDialog::inputMode(int row) const |
171 HbInputDialog::InputMode HbInputDialog::inputMode(int row) const |
137 { |
172 { |
146 } |
181 } |
147 } |
182 } |
148 } |
183 } |
149 |
184 |
150 /*! |
185 /*! |
151 Sets the prompt \a text for top/default line edit. |
186 Sets the prompt text for the user field. This prompt text text can be very descriptive like username,password etc. |
152 |
187 |
153 \param text. Text for the label which describes the purpose of the corresponding input line edit field. |
188 \param text The des |
154 \param row. value 0 or 1 |
189 \param row This parameter indicates which row of the user field.0 (by default) means the |
|
190 the first user field and 1 means second user field. |
155 |
191 |
156 \sa promtText() |
192 \sa promtText() |
157 */ |
193 */ |
158 void HbInputDialog::setPromptText(const QString &text, int row) |
194 void HbInputDialog::setPromptText(const QString &text, int row) |
159 { |
195 { |
160 Q_D(HbInputDialog); |
196 Q_D(HbInputDialog); |
161 d->setPromptText(text, row); |
197 d->setPromptText(text, row); |
162 } |
198 } |
163 |
199 |
164 /*! |
200 /*! |
165 Returns prompt text for top/default line edit. |
201 Returns descriptive prompt text. |
166 the default is null string. |
202 |
167 \param row. value 0 or 1 |
203 \param row This parameter indicates which row of the field. 0 means the |
|
204 the user field in the first row and 1 means user field in the second row. |
168 |
205 |
169 \sa setPromptText() |
206 \sa setPromptText() |
170 */ |
207 */ |
171 QString HbInputDialog::promptText(int row) const |
208 QString HbInputDialog::promptText(int row) const |
172 { |
209 { |
173 Q_D(const HbInputDialog); |
210 Q_D(const HbInputDialog); |
174 return d->promptText(row); |
211 return d->promptText(row); |
175 } |
212 } |
176 |
213 |
177 /*! |
214 /*! |
178 Sets the top/default line edit value in \a text format. |
215 Sets the value for the user input field.The value should in sync HbInputDialog::InputMode of the field. |
179 |
216 |
180 \param value. user defined value for the default line edit. |
217 \param value The value that should be presented to the user. |
181 \param row. value 0 or 1 |
218 |
|
219 \param row This parameter indicates which row of the user field.0 (by default) means the |
|
220 the first user field and 1 means second user field. |
182 |
221 |
183 \sa value() |
222 \sa value() |
184 */ |
223 */ |
185 void HbInputDialog::setValue(const QVariant &value,int row) |
224 void HbInputDialog::setValue(const QVariant &value,int row) |
186 { |
225 { |
187 Q_D(HbInputDialog); |
226 Q_D(HbInputDialog); |
188 d->setText(value.toString(),row); |
227 d->setText(value.toString(),row); |
189 } |
228 } |
190 |
229 |
191 /*! |
230 /*! |
192 Returns top/default line edit value as QVariant object. |
231 This returns the value of the user field row. The return type is QVariant which can be converted to |
193 |
232 corresponding type based on HbInputDialog::InputMode of the field. |
194 \param row. value 0 or 1 |
233 |
|
234 \param row This parameter indicates which row of the user field.0 (by default) means the |
|
235 the first user field and 1 means second user field |
195 |
236 |
196 \sa setValue() |
237 \sa setValue() |
197 */ |
238 */ |
198 QVariant HbInputDialog::value(int row) const |
239 QVariant HbInputDialog::value(int row) const |
199 { |
240 { |
200 Q_D(const HbInputDialog); |
241 Q_D(const HbInputDialog); |
201 return QVariant(d->text(row)); |
242 return QVariant(d->text(row)); |
202 } |
243 } |
203 |
244 |
204 /*! |
245 /*! |
205 Sets the visibility of bottom line edit and prompt text. |
246 HbInputDialog is capable of showing one or two user input fields. This can be set using this function. |
206 |
247 By default this is false and only first row is visible. |
207 \param visible true or false. |
248 |
|
249 \param visible true or false. If true then two user fields will be visible otherwise one. |
208 |
250 |
209 \sa isAdditionalRowVisible() |
251 \sa isAdditionalRowVisible() |
210 */ |
252 */ |
211 void HbInputDialog::setAdditionalRowVisible(bool visible) |
253 void HbInputDialog::setAdditionalRowVisible(bool visible) |
212 { |
254 { |
213 Q_D(HbInputDialog); |
255 Q_D(HbInputDialog); |
214 d->setAdditionalRowVisible(visible); |
256 d->setAdditionalRowVisible(visible); |
215 } |
257 } |
216 |
258 |
217 /*! |
259 /*! |
218 Returns the visibility of secondary row(bottom line edit and prompt text). |
260 Returns the visibility of second row user input field.The default is false. |
219 the default is false |
261 |
220 \sa setAdditionalRowVisible() |
262 \sa setAdditionalRowVisible() |
221 */ |
263 */ |
222 bool HbInputDialog::isAdditionalRowVisible() |
264 bool HbInputDialog::isAdditionalRowVisible() |
223 { |
265 { |
224 Q_D(HbInputDialog); |
266 Q_D(HbInputDialog); |
225 return d->isAdditionalRowVisible(); |
267 return d->isAdditionalRowVisible(); |
226 } |
268 } |
227 |
269 |
228 /*! |
270 /*! |
229 Validator is used to validate the content and cursor movements. |
271 |
230 |
272 This API allows the user to set any validator to the user input field. |
231 \param validator. Validator uses undo stack to back out invalid changes. Therefore undo |
273 |
|
274 \param validator Validator uses undo stack to back out invalid changes. Therefore undo |
232 is enabled when validator is set. |
275 is enabled when validator is set. |
233 |
276 |
234 \sa HbAbstractEdit::setValidator |
277 \param row This parameter indicates which row of the user field.0 means the |
|
278 the first user field and 1 means second user field |
|
279 |
|
280 \sa HbAbstractEdit::validator |
235 */ |
281 */ |
236 void HbInputDialog::setValidator(HbValidator *validator,int row) |
282 void HbInputDialog::setValidator(HbValidator *validator,int row) |
237 { |
283 { |
238 Q_D(HbInputDialog); |
284 Q_D(HbInputDialog); |
239 if( (row == 0) && (d->mContentWidget->mEdit1) ) { |
285 if( (row == 0) && (d->mContentWidget->mEdit1) ) { |
276 } |
323 } |
277 return NULL; |
324 return NULL; |
278 } |
325 } |
279 |
326 |
280 /*! |
327 /*! |
281 sets the echo mode for the given row. |
328 sets the echo mode for the user input fiels. The echo mode is defined in HbLineEdit. |
282 |
329 Normal, NoEcho, Password, PasswordEchoOnEdit are the different echo modes supportted in HbLineEdit. |
283 \param echoMode |
330 |
284 \param row. A value 0 or 1 |
331 \param echoMode which can be HbLineEdit::Normal, HbLineEdit::NoEcho, HbLineEdit::Password or HbLineEdit::PasswordEchoOnEdit. |
285 |
332 |
286 \sa HbLineEdit::setEchoMode |
333 \param row This parameter indicates which row of the user field.0 (by default) means the |
|
334 the first user input field and 1 means second user input field |
|
335 |
|
336 \sa echoMode() , HbLineEdit::setEchoMode() |
287 */ |
337 */ |
288 void HbInputDialog::setEchoMode(HbLineEdit::EchoMode echoMode,int row) |
338 void HbInputDialog::setEchoMode(HbLineEdit::EchoMode echoMode,int row) |
289 { |
339 { |
290 Q_D(HbInputDialog); |
340 Q_D(HbInputDialog); |
291 if( (row == 0) && (d->mContentWidget->mEdit1) ) { |
341 if( (row == 0) && (d->mContentWidget->mEdit1) ) { |
368 } |
417 } |
369 return HbLineEdit::EchoMode(-1);// |
418 return HbLineEdit::EchoMode(-1);// |
370 } |
419 } |
371 |
420 |
372 /*! |
421 /*! |
373 Static convenience function for creating an input dialog to get a string from the user. |
422 This is a static convenience function for creating an Input Dialog and to get a string data from the the user. The Application can use this |
374 \a label is the text which is shown to the user (it should |
423 function in order to get any text data from user like username,search data etc. This API allows a slot to be passed as a param. This slot will |
375 say what should be entered). \a text is the default text which is |
424 be invoked when the user does the action like OK press or CANCEL press. |
376 placed in the line edit. If \a ok is non-null \e *\a ok will be |
425 |
377 set to true if the user pressed \gui OK and to false if the user pressed |
426 HbInputDialog::getText(iTitle,this,SLOT(dialogClosed(HbAction*)),iText); iTitle is the prompt text.dialogClosed will be invoked when the user does the action. |
378 \gui Cancel. The dialog's parent is \a parent. The dialog will be |
427 Please refer the class documentation to know how to handle the slot. |
379 modal. |
428 |
380 |
429 \param label The prompt text which gives information on user input field. |
381 This function return data has to be queried in the finished(HbAction*) slot. |
430 \param receiver The instance where the slot is declared. |
382 |
431 \param member The slot which has dialogClosed(HbAction*) signature. |
|
432 \param text The default text that should be presented to the user. |
|
433 \param scene The scene parameter. |
|
434 \param parent The parent item for the dialog. |
|
435 |
383 \sa getInteger(), getDouble(), getIp() |
436 \sa getInteger(), getDouble(), getIp() |
384 */ |
437 */ |
385 void HbInputDialog::getText(const QString &label, |
438 void HbInputDialog::getText(const QString &label, |
386 QObject *receiver, |
439 QObject *receiver, |
387 const char* member, |
440 const char* member, |
400 dlg->open(receiver,member); |
453 dlg->open(receiver,member); |
401 } |
454 } |
402 |
455 |
403 |
456 |
404 /*! |
457 /*! |
405 Static convenience function to get an integer input from the |
458 This is a static convenience function for creating an Input Dialog and to get an integer data from the the user. The Application can use this |
406 user.\a label is the text which is shown to the user |
459 function in order to get any integer data from user like year , any number etc. This API allows a slot to be passed as a param. This slot will |
407 (it should say what should be entered). \a value is the default |
460 be invoked when the user does the action like OK press or CANCEL press. |
408 integer which the spinbox will be set to. |
461 |
409 If \a ok is non-null *\a ok will be set to true if the user |
462 HbInputDialog::getInt(iTitle,this,SLOT(dialogClosed(HbAction*)),iText); iTitle is the prompt text.dialogClosed will be invoked when the user does the action. |
410 pressed \gui OK and to false if the user pressed \gui Cancel. The |
463 Please refer the class documentation to know how to handle the slot. |
411 dialog's parent is \a parent. The dialog will be modal. |
464 |
412 |
465 \param label The prompt text which gives information on user input field. |
413 This function return data has to be queried in the finished(HbAction*) slot. |
466 \param receiver The instance where the slot is declared. |
414 |
467 \param member The slot which has dialogClosed(HbAction*) signature. |
|
468 \param value The default value that should be presented to the user. |
|
469 \param scene The scene parameter. |
|
470 \param parent The parent widget for the dialog. |
|
471 |
415 \sa getText(), getDouble(), getIp() |
472 \sa getText(), getDouble(), getIp() |
416 */ |
473 */ |
417 void HbInputDialog::getInteger(const QString &label, |
474 void HbInputDialog::getInteger(const QString &label, |
418 QObject *receiver, |
475 QObject *receiver, |
419 const char *member, |
476 const char *member, |
430 dlg->setValue(QString::number(value)); |
487 dlg->setValue(QString::number(value)); |
431 dlg->setAttribute(Qt::WA_DeleteOnClose); |
488 dlg->setAttribute(Qt::WA_DeleteOnClose); |
432 dlg->open(receiver,member); |
489 dlg->open(receiver,member); |
433 } |
490 } |
434 /*! |
491 /*! |
435 Static convenience function to get a floating point number from |
492 This is a static convenience function for creating an Input Dialog and to get a double data from the the user. The Application can use this |
436 the user.\a label is the text which is shown to the user |
493 function in order to get any double data from user. This API allows a slot to be passed as a param. This slot will |
437 (it should say what should be entered). \a value is the default |
494 be invoked when the user does the action like OK press or CANCEL press. |
438 floating point number that the line edit will be set to. |
495 |
439 |
496 HbInputDialog::getDouble(iTitle,this,SLOT(dialogClosed(HbAction*)),iText); iTitle is the prompt text.dialogClosed will be invoked when the user does the action. |
440 If \a ok is non-null, *\a ok will be set to true if the user |
497 Please refer the class documentation to know how to handle the slot. |
441 pressed \gui OK and to false if the user pressed \gui Cancel. The |
498 |
442 dialog's parent is \a parent. The dialog will be modal. |
499 \param label The prompt text which gives information on user input field. |
443 |
500 \param receiver the instance where the slot is declared. |
444 This function return data has to be queried in the finished(HbAction*) slot. |
501 \param member the slot which has dialogClosed(HbAction*) signature. |
445 |
502 \param value the default value that should be presented to the user. |
|
503 \param scene the scene parameter. |
|
504 \param parent the parent widget for the dialog. |
|
505 |
446 \sa getText(), getInteger(), getIp() |
506 \sa getText(), getInteger(), getIp() |
447 */ |
507 */ |
448 void HbInputDialog::getDouble(const QString &label, |
508 void HbInputDialog::getDouble(const QString &label, |
449 QObject *receiver, |
509 QObject *receiver, |
450 const char *member, |
510 const char *member, |
462 dlg->open(receiver,member); |
522 dlg->open(receiver,member); |
463 } |
523 } |
464 |
524 |
465 |
525 |
466 /*! |
526 /*! |
467 Static convenience function to get an ip address from |
527 This is a static convenience function for creating an Input Dialog and to get an IP information from the the user. This API allows a slot to be passed as a param. This slot will |
468 the user.\a label is the text which is shown to the user |
528 be invoked when the user does the action like OK press or CANCEL press. |
469 (it should say what should be entered). \a address is the default |
529 |
470 QHostAddress that the line edit will be set to. |
530 HbInputDialog::getIp(iTitle,this,SLOT(dialogClosed(HbAction*)),iText); iTitle is the prompt text.dialogClosed will be invoked when the user does the action. |
471 |
531 Please refer the class documentation to know how to handle the slot. |
472 If \a ok is non-null, *\a ok will be set to true if the user |
532 |
473 pressed \gui OK and to false if the user pressed \gui Cancel. The |
533 \param label The prompt text which gives information on user input field. |
474 dialog's parent is \a parent. The dialog will be modal. |
534 \param receiver the instance where the slot is declared. |
475 |
535 \param member the slot which has dialogClosed(HbAction*) signature. |
476 This function return data has to be queried in the finished(HbAction*) slot. |
536 \param ipaddress the default value that should be presented to the user. |
477 |
537 \param scene the scene parameter. |
|
538 \param parent the parent widget for the dialog. |
|
539 |
478 \sa getText(), getInteger(), getDouble() |
540 \sa getText(), getInteger(), getDouble() |
479 */ |
541 */ |
|
542 |
480 void HbInputDialog::getIp(const QString &label, |
543 void HbInputDialog::getIp(const QString &label, |
481 QObject *receiver, |
544 QObject *receiver, |
482 const char *member, |
545 const char *member, |
483 const QString &ipaddress, |
546 const QString &ipaddress, |
484 QGraphicsScene *scene, |
547 QGraphicsScene *scene, |