src/hbwidgets/popups/hbnotificationdialog.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    42 
    42 
    43 #ifdef HB_EFFECTS
    43 #ifdef HB_EFFECTS
    44 #include "hbeffectinternal_p.h"
    44 #include "hbeffectinternal_p.h"
    45 #endif
    45 #endif
    46 
    46 
    47 #include <hbstyleoptionnotificationdialog.h>
    47 #include <hbstyleoptionnotificationdialog_p.h>
    48 #include "hbnotificationdialogcontent_p.h"
    48 #include "hbnotificationdialogcontent_p.h"
    49 
    49 
    50 #define H_MARGIN QString("hb-param-margin-gene-middle-horizontal")
    50 #define H_MARGIN QString("hb-param-margin-gene-middle-horizontal")
    51 #define V_MARGIN QString("hb-param-margin-gene-middle-vertical")
    51 #define V_MARGIN QString("hb-param-margin-gene-middle-vertical")
    52 
    52 
    84 {
    84 {
    85     return notificationDialogSequentialShowInstance();
    85     return notificationDialogSequentialShowInstance();
    86 }
    86 }
    87 
    87 
    88 /*!
    88 /*!
       
    89     @beta
       
    90     @hbwidgets
    89     \class HbNotificationDialog
    91     \class HbNotificationDialog
    90     \brief HbNotificationDialog is a non-modal dialog displayed on top of applications.
    92     \brief HbNotificationDialog can be used to notify users of system
    91     Notification dialog is a dialog that can be used for notifying users of the system
    93     generated or user activated events in the UI.
    92     generated or user activated events in the UI. These notifications do not require
    94 
       
    95     HbNotificationDialog is a non-modal dialog displayed on top of applications.
       
    96     These notifications do not require
    93     user input.
    97     user input.
    94 
    98 
    95     If wanted, some action can be activated with a tap to the notification dialog. The user
    99     Optionally, an action can be activated with a tap to the notification dialog. This is enabled
    96     of notification dialog can do this by first enabling the touch activation with
   100     by first enabling the touch activation with
    97     enableTouchActivation() and then starting the action with the signal
   101     enableTouchActivation() and then starting the action with the signal
    98     HbNotificationDialog::activated()
   102     HbNotificationDialog::activated().
    99 
   103 
   100     HbNotificationDialog is a concrete class. For the content, you can use the default content
   104     HbNotificationDialog is a concrete class. For the content, you can use the default content
   101     widgets which provides two rows of text (title only, or title and text) and optionally an icon.
   105     widgets which provides two rows of text (title spanning both lines, or title and text) and optionally an icon.
   102 	You can use the default content widget by invoking the HbNotificationDialog with its
   106 	You can use the default content widget by invoking the HbNotificationDialog with its
   103     static launch-methods or by using the methods setText, setTitle, setIcon.
   107     static launch-methods or by using the methods setText(), setTitle() and setIcon().
   104 
   108 
   105     Alternatively, you can create a separate widget, and set it to the dialog with inherited method
   109     Alternatively, you can create a separate widget, and set it to the dialog with the inherited method
   106     HbNotificationDialog::setContentWidget().
   110     HbNotificationDialog::setContentWidget().
   107 
   111 
   108     To display a notification dialog, show() or exec() has to be called. By default, notifications
   112     To display a notification dialog, show() or open() must be called. By default, notifications
   109     are synchronized with device dialogs. Showing of notification dialogs are delayed until there
   113     are synchronized with device dialogs. The display of notification dialogs is delayed until there
   110     are no device dialogs on display. Notifications are also synchronized with each other.
   114     are no device dialogs on display. Notifications are also synchronized with each other.
   111     If several notifications are shown at the same time with show() function, they are shown
   115     If several notifications are shown at the same time with the show() function, they are shown
   112     sequentially instead of on top of each other. Sequential show and device dialog
   116     sequentially instead of on top of each other. The synchronization of dialogs and sequential display of dialogs 
   113     synchronization can be disabled by setSequentialShow() function.
   117     can be disabled using the setSequentialShow() function.
   114 
       
   115     \beta
       
   116     \hbwidgets
       
   117 */
   118 */
   118 
   119 
   119 /*!
   120 /*!
   120     \fn void HbNotificationDialog::activated();
   121     \fn void HbNotificationDialog::activated();
   121 
   122 
   122     This signal is emitted when the dialog is closed with a pointer tap
   123     This signal is emitted when the dialog is closed with a pointer tap.
   123  */
   124  */
   124 
   125 
   125 /*!
   126 /*!
   126     \enum HbNotificationDialog::WrapMode
   127     Constructor.
   127     \deprecated HbNotificationDialog::WrapMode
   128  */
   128         is deprecated and will be removed in future.
       
   129 */
       
   130 
       
   131 HbNotificationDialog::HbNotificationDialog() : HbDialog(*new HbNotificationDialogPrivate, 0)
   129 HbNotificationDialog::HbNotificationDialog() : HbDialog(*new HbNotificationDialogPrivate, 0)
   132 {
   130 {
   133     Q_D(HbNotificationDialog);
   131     Q_D(HbNotificationDialog);
   134     d->q_ptr = this;
   132     d->q_ptr = this;
   135     setFocusPolicy(Qt::NoFocus);
   133     setFocusPolicy(Qt::NoFocus);
   141     if ((style()->parameter(H_MARGIN, hMargin)) &&
   139     if ((style()->parameter(H_MARGIN, hMargin)) &&
   142         (style()->parameter(V_MARGIN, vMargin))) {
   140         (style()->parameter(V_MARGIN, vMargin))) {
   143         setPreferredPos(QPointF(hMargin, vMargin));
   141         setPreferredPos(QPointF(hMargin, vMargin));
   144     }
   142     }
   145 
   143 
   146     // todo: priority
   144     //d->setPriority(1);
   147     d->setPriority(1);
       
   148 
   145 
   149     setModal(false);
   146     setModal(false);
   150 
   147 
   151     setBackgroundFaded(false);
   148     setBackgroundFaded(false);
   152     setDismissPolicy(HbPopup::NoDismiss);
   149     setDismissPolicy(HbPopup::NoDismiss);
   160     HbEffectInternal::add(this, "notificationdialog_appear", "appear");
   157     HbEffectInternal::add(this, "notificationdialog_appear", "appear");
   161     HbEffectInternal::add(this, "notificationdialog_disappear", "disappear");
   158     HbEffectInternal::add(this, "notificationdialog_disappear", "disappear");
   162 #endif
   159 #endif
   163 }
   160 }
   164 
   161 
       
   162 /*!
       
   163     Destructor.
       
   164  */
   165 HbNotificationDialog::~HbNotificationDialog()
   165 HbNotificationDialog::~HbNotificationDialog()
   166 {
   166 {
   167     Q_D(HbNotificationDialog);
   167     Q_D(HbNotificationDialog);
   168     if (d->sequentialShow) {
   168     if (d->sequentialShow) {
   169         sequentialShowInstance()->remove(this);
   169         sequentialShowInstance()->remove(this);
   170     }
   170     }
   171 }
   171 }
   172 
   172 
   173 /*!
   173 /*!
   174     Enable user interaction on dialog.
   174     Enable user interaction on dialog.
   175     \param enable - When enabled, activated() signal is emitted on user action.
   175     \param enabled - When enabled, the activated() signal is emitted on user action.
       
   176 
   176     \sa isTouchActivating()
   177     \sa isTouchActivating()
   177 */
   178 */
   178 void HbNotificationDialog::enableTouchActivation(bool enabled)
   179 void HbNotificationDialog::enableTouchActivation(bool enabled)
   179 {
   180 {
   180     Q_D(HbNotificationDialog);
   181     Q_D(HbNotificationDialog);
   183         d->content->enableTouchActivation(enabled);
   184         d->content->enableTouchActivation(enabled);
   184     }
   185     }
   185 }
   186 }
   186 
   187 
   187 /*!
   188 /*!
   188     returns true if the use interaction is enabled.
   189     Returns true if user interaction is enabled.
       
   190 
   189     \sa enableTouchActivation()
   191     \sa enableTouchActivation()
   190 */
   192 */
   191 bool HbNotificationDialog::isTouchActivating() const
   193 bool HbNotificationDialog::isTouchActivating() const
   192 {
   194 {
   193     Q_D(const HbNotificationDialog);
   195     Q_D(const HbNotificationDialog);
   194     return d->isTouchActivating;
   196     return d->isTouchActivating;
   195 }
   197 }
   196 
   198 
   197 /*!
   199 /*!
   198  Convenience method for using HbNotificationDialog. Shows a notification dialog with
   200     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   199  the given parameters. The dialog is owned by HbNotificationDialog.
   201     the given parameters. The dialog is owned by HbNotificationDialog.
   200 */
   202 */
   201 void HbNotificationDialog::launchDialog(const QString &title, const QString &text, QGraphicsScene* scene)
   203 void HbNotificationDialog::launchDialog(const QString &title, const QString &text, QGraphicsScene* scene)
   202 {
   204 {
   203     HbNotificationDialog *self = new HbNotificationDialog();
   205     HbNotificationDialog *self = new HbNotificationDialog();
   204     if (scene) {
   206     if (scene) {
   209     self->setTitle(title);
   211     self->setTitle(title);
   210     self->show();
   212     self->show();
   211 }
   213 }
   212 
   214 
   213 /*!
   215 /*!
   214  Convenience method for using HbNotificationDialog. Shows a notification dialog with
   216     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   215  the given parameters. The dialog is owned by NotificationDialog.
   217     the given parameters. The dialog is owned by NotificationDialog.
   216 
   218 */
   217  \deprecated HbNotificationDialog::launchDialog(const HbIcon&, QGraphicsScene*)
   219 void HbNotificationDialog::launchDialog(const QString &title, QGraphicsScene* scene)
   218      is deprecated. Showing only icon is not supported by the layout. Use other launchDialog-methods instead.
       
   219 */
       
   220 void HbNotificationDialog::launchDialog(const HbIcon &icon, QGraphicsScene* scene)
       
   221 {
   220 {
   222     HbNotificationDialog *self = new HbNotificationDialog();
   221     HbNotificationDialog *self = new HbNotificationDialog();
   223     if (scene) {
   222     if (scene) {
   224         scene->addItem(self);
   223         scene->addItem(self);
   225     }
   224     }
   226     self->setAttribute(Qt::WA_DeleteOnClose, true);
   225     self->setAttribute(Qt::WA_DeleteOnClose, true);
   227     self->setIcon(icon);
       
   228     self->show();
       
   229 }
       
   230 
       
   231 /*!
       
   232  Convenience method for using HbNotificationDialog. Shows a notification dialog with
       
   233  the given parameters. The dialog is owned by NotificationDialog.
       
   234 */
       
   235 void HbNotificationDialog::launchDialog(const QString &title, QGraphicsScene* scene)
       
   236 {
       
   237     HbNotificationDialog *self = new HbNotificationDialog();
       
   238     if (scene) {
       
   239         scene->addItem(self);
       
   240     }
       
   241     self->setAttribute(Qt::WA_DeleteOnClose, true);
       
   242     self->setTitle(title);
   226     self->setTitle(title);
   243     self->show();
   227     self->show();
   244 }
   228 }
   245 
   229 
   246 /*!
   230 /*!
   247  Convenience method for using HbNotificationDialog. Shows a notification dialog with
   231     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   248  the given parameters. The dialog is owned by HbNotificationDialog.
   232     the given parameters. The dialog is owned by HbNotificationDialog.
   249 */
   233 */
   250 void HbNotificationDialog::launchDialog(const HbIcon &icon, const QString &title,
   234 void HbNotificationDialog::launchDialog(const HbIcon &icon, const QString &title,
   251                                         const QString &text, QGraphicsScene* scene)
   235                                         const QString &text, QGraphicsScene* scene)
   252 {
   236 {
   253     HbNotificationDialog *self = new HbNotificationDialog();
   237     HbNotificationDialog *self = new HbNotificationDialog();
   260     self->setTitle(title);
   244     self->setTitle(title);
   261     self->show();
   245     self->show();
   262 }
   246 }
   263 
   247 
   264 /*!
   248 /*!
   265     \property HbNotificationDialog::title
   249     Returns the title text.
   266     \brief title text
       
   267 
   250 
   268     If a default content widget doesn't exist, it is created.
   251     If a default content widget doesn't exist, it is created.
   269 */
   252 
   270 /*!
   253     \sa setTitle()
   271  returns title text.
       
   272  \sa setTitle()
       
   273 */
   254 */
   274 QString HbNotificationDialog::title() const
   255 QString HbNotificationDialog::title() const
   275 {
   256 {
   276     Q_D(const HbNotificationDialog);
   257     Q_D(const HbNotificationDialog);
   277     if(d->content) {
   258     if(d->content) {
   280         return QString();
   261         return QString();
   281     }
   262     }
   282 }
   263 }
   283 
   264 
   284 /*!
   265 /*!
   285  set title text
   266     Set the dialog title text.
   286  \sa title()
   267 
       
   268     \sa title()
   287 */
   269 */
   288 void HbNotificationDialog::setTitle(const QString& title)
   270 void HbNotificationDialog::setTitle(const QString& title)
   289 {
   271 {
   290     Q_D(HbNotificationDialog);
   272     Q_D(HbNotificationDialog);
   291     d->checkAndCreateContentWidget();
   273     d->checkAndCreateContentWidget();
   292     d->content->setTitle( title );
   274     d->content->setTitle(title);
   293     d->setNotificationDialogContent();
   275     d->setNotificationDialogContent();
   294 }
   276 }
   295 
   277 
   296 /*!
   278 /*!
   297     \property HbNotificationDialog::text
   279     Returns the text for the dialog.
   298     \brief text for the dialog
       
   299 
   280 
   300     If a default content widget doesn't exist, it is created.
   281     If a default content widget doesn't exist, it is created.
   301 */
   282 
   302 /*!
   283     \sa setText()
   303  returns text for the dialog.
       
   304  \sa setText()
       
   305 */
   284 */
   306 QString HbNotificationDialog::text() const
   285 QString HbNotificationDialog::text() const
   307 {
   286 {
   308     Q_D(const HbNotificationDialog);
   287     Q_D(const HbNotificationDialog);
   309     if(d->content) {
   288     if(d->content) {
   312         return QString();
   291         return QString();
   313     }
   292     }
   314 }
   293 }
   315 
   294 
   316 /*!
   295 /*!
   317  set text for the dialog.
   296     Set the text for the dialog.
   318  \sa text()
   297 
       
   298     \sa text()
   319 */
   299 */
   320 void HbNotificationDialog::setText(const QString& text)
   300 void HbNotificationDialog::setText(const QString& text)
   321 {
   301 {
   322     Q_D(HbNotificationDialog);
   302     Q_D(HbNotificationDialog);
   323     d->checkAndCreateContentWidget();
   303     d->checkAndCreateContentWidget();
   324     d->content->setText( text );
   304     d->content->setText( text );
   325     d->setNotificationDialogContent();
   305     d->setNotificationDialogContent();
   326 }
   306 }
   327 
   307 
   328 /*!
   308 /*!
   329     \property HbNotificationDialog::icon
   309     Returns the icon for the dialog.
   330     \brief icon
       
   331 
   310 
   332     If a default content widget doesn't exist, it is created.
   311     If a default content widget doesn't exist, it is created.
   333 */
   312 
   334 /*!
   313     \sa setIcon()
   335  returns the icon.
       
   336  \sa setIcon()
       
   337 */
   314 */
   338 HbIcon HbNotificationDialog::icon() const
   315 HbIcon HbNotificationDialog::icon() const
   339 {
   316 {
   340     Q_D(const HbNotificationDialog);
   317     Q_D(const HbNotificationDialog);
   341     if(d->content) {
   318     if(d->content) {
   344         return QString();
   321         return QString();
   345     }
   322     }
   346 }
   323 }
   347 
   324 
   348 /*!
   325 /*!
   349  set the icon.
   326     Set the icon.
   350  \sa icon()
   327 
       
   328     \sa icon()
   351 */
   329 */
   352 void HbNotificationDialog::setIcon(const HbIcon& icon)
   330 void HbNotificationDialog::setIcon(const HbIcon& icon)
   353 {
   331 {
   354     Q_D(HbNotificationDialog);
   332     Q_D(HbNotificationDialog);
   355     d->checkAndCreateContentWidget();
   333     d->checkAndCreateContentWidget();
   356     d->content->setIcon( icon );
   334     d->content->setIcon( icon );
   357     d->setNotificationDialogContent();
   335     d->setNotificationDialogContent();
   358 }
   336 }
   359 
   337 
   360 /*!
   338 /*!
   361 \deprecated HbNotificationDialog::setWrapMode(int)
   339     Returns the style of text wrapping for the title.
   362     is deprecated. Please use setTitleTextWrapping(Hb::TextWrapping wrapping) instead.
   340     
   363 */
   341     The title can wrap only if there is no other text for the dialog. The title can wrap to a maximum of two lines.
   364 void HbNotificationDialog::setWrapMode(int mode)
   342     The default is Hb::TextWordWrap.
   365 {
   343 
   366     if (mode == NoWrap) {
   344     \sa setTitleTextWrapping(), HbNotificationDialog::title, HbNotificationDialog::text
   367         setTitleTextWrapping(Hb::TextNoWrap);
       
   368     } else {
       
   369         setTitleTextWrapping(Hb::TextWordWrap);
       
   370     }
       
   371 }
       
   372 
       
   373 /*!
       
   374     \property HbNotificationDialog::titleTextWrapping
       
   375     \brief sets the wrapping for title.
       
   376 
       
   377     The title can wrap to two lines only if the text is empty.
       
   378     \sa HbNotificationDialog::title, HbNotificationDialog::text
       
   379 */
       
   380 /*!
       
   381     Returns the wrapping mode. The title can wrap to two lines only if the text is empty.
       
   382     \sa setTitleTextWrapping()
       
   383 */
   345 */
   384 Hb::TextWrapping HbNotificationDialog::titleTextWrapping() const
   346 Hb::TextWrapping HbNotificationDialog::titleTextWrapping() const
   385 {
   347 {
   386     Q_D(const HbNotificationDialog);
   348     Q_D(const HbNotificationDialog);
   387     return d->titleWrapping;
   349     return d->titleWrapping;
   388 }
   350 }
   389 
   351 
   390 /*!
   352 /*!
   391     \brief sets the wrapping for title.
   353     Sets whether the text for the title is wrapped.
   392 
   354 
   393     The title can wrap to two lines only if the text is empty.
   355     The title can wrap only if there is no text for the dialog. The title can wrap to a maximum of two lines.
   394     \sa titleTextWrapping()
   356     \sa titleTextWrapping()
   395 */
   357 */
   396 void HbNotificationDialog::setTitleTextWrapping(Hb::TextWrapping wrapping)
   358 void HbNotificationDialog::setTitleTextWrapping(Hb::TextWrapping wrapping)
   397 {
   359 {
   398     Q_D(HbNotificationDialog);
   360     Q_D(HbNotificationDialog);
   404         d->doLayout();
   366         d->doLayout();
   405     }
   367     }
   406 }
   368 }
   407 
   369 
   408 /*!
   370 /*!
   409     Enables or disables sequential showing of Notification Dialog. Notification dialogs are by
   371     Enables or disables sequential display of the Notification Dialog.
   410     default shown sequentially. Several dialogs displayed by show() at the same time are shown
   372 
   411     one after another instead of on top of each other. Showing of the dialogs are also synchronized
   373     When enabled, notification dialogs are shown sequentially. If multiple calls to show() occur at the same time then the dialogs are displayed
   412     with device dialogs by delaying until none of them are shown. With sequential show disabled,
   374     in sequence instead of on top of each other. The display of the dialogs is also synchronized
       
   375     with the device dialogs such that the notification dialogs do not appear until there are no device dialogs being displayed.
       
   376 
       
   377     With sequential show disabled,
   413     HbNotificationDialog behaves like other popups. While a dialog is waiting to be shown,
   378     HbNotificationDialog behaves like other popups. While a dialog is waiting to be shown,
   414     setVisible(), hide() or show() has no effect. setSequentialShow(false) removes a dialog from the
   379     setVisible(), hide() and show() have no effect. To remove a dialog from the wait queue, call setSequentialShow(false).
   415     wait queue.
   380 
       
   381     This setting is enabled by default. 
   416 
   382 
   417     \sa isSequentialShow()
   383     \sa isSequentialShow()
   418 */
   384 */
   419 void HbNotificationDialog::setSequentialShow(bool sequentially)
   385 void HbNotificationDialog::setSequentialShow(bool sequentially)
   420 {
   386 {
   424     }
   390     }
   425     d->sequentialShow = sequentially;
   391     d->sequentialShow = sequentially;
   426 }
   392 }
   427 
   393 
   428 /*!
   394 /*!
   429     Returns sequential show setting.
   395     Returns the sequential show setting.
   430 
   396 
   431     \sa setSequentialShow()
   397     \sa setSequentialShow()
   432 */
   398 */
   433 bool HbNotificationDialog::isSequentialShow() const
   399 bool HbNotificationDialog::isSequentialShow() const
   434 {
   400 {
   435     Q_D(const HbNotificationDialog);
   401     Q_D(const HbNotificationDialog);
   436     return d->sequentialShow;
   402     return d->sequentialShow;
   437 }
       
   438 
       
   439 /*!
       
   440 \deprecated HbNotificationDialog::wrapMode() const
       
   441     is deprecated. Please use titleTextWrapping() const instead.
       
   442 */
       
   443 int HbNotificationDialog::wrapMode() const
       
   444 {
       
   445     return NoWrap;
       
   446 }
   403 }
   447 
   404 
   448 /*!
   405 /*!
   449  Constructor required by the shared d-pointer paradigm.
   406  Constructor required by the shared d-pointer paradigm.
   450 */
   407 */
   451 HbNotificationDialog::HbNotificationDialog(HbNotificationDialogPrivate &dd, QGraphicsItem *parent) :
   408 HbNotificationDialog::HbNotificationDialog(HbNotificationDialogPrivate &dd, QGraphicsItem *parent) :
   452     HbDialog(dd, parent)
   409     HbDialog(dd, parent)
   453 {
   410 {
       
   411 }
       
   412 
       
   413 /*!
       
   414     \reimp
       
   415 */
       
   416 QGraphicsItem *HbNotificationDialog::primitive(const QString &itemName) const
       
   417 {
       
   418     Q_D(const HbNotificationDialog);
       
   419     
       
   420     if (itemName == "") {
       
   421         return 0;
       
   422     } else {
       
   423         if(d->content) {
       
   424             return d->content->primitive(itemName);
       
   425         } else {
       
   426              return HbWidget::primitive(itemName);
       
   427         }
       
   428     }
   454 }
   429 }
   455 
   430 
   456 void HbNotificationDialog::gestureEvent(QGestureEvent *event)
   431 void HbNotificationDialog::gestureEvent(QGestureEvent *event)
   457 {
   432 {
   458     Q_D(HbNotificationDialog);
   433     Q_D(HbNotificationDialog);