src/hbwidgets/popups/hbnotificationdialog.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    50 
    50 
    51 #define H_MARGIN QString("hb-param-margin-gene-middle-horizontal")
    51 #define H_MARGIN QString("hb-param-margin-gene-middle-horizontal")
    52 #define V_MARGIN QString("hb-param-margin-gene-middle-vertical")
    52 #define V_MARGIN QString("hb-param-margin-gene-middle-vertical")
    53 
    53 
    54 // Container to encapsulate device dialog server status and sequential show
    54 // Container to encapsulate device dialog server status and sequential show
       
    55 /// \cond
    55 class SequentialShow : public HbWidgetSequentialShow
    56 class SequentialShow : public HbWidgetSequentialShow
    56 {
    57 {
    57 public:
    58 public:
    58     SequentialShow();
    59     SequentialShow();
    59     static bool allowNotification(void *serverStatus);
    60     static bool allowNotification(void *serverStatus);
    60 private:
    61 private:
    61     HbDeviceDialogServerStatus mServerStatus;
    62     HbDeviceDialogServerStatus mServerStatus;
    62 };
    63 };
       
    64 /// \endcond
       
    65 
    63 // Constructor
    66 // Constructor
    64 SequentialShow::SequentialShow() :
    67 SequentialShow::SequentialShow() :
    65     HbWidgetSequentialShow(SequentialShow::allowNotification, &mServerStatus), mServerStatus(false)
    68     HbWidgetSequentialShow(SequentialShow::allowNotification, &mServerStatus), mServerStatus(false)
    66 {
    69 {
    67     connect(&mServerStatus, SIGNAL(statusChanged()), SLOT(externalStatusChanged()));
    70     connect(&mServerStatus, SIGNAL(statusChanged()), SLOT(externalStatusChanged()));
    85 {
    88 {
    86     return notificationDialogSequentialShowInstance();
    89     return notificationDialogSequentialShowInstance();
    87 }
    90 }
    88 
    91 
    89 /*!
    92 /*!
    90     @beta
    93     @stable
    91     @hbwidgets
    94     @hbwidgets
       
    95 
    92     \class HbNotificationDialog
    96     \class HbNotificationDialog
    93     \brief HbNotificationDialog can be used to notify users of system
    97     \brief HbNotificationDialog is a non-modal dialog for displaying application notifications.
    94     generated or user activated events in the UI.
    98 
    95 
    99     HbNotificationDialog is displayed at top left corner of a display. It is intended for
    96     HbNotificationDialog is a non-modal dialog displayed on top of applications.
   100     applications to show notifications to user in non-intrusive way. The dialog does not
    97     These notifications do not require
   101     require user input and is usually closed by timeout.
    98     user input.
   102 
    99 
   103     For content, HbNotificationDialog supports two rows of text and an icon. Two text rows may
   100     Optionally, an action can be activated with a tap to the notification dialog. This is enabled
   104     consist either of a title spanning two lines or title and text. Setters are provided for
   101     by first enabling the touch activation with
   105     setting title, text and icon. Alternatively, a custom widget can be created and set as
   102     enableTouchActivation() and then starting the action with the signal
   106     content by an inherited method setContentWidget().
   103     HbNotificationDialog::activated().
   107 
   104 
   108     HbNotificationDialog closes when tapped. A tap triggers HbNotificationDialog::activated() signal
   105     HbNotificationDialog is a concrete class. For the content, you can use the default content
   109     if enabled by enableTouchActivation().
   106     widgets which provides two rows of text (title spanning both lines, or title and text) and optionally an icon.
   110 
   107     You can use the default content widget by invoking the HbNotificationDialog with its
   111     Notification dialog is displayed by show() or open() methods. Static helper functions
   108     static launch-methods or by using the methods setText(), setTitle() and setIcon().
   112     launchDialog() can be used to show dialogs. 
   109 
   113 
   110     Alternatively, you can create a separate widget, and set it to the dialog with the inherited method
   114     By default, notification dialogs are synchronized with device dialogs. The display of
   111     HbNotificationDialog::setContentWidget().
   115     notification dialogs is delayed until there are no device dialogs on display.
   112 
   116     Notifications dialogs are also synchronized with each other. If several of them
   113     To display a notification dialog, show() or open() must be called. By default, notifications
   117     are shown at the same time, they are shown sequentially instead of on top of each other.
   114     are synchronized with device dialogs. The display of notification dialogs is delayed until there
   118     The synchronization with device dialogs and sequential display of notification dialogs 
   115     are no device dialogs on display. Notifications are also synchronized with each other.
       
   116     If several notifications are shown at the same time with the show() function, they are shown
       
   117     sequentially instead of on top of each other. The synchronization of dialogs and sequential display of dialogs 
       
   118     can be disabled using the setSequentialShow() function.
   119     can be disabled using the setSequentialShow() function.
       
   120 
       
   121     Following sample code sets dialog title, text, icon and shows it.
       
   122     \code
       
   123     HbNotificationDialog *dialog = new HbNotificationDialog();
       
   124     dialog->setAttribute(Qt::WA_DeleteOnClose, true);
       
   125     dialog->setTitle("My title");
       
   126     dialog->setText("My text");
       
   127     dialog->setIcon(HbIcon("qtg_large_info"));
       
   128     dialog->show();
       
   129     \endcode
       
   130 
       
   131     Using a static helper to show a dialog.
       
   132     \code
       
   133     HbNotificationDialog::launchDialog(HbIcon("qtg_large_info"), "My title", "My text");
       
   134     \endcode
       
   135 
       
   136     Connecting to activated signal.
       
   137     \code
       
   138     HbNotificationDialog *dialog = new HbNotificationDialog();
       
   139     connect(dialog, SIGNAL(activated()), this, SLOT(dialogActivated()));
       
   140     dialog->enableTouchActivation(true);
       
   141     dialog->setAttribute(Qt::WA_DeleteOnClose, true);
       
   142     dialog->setTitle("My title");
       
   143     dialog->setText("My text");
       
   144     dialog->setIcon(HbIcon("qtg_large_info"));
       
   145     dialog->show();
       
   146     \endcode
   119 */
   147 */
   120 
   148 
   121 /*!
   149 /*!
   122     \fn void HbNotificationDialog::activated();
   150     \fn void HbNotificationDialog::activated();
   123 
   151 
   124     This signal is emitted when the dialog is closed with a pointer tap.
   152     This signal is emitted when the dialog is tapped and touch activation is
       
   153     enabled.
       
   154     
       
   155     \sa enableTouchActivation()
   125  */
   156  */
   126 
   157 
   127 /*!
   158 /*!
   128     Constructor.
   159     Default constructor.
   129  */
   160  */
   130 HbNotificationDialog::HbNotificationDialog() : HbDialog(*new HbNotificationDialogPrivate, 0)
   161 HbNotificationDialog::HbNotificationDialog() : HbDialog(*new HbNotificationDialogPrivate, 0)
   131 {
   162 {
   132     Q_D(HbNotificationDialog);
   163     Q_D(HbNotificationDialog);
   133     d->q_ptr = this;
   164     d->q_ptr = this;
   140     if ((style()->parameter(H_MARGIN, hMargin)) &&
   171     if ((style()->parameter(H_MARGIN, hMargin)) &&
   141         (style()->parameter(V_MARGIN, vMargin))) {
   172         (style()->parameter(V_MARGIN, vMargin))) {
   142         setPreferredPos(QPointF(hMargin, vMargin));
   173         setPreferredPos(QPointF(hMargin, vMargin));
   143     }
   174     }
   144 
   175 
   145     //d->setPriority(1);
       
   146 
       
   147     setModal(false);
   176     setModal(false);
   148 
   177 
   149     setBackgroundFaded(false);
   178     setBackgroundFaded(false);
   150     setDismissPolicy(HbPopup::NoDismiss);
   179     setDismissPolicy(HbPopup::NoDismiss);
   151     setTimeout(HbPopup::StandardTimeout);
   180     setTimeout(HbPopup::StandardTimeout);
   171     }
   200     }
   172 }
   201 }
   173 
   202 
   174 /*!
   203 /*!
   175     Enable user interaction on dialog.
   204     Enable user interaction on dialog.
   176     \param enabled - When enabled, the activated() signal is emitted on user action.
   205 
       
   206     \param enabled True enables activated() signal on user action.
   177 
   207 
   178     \sa isTouchActivating()
   208     \sa isTouchActivating()
   179 */
   209 */
   180 void HbNotificationDialog::enableTouchActivation(bool enabled)
   210 void HbNotificationDialog::enableTouchActivation(bool enabled)
   181 {
   211 {
   196     Q_D(const HbNotificationDialog);
   226     Q_D(const HbNotificationDialog);
   197     return d->isTouchActivating;
   227     return d->isTouchActivating;
   198 }
   228 }
   199 
   229 
   200 /*!
   230 /*!
   201     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   231     Convenience method to display HbNotificationDialog. Constructs a notification dialog and shows
   202     the given parameters. The dialog is owned by HbNotificationDialog.
   232     it. Constructed object is deleted on close.
       
   233 
       
   234     \param title Dialog title.
       
   235     \param text Dialog text.
       
   236     \param scene Scene to add the dialog into (optional).
   203 */
   237 */
   204 void HbNotificationDialog::launchDialog(const QString &title, const QString &text, QGraphicsScene* scene)
   238 void HbNotificationDialog::launchDialog(const QString &title, const QString &text, QGraphicsScene* scene)
   205 {
   239 {
   206     HbNotificationDialog *self = new HbNotificationDialog();
   240     HbNotificationDialog *self = new HbNotificationDialog();
   207     if (scene) {
   241     if (scene) {
   212     self->setTitle(title);
   246     self->setTitle(title);
   213     self->show();
   247     self->show();
   214 }
   248 }
   215 
   249 
   216 /*!
   250 /*!
   217     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   251     Convenience method to display HbNotificationDialog. Constructs a notification dialog and shows
   218     the given parameters. The dialog is owned by NotificationDialog.
   252     it. Constructed object is deleted on close.
       
   253 
       
   254     \param title Dialog title.
       
   255     \param scene Scene to add the dialog into (optional).
   219 */
   256 */
   220 void HbNotificationDialog::launchDialog(const QString &title, QGraphicsScene* scene)
   257 void HbNotificationDialog::launchDialog(const QString &title, QGraphicsScene* scene)
   221 {
   258 {
   222     HbNotificationDialog *self = new HbNotificationDialog();
   259     HbNotificationDialog *self = new HbNotificationDialog();
   223     if (scene) {
   260     if (scene) {
   227     self->setTitle(title);
   264     self->setTitle(title);
   228     self->show();
   265     self->show();
   229 }
   266 }
   230 
   267 
   231 /*!
   268 /*!
   232     Convenience method for using HbNotificationDialog. Shows a notification dialog with
   269     Convenience method to display HbNotificationDialog. Constructs a notification dialog and shows
   233     the given parameters. The dialog is owned by HbNotificationDialog.
   270     it. Constructed object is deleted on close.
       
   271 
       
   272     \param icon Dialog icon.
       
   273     \param title Dialog title.
       
   274     \param text Dialog text.
       
   275     \param scene Scene to add the dialog into (optional).
   234 */
   276 */
   235 void HbNotificationDialog::launchDialog(const HbIcon &icon, const QString &title,
   277 void HbNotificationDialog::launchDialog(const HbIcon &icon, const QString &title,
   236                                         const QString &text, QGraphicsScene* scene)
   278     const QString &text, QGraphicsScene* scene)
   237 {
   279 {
   238     HbNotificationDialog *self = new HbNotificationDialog();
   280     HbNotificationDialog *self = new HbNotificationDialog();
   239     if (scene) {
   281     if (scene) {
   240         scene->addItem(self);
   282         scene->addItem(self);
   241     }
   283     }
   245     self->setTitle(title);
   287     self->setTitle(title);
   246     self->show();
   288     self->show();
   247 }
   289 }
   248 
   290 
   249 /*!
   291 /*!
   250     Returns the title text.
   292     Returns title text. If a default content widget doesn't exist, it is created.
   251 
       
   252     If a default content widget doesn't exist, it is created.
       
   253 
   293 
   254     \sa setTitle()
   294     \sa setTitle()
   255 */
   295 */
   256 QString HbNotificationDialog::title() const
   296 QString HbNotificationDialog::title() const
   257 {
   297 {
   262         return QString();
   302         return QString();
   263     }
   303     }
   264 }
   304 }
   265 
   305 
   266 /*!
   306 /*!
   267     Set the dialog title text.
   307     Sets title text.
   268 
   308 
   269     \sa title()
   309     \sa title()
   270 */
   310 */
   271 void HbNotificationDialog::setTitle(const QString& title)
   311 void HbNotificationDialog::setTitle(const QString& title)
   272 {
   312 {
   275     d->content->setTitle(title);
   315     d->content->setTitle(title);
   276     d->setNotificationDialogContent();
   316     d->setNotificationDialogContent();
   277 }
   317 }
   278 
   318 
   279 /*!
   319 /*!
   280     Returns the text for the dialog.
   320     Returns dialog text. If a default content widget doesn't exist, it is created.
   281 
       
   282     If a default content widget doesn't exist, it is created.
       
   283 
   321 
   284     \sa setText()
   322     \sa setText()
   285 */
   323 */
   286 QString HbNotificationDialog::text() const
   324 QString HbNotificationDialog::text() const
   287 {
   325 {
   292         return QString();
   330         return QString();
   293     }
   331     }
   294 }
   332 }
   295 
   333 
   296 /*!
   334 /*!
   297     Set the text for the dialog.
   335     Sets dialog text. Changes also title text wrapping. If text is empty,
   298 
   336     sets title text wrapping to Hb::TextWordWrap, otherwise Hb::TextNoWrap. 
   299     \sa text()
   337 
       
   338     \sa text(), setTitleTextWrapping()
   300 */
   339 */
   301 void HbNotificationDialog::setText(const QString& text)
   340 void HbNotificationDialog::setText(const QString& text)
   302 {
   341 {
   303     Q_D(HbNotificationDialog);
   342     Q_D(HbNotificationDialog);
   304     d->checkAndCreateContentWidget();
   343     d->checkAndCreateContentWidget();
   310     }
   349     }
   311     d->setNotificationDialogContent();
   350     d->setNotificationDialogContent();
   312 }
   351 }
   313 
   352 
   314 /*!
   353 /*!
   315     Returns the icon for the dialog.
   354     Returns dialog icon. If a default content widget doesn't exist, it is created.
   316 
       
   317     If a default content widget doesn't exist, it is created.
       
   318 
   355 
   319     \sa setIcon()
   356     \sa setIcon()
   320 */
   357 */
   321 HbIcon HbNotificationDialog::icon() const
   358 HbIcon HbNotificationDialog::icon() const
   322 {
   359 {
   327         return QString();
   364         return QString();
   328     }
   365     }
   329 }
   366 }
   330 
   367 
   331 /*!
   368 /*!
   332     Set the icon.
   369     Sets dialog icon.
   333 
   370 
   334     \sa icon()
   371     \sa icon()
   335 */
   372 */
   336 void HbNotificationDialog::setIcon(const HbIcon& icon)
   373 void HbNotificationDialog::setIcon(const HbIcon& icon)
   337 {
   374 {
   340     d->content->setIcon( icon );
   377     d->content->setIcon( icon );
   341     d->setNotificationDialogContent();
   378     d->setNotificationDialogContent();
   342 }
   379 }
   343 
   380 
   344 /*!
   381 /*!
   345     Returns the style of text wrapping for the title.
   382     Returns title text wrapping.
   346     
   383     
   347     The title can wrap only if there is no other text for the dialog. The title can wrap to a maximum of two lines.
   384     The title can wrap only if dialog text is empty. The title can wrap to a maximum of two lines.
   348     The default is Hb::TextWordWrap.
   385     The default is Hb::TextWordWrap.
   349 
   386 
   350     \sa setTitleTextWrapping(), HbNotificationDialog::title, HbNotificationDialog::text
   387     \sa setTitleTextWrapping(), title(), text()
   351 */
   388 */
   352 Hb::TextWrapping HbNotificationDialog::titleTextWrapping() const
   389 Hb::TextWrapping HbNotificationDialog::titleTextWrapping() const
   353 {
   390 {
   354     Q_D(const HbNotificationDialog);
   391     Q_D(const HbNotificationDialog);
   355     return d->titleTextWrapping;
   392     return d->titleTextWrapping;
   356 }
   393 }
   357 
   394 
   358 /*!
   395 /*!
   359     Sets whether the text for the title is wrapped.
   396     Sets title text wrapping. The title can wrap only if there is no text for the dialog.
   360 
   397     The title can wrap to a maximum of two lines. setText() also changes title text wrapping.
   361     The title can wrap only if there is no text for the dialog. The title can wrap to a maximum of two lines.
   398 
   362     \sa titleTextWrapping()
   399     \sa titleTextWrapping(), setText()
   363 */
   400 */
   364 void HbNotificationDialog::setTitleTextWrapping(Hb::TextWrapping wrapping)
   401 void HbNotificationDialog::setTitleTextWrapping(Hb::TextWrapping wrapping)
   365 {
   402 {
   366     Q_D(HbNotificationDialog);
   403     Q_D(HbNotificationDialog);
   367     if (d->titleTextWrapping != wrapping) {
   404     if (d->titleTextWrapping != wrapping) {
   372         d->doLayout();
   409         d->doLayout();
   373     }
   410     }
   374 }
   411 }
   375 
   412 
   376 /*!
   413 /*!
   377     Enables or disables sequential display of the Notification Dialog.
   414     Enables or disables sequential display of notification dialog.
   378 
   415 
   379     When enabled, notification dialogs are shown sequentially. If multiple calls to show() occur at the same time then the dialogs are displayed
   416     When enabled, the dialog is synchronized with other notification dialogs. If multiple calls
   380     in sequence instead of on top of each other. The display of the dialogs is also synchronized
   417     to show() occur at the same time then dialogs are displayed in sequence instead of on top
   381     with the device dialogs such that the notification dialogs do not appear until there are no device dialogs being displayed.
   418     of each other. The display of the dialog is also synchronized with device dialogs such
   382 
   419     that it does not appear until there are no device dialogs being displayed.
   383     With sequential show disabled,
   420 
   384     HbNotificationDialog behaves like other popups. While a dialog is waiting to be shown,
   421     With sequential show disabled, HbNotificationDialog behaves like other popups.
   385     setVisible(), hide() and show() have no effect. To remove a dialog from the wait queue, call setSequentialShow(false).
   422 
       
   423     While a dialog is waiting to be shown, setVisible(), hide() and show() have no effect.
       
   424     To remove a dialog from the wait queue, call setSequentialShow(false).
   386 
   425 
   387     This setting is enabled by default. 
   426     This setting is enabled by default. 
   388 
   427 
   389     \sa isSequentialShow()
   428     \sa isSequentialShow()
   390 */
   429 */