27 #include "hbnamespace_p.h" |
27 #include "hbnamespace_p.h" |
28 #include <hbmessagebox.h> |
28 #include <hbmessagebox.h> |
29 #include <hbstyleoptionmessagebox_p.h> |
29 #include <hbstyleoptionmessagebox_p.h> |
30 #include <hbmainwindow.h> |
30 #include <hbmainwindow.h> |
31 #include <hbaction.h> |
31 #include <hbaction.h> |
32 #include <hblineedit.h> |
32 #include <hblabel.h> |
33 #include <hbscrollbar.h> |
|
34 #include <hbscrollarea.h> |
33 #include <hbscrollarea.h> |
35 #include "hbglobal_p.h" |
34 #include <hbstyleprimitivedata.h> |
36 #include <QGraphicsItem> |
35 #include <hbstyleiconprimitivedata.h> |
37 #include <QGraphicsSceneMouseEvent> |
36 #include <QGraphicsSceneMouseEvent> |
38 #include <QTimer> |
37 #include <QTimer> |
39 #include <QTextOption> |
38 #include <QTextDocument> |
|
39 |
40 #ifdef Q_OS_SYMBIAN |
40 #ifdef Q_OS_SYMBIAN |
41 #include <systemtoneservice.h> |
41 #include <systemtoneservice.h> |
42 #endif |
42 #endif |
43 |
43 |
44 class HbStyle; |
44 class HbStyle; |
45 |
45 |
46 class HbMessageBoxEditor : public HbLineEdit |
46 class HbMessageBoxWidget : public HbLabel |
47 { |
47 { |
48 Q_OBJECT |
48 Q_OBJECT |
49 public: |
49 public: |
50 HbMessageBoxEditor(QGraphicsItem* parent =0) : HbLineEdit(parent),mText() |
50 HbMessageBoxWidget(QGraphicsItem* parent =0):HbLabel(parent){ |
|
51 setTextWrapping(Hb::TextWordWrap); |
|
52 } |
|
53 HbMessageBoxWidget(const QString& text, QGraphicsItem *parent=0):HbLabel(text, parent){ |
|
54 HbStyle::setItemName(this, "text"); |
|
55 } |
|
56 }; |
|
57 class HbMessageBoxScrollArea : public HbScrollArea |
|
58 { |
|
59 public: |
|
60 HbMessageBoxWidget *widget; |
|
61 HbMessageBoxScrollArea(QGraphicsItem* parent =0):HbScrollArea(parent),widget(0) |
51 { |
62 { |
52 setReadOnly(true); |
63 setScrollDirections(Qt::Vertical); |
53 setCursorVisibility(Hb::TextCursorHidden); |
64 widget = new HbMessageBoxWidget(this); |
54 HbScrollArea *scroll = scrollArea(); |
65 setContentWidget(widget); |
55 scroll->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
66 setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
56 clearContextMenuFlag(Hb::ShowTextContextMenuOnLongPress); |
67 setClampingStyle(HbScrollArea::StrictClamping); |
57 clearContextMenuFlag(Hb::ShowTextContextMenuOnSelectionClicked); |
68 setFlag(QGraphicsItem::ItemIsFocusable, false); |
58 setBackgroundItem(0,0); |
69 setFrictionEnabled(true); |
59 } |
70 } |
60 |
71 void triggerPolish() |
61 void focusInEvent(QFocusEvent * event) |
|
62 { |
72 { |
63 Q_UNUSED(event); |
73 repolish(); |
64 } |
74 } |
65 void focusOutEvent(QFocusEvent * event) |
75 }; |
|
76 |
|
77 |
|
78 class HbMessageBoxContentWidget : public HbWidget |
|
79 { |
|
80 Q_OBJECT |
|
81 public: |
|
82 HbMessageBoxPrivate *d; |
|
83 QGraphicsObject *mIconItem; |
|
84 HbMessageBoxScrollArea *mScrollArea; |
|
85 |
|
86 HbMessageBoxContentWidget(HbMessageBoxPrivate *priv, |
|
87 QGraphicsItem* parent =0) : HbWidget(parent),d(priv),mIconItem(0),mScrollArea(0) |
66 { |
88 { |
67 Q_UNUSED(event); |
89 mScrollArea = new HbMessageBoxScrollArea(this); |
68 } |
90 mIconItem = style()->createPrimitive(HbStyle::PT_IconItem, "icon", this); |
69 |
91 setProperty("hasIcon",true); |
70 void setHtmlText(const QString &text) |
92 HbStyle::setItemName(mScrollArea, "scrollArea"); |
|
93 } |
|
94 |
|
95 void triggerPolish() |
71 { |
96 { |
72 mText = text; |
97 repolish(); |
73 if(Qt::mightBeRichText(mText)){ |
98 } |
74 setHtml(text); |
99 |
75 } |
|
76 else { |
|
77 QString htmlString = Qt::convertFromPlainText(mText); |
|
78 setHtml(htmlString); |
|
79 } |
|
80 } |
|
81 |
|
82 QString htmlText() const |
|
83 { |
|
84 return mText; |
|
85 } |
|
86 private: |
|
87 QString mText; |
|
88 |
|
89 }; |
|
90 |
|
91 class HbMessageBoxContentWidget : public HbWidget |
|
92 { |
|
93 Q_OBJECT |
|
94 |
|
95 public: |
|
96 HbMessageBoxPrivate *d; |
|
97 HbMessageBoxEditor *mTextEdit; |
|
98 QGraphicsItem *mIconItem; |
|
99 HbMessageBoxContentWidget(HbMessageBoxPrivate *priv, |
|
100 QGraphicsItem* parent =0) : HbWidget(parent),d(priv),mTextEdit(0),mIconItem(0) |
|
101 { |
|
102 |
|
103 mTextEdit = new HbMessageBoxEditor(this); |
|
104 mIconItem = style()->createPrimitive(HbStyle::P_MessageBox_icon, this); |
|
105 setProperty("hasIcon",true); |
|
106 HbStyle::setItemName(mTextEdit, "text"); |
|
107 HbStyle::setItemName(mIconItem, "icon"); |
|
108 } |
|
109 enum { Type = HbPrivate::ItemType_MessageNoteContentWidget }; |
100 enum { Type = HbPrivate::ItemType_MessageNoteContentWidget }; |
110 int type() const { return Type; } |
101 int type() const { return Type; } |
111 }; |
102 }; |
112 |
103 |
113 /* |
104 /* |
114 constructor |
105 constructor |
115 |
|
116 */ |
106 */ |
117 |
107 |
118 HbMessageBoxPrivate::HbMessageBoxPrivate() : |
108 HbMessageBoxPrivate::HbMessageBoxPrivate() : |
119 HbDialogPrivate(), |
109 HbDialogPrivate(), |
120 mIcon(), |
110 mIcon(), |
121 mMessageBoxContentWidget(0), |
111 mMessageBoxContentWidget(0), |
122 mMessageBoxType(HbMessageBox::MessageTypeNone), |
112 mMessageBoxType(HbMessageBox::MessageTypeNone), |
123 mIconVisible(true) |
113 mIconVisible(false), |
|
114 mBoxText("") |
124 { |
115 { |
125 } |
116 } |
126 |
117 |
127 void HbMessageBoxPrivate::_q_buttonClicked() |
118 void HbMessageBoxPrivate::_q_buttonClicked() |
128 { |
119 { |
142 */ |
133 */ |
143 void HbMessageBoxPrivate::init() |
134 void HbMessageBoxPrivate::init() |
144 { |
135 { |
145 Q_Q(HbMessageBox); |
136 Q_Q(HbMessageBox); |
146 |
137 |
147 mMessageBoxContentWidget = new HbMessageBoxContentWidget( this ); |
138 mMessageBoxContentWidget = new HbMessageBoxContentWidget(this); |
148 q->setContentWidget( mMessageBoxContentWidget ); |
139 q->setContentWidget( mMessageBoxContentWidget ); |
149 q->setDismissPolicy(HbPopup::NoDismiss); |
140 q->setDismissPolicy(HbPopup::NoDismiss); |
150 q->setTimeout(HbPopup::NoTimeout); |
141 q->setTimeout(HbPopup::NoTimeout); |
151 q->setStandardButtons(HbMessageBox::Ok); |
142 q->setStandardButtons(HbMessageBox::Ok); |
152 |
143 |
153 switch(mMessageBoxType) { |
144 switch(mMessageBoxType) { |
154 case HbMessageBox::MessageTypeNone: |
145 case HbMessageBox::MessageTypeNone: |
155 mMessageBoxContentWidget->mIconItem->hide(); |
|
156 mMessageBoxContentWidget->setProperty("hasIcon",false); |
|
157 break; |
|
158 case HbMessageBox::MessageTypeInformation: |
146 case HbMessageBox::MessageTypeInformation: |
159 case HbMessageBox::MessageTypeWarning: |
147 case HbMessageBox::MessageTypeWarning: |
160 case HbMessageBox::MessageTypeQuestion: |
148 case HbMessageBox::MessageTypeQuestion: |
|
149 mIconVisible =true; |
161 break; |
150 break; |
162 |
151 |
163 } |
152 } |
164 |
153 |
165 } |
154 } |
|
155 #ifdef HB_EFFECTS |
166 void HbMessageBoxPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status) |
156 void HbMessageBoxPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status) |
167 { |
157 { |
|
158 |
168 #ifdef Q_OS_SYMBIAN |
159 #ifdef Q_OS_SYMBIAN |
169 |
160 if ( (status.reason == Hb::EffectFinished) || ( (status.reason == Hb::EffectCancelled) && (!mStartEffect) )) { |
170 if ( (status.reason == Hb::EffectFinished) || ( (status.reason == Hb::EffectCancelled) && (!mStartEffect) )) { |
161 CSystemToneService *pSystemTone = systemToneService(); |
171 CSystemToneService *pSystemTone = systemToneService(); |
162 if(!pSystemTone) { |
172 if(!pSystemTone) { |
163 return ; |
173 return ; |
164 } |
174 } |
165 switch(mMessageBoxType) { |
175 switch(mMessageBoxType) { |
166 case HbMessageBox::MessageTypeInformation: |
176 case HbMessageBox::MessageTypeInformation: |
167 pSystemTone->PlayTone(CSystemToneService::EInformationBeep); |
177 pSystemTone->PlayTone(CSystemToneService::EInformationBeep); |
168 break; |
178 break; |
169 case HbMessageBox::MessageTypeWarning: |
179 case HbMessageBox::MessageTypeWarning: |
170 pSystemTone->PlayTone(CSystemToneService::EWarningBeep); |
180 pSystemTone->PlayTone(CSystemToneService::EWarningBeep); |
171 break; |
181 break; |
172 case HbMessageBox::MessageTypeQuestion: |
182 case HbMessageBox::MessageTypeQuestion: |
173 pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep); |
183 pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep); |
174 break; |
184 break; |
175 default: |
185 default: |
176 break; |
186 break; |
177 } |
187 } |
178 } |
188 |
179 #else |
189 } |
180 Q_UNUSED(status); |
190 #else |
181 |
191 Q_UNUSED(status); |
|
192 #endif // Q_OS_SYMBIAN |
182 #endif // Q_OS_SYMBIAN |
193 } |
183 } |
|
184 #endif |
194 |
185 |
195 /*! |
186 /*! |
196 @beta |
187 @beta |
197 |
188 |
198 \class HbMessageBox |
189 \class HbMessageBox |
199 \brief HbMessageBox is a convenience modal dialog class. HbMessageBox can be used to launch a information,question,warning or any other |
190 \brief HbMessageBox is a convenience modal dialog class. HbMessageBox can be used to launch a information,question,warning or any other |
200 general messages. |
191 general messages. |
201 |
192 |
202 \image html information.PNG "An information MessageBox" |
193 \image html information.PNG "An information MessageBox" |
203 \image html question.PNG "A question MessageBox" |
194 \image html question.PNG "A question MessageBox" |
204 \image html warning.PNG "A warning MessageBox" |
195 \image html warning.PNG "A warning MessageBox" |
205 |
196 |
206 Using HbMessageBox, the following dialogs can be created: |
197 Using HbMessageBox, the following dialogs can be created: |
207 |
198 |
208 <b>Information:</b> a statement to the user to which they may respond by acknowledging the information ('Ok').<br> |
199 <b>Information:</b> a statement to the user to which they may respond by acknowledging the information ('Ok').<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> |
200 <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> |
335 d->q_ptr = this; |
328 d->q_ptr = this; |
336 d->init(); |
329 d->init(); |
337 } |
330 } |
338 |
331 |
339 /*! |
332 /*! |
340 \deprecated HbMessageBox::primitive(HbStyle::Primitive) |
|
341 is deprecated. |
|
342 |
|
343 Provides access to primitives of HbMessageBox. |
|
344 \param primitive is the type of the requested primitive. The available |
|
345 primitives are P_MessageBox_icon. |
|
346 |
|
347 */ |
|
348 QGraphicsItem *HbMessageBox::primitive(HbStyle::Primitive primitive) const |
|
349 { |
|
350 Q_D(const HbMessageBox); |
|
351 switch (primitive) { |
|
352 case HbStyle::P_MessageBox_icon: |
|
353 return d->mMessageBoxContentWidget->mIconItem; |
|
354 default: |
|
355 return 0; |
|
356 } |
|
357 } |
|
358 |
|
359 /*! |
|
360 \reimp |
333 \reimp |
361 */ |
334 */ |
362 void HbMessageBox::initStyleOption(HbStyleOptionMessageBox *option) const |
335 void HbMessageBox::initStyleOption(HbStyleOptionMessageBox *option) const |
363 { |
336 { |
364 Q_D(const HbMessageBox); |
337 Q_D(const HbMessageBox); |
365 HbDialog::initStyleOption(option); |
338 HbDialog::initStyleOption(option); |
366 option->icon = d->mIcon; |
339 option->icon = d->mIcon; |
367 option->messageBoxType = d->mMessageBoxType; |
340 option->messageBoxType = d->mMessageBoxType; |
368 } |
341 } |
|
342 void HbMessageBox::changeEvent(QEvent *event) |
|
343 { |
|
344 Q_UNUSED(event); |
|
345 updatePrimitives(); |
|
346 } |
|
347 |
|
348 void HbMessageBox::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive) |
|
349 { |
|
350 Q_D(HbMessageBox); |
|
351 HbWidgetBase::initPrimitiveData(primitiveData, primitive); |
|
352 QString itemName = HbStyle::itemName(primitive); |
|
353 if (itemName == QLatin1String("icon")) { |
|
354 HbStyleIconPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData); |
|
355 data->icon = icon(); |
|
356 |
|
357 if (data->icon.value().isNull()) { |
|
358 switch (d->mMessageBoxType) { |
|
359 case HbMessageBox::MessageTypeInformation: |
|
360 data->icon = HbIcon(QLatin1String("qtg_large_info")); |
|
361 break; |
|
362 case HbMessageBox::MessageTypeQuestion: |
|
363 if(layoutDirection() == Qt::RightToLeft) { |
|
364 data->icon = HbIcon(QLatin1String("qtg_large_query_ah")); |
|
365 } |
|
366 else { |
|
367 data->icon = HbIcon(QLatin1String("qtg_large_query")); |
|
368 } |
|
369 break; |
|
370 case HbMessageBox::MessageTypeWarning: |
|
371 data->icon = HbIcon(QLatin1String("qtg_large_warning")); |
|
372 break; |
|
373 default: |
|
374 break; |
|
375 } |
|
376 } |
|
377 |
|
378 if(d->mIconVisible) { |
|
379 if (data->icon.value().isNull()) { |
|
380 d->mMessageBoxContentWidget->setProperty("hasIcon",false); |
|
381 d->mMessageBoxContentWidget->mIconItem->hide(); |
|
382 } |
|
383 else { |
|
384 d->mMessageBoxContentWidget->setProperty("hasIcon",true); |
|
385 d->mMessageBoxContentWidget->mIconItem->show(); |
|
386 } |
|
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 void HbMessageBox::recreatePrimitives() |
|
392 { |
|
393 Q_D(HbMessageBox); |
|
394 if (d->mMessageBoxContentWidget->mIconItem) { |
|
395 delete d->mMessageBoxContentWidget->mIconItem; |
|
396 d->mMessageBoxContentWidget->mIconItem = 0; |
|
397 d->mMessageBoxContentWidget->mIconItem = style()->createPrimitive(HbStyle::PT_IconItem, "icon",d->mMessageBoxContentWidget); |
|
398 d->mMessageBoxContentWidget->setProperty("hasIcon",true); |
|
399 } |
|
400 } |
369 |
401 |
370 /*! |
402 /*! |
371 \reimp |
403 \reimp |
372 */ |
404 */ |
373 void HbMessageBox::updatePrimitives() |
405 void HbMessageBox::updatePrimitives() |
374 { |
406 { |
375 Q_D(HbMessageBox); |
407 Q_D(HbMessageBox); |
376 HbDialog::updatePrimitives(); |
408 HbDialog::updatePrimitives(); |
377 HbStyleOptionMessageBox option; |
409 |
378 initStyleOption(&option); |
|
379 if (d->mMessageBoxContentWidget->mIconItem) { |
410 if (d->mMessageBoxContentWidget->mIconItem) { |
380 style()->updatePrimitive(d->mMessageBoxContentWidget->mIconItem, HbStyle::P_MessageBox_icon, &option); |
411 HbStyleIconPrimitiveData data; |
|
412 initPrimitiveData(&data, d->mMessageBoxContentWidget->mIconItem); |
|
413 style()->updatePrimitive(d->mMessageBoxContentWidget->mIconItem, &data, this); |
381 } |
414 } |
382 |
415 |
383 } |
416 } |
384 |
417 |
385 /*! |
418 /*! |
388 \sa text() |
421 \sa text() |
389 */ |
422 */ |
390 void HbMessageBox::setText(const QString &text) |
423 void HbMessageBox::setText(const QString &text) |
391 { |
424 { |
392 Q_D(HbMessageBox); |
425 Q_D(HbMessageBox); |
393 if ( text != d->mMessageBoxContentWidget->mTextEdit->htmlText() ) { |
426 if ( text != d->mBoxText ) { |
394 d->mMessageBoxContentWidget->mTextEdit->setHtmlText(text); |
427 d->mBoxText = text; |
|
428 if (d->mMessageBoxContentWidget->mScrollArea->widget) { |
|
429 |
|
430 if(Qt::mightBeRichText(text)){ |
|
431 d->mMessageBoxContentWidget->mScrollArea->widget->setHtml(text); |
|
432 |
|
433 } |
|
434 else { |
|
435 d->mMessageBoxContentWidget->mScrollArea->widget->setPlainText(text); |
|
436 } |
|
437 } |
|
438 d->mMessageBoxContentWidget->mScrollArea->triggerPolish(); |
|
439 |
395 } |
440 } |
396 } |
441 } |
397 |
442 |
398 /*! |
443 /*! |
399 Returns descriptive text from the messagebox. |
444 Returns descriptive text from the messagebox. |
400 \sa setText() |
445 \sa setText() |
401 */ |
446 */ |
402 QString HbMessageBox::text() const |
447 QString HbMessageBox::text() const |
403 { |
448 { |
404 Q_D(const HbMessageBox); |
449 Q_D(const HbMessageBox); |
405 return d->mMessageBoxContentWidget->mTextEdit->htmlText(); |
450 return d->mBoxText; |
406 } |
451 } |
407 |
452 |
408 /*! |
453 /*! |
409 Sets a custom Icon for the MessageBox. Not recommended to change the icon unless there is a real use case. |
454 Sets a custom Icon for the MessageBox. Not recommended to change the icon unless there is a real use case. |
410 \icon An icon instance |
455 \icon An icon instance |
571 HbMessageBox::StandardButtons HbMessageBox::standardButtons() const |
612 HbMessageBox::StandardButtons HbMessageBox::standardButtons() const |
572 { |
613 { |
573 Q_D(const HbMessageBox); |
614 Q_D(const HbMessageBox); |
574 return d->mStandardButtons; |
615 return d->mStandardButtons; |
575 |
616 |
|
617 } |
|
618 |
|
619 void HbMessageBox::showEvent(QShowEvent *event) |
|
620 { |
|
621 #ifndef HB_EFFECTS |
|
622 #ifdef Q_OS_SYMBIAN |
|
623 CSystemToneService *pSystemTone = systemToneService(); |
|
624 if(!pSystemTone) { |
|
625 return ; |
|
626 } |
|
627 switch(mMessageBoxType) { |
|
628 case HbMessageBox::MessageTypeInformation: |
|
629 pSystemTone->PlayTone(CSystemToneService::EInformationBeep); |
|
630 break; |
|
631 case HbMessageBox::MessageTypeWarning: |
|
632 pSystemTone->PlayTone(CSystemToneService::EWarningBeep); |
|
633 break; |
|
634 case HbMessageBox::MessageTypeQuestion: |
|
635 pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep); |
|
636 break; |
|
637 default: |
|
638 break; |
|
639 } |
|
640 #endif // Q_OS_SYMBIAN |
|
641 #endif //HB_EFFECTS |
|
642 HbDialog::showEvent(event); |
576 } |
643 } |
577 |
644 |
578 /*! |
645 /*! |
579 |
646 |
580 \deprecated HbMessageBox::question(const QString&,QObject*,const char*,const QString&,const QString&,QGraphicsWidget*,QGraphicsScene*,QGraphicsItem*) |
647 \deprecated HbMessageBox::question(const QString&,QObject*,const char*,const QString&,const QString&,QGraphicsWidget*,QGraphicsScene*,QGraphicsItem*) |