136 init() |
141 init() |
137 */ |
142 */ |
138 void HbMessageBoxPrivate::init() |
143 void HbMessageBoxPrivate::init() |
139 { |
144 { |
140 Q_Q(HbMessageBox); |
145 Q_Q(HbMessageBox); |
141 |
146 |
|
147 mMessageBoxContentWidget = new HbMessageBoxContentWidget( this ); |
|
148 q->setContentWidget( mMessageBoxContentWidget ); |
|
149 q->setDismissPolicy(HbPopup::NoDismiss); |
|
150 q->setTimeout(HbPopup::NoTimeout); |
|
151 q->setStandardButtons(HbMessageBox::Ok); |
|
152 |
142 switch(mMessageBoxType) { |
153 switch(mMessageBoxType) { |
|
154 case HbMessageBox::MessageTypeNone: |
|
155 mMessageBoxContentWidget->mIconItem->hide(); |
|
156 mMessageBoxContentWidget->setProperty("hasIcon",false); |
|
157 break; |
143 case HbMessageBox::MessageTypeInformation: |
158 case HbMessageBox::MessageTypeInformation: |
144 case HbMessageBox::MessageTypeWarning: |
159 case HbMessageBox::MessageTypeWarning: |
145 mMessageBoxContentWidget = new HbMessageBoxContentWidget( this ); |
160 case HbMessageBox::MessageTypeQuestion: |
146 q->setContentWidget( mMessageBoxContentWidget ); |
|
147 q->setDismissPolicy(HbPopup::NoDismiss); |
|
148 q->setTimeout(HbPopup::NoTimeout); |
|
149 q->addAction(new HbAction(q->tr("OK"),q)); |
|
150 break; |
161 break; |
151 |
162 |
152 case HbMessageBox::MessageTypeQuestion: |
163 } |
153 mMessageBoxContentWidget = new HbMessageBoxContentWidget( this ); |
164 |
154 q->setContentWidget( mMessageBoxContentWidget ); |
165 } |
155 q->setDismissPolicy(HbPopup::NoDismiss); |
166 void HbMessageBoxPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status) |
156 q->setTimeout(HbPopup::NoTimeout); |
167 { |
157 q->addAction(new HbAction(q->tr("Yes"),q)); |
168 #ifdef Q_OS_SYMBIAN |
158 q->addAction(new HbAction(q->tr("No"),q)); |
169 |
159 break; |
170 if ( (status.reason == Hb::EffectFinished) || ( (status.reason == Hb::EffectCancelled) && (!mStartEffect) )) { |
160 } |
171 CSystemToneService *pSystemTone = systemToneService(); |
161 |
172 if(!pSystemTone) { |
|
173 return ; |
|
174 } |
|
175 switch(mMessageBoxType) { |
|
176 case HbMessageBox::MessageTypeInformation: |
|
177 pSystemTone->PlayTone(CSystemToneService::EInformationBeep); |
|
178 break; |
|
179 case HbMessageBox::MessageTypeWarning: |
|
180 pSystemTone->PlayTone(CSystemToneService::EWarningBeep); |
|
181 break; |
|
182 case HbMessageBox::MessageTypeQuestion: |
|
183 pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep); |
|
184 break; |
|
185 default: |
|
186 break; |
|
187 } |
|
188 |
|
189 } |
|
190 #else |
|
191 Q_UNUSED(status); |
|
192 #endif // Q_OS_SYMBIAN |
162 } |
193 } |
163 |
194 |
164 /*! |
195 /*! |
165 @beta |
196 @beta |
166 |
197 |
167 \class HbMessageBox |
198 \class HbMessageBox |
168 \brief HbMessageBox is a convenience modal dialog class, using which a simple information, a question, or a simple warning can be shown to the user. |
199 \brief HbMessageBox is a convenience modal dialog class. HbMessageBox can be used to launch a information,question,warning or any other |
|
200 general messages. |
|
201 |
|
202 \image html information.PNG "An information MessageBox" |
|
203 \image html question.PNG "A question MessageBox" |
|
204 \image html warning.PNG "A warning MessageBox" |
169 |
205 |
170 Using HbMessageBox, the following dialogs can be created: |
206 Using HbMessageBox, the following dialogs can be created: |
171 |
207 |
172 <b>Information:</b> a statement to the user to which they may respond by acknowledging the information ('OK').<br> |
208 <b>Information:</b> a statement to the user to which they may respond by acknowledging the information ('Ok').<br> |
173 <b>Question:</b> a query to the user requiring a response. User needs to select between two alternatives, the positive or negative (For example: 'Delete Mailbox?' 'Yes'/'No').<br> |
209 <b>Question:</b> a query to the user requiring a response. User needs to select between two alternatives, the positive or negative (For example: 'Delete Mailbox?' 'Yes'/'No').<br> |
174 <b>Warning:</b> a statement to the user to which they may respond by acknowledging the warning ('OK').<br> |
210 <b>Warning:</b> a statement to the user to which they may respond by acknowledging the warning ('OK').<br> |
175 |
211 <b>None:</b> Any general messages to which user responds. |
176 By default, Message box launches an information dialog which contains a description text and user actions visualized as command buttons. |
212 |
|
213 By default, Message box launches a None dialog which can contain a text, an icon and action buttons |
177 |
214 |
178 Default properties for the MessageBox (warning, information and question dialogs) are: |
215 Default properties for the MessageBox (warning, information and question dialogs) are: |
179 |
216 |
180 Description text: Text shown to the user as information. The amount of text rows is not limited, but after five rows the text starts scrolling. |
217 Description text: Text shown to the user as information. The amount of text rows is not limited, but after five rows the text starts scrolling. |
181 Icon: Default icons are available for each dialog type using the MessageBox template. Changing the default icons is not recommended. |
218 Icon: Default icons are available for each dialog type using the MessageBox template. Changing the default icons is not recommended. |
182 Action buttons (one or two): one button for information and warning MessageBox, two buttons for question MessageBox. |
219 Action button : One action button ("Ok") for all the types. |
183 |
220 |
184 All the three dialogs(information, warning, question) supported by MessageBox are by default modal in nature, with |
221 All the four dialogs(information, warning, question and none) supported by MessageBox are by default modal in nature, with |
185 a dismiss policy of NoDismiss, timeout policy of NoTimeout, and with a BackgroundFade property on. |
222 a dismiss policy of NoDismiss, timeout policy of NoTimeout, and with a BackgroundFade property on. |
186 |
223 |
187 Example code for launching MessageBox using static convenience functions: |
224 Example code for launching MessageBox using static convenience functions: |
188 |
225 |
189 \code |
226 \code |
190 //Information MessageBox |
227 //Information MessageBox |
191 HbMessageBox::information(informationText, this, SLOT(onDialogClose(HbAction*)), headWidget, scene, parent); |
228 HbMessageBox::information("The file is deleted",0,0,HbMessageBox::Ok); |
192 |
229 |
193 //Warning MessageBox |
230 //Warning MessageBox |
194 HbMessageBox::warning(warningText, this, SLOT(onDialogClose(HbAction*)), headWidget, scene, parent); |
231 HbMessageBox::warning("This will change the name",0,0,HbMessageBox::Ok); |
195 |
232 |
196 //Question MessageBox |
233 //Question MessageBox |
197 HbMessageBox::question(questionText, this, SLOT(onDialogClose(HbAction*)), primaryButtonText, secondaryButtonText, headWidget, scene, parent); |
234 HbMessageBox::question("Do you want to delete the file ?", this, SLOT(onDialogClose(int)),HbMessageBox::Yes |HbMessageBox::No ); |
198 \endcode |
235 \endcode |
199 |
236 |
200 Example code to show an information messagebox: |
237 Example code to show an information messagebox: |
201 |
|
202 \code |
238 \code |
203 HbMessageBox *box = new HbMessageBox("This is an information dialog."); |
239 HbMessageBox *box = new HbMessageBox("This is a general note."); |
204 box->setAttribute(Qt::WA_DeleteOnClose); |
240 box->setAttribute(Qt::WA_DeleteOnClose); |
205 box->open(); |
241 box->open(); |
206 \endcode |
242 \endcode |
207 |
243 |
208 Example code to show an information messagebox with two action buttons: |
|
209 \code |
|
210 HbMessageBox *box = new HbMessageBox("XX will be deleted. Do you want to Continue ? "); |
|
211 |
|
212 //Add new action. |
|
213 box->addAction(new HbAction(HbWidget::tr("Cancel"), q)); |
|
214 |
|
215 box->setAttribute(Qt::WA_DeleteOnClose); |
|
216 |
|
217 box->open(); |
|
218 \endcode |
|
219 |
|
220 Example code to show a question messagebox with a return value based action |
244 Example code to show a question messagebox with a return value based action |
221 \code |
245 \code |
222 HbMessageBox *box = new HbMessageBox(" Delete file IC0002 ? ",HbMessageBox::MessageTypeQuestion); |
246 HbMessageBox *box = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
247 box->setText("Delete file IC0002 ? "); |
223 box->setAttribute(Qt::WA_DeleteOnClose); |
248 box->setAttribute(Qt::WA_DeleteOnClose); |
224 box->open(this,SLOT(dialogClosed(HbAction*))); |
249 box->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No); |
225 |
250 box->open(this,SLOT(onDialogClosed(int))); |
|
251 |
226 //Slot implementation |
252 //Slot implementation |
227 void dialogClosed(HbAction *action) |
253 void MessageBoxView::onDialogClosed(int action) |
228 { |
254 { |
229 HbMessageBox *dlg = static_cast<HbMessageBox*>(sender()); |
255 if (action == HbMessageBox::Yes) { |
230 if(action == dlg->actions().at(0)) |
256 //User Clicked Yes// |
231 { |
257 //Delete the file// |
232 // Delete file |
258 } |
233 } |
259 else if (action == HbMessageBox::No) { |
234 else |
260 //User Clicked No// |
235 { |
261 //do not delete the file// |
236 // Cancellation is done.Dont delete the file |
262 } |
237 } |
263 |
238 } |
264 } |
|
265 \endcode |
|
266 |
|
267 Example code to show a question messagebox using static API |
|
268 \code |
|
269 HbMessageBox::question("Delete file IC0002 ? ",this,SLOT(onDialogClosed(int)),HbMessageBox::Yes | HbMessageBox::No); |
|
270 // Here the SLOT implementation is same as above |
239 \endcode |
271 \endcode |
240 |
272 |
|
273 |
241 \enum HbMessageBox::MessageBoxType |
274 \enum HbMessageBox::MessageBoxType |
242 |
275 |
243 \value \b MessageTypeInformation creates a modal information dialog, which by default will have one OK button |
276 \value \b MessageTypeNone creates a modal dialog, which by default will have one OK button |
244 for the user to dismiss the dialog. |
277 for the user to dismiss the dialog. |
245 |
278 |
246 \value \b MessageTypeWarning creates a simple modal dialog with a warning icon and a description text. |
279 \value \b MessageTypeWarning creates a simple modal dialog with a warning icon and a description text. |
247 Dialog by default will have one OK button, for the user to dismiss the dialog. |
280 This Dialog by default will have one Ok button, for the user to dismiss the dialog. |
248 |
281 |
249 \value \b MessageTypeQuestion Shows a modal dialog with question icon and a description text. The user can either confirm or |
282 \value \b MessageTypeWarning creates a simple modal dialog with a information icon and a description text. |
250 reject the dialog. By default dialog supports two buttons, using which user can dismiss the dialog. |
283 This Dialog by default will have one Ok button, for the user to dismiss the dialog. |
251 |
284 |
|
285 \value \b MessageTypeQuestion creates a simple modal dialog with a question icon and a description text. |
|
286 This Dialog by default will have one Ok button, for the user to dismiss the dialog. |
252 */ |
287 */ |
253 |
288 |
254 /*! |
289 /*! |
255 Constructs a MessageBox with \a type and a \a parent. |
290 Constructs a MessageBox with \a type and a \a parent. |
256 \param type User can create information/warning/question dialogs by passing appropriate MessageBoxType. |
291 \param type User can create information/warning/question dialogs by passing appropriate MessageBoxType. |
433 { |
472 { |
434 Q_D(const HbMessageBox); |
473 Q_D(const HbMessageBox); |
435 return d->mIconVisible; |
474 return d->mIconVisible; |
436 |
475 |
437 } |
476 } |
438 |
477 /*! |
439 |
478 sets the buttons for the dialog. If the Application wants "Yes" and "No" buttons |
440 /*! |
479 can set it like setStandardButtons(HbMessageBox::Yes | HbMessageBox::No). |
441 This is a convenience function for showing a question dialog with \a questionText and buttons with specified \a primaryButtonText and |
480 If only yes Button then setStandardButtons(HbMessageBox::Yes). |
442 \a secondaryButtonText. |
481 |
|
482 \param buttons the button set |
|
483 \sa standardButtons() |
|
484 |
|
485 */ |
|
486 void HbMessageBox::setStandardButtons(HbMessageBox::StandardButtons buttons) |
|
487 { |
|
488 Q_D(HbMessageBox); |
|
489 if(d->mStandardButtons == buttons ) { |
|
490 return; |
|
491 } |
|
492 clearActions(); |
|
493 d->mStandardButtons = buttons; |
|
494 uint i = HbMessageBox::Ok; |
|
495 int count =0; |
|
496 while (i <= HbMessageBox::Reset) { |
|
497 HbAction *action=0; |
|
498 if (i & buttons) { |
|
499 StandardButton button = HbMessageBox::StandardButton(i); |
|
500 switch(button){ |
|
501 case Ok: |
|
502 action = new HbAction(hbTrId("txt_common_button_ok"),this); |
|
503 d->mActionList.insert(action,Ok); |
|
504 break; |
|
505 case Save: |
|
506 action = new HbAction(hbTrId("txt_common_button_save"),this); |
|
507 d->mActionList.insert(action,Save); |
|
508 break; |
|
509 case Open: |
|
510 action = new HbAction(hbTrId("txt_common_button_open"),this); |
|
511 d->mActionList.insert(action,Open); |
|
512 break; |
|
513 case Yes: |
|
514 action = new HbAction(hbTrId("txt_common_button_yes"),this); |
|
515 d->mActionList.insert(action,Yes); |
|
516 break; |
|
517 case No: |
|
518 action = new HbAction(hbTrId("txt_common_button_no"),this); |
|
519 d->mActionList.insert(action,No); |
|
520 break; |
|
521 case Retry: |
|
522 action = new HbAction(hbTrId("txt_common_button_retry"),this); |
|
523 d->mActionList.insert(action,Retry); |
|
524 break; |
|
525 case Continue: |
|
526 action = new HbAction(hbTrId("txt_common_button_continue"),this); |
|
527 d->mActionList.insert(action,Continue); |
|
528 break; |
|
529 case Close: |
|
530 action = new HbAction(hbTrId("txt_common_button_close"),this); |
|
531 d->mActionList.insert(action,Close); |
|
532 break; |
|
533 case Cancel: |
|
534 action = new HbAction(hbTrId("txt_common_button_cancel"),this); |
|
535 d->mActionList.insert(action,Cancel); |
|
536 break; |
|
537 case Help: |
|
538 action = new HbAction(hbTrId("txt_common_button_help"),this); |
|
539 d->mActionList.insert(action,Help); |
|
540 break; |
|
541 case Reset: |
|
542 action = new HbAction(hbTrId("txt_common_button_reset"),this); |
|
543 d->mActionList.insert(action,Reset); |
|
544 break; |
|
545 case Delete: |
|
546 action = new HbAction(hbTrId("txt_common_button_delete"),this); |
|
547 d->mActionList.insert(action,Delete); |
|
548 break; |
|
549 default : |
|
550 break; |
|
551 |
|
552 }; |
|
553 |
|
554 } |
|
555 i = i << 1; |
|
556 |
|
557 if(action) { |
|
558 connect(action,SIGNAL(triggered()),this,SLOT(_q_buttonClicked())); |
|
559 addAction(action); |
|
560 count++; |
|
561 } |
|
562 |
|
563 } |
|
564 } |
|
565 /*! |
|
566 Returns the standared button list |
|
567 |
|
568 \sa setStandardButtons() |
|
569 |
|
570 */ |
|
571 HbMessageBox::StandardButtons HbMessageBox::standardButtons() const |
|
572 { |
|
573 Q_D(const HbMessageBox); |
|
574 return d->mStandardButtons; |
|
575 |
|
576 } |
|
577 |
|
578 /*! |
|
579 |
|
580 \deprecated HbMessageBox::question(const QString&,QObject*,const char*,const QString&,const QString&,QGraphicsWidget*,QGraphicsScene*,QGraphicsItem*) |
|
581 is deprecated. |
|
582 |
|
583 Please use |
|
584 |
|
585 question(const QString &questionText, |
|
586 QObject *receiver, |
|
587 const char *member, |
|
588 HbMessageBox::StandardButtons buttons, |
|
589 QGraphicsWidget *headWidget, |
|
590 QGraphicsScene *scene, |
|
591 QGraphicsItem *parent) |
|
592 |
|
593 This is a convenience function for showing a question dialog with \a questionText with provided buttons. |
443 \param questionText descriptive text for the messagebox |
594 \param questionText descriptive text for the messagebox |
444 \param receiver Object which has the slot, which acts as a handler once the dialog closes. |
595 \param receiver Object which has the slot, which acts as a handler once the dialog closes. |
445 \param member the slot, where the control will come, once the dialog is closed. |
596 \param member the slot, where the control will come, once the dialog is closed. |
446 \param primaryButtonText text for the primary button. |
597 \param primaryButtonText text for the primary button. |
447 \param secondaryButtonText text for the secondary button. |
598 \param secondaryButtonText text for the secondary button. |
532 messageBox->setHeadingWidget(headWidget); |
708 messageBox->setHeadingWidget(headWidget); |
533 } |
709 } |
534 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
710 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
535 messageBox->open(receiver,member); |
711 messageBox->open(receiver,member); |
536 } |
712 } |
|
713 |
|
714 /*! |
|
715 This is a convenience function for showing a question dialog with \a questionText and a default OK button. |
|
716 \param questionText descriptive text for the messagebox |
|
717 \param receiver Object which has the slot, which acts as a handler once the dialog closes. |
|
718 \param member the slot, where the control will come, once the dialog is closed.The signature of member is void dialogClosed(int val); |
|
719 \param buttons The action buttons of the dialog. |
|
720 \param headWidget the heading widget, where the user can set a title, Null by default. |
|
721 \param scene the scene for the MessageBox. Null by default. |
|
722 \param parent the parent widget. Null by default. |
|
723 */ |
|
724 void HbMessageBox::question(const QString &questionText, |
|
725 QObject *receiver, |
|
726 const char *member, |
|
727 HbMessageBox::StandardButtons buttons, |
|
728 QGraphicsWidget *headingWidget, |
|
729 QGraphicsScene *scene, |
|
730 QGraphicsItem *parent) |
|
731 { |
|
732 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion, parent); |
|
733 if (scene && !parent) { |
|
734 scene->addItem(messageBox); |
|
735 } |
|
736 messageBox->setText(questionText); |
|
737 |
|
738 messageBox->setStandardButtons(buttons); |
|
739 |
|
740 if(headingWidget) { |
|
741 messageBox->setHeadingWidget(headingWidget); |
|
742 } |
|
743 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
744 messageBox->open(receiver,member); |
|
745 } |
|
746 |
|
747 /*! |
|
748 This is a convenience function for showing an information dialog with a descriptive text and a default OK button. |
|
749 \param informationText Descriptive text for the information dialog. |
|
750 \param receiver Which has the slot, which acts as a handler once the dialog closes. |
|
751 \param member the slot, where the control will come, once the dialog is closed.The signature of member is void dialogClosed(int val); |
|
752 \param buttons The action buttons of the dialog. |
|
753 \param headWidget This can used by the user to set a title widget. Null by default. |
|
754 \param scene the scene for the MessageBox, Null by default. |
|
755 \param parent the parent widget. Null by default |
|
756 */ |
|
757 void HbMessageBox::information(const QString &informationText, |
|
758 QObject *receiver, |
|
759 const char *member, |
|
760 HbMessageBox::StandardButtons buttons, |
|
761 QGraphicsWidget *headingWidget, |
|
762 QGraphicsScene *scene, |
|
763 QGraphicsItem *parent) |
|
764 { |
|
765 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation, parent); |
|
766 if (scene && !parent) { |
|
767 scene->addItem(messageBox); |
|
768 } |
|
769 messageBox->setText(informationText); |
|
770 |
|
771 messageBox->setStandardButtons(buttons); |
|
772 |
|
773 if(headingWidget) { |
|
774 messageBox->setHeadingWidget(headingWidget); |
|
775 } |
|
776 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
777 messageBox->open(receiver,member); |
|
778 } |
|
779 |
|
780 /*! |
|
781 This is a convenience function for showing a warning dialog with a descriptive text and an OK button. |
|
782 \param warningText Descriptive text for the warning dialog. |
|
783 \param receiver Which has the slot, which acts as a handler once the dialog closes. |
|
784 \param member the slot, where the control will come, once the dialog is closed.The signature of member is void dialogClosed(int val); |
|
785 \param buttons The action buttons of the dialog. |
|
786 \param headWidget This can used by the user to set a title widget, Null by default. |
|
787 \param scene the scene for the messagebox, Null by default. |
|
788 \param parent the parent widget, Null by default. |
|
789 */ |
|
790 void HbMessageBox::warning(const QString &warningText, |
|
791 QObject *receiver, |
|
792 const char *member, |
|
793 HbMessageBox::StandardButtons buttons, |
|
794 QGraphicsWidget *headingWidget, |
|
795 QGraphicsScene *scene, |
|
796 QGraphicsItem *parent) |
|
797 { |
|
798 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning, parent); |
|
799 if (scene && !parent) { |
|
800 scene->addItem(messageBox); |
|
801 } |
|
802 messageBox->setText(warningText); |
|
803 |
|
804 messageBox->setStandardButtons(buttons); |
|
805 |
|
806 if(headingWidget) { |
|
807 messageBox->setHeadingWidget(headingWidget); |
|
808 } |
|
809 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
810 messageBox->open(receiver,member); |
|
811 } |
537 #include "moc_hbmessagebox.cpp" |
812 #include "moc_hbmessagebox.cpp" |
538 #include "hbmessagebox.moc" |
813 #include "hbmessagebox.moc" |
539 |
814 |