src/hbwidgets/popups/hbprogressdialog.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 3 11d3954df52a
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <hbprogressdialog.h>
    26 #include <hbprogressdialog.h>
    27 #include <hbprogressdialog_p.h>
    27 #include <hbprogressdialog_p.h>
    28 #include <hbstyleoptionprogressdialog.h>
    28 #include <hbstyleoptionprogressdialog_p.h>
    29 
    29 
    30 #include <hbnamespace_p.h>
    30 #include <hbnamespace_p.h>
    31 #include <hbaction.h>
    31 #include <hbaction.h>
    32 #include <hbpopup.h>
    32 #include <hbpopup.h>
    33 #include <hbtextitem.h>
    33 #include <hbtextitem.h>
    34 #include <QGraphicsItem>
    34 #include <QGraphicsItem>
    35 
    35 
    36 /*
    36 /*
    37     internal
    37     \internal
    38     HbProgressDialogContentWidget class
    38     HbProgressDialogContentWidget class
    39 
    39 
    40     HbProgressDialogContentWidget is internal to HbProgressDialog and is the content widget to progressDialog
    40     HbProgressDialogContentWidget is internal to HbProgressDialog and is the content widget to progressDialog
    41 
    41 
    42     HbProgressDialogContentWidget holds the text, icon and progressbar.
    42     HbProgressDialogContentWidget holds the text, icon and progressbar.
    68         repolish();
    68         repolish();
    69     }
    69     }
    70 };
    70 };
    71 
    71 
    72 /*!
    72 /*!
    73     internal
    73     \internal
    74 
    74 
    75     HbProgressDialogPrivate class constructor
    75     HbProgressDialogPrivate class constructor
    76 */
    76 */
    77 HbProgressDialogPrivate::HbProgressDialogPrivate() :mAction(0),mTimer(0),mIcon(0),mContentWidget(0),
    77 HbProgressDialogPrivate::HbProgressDialogPrivate() :mTimer(0),mIcon(0),mContentWidget(0),
    78                                                     mMinDuration(0),mDelayTime(0),mTextString(QString()),
    78                                                     mMinDuration(0),mDelayTime(0),mTextString(QString()),
    79                                                     mAlign(Qt::AlignTop|Qt::AlignLeft)
    79                                                     mAlign(Qt::AlignTop|Qt::AlignLeft)
    80 {
    80 {
    81 }
    81 }
    82 
    82 
    83 /*!
    83 /*!
    84     internal
    84     \internal
    85 
    85 
    86     HbProgressDialogPrivate class destructor
    86     HbProgressDialogPrivate class destructor
    87 */
    87 */
    88 HbProgressDialogPrivate::~HbProgressDialogPrivate()
    88 HbProgressDialogPrivate::~HbProgressDialogPrivate()
    89 {  
    89 {  
    90 }
    90 }
    91 
    91 
    92 /*!
    92 /*!
    93     internal
    93     \internal
    94 
    94 
    95     initialises HbProgressDialogPrivate class 
    95     Initializes HbProgressDialogPrivate class 
    96 */
    96 */
    97 void HbProgressDialogPrivate::init(HbProgressDialog::ProgressDialogType type)
    97 void HbProgressDialogPrivate::init(HbProgressDialog::ProgressDialogType type)
    98 {
    98 {
    99     Q_Q(HbProgressDialog);
    99     Q_Q(HbProgressDialog);
   100     
   100     
   109     }
   109     }
   110     else{
   110     else{
   111         mContentWidget->mProgressBar->setRange(0,100);
   111         mContentWidget->mProgressBar->setRange(0,100);
   112     }
   112     }
   113     
   113     
   114     mAction = new HbAction(q->tr("Cancel"));
   114     HbAction *action = new HbAction(q->tr("Cancel"), q);
   115     QObject::connect(mAction, SIGNAL(triggered()), q, SLOT(_q_userCancel()));
   115     QObject::connect(action, SIGNAL(triggered()), q, SLOT(_q_userCancel()));
   116     q->setPrimaryAction(mAction);
   116     q->addAction(action);
   117     
   117     
   118     mMinDuration = 1500;
   118     mMinDuration = 1500;
   119     mDelayTime = 1000;
   119     mDelayTime = 1000;
   120 
   120 
   121     mTimer = new QTimeLine(mDelayTime, q);
   121     mTimer = new QTimeLine(mDelayTime, q);
   122     mTimer->setFrameRange(0, 100);  
   122     mTimer->setFrameRange(0, 100);  
   123     QObject::connect(mTimer, SIGNAL(finished()), q, SLOT(_q_finished()));
   123     QObject::connect(mTimer, SIGNAL(finished()), q, SLOT(_q_finished()));
   124 
   124 
   125     q->setTimeout(HbPopup::NoTimeout);
   125     q->setTimeout(HbPopup::NoTimeout);
   126     q->setDismissPolicy(HbPopup::NoDismiss);
   126     q->setDismissPolicy(HbPopup::NoDismiss);
   127     q->setModal(false);
       
   128     q->hide();
   127     q->hide();
   129 }
   128 }
   130 
   129 
   131 /*
   130 /*
   132     internal
   131     \internal
   133 
   132 
   134     createPrimitives.
   133     createPrimitives.
   135  */
   134  */
   136 void HbProgressDialogPrivate::createPrimitives()
   135 void HbProgressDialogPrivate::createPrimitives()
   137 {
   136 {
   138     Q_Q(HbProgressDialog);
   137     Q_Q(HbProgressDialog);
   139 
   138 
   140     if( !mContentWidget->mProgressBar ){
   139     if( !mContentWidget->mProgressBar ){
   141             mContentWidget->mProgressBar = new HbProgressBar(HbProgressBar::SimpleProgressBar,mContentWidget);
   140             mContentWidget->mProgressBar = new HbProgressBar(mContentWidget);
   142             HbStyle::setItemName(mContentWidget->mProgressBar, "pbar");
   141             HbStyle::setItemName(mContentWidget->mProgressBar, "pbar");
   143     }
   142     }
   144 
   143 
   145     if ( !mContentWidget->mTextItem ) {
   144     if ( !mContentWidget->mTextItem ) {
   146         mContentWidget->mTextItem = q->style()->createPrimitive(HbStyle::P_ProgressDialog_text,mContentWidget);
   145         mContentWidget->mTextItem = q->style()->createPrimitive(HbStyle::P_ProgressDialog_text,mContentWidget);
   159         mContentWidget->mIconItem = 0;
   158         mContentWidget->mIconItem = 0;
   160     }
   159     }
   161 }
   160 }
   162 
   161 
   163 /*!
   162 /*!
   164     internal
   163     \internal
   165 
   164 
   166     private slot which stops the timer and 
   165     Private slot for, when user clicks on cancel button. This stops the timer and 
   167     dismisses the dialog
   166     dismisses the dialog.
   168 */
   167 */
   169 void HbProgressDialogPrivate::_q_userCancel()
   168 void HbProgressDialogPrivate::_q_userCancel()
   170 {
   169 {
   171     Q_Q(HbProgressDialog);
   170     Q_Q(HbProgressDialog);
   172     
   171     
   174     mTimer->stop();
   173     mTimer->stop();
   175     q->cancel();
   174     q->cancel();
   176 }
   175 }
   177 
   176 
   178 /*!
   177 /*!
   179     internal
   178     \internal
   180 
   179 
   181     private slot which stops the timer and 
   180     Private slot which stops the timer and 
   182     dismisses the dialog
   181     dismisses the dialog
   183 */
   182 */
   184 void HbProgressDialogPrivate::_q_finished()
   183 void HbProgressDialogPrivate::_q_finished()
   185 {
   184 {
   186     Q_Q(HbProgressDialog);
   185     Q_Q(HbProgressDialog);
   201         }
   200         }
   202     }
   201     }
   203 }
   202 }
   204 
   203 
   205 /*!
   204 /*!
   206     internal
   205     \internal
   207 
   206 
   208     private slot which stops the timer and 
   207     Private slot, for when progress value changes. When maximum value, stop the timer and close the dialog.
   209     dismisses the dialog
       
   210 */
   208 */
   211 void HbProgressDialogPrivate::_q_progressValueChanged(int value)
   209 void HbProgressDialogPrivate::_q_progressValueChanged(int value)
   212 {
   210 {
   213     Q_Q(HbProgressDialog);
   211     Q_Q(HbProgressDialog);
   214     
   212     
   231     @beta
   229     @beta
   232     @hbwidgets
   230     @hbwidgets
   233     \class HbProgressDialog
   231     \class HbProgressDialog
   234     \brief HbProgressDialog provides feedback on the progress of a slow operation.
   232     \brief HbProgressDialog provides feedback on the progress of a slow operation.
   235 
   233 
   236     \image html hbprogressnote.png  A progress dialog.
   234     \image html hbprogressdialog.png  A progress dialog.
   237 
   235 
   238     ProgressDialog widget displays that a process is active and also the completion level of the process to the user.
   236     ProgressDialog widget displays that a process is active and also the completion level of the process to the user.
   239 
   237 
   240     A progress dialog is used to give the user an indication of how long an operation is going to take, and 
   238     A progress dialog is used to give the user an indication of how long an operation is going to take, and 
   241     to demonstrate that the application has not frozen. It can also give the user an opportunity to abort the operation.
   239     to demonstrate that the application has not frozen. It can also give the user an opportunity to abort the operation.
   442     d->mContentWidget->mProgressBar->setRange(min,max);
   440     d->mContentWidget->mProgressBar->setRange(min,max);
   443 }
   441 }
   444 
   442 
   445 /*!
   443 /*!
   446     @beta
   444     @beta
   447     Returns the value of the progressbar within the note.
   445     Returns the value of the progressbar within the dialog.
   448 
   446 
   449     This value is constrained as follows:
   447     This value is constrained as follows:
   450     \b minimum <= \c value <= \b maximum.
   448     \b minimum <= \c value <= \b maximum.
   451 
   449 
   452     \sa setValue()
   450     \sa setValue()
   458     return d->mContentWidget->mProgressBar->progressValue();
   456     return d->mContentWidget->mProgressBar->progressValue();
   459 }
   457 }
   460 
   458 
   461 /*!
   459 /*!
   462     @beta
   460     @beta
   463     Sets the value of the progressbar within the progress dialog.
   461     Sets the value for the progressbar within the progress dialog.
   464     After the timeline has been started the value is updated automatically.
   462     After the timeline has been started the value is updated automatically.
   465     Use this function only if the timer is not used.
   463     Use this function only if the timer is not used.
   466 
   464 
   467     This value is constrained as follows:
   465     This value is constrained as follows:
   468     \b minimum <= \c value <= \b maximum.
   466     \b minimum <= \c value <= \b maximum.
   480 }
   478 }
   481 
   479 
   482 /*!
   480 /*!
   483     @beta
   481     @beta
   484     Closes the dialog while emitting the cancelled() signal. This function is called when 
   482     Closes the dialog while emitting the cancelled() signal. This function is called when 
   485     user presses the Cancel button or then the timer expires.
   483     user presses the Cancel button or when the timer expires.
   486  */
   484  */
   487 void HbProgressDialog::cancel() 
   485 void HbProgressDialog::cancel() 
   488 {
   486 {
   489     emit cancelled();
   487     emit cancelled();
   490     close();
   488     close();
   517     Sets the progressdialog type. 
   515     Sets the progressdialog type. 
   518 
   516 
   519     The type of the progress dialog can be specified with one of the values:
   517     The type of the progress dialog can be specified with one of the values:
   520     \li HbProgressDialog::ProgressDialog
   518     \li HbProgressDialog::ProgressDialog
   521     \li HbProgressDialog::WaitDialog
   519     \li HbProgressDialog::WaitDialog
       
   520 
       
   521     \param type type for the progress dialog.
       
   522 
   522     \sa progressDialogType()
   523     \sa progressDialogType()
   523  */
   524  */
   524 void HbProgressDialog::setProgressDialogType(HbProgressDialog::ProgressDialogType type)
   525 void HbProgressDialog::setProgressDialogType(HbProgressDialog::ProgressDialogType type)
   525 {
   526 {
   526     Q_D(HbProgressDialog);
   527     Q_D(HbProgressDialog);
   548     return d->mNoteType;
   549     return d->mNoteType;
   549 }
   550 }
   550 
   551 
   551 /*!
   552 /*!
   552     @beta
   553     @beta
   553     Shows the progress dialog after a delay(say 1sec). This is a convenient slot.
   554     Shows the progress dialog after a delay, say 1sec. This is a convenient slot for the user.
   554     if user cancels progress dialog before delay getting expired, then progress dialog wont be shown at all 
   555     if user cancels progress dialog before delay getting expired, then progress dialog wont be shown at all.
   555  */
   556  */
   556 void HbProgressDialog::delayedShow()
   557 void HbProgressDialog::delayedShow()
   557 {
   558 {
   558     Q_D(HbProgressDialog);
   559     Q_D(HbProgressDialog);
   559     
   560     
   563 }
   564 }
   564 
   565 
   565 /*!
   566 /*!
   566     @beta
   567     @beta
   567     Returns the auto close flag.
   568     Returns the auto close flag.
       
   569     \return autoclose flag.
   568     \sa setAutoClose()
   570     \sa setAutoClose()
   569  */
   571  */
   570 bool HbProgressDialog::autoClose () const 
   572 bool HbProgressDialog::autoClose () const 
   571 {
   573 {
   572     Q_D(const HbProgressDialog);
   574     Q_D(const HbProgressDialog);
   575 }
   577 }
   576 
   578 
   577 /*!
   579 /*!
   578     @beta
   580     @beta
   579     Sets the auto close flag.
   581     Sets the auto close flag.
       
   582     \param close based on which autoclose flag is set or reset.
   580     \sa autoClose()
   583     \sa autoClose()
   581  */
   584  */
   582 void HbProgressDialog::setAutoClose ( bool close )
   585 void HbProgressDialog::setAutoClose ( bool close )
   583 {
   586 {
   584     Q_D(HbProgressDialog);
   587     Q_D(HbProgressDialog);
   586     close?d->flags 
   589     close?d->flags 
   587         |= HbProgressDialogPrivate::Autoclose : d->flags &= ~HbProgressDialogPrivate::Autoclose;
   590         |= HbProgressDialogPrivate::Autoclose : d->flags &= ~HbProgressDialogPrivate::Autoclose;
   588 }
   591 }
   589 
   592 
   590 /*!
   593 /*!
   591     Initializes \a option with the values from this HbProgressDialog. 
   594     \reimp
   592     This method is useful for subclasses when they need a HbStyleOptionProgressDialog,
       
   593     but don't want to fill in all the information themselves.
       
   594  */
   595  */
   595 void HbProgressDialog::initStyleOption(HbStyleOptionProgressDialog *option) const
   596 void HbProgressDialog::initStyleOption(HbStyleOptionProgressDialog *option) const
   596 {
   597 {
   597     Q_D(const HbProgressDialog);
   598     Q_D(const HbProgressDialog);
   598 
   599 
   619 /*!
   620 /*!
   620     \reimp
   621     \reimp
   621  */
   622  */
   622 void HbProgressDialog::closeEvent ( QCloseEvent * event )
   623 void HbProgressDialog::closeEvent ( QCloseEvent * event )
   623 {
   624 {
   624     Q_D(HbProgressDialog);
   625     Q_D(HbProgressDialog);    
   625     
   626 
   626     d->mAction->setToolTip("");
       
   627     if(d->flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   627     if(d->flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   628         d->flags |= HbProgressDialogPrivate::Closepending;
   628         d->flags |= HbProgressDialogPrivate::Closepending;
   629         event->setAccepted(false);
   629         event->setAccepted(false);
   630         return;
   630         return;
   631     }
   631     }
   719 
   719 
   720     return d->mIcon;
   720     return d->mIcon;
   721 }
   721 }
   722 
   722 
   723 
   723 
   724 /*!
       
   725     \deprecated HbProgressDialog::setTextAlignment( Qt::Alignment )
       
   726         is deprecated.
       
   727 
       
   728     Sets the text alignment.
       
   729     \param align Qt defined alignment options can used.
       
   730 
       
   731     The default value is Qt::AlignLeft|Qt::AlignVCenter
       
   732 
       
   733     \sa mTextAlignment()
       
   734 */
       
   735 void HbProgressDialog::setTextAlignment( Qt::Alignment align )
       
   736 {
       
   737     Q_D(HbProgressDialog);
       
   738     
       
   739     if (align != d->mAlign ){
       
   740         d->mAlign = align;
       
   741         if(d->mContentWidget->mTextItem)
       
   742         {
       
   743             HbStyleOptionProgressDialog progressDialogOption;
       
   744             initStyleOption(&progressDialogOption);
       
   745             style()->updatePrimitive(d->mContentWidget->mTextItem, HbStyle::P_ProgressDialog_text, &progressDialogOption); 
       
   746         }
       
   747     }
       
   748 }
       
   749 
       
   750 /*!
       
   751     \deprecated HbProgressDialog::textAlignment() const
       
   752         is deprecated.
       
   753 
       
   754     Returns the text alignment.
       
   755 
       
   756     \sa setTextAlignment()
       
   757 */
       
   758 Qt::Alignment HbProgressDialog::textAlignment() const
       
   759 {
       
   760     Q_D(const HbProgressDialog);
       
   761     
       
   762     return d->mAlign;
       
   763 }
       
   764 
       
   765 /*!
       
   766    \deprecated HbProgressDialog::setIconAlignment( Qt::Alignment )
       
   767         is deprecated.
       
   768 
       
   769     Sets the icon alignment.
       
   770 
       
   771     \param align Qt defined alignment options can used.
       
   772 
       
   773     The default value is Qt::AlignCenter.
       
   774 
       
   775     \sa mIconAlignment()
       
   776 */
       
   777 void HbProgressDialog::setIconAlignment( Qt::Alignment align )
       
   778 {
       
   779     Q_D(HbProgressDialog);
       
   780     
       
   781     if (align != d->mIconAlignment){
       
   782         d->mIconAlignment = align;
       
   783         if (d->mContentWidget->mIconItem) {
       
   784             HbStyleOptionProgressDialog progressDialogOption;
       
   785             initStyleOption(&progressDialogOption);
       
   786             style()->updatePrimitive(d->mContentWidget->mIconItem, HbStyle::P_ProgressDialog_icon, &progressDialogOption);
       
   787         }
       
   788     }
       
   789 }
       
   790 
       
   791 
       
   792 /*!
       
   793     \deprecated HbProgressDialog::iconAlignment() const
       
   794         is deprecated.
       
   795 
       
   796     Returns the icon alignment.
       
   797 
       
   798     \sa setIconAlignment()
       
   799 */
       
   800 Qt::Alignment HbProgressDialog::iconAlignment() const
       
   801 {
       
   802     Q_D(const HbProgressDialog);
       
   803 
       
   804     return d->mIconAlignment;
       
   805 }
       
   806 
       
   807 #include "moc_hbprogressdialog.cpp"
   724 #include "moc_hbprogressdialog.cpp"
   808 #include "hbprogressdialog.moc"
   725 #include "hbprogressdialog.moc"