41 #include <QEventLoop> |
43 #include <QEventLoop> |
42 #include <QPointer> |
44 #include <QPointer> |
43 #include <QDebug> |
45 #include <QDebug> |
44 #include <QApplication> // krazy:exclude=qclasses |
46 #include <QApplication> // krazy:exclude=qclasses |
45 |
47 |
46 #include <hbfeedbackmanager.h> |
|
47 |
|
48 #ifdef HB_EFFECTS |
48 #ifdef HB_EFFECTS |
49 #include "hbeffectinternal_p.h" |
49 #include "hbeffectinternal_p.h" |
50 #define HB_POPUP_ITEM_TYPE "HB_POPUP" |
|
51 #endif |
50 #endif |
52 |
51 |
53 /*! |
52 /*! |
54 @beta |
53 @beta |
55 @hbcore |
54 @hbcore |
56 \class HbDialog |
55 \class HbDialog |
57 \brief HbDialog is a base class for different dialogs in Hb library. |
56 \brief The HbDialog class is a concrete class for simple application dialogs |
58 |
57 and a base class for a variety of convenience application dialog and popup classes. |
59 \image html hbpopup.png "A dialog with a header widget, a list as a content widget, and two action buttons." |
58 |
60 |
59 An application dialog is a popup that opens in response to application events. |
61 HbDialog is a concrete class. The content for a custom dialog is |
60 Popup dialogs float above the top layer of the application view, usually overlapping |
62 implemented in a separate widget, which is set to the dialog with |
61 the area reserved for the application content. An application can use a dialog to |
63 method setContentWidget(). |
62 provide information, give warnings, and ask the user to answer a question or |
64 |
63 select an option. Avoid overusing dialogs because they can interrupt the user's |
65 |
64 workflow. When dialogs appear too frequently, users tend to dismiss them without |
66 An example of how to create a simple modal dialog and show it. |
65 reading them properly, just to get them out of the way. |
|
66 |
|
67 %HbDialog is a concrete class that you can use directly in your applications. |
|
68 However, there are a variety of convenience classes that derive from it, |
|
69 so check whether there is one that meets your needs. You can create a custom |
|
70 dialog by deriving a class from %HbDialog and adding a custom widget to it. |
|
71 |
|
72 \image html hbpopup.png "A dialog with a heading widget, a list content widget, and two action buttons" |
|
73 |
|
74 You can add three types of content to an %HbDialog object. If you do not add any |
|
75 content, an %HbDialog object is simply a bordered rectangle. The three types of |
|
76 content are: |
|
77 |
|
78 - <b>A heading widget</b>. This is shown at the top of the dialog and is typically |
|
79 a simple HbLabel object that describes the purpose of the dialog. To add a heading |
|
80 widget, call setHeadingWidget(). |
|
81 |
|
82 - <b>A content widget</b>. Positioned below the heading, this contains the main |
|
83 dialog content. To add a content widget, call setContentWidget(). |
|
84 |
|
85 - \b Actions. These are generic command (HbAction) objects, which you add to the |
|
86 dialog by calling the QGraphicsWidget::addAction() family of functions. The actions |
|
87 appear as buttons on a toolbar at the bottom of the dialog. (The toolbar appears when |
|
88 you add the first action to the dialog.) When the user taps one of these buttons, it |
|
89 dismisses the dialog and the action's \link HbAction::triggered() triggered()\endlink |
|
90 signal is emitted. Connect this signal to the slot that will perform the command. |
|
91 |
|
92 %HbDialog is derived from HbPopup, which provides generic features for all popup |
|
93 classes. These features include properties that control the dialog's dismiss policy, |
|
94 background fade policy, timeout, frame background type, and whether it is modal. |
|
95 |
|
96 Unlike a non-modal dialog, a modal dialog stops the user interacting with anything outside |
|
97 of the dialog until it closes. You set and get the modality by calling setModal() |
|
98 and isModal(), respectively. Typically modal dialogs use the fade background feature, |
|
99 whereas non-modal dialogs do not. How you open a dialog depends on whether it is |
|
100 modal: if the dialog is modal use one of the open() overloads and otherwise use |
|
101 \link QGraphicsItem::show() show()\endlink. Make sure you use the appropriate method, |
|
102 because this ensures the correct touch event handling. |
|
103 |
|
104 \note Services that generate device-wide and system-wide messages use the HbDeviceDialog |
|
105 class and not HbDialog. |
|
106 |
|
107 \section _usecases_hbdialog Using the HbDialog class |
|
108 |
|
109 \subsection _uc_001_hbdialog Creating and showing a simple modal dialog |
|
110 |
|
111 This example demonstrates how to create a simple modal dialog and show it. Notice |
|
112 that we show a modal dialog by calling one of the open() overloads. |
67 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,13} |
113 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,13} |
68 |
114 |
69 An example of how to handle dialog signals from previous example. |
115 \subsection _uc_002_hbdialog Handling dialog signals |
|
116 |
|
117 This example continues the previous one, which connects the dialog's |
|
118 finished(HbAction*) signal to the following slot in the call to |
|
119 open(QObject *,const char*) on the final line. This example shows how this slot |
|
120 handles the finished(HbAction*) signal. |
|
121 |
70 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,53} |
122 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,53} |
71 |
123 |
72 An example of how to handle if finished(int) is connected instead of finished(HbAction*) in above example. |
124 \subsection _uc_003_hbdialog Handling dialog signals: alternative method |
73 \snippet{ultimatecodesnipped/ultimatecodesnippet.cpp,55} |
125 |
74 |
126 This example demonstrates an alternative way of handling dialog signals. |
75 An example of how to create a non-modal dialog and show it. |
127 This example assumes that the finished(int) overload is connected instead of |
|
128 finished(HbAction*); for example, by using open(QObject *, const char *), like |
|
129 this: |
|
130 |
|
131 \code |
|
132 dialog->open(this, SLOT(dialogClosed(int))); |
|
133 \endcode |
|
134 |
|
135 The finished(int) signal is emitted by calling accept() and reject() or done(). |
|
136 |
|
137 Here is an example of a function that handles finished(int): |
|
138 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,58} |
|
139 |
|
140 \subsection _uc_004_hbdialog Creating and showing a non-modal dialog |
|
141 |
|
142 This final example shows how to create a non-modal dialog and show it. |
|
143 Notice that we display a non-modal dialog by calling \link QGraphicsItem::show() |
|
144 show()\endlink. |
76 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,26} |
145 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,26} |
77 |
146 |
78 */ |
147 \sa HbPopup, HbDeviceDialog, HbInputDialog, HbMessageBox, HbProgressDialog, |
|
148 HbNotificationDialog, HbColorDialog, HbSelectionDialog, HbVolumeSliderPopup, |
|
149 HbZoomSliderPopup |
|
150 */ |
|
151 |
|
152 /*! |
|
153 \enum HbDialog::DialogCode |
|
154 Indicates whether the dialog was accepted or rejected. |
|
155 |
|
156 \sa finished(int), done() |
|
157 |
|
158 */ |
|
159 |
|
160 /*! |
|
161 \var HbDialog::Rejected |
|
162 Indicates that the user selected the Cancel action (or equivalent). |
|
163 */ |
|
164 |
|
165 /*! |
|
166 \var HbDialog::Accepted |
|
167 Indicates that the user selected the OK action (or equivalent). |
|
168 */ |
79 |
169 |
80 /*! |
170 /*! |
81 \fn void HbDialog::finished( int code ) |
171 \fn void HbDialog::finished( int code ) |
82 |
172 |
83 This signal is emitted when the dialog is closed. |
173 This signal is emitted when the dialog closes. \a code is an |
84 This will have the HbDialog::DialogCode as the parameter code. |
174 HbDialog::DialogCode value. |
85 |
175 |
86 \sa done(), accept(), reject() |
176 \sa done(), accept(), reject() |
87 */ |
177 */ |
88 /*! |
178 /*! |
89 \fn void HbDialog::finished( HbAction *action ) |
179 \fn void HbDialog::finished( HbAction *action ) |
90 |
180 |
91 This signal is emitted when an action has been triggered in a dialog. |
181 This signal is emitted when an action is triggered in a dialog. |
92 The parameter will be the triggered action. |
182 The parameter is the action that was triggered. |
93 */ |
183 */ |
94 /*! |
184 /*! |
95 \fn void HbDialog::accepted( ) |
185 \fn void HbDialog::accepted( ) |
96 |
186 |
97 This signal is emitted when the dialog is closed and the user |
187 This signal is emitted by a call to accept() or to \link done() |
98 has accepted the dialog. which implies that either action has triggered |
188 done(HbDialog::Accepted)\endlink. Typically this means that the user |
99 or through function call the accept method is called, causing this signal. |
189 has selected the OK button (or equivalent). |
100 |
190 |
101 \sa done(), accept(), reject() |
191 \sa done(), accept(), reject() |
102 */ |
192 */ |
103 /*! |
193 /*! |
104 \fn void HbDialog::rejected( ) |
194 \fn void HbDialog::rejected( ) |
105 |
195 |
106 This signal is emitted when the dialog is closed and the user |
196 This signal is emitted by a call to reject() or to \link done() |
107 has rejected the dialog. which implies that either action triggered |
197 done(HbDialog::Rejected)\endlink. Typically this means that the user |
108 or through function call the reject method is called, causing this signal. |
198 has selected the Cancel action (or equivalent). |
109 |
199 |
110 \sa done(), accept(), reject() |
200 \sa done(), accept(), reject() |
111 */ |
201 */ |
112 |
202 |
113 |
203 /*! |
114 /*! |
|
115 \reimp |
|
116 \fn int HbDialog::type() const |
204 \fn int HbDialog::type() const |
117 */ |
205 */ |
118 |
206 |
119 HbDialogPrivate::HbDialogPrivate( ) : |
207 HbDialogPrivate::HbDialogPrivate( ) : |
120 contentWidget(0), |
208 contentWidget(0), |
121 headingWidget(0), |
209 headingWidget(0), |
122 primaryAction(0), |
210 primaryAction(0), |
123 secondaryAction(0), |
211 secondaryAction(0), |
124 closingAction(0), |
212 closingAction(0), |
125 toolBar(0) |
213 toolBar(0), |
|
214 dismissOnAction(true), |
|
215 headingFrameItem(0) |
126 { |
216 { |
127 } |
217 } |
128 |
218 |
129 HbDialogPrivate::~HbDialogPrivate() |
219 HbDialogPrivate::~HbDialogPrivate() |
130 { |
220 { |
131 } |
221 } |
132 |
222 |
133 /*! |
223 /* |
134 Relayouts the popup. If expandSize is true it the new calculated size of the popup |
224 Relayouts the popup. If expandSize is true it the new calculated size of the popup |
135 cannot be smaller than the current size. |
225 cannot be smaller than the current size. |
136 */ |
226 */ |
137 void HbDialogPrivate::doLayout() |
227 void HbDialogPrivate::doLayout() |
138 { |
228 { |
165 if(!ch.isSpace()) |
283 if(!ch.isSpace()) |
166 string.append(ch); |
284 string.append(ch); |
167 } |
285 } |
168 } |
286 } |
169 |
287 |
170 /*! |
288 void HbDialogPrivate::setFullScreen(bool enable) |
171 Constructs a dialog with given \a parent graphics item.\n |
289 { |
172 Note: dialogs with \a parent set as 0 are behaving as real popups. |
290 //If the dialog is in fullscreen, normal toolbar graphics will be used |
173 This is actually the intended use. \sa HbPopup::HbPopup |
291 if (enable) { |
|
292 if (toolBar) { |
|
293 HbToolBarPrivate::d_ptr(toolBar)->updateDialogToolbar(false); |
|
294 } |
|
295 } else { |
|
296 if (toolBar){ |
|
297 HbToolBarPrivate::d_ptr(toolBar)->updateDialogToolbar(true); |
|
298 } |
|
299 } |
|
300 HbPopupPrivate::setFullScreen(enable); |
|
301 //If heading is available, update fullscreen heading graphics |
|
302 if (!headingText.isEmpty() || headingWidget) { |
|
303 createHeadingBackground(); |
|
304 } |
|
305 } |
|
306 |
|
307 /*! |
|
308 Constructs a dialog with the given \a parent. For a popup dialog (which |
|
309 means that it opens above all other objects, at the highest z-order), |
|
310 set \a parent to 0. This is the primary intended use of this class. |
|
311 |
|
312 If \a parent is non-zero, the dialog is embedded in the parent QGraphicsItem. |
|
313 The properties provided by HbPopup are then ignored and the aboutToClose() signal is |
|
314 not emitted. |
|
315 |
|
316 \sa HbPopup::HbPopup() |
174 */ |
317 */ |
175 HbDialog::HbDialog(QGraphicsItem *parent) : |
318 HbDialog::HbDialog(QGraphicsItem *parent) : |
176 HbPopup(*new HbDialogPrivate, parent) |
319 HbPopup(*new HbDialogPrivate, parent) |
177 { |
320 { |
178 Q_D(HbDialog); |
321 Q_D(HbDialog); |
179 d->q_ptr = this; |
322 d->q_ptr = this; |
180 d->timeout = HbPopupPrivate::timeoutValue(HbPopup::NoTimeout); |
323 d->pendingTimeout = HbPopup::NoTimeout; |
181 } |
324 } |
182 |
325 |
183 /*! |
326 /*! |
184 \internal |
327 \internal |
185 */ |
328 */ |
186 HbDialog::HbDialog(HbDialogPrivate &dd, QGraphicsItem *parent) : |
329 HbDialog::HbDialog(HbDialogPrivate &dd, QGraphicsItem *parent) : |
187 HbPopup(dd, parent) |
330 HbPopup(dd, parent) |
188 { |
331 { |
189 Q_D(HbDialog); |
332 Q_D(HbDialog); |
190 d->q_ptr = this; |
333 d->q_ptr = this; |
191 d->timeout = HbPopupPrivate::timeoutValue(HbPopup::NoTimeout); |
334 d->pendingTimeout = HbPopup::NoTimeout; |
192 } |
335 } |
193 |
336 |
194 /*! |
337 /*! |
195 Destroys the popup. |
338 Destructor. |
196 */ |
339 */ |
197 HbDialog::~HbDialog() |
340 HbDialog::~HbDialog() |
198 { |
341 { |
199 } |
342 } |
200 |
343 |
201 /*! |
344 /*! |
202 Returns the widget which is being added to the heading area |
345 Returns the heading widget, if one has been added to the dialog; otherwise this |
203 \sa setHeadingWidget() |
346 function returns null. |
|
347 \sa setHeadingWidget() |
204 */ |
348 */ |
205 QGraphicsWidget * HbDialog::headingWidget() const |
349 QGraphicsWidget * HbDialog::headingWidget() const |
206 { |
350 { |
207 Q_D(const HbDialog); |
351 Q_D(const HbDialog); |
208 return (d->headingWidget); |
352 return (d->headingWidget); |
209 } |
353 } |
210 |
354 |
211 /*! |
355 /*! |
212 Adds \a widget to the heading area. Ownership of the widget is transferred |
356 Adds \a headingWidget to the heading area of the dialog. This transfers ownership |
213 to popup. If \a headingWidget is 0 the heading widget is removed. |
357 of the heading widget to the dialog. |
214 \sa headingWidget() |
358 |
|
359 To remove a heading widget from a dialog, set \a headingWidget to 0. |
|
360 \sa headingWidget() |
215 */ |
361 */ |
216 void HbDialog::setHeadingWidget(QGraphicsWidget *headingWidget) |
362 void HbDialog::setHeadingWidget(QGraphicsWidget *headingWidget) |
217 { |
363 { |
218 Q_D(HbDialog); |
364 Q_D(HbDialog); |
219 if (d->headingWidget == headingWidget) |
365 if (d->headingWidget == headingWidget) |
220 return; |
366 return; |
221 if (d->headingWidget) |
367 if (d->headingWidget) |
222 delete d->headingWidget; |
368 delete d->headingWidget; |
223 d->headingWidget = headingWidget; |
369 d->headingWidget = headingWidget; |
|
370 d->headingText = QString(); |
224 if (headingWidget) { |
371 if (headingWidget) { |
225 setProperty("heading_layout", true); |
372 setProperty("heading_layout", true); |
226 headingWidget->setParentItem(this); |
373 d->headingWidget->setParentItem(this); |
|
374 d->headingWidget->setZValue(zValue()+1); |
227 HbStyle::setItemName(headingWidget,"heading"); |
375 HbStyle::setItemName(headingWidget,"heading"); |
228 } else { |
376 } else { |
229 setProperty("heading_layout", false); |
377 setProperty("heading_layout", false); |
230 } |
378 } |
|
379 |
|
380 if (headingWidget) { |
|
381 d->createHeadingBackground(); |
|
382 } else { |
|
383 if (d->headingFrameItem) { |
|
384 delete d->headingFrameItem; |
|
385 d->headingFrameItem = 0; |
|
386 } |
|
387 } |
231 repolish(); |
388 repolish(); |
232 } |
389 } |
233 |
390 |
234 /*! |
391 /*! |
235 Returns the content widget property of the popup. |
392 Returns the heading text, if one has been added to the dialog; otherwise this |
236 HbDialog only draws a bordered rect, the rest is drawn by the content widget. |
393 function returns empty string. |
237 \sa setContentWidget() |
394 \sa setHeadingText() |
|
395 */ |
|
396 QString HbDialog::headingText() const |
|
397 { |
|
398 Q_D(const HbDialog); |
|
399 return d->headingText; |
|
400 } |
|
401 |
|
402 /*! |
|
403 Sets \a heading as the title of the dialog. |
|
404 |
|
405 To remove the title from the dialog, set an empty string as \a heading. |
|
406 \sa headingText() |
|
407 */ |
|
408 void HbDialog::setHeadingText(const QString &heading) |
|
409 { |
|
410 Q_D(HbDialog); |
|
411 if (d->headingWidget) { |
|
412 delete d->headingWidget; |
|
413 d->headingWidget = 0; |
|
414 } |
|
415 |
|
416 d->headingText = heading; |
|
417 |
|
418 if (!heading.isEmpty()) { |
|
419 d->headingWidget = qobject_cast<QGraphicsWidget *>(style()->createPrimitive(HbStyle::PT_TextItem, "heading", this)); |
|
420 d->headingWidget->setZValue(zValue()+1); |
|
421 HbStyleTextPrimitiveData data; |
|
422 initPrimitiveData(&data, d->headingWidget); |
|
423 data.text = heading; |
|
424 style()->updatePrimitive(d->headingWidget, &data, this); |
|
425 d->headingWidget->update(); |
|
426 |
|
427 d->createHeadingBackground(); |
|
428 |
|
429 setProperty("heading_layout", true); |
|
430 } else { |
|
431 setProperty("heading_layout", false); |
|
432 if (d->headingFrameItem) { |
|
433 delete d->headingFrameItem; |
|
434 d->headingFrameItem = 0; |
|
435 } |
|
436 } |
|
437 repolish(); |
|
438 } |
|
439 |
|
440 /*! |
|
441 Returns the content widget, if one has been added to the dialog; otherwise this |
|
442 function returns null. |
|
443 |
|
444 The content widget provides the main content for the dialog. Without a content |
|
445 widget (and a heading widget and some actions), an HbDialog object is simply a |
|
446 bordered rectangle. |
|
447 \sa setContentWidget() |
238 */ |
448 */ |
239 QGraphicsWidget *HbDialog::contentWidget() const |
449 QGraphicsWidget *HbDialog::contentWidget() const |
240 { |
450 { |
241 Q_D(const HbDialog); |
451 Q_D(const HbDialog); |
242 return d->contentWidget; |
452 return d->contentWidget; |
243 } |
453 } |
244 |
454 |
245 /*! |
455 /*! |
246 Sets the content widget property of the popup. |
456 Adds \a contentWidget to the dialog. This transfers ownership of the content |
247 HbDialog only draws a bordered rect, the rest is drawn by the content widget. |
457 widget to the dialog. |
248 Ownership of the widget is transferred |
458 |
249 to popup. If \a contentWidget is 0 the content widget is removed. |
459 To remove a content widget from a dialog, set \a headingWidget to 0. |
250 \sa contentWidget() |
460 |
|
461 \sa contentWidget() |
251 */ |
462 */ |
252 void HbDialog::setContentWidget(QGraphicsWidget *contentWidget) |
463 void HbDialog::setContentWidget(QGraphicsWidget *contentWidget) |
253 { |
464 { |
254 Q_D(HbDialog); |
465 Q_D(HbDialog); |
255 |
466 |
256 if (d->contentWidget == contentWidget) |
467 if (d->contentWidget == contentWidget) |
257 return; |
468 return; |
258 if (d->contentWidget) |
469 if (d->contentWidget) |
259 delete d->contentWidget; |
470 delete d->contentWidget; |
260 prepareGeometryChange(); // needed to paint screen properly |
|
261 d->contentWidget = contentWidget; |
471 d->contentWidget = contentWidget; |
262 if (contentWidget) { |
472 if (contentWidget) { |
263 contentWidget->setParentItem(this); |
473 contentWidget->setParentItem(this); |
|
474 if (contentWidget->inherits("HbAbstractItemView")) { |
|
475 setProperty("list_content", true); |
|
476 } else { |
|
477 setProperty("list_content", false); |
|
478 } |
264 HbStyle::setItemName(contentWidget,"content"); |
479 HbStyle::setItemName(contentWidget,"content"); |
265 } |
480 } |
266 repolish(); |
481 repolish(); |
267 } |
482 } |
268 |
483 |
269 /*! |
484 /*! |
270 \deprecated HbDialog::primaryAction() const |
485 \deprecated This function is deprecated. |
271 is deprecated. |
486 |
272 It returns the primary action added to the control area |
487 Returns the action added by calling setPrimaryAction(). |
273 \sa setPrimaryAction() |
|
274 */ |
488 */ |
275 HbAction* HbDialog::primaryAction() const |
489 HbAction* HbDialog::primaryAction() const |
276 { |
490 { |
277 HB_DEPRECATED("HbAction* HbDialog::primaryAction() is deprecated. Use QGraphicsWidget action api instead"); |
491 HB_DEPRECATED("HbAction* HbDialog::primaryAction() is deprecated. Use QGraphicsWidget action api instead"); |
278 Q_D(const HbDialog); |
492 Q_D(const HbDialog); |
279 return d->primaryAction; |
493 return d->primaryAction; |
280 } |
494 } |
281 |
495 |
282 /*! |
496 /*! |
283 \deprecated HbDialog::setPrimaryAction(HbAction*) |
497 Returns the \c dismissOnAction property, which controls whether the dialog closes |
284 is deprecated. Please use QGraphicsWidget::addAction() family of functions instead. |
498 when one of its actions is triggered. |
285 It adds the given action to the control area. |
499 \sa setDismissOnAction() |
286 It is added to the left side of the control area if the layout direction of the application |
500 */ |
287 is left-to-right and in the vice-versa if the layout direction of the application |
501 bool HbDialog::dismissOnAction() const |
288 is right-to-left. |
502 { |
289 \sa primaryAction() |
503 Q_D(const HbDialog); |
|
504 return d->dismissOnAction; |
|
505 } |
|
506 |
|
507 /*! |
|
508 Sets the \c dismissOnAction property, which controls whether the dialog closes |
|
509 when one of its actions is triggered. |
|
510 \sa dismissOnAction() |
|
511 */ |
|
512 void HbDialog::setDismissOnAction( bool dismissOnAction ) |
|
513 { |
|
514 Q_D(HbDialog); |
|
515 d->dismissOnAction = dismissOnAction; |
|
516 } |
|
517 |
|
518 /*! |
|
519 \deprecated This function is deprecated. Add actions by calling one of |
|
520 the QGraphicsWidget::addAction() family of functions instead. |
|
521 |
|
522 Adds \a action to the left side of the dialog's toolbar if the layout is left |
|
523 to right and to the right side of the toolbar if the layout is right to left. |
|
524 |
|
525 \sa primaryAction() |
290 */ |
526 */ |
291 void HbDialog::setPrimaryAction(HbAction *action) |
527 void HbDialog::setPrimaryAction(HbAction *action) |
292 { |
528 { |
293 HB_DEPRECATED("HbDialog::setPrimaryAction(HbAction *action) is deprecated. Use QGraphicsWidget action api instead"); |
529 HB_DEPRECATED("HbDialog::setPrimaryAction(HbAction *action) is deprecated. Use QGraphicsWidget action api instead"); |
|
530 /* HbDialog::setPrimaryAction deprecation action coloring - begin */ |
|
531 action->setProperty("invalid_addition", true); |
|
532 /* HbDialog::setPrimaryAction deprecation action coloring - end */ |
294 Q_D(HbDialog); |
533 Q_D(HbDialog); |
295 if (d->primaryAction && action != d->primaryAction) { |
534 if (d->primaryAction && action != d->primaryAction) { |
296 removeAction(d->primaryAction); |
535 removeAction(d->primaryAction); |
297 } |
536 } |
298 d->primaryAction = action; |
537 d->primaryAction = action; |
302 } |
541 } |
303 insertAction(before, action); |
542 insertAction(before, action); |
304 } |
543 } |
305 |
544 |
306 /*! |
545 /*! |
307 \deprecated HbDialog::secondaryAction() const |
546 \deprecated This function is deprecated. |
308 is deprecated. |
547 |
309 It returns the secondary action added to the control area |
548 Returns the action added by calling setSecondaryAction(). |
310 \sa setSecondaryAction() |
|
311 */ |
549 */ |
312 HbAction* HbDialog::secondaryAction() const |
550 HbAction* HbDialog::secondaryAction() const |
313 { |
551 { |
314 HB_DEPRECATED("HbAction* HbDialog::secondaryAction() is deprecated. Use QGraphicsWidget action api instead"); |
552 HB_DEPRECATED("HbAction* HbDialog::secondaryAction() is deprecated. Use QGraphicsWidget action api instead"); |
315 Q_D(const HbDialog); |
553 Q_D(const HbDialog); |
316 return(d->secondaryAction); |
554 return(d->secondaryAction); |
317 } |
555 } |
318 |
556 |
319 /*! |
557 /*! |
320 \deprecated HbDialog::setSecondaryAction(HbAction*) |
558 \deprecated This function is deprecated. Add actions by calling one of |
321 is deprecated. Please use QGraphicsWidget::addAction() family of functions instead. |
559 the QGraphicsWidget::addAction() family of functions instead. |
322 It adds the given action to the control area. |
560 |
323 It is added to the right side of the control area if the layout direction of the application |
561 Adds \a action to the right side of the dialog's toolbar if the layout is left |
324 is left-to-right and in the vice-versa if the layout direction of the application |
562 to right and to the left side of the toolbar if the layout is right to left. |
325 is right-to-left. |
563 |
326 \sa secondaryAction() |
564 \sa secondaryAction() |
327 */ |
565 */ |
328 void HbDialog::setSecondaryAction(HbAction *action) |
566 void HbDialog::setSecondaryAction(HbAction *action) |
329 { |
567 { |
330 HB_DEPRECATED("HbDialog::setSecondaryAction(HbAction *action) is deprecated. Use QGraphicsWidget action api instead"); |
568 HB_DEPRECATED("HbDialog::setSecondaryAction(HbAction *action) is deprecated. Use QGraphicsWidget action api instead"); |
|
569 /* HbDialog::setPrimaryAction deprecation action coloring - begin */ |
|
570 action->setProperty("invalid_addition", true); |
|
571 /* HbDialog::setPrimaryAction deprecation action coloring - end */ |
331 Q_D(HbDialog); |
572 Q_D(HbDialog); |
332 if (d->secondaryAction && action != d->secondaryAction) { |
573 if (d->secondaryAction && action != d->secondaryAction) { |
333 removeAction(d->secondaryAction); |
574 removeAction(d->secondaryAction); |
334 } |
575 } |
335 d->secondaryAction = action; |
576 d->secondaryAction = action; |
336 addAction(action); |
577 addAction(action); |
337 } |
578 } |
338 |
579 |
339 /*! |
580 /*! |
340 This is a slot which shows the dialog and returns immediately. |
581 Displays the dialog and returns immediately. |
341 |
582 |
342 \sa open(QObject*,const char*) |
583 Use this function to open \b modal dialogs. To open \b non-modal dialogs, |
|
584 call \link QGraphicsItem::show() show()\endlink. |
|
585 |
|
586 \overload |
|
587 |
|
588 \sa open(QObject*, const char*), HbPopup::isModal() |
343 */ |
589 */ |
344 void HbDialog::open() |
590 void HbDialog::open() |
345 { |
591 { |
346 open(0,0); |
592 open(0,0); |
347 } |
593 } |
348 /*! |
594 /*! |
349 |
595 Displays the dialog, connects the finished(HbAction*) or finished(int) signal to a |
350 Shows the dialog as modal dialog returning immediately. |
596 receiver object's slot, and returns immediately. Disambiguation between the two |
351 |
597 signals is done at runtime. The signal is disconnected from the slot when the dialog |
352 Connects finished(HbAction*) or finished(int) signal to the slot specified by \a receiver and |
598 closes. |
353 \a member. The signal will be disconnected from the slot when the |
599 |
354 popup is closed. disambiguation between which method to connect to is done at runtime. |
600 Use this function to open \b modal dialogs. To open \b non-modal dialogs, |
355 |
601 call \link QGraphicsItem::show() show()\endlink. |
356 For non modal popups, use show(). |
602 |
357 */ |
603 \overload |
358 |
604 |
|
605 \param receiver The object that is to receive the signal. |
|
606 \param member The slot on the receiver to which the signal is to connect. |
|
607 |
|
608 \sa HbPopup::isModal() |
|
609 */ |
359 void HbDialog::open( QObject* receiver, const char* member ) |
610 void HbDialog::open( QObject* receiver, const char* member ) |
360 { |
611 { |
361 Q_D(HbDialog); |
612 Q_D(HbDialog); |
362 if ( receiver && member ) { |
613 if ( receiver && member ) { |
363 |
614 |
408 else if(code == Rejected) { |
664 else if(code == Rejected) { |
409 emit rejected(); |
665 emit rejected(); |
410 } |
666 } |
411 } |
667 } |
412 /*! |
668 /*! |
413 Hides the modal dialog and emits finished(HbDialog::Accepted),accepted() and finished(HbAction*) signals. |
669 Closes the dialog and emits the \link finished(int) finished(HbDialog::Accepted)\endlink, |
414 |
670 accepted(), and finished(HbAction*) signals. Typically, you call this function when the |
415 \sa reject(), done() |
671 user selects the OK action (or equivalent). |
|
672 |
|
673 Like \link QGraphicsWidget::close() close()\endlink, this function deletes the |
|
674 dialog if the Qt::WA_DeleteOnClose flag is set. |
|
675 |
|
676 \b Example: |
|
677 \code |
|
678 // Create the OK action. |
|
679 mOkAction = new HbAction("OK"); |
|
680 |
|
681 // Connect its triggered signal to the dialog's accept() slot. |
|
682 connect(mOkAction, SIGNAL(triggered()), this, SLOT(accept())); |
|
683 |
|
684 // Add the action to the dialog. |
|
685 addAction(mOkAction); |
|
686 \endcode |
|
687 |
|
688 \sa reject(), done() |
416 */ |
689 */ |
417 void HbDialog::accept() |
690 void HbDialog::accept() |
418 { |
691 { |
419 done(Accepted); |
692 done(Accepted); |
420 } |
693 } |
421 /*! |
694 /*! |
422 Hides the modal dialog and emits finished(HbDialog::Rejected),rejected() and finished(HbAction*) signals. |
695 Closes the dialog and emits the \link finished(int) finished(HbDialog::Rejected)\endlink, |
423 |
696 rejected(), and finished(HbAction*) signals. Typically, you call this function when |
424 \sa accept(), done() |
697 the user selects the Cancel action (or equivalent). |
|
698 |
|
699 Like \link QGraphicsWidget::close() close()\endlink, this function deletes the |
|
700 dialog if the Qt::WA_DeleteOnClose flag is set. |
|
701 |
|
702 \b Example: |
|
703 \code |
|
704 // Create the Cancel action. |
|
705 mCancelAction = new HbAction("Cancel"); |
|
706 |
|
707 // Connect its triggered signal to the dialog's reject() slot. |
|
708 connect(mCancelAction, SIGNAL(triggered()), this, SLOT(reject())); |
|
709 |
|
710 // Add the action to the dialog. |
|
711 addAction(mCancelAction); |
|
712 \endcode |
|
713 |
|
714 \sa accept(), done() |
425 */ |
715 */ |
426 void HbDialog::reject() |
716 void HbDialog::reject() |
427 { |
717 { |
428 done(Rejected); |
718 done(Rejected); |
429 } |
719 } |
430 |
720 |
431 /*! |
721 /*! |
432 \reimp |
722 |
433 */ |
723 */ |
434 // |
724 // |
435 // Sets the focus to its content widget. |
725 // Sets the focus to its content widget. |
436 // |
726 // |
437 void HbDialog::focusInEvent(QFocusEvent *event) |
727 void HbDialog::focusInEvent(QFocusEvent *event) |
481 |
771 |
482 HbPopup::changeEvent(event); |
772 HbPopup::changeEvent(event); |
483 } |
773 } |
484 |
774 |
485 /*! |
775 /*! |
486 \reimp |
776 |
487 */ |
777 */ |
488 bool HbDialog::event(QEvent *event) |
778 bool HbDialog::event(QEvent *event) |
489 { |
779 { |
490 Q_D(HbDialog); |
780 Q_D(HbDialog); |
491 if(event->type() != QEvent::ShortcutOverride && event->type() != QEvent::GestureOverride) |
781 if(event->type() != QEvent::ShortcutOverride && event->type() != QEvent::GestureOverride) |
492 event->accept(); |
782 event->accept(); |
493 |
783 |
494 if (event->type() == QEvent::ActionAdded) { |
784 if (event->type() == QEvent::ActionAdded) { |
495 if (!d->toolBar) { |
785 if (!d->toolBar) { |
496 // TODO: HbToolBar private interface should make it possible to choose |
|
497 // different graphics for tool buttons. |
|
498 d->toolBar = new HbToolBar(); |
786 d->toolBar = new HbToolBar(); |
|
787 d->toolBar->setFlag(QGraphicsItem::ItemIsPanel, false); |
499 d->toolBar->setParentItem(this); |
788 d->toolBar->setParentItem(this); |
500 HbStyle::setItemName(d->toolBar ,"controls"); |
789 HbStyle::setItemName(d->toolBar ,"controls"); |
501 setProperty("controls_layout", true); |
790 setProperty("controls_layout", true); |
502 d->toolBar->setOrientation(Qt::Horizontal); |
791 d->toolBar->setOrientation(Qt::Horizontal); |
503 HbToolBarPrivate::d_ptr(d->toolBar)->mDialogToolBar = true; |
792 // Choose different graphics for tool buttons. |
|
793 if (!d->mFullScreen) { |
|
794 HbToolBarPrivate::d_ptr(d->toolBar)->mDialogToolBar = true; |
|
795 } |
504 repolish(); |
796 repolish(); |
505 } |
797 } |
506 QActionEvent *actionEvent = static_cast<QActionEvent *>(event); |
798 QActionEvent *actionEvent = static_cast<QActionEvent *>(event); |
507 d->toolBar->insertAction (actionEvent->before(), actionEvent->action()); |
799 d->toolBar->insertAction (actionEvent->before(), actionEvent->action()); |
508 if (!parentItem()) { // only for popup without parent |
800 if (!parentItem()) { // only for popup without parent |
509 connect(actionEvent->action(), SIGNAL(triggered()), this, SLOT(close())); |
801 connect(actionEvent->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); |
510 } |
802 } |
511 d->doLayout(); |
803 d->doLayout(); |
512 return true; |
804 return true; |
513 |
805 |
514 } else if (event->type() == QEvent::ActionRemoved) { |
806 } else if (event->type() == QEvent::ActionRemoved) { |