src/hbwidgets/popups/hbprogressdialog.cpp
changeset 34 ed14f46c0e55
parent 5 627c4a0fd0e7
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    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_p.h>
    28 #include <hbstyleoptionprogressdialog_p.h>
    29 
       
    30 #include <hbnamespace_p.h>
    29 #include <hbnamespace_p.h>
    31 #include <hbaction.h>
    30 #include <hbaction.h>
    32 #include <hbpopup.h>
    31 #include <hbpopup.h>
    33 #include <hbtextitem.h>
    32 #include <hbtextitem.h>
    34 #include <QGraphicsItem>
    33 #include <QGraphicsItem>
    35 
    34 #include <hbstyleprimitivedata.h>
       
    35 #include <hbstyleiconprimitivedata.h>
       
    36 #include <hbstyletextprimitivedata.h>
    36 /*
    37 /*
    37     \internal
    38     \internal
    38     HbProgressDialogContentWidget class
    39     HbProgressDialogContentWidget class
    39 
    40 
    40     HbProgressDialogContentWidget is internal to HbProgressDialog and is the content widget to progressDialog
    41     HbProgressDialogContentWidget is internal to HbProgressDialog and is the content widget to progressDialog
    46 {
    47 {
    47     Q_OBJECT
    48     Q_OBJECT
    48     
    49     
    49     public:
    50     public:
    50     
    51     
    51     QGraphicsItem *mIconItem;
    52     QGraphicsObject  *mIconItem;
    52     HbProgressBar *mProgressBar;
    53     HbProgressBar *mProgressBar;
    53     QGraphicsItem *mTextItem;
    54     QGraphicsObject  *mTextItem;
    54     HbProgressDialogPrivate *d;
    55     HbProgressDialogPrivate *d;
    55     
    56     
    56     enum { Type = HbPrivate::ItemType_ProgressDialogContentWidget };
    57     enum { Type = HbPrivate::ItemType_ProgressDialogContentWidget };
    57     int type() const { return Type; }
    58     int type() const { return Type; }
    58     
    59     
   109     }
   110     }
   110     else{
   111     else{
   111         mContentWidget->mProgressBar->setRange(0,100);
   112         mContentWidget->mProgressBar->setRange(0,100);
   112     }
   113     }
   113     
   114     
   114     HbAction *action = new HbAction(hbTrId("txt_common_button_cancel"), q);
   115     mAction = new HbAction(hbTrId("txt_common_button_cancel"), q);
   115     QObject::connect(action, SIGNAL(triggered()), q, SLOT(_q_userCancel()));
   116     QObject::connect(mAction, SIGNAL(triggered()), q, SLOT(_q_userCancel()));
   116     q->addAction(action);
   117     q->addAction(mAction);
   117     
   118     
   118     mMinDuration = 1500;
   119     mMinDuration = 1500;
   119     mDelayTime = 1000;
   120     mDelayTime = 1000;
   120 
   121 
   121     mTimer = new QTimeLine(mDelayTime, q);
   122     mTimer = new QTimeLine(mDelayTime, q);
   133     createPrimitives.
   134     createPrimitives.
   134  */
   135  */
   135 void HbProgressDialogPrivate::createPrimitives()
   136 void HbProgressDialogPrivate::createPrimitives()
   136 {
   137 {
   137     Q_Q(HbProgressDialog);
   138     Q_Q(HbProgressDialog);
   138 
   139     bool repolish = false;
   139     if( !mContentWidget->mProgressBar ){
   140 
   140             mContentWidget->mProgressBar = new HbProgressBar(mContentWidget);
   141     if( !mContentWidget->mProgressBar ){ 
   141             HbStyle::setItemName(mContentWidget->mProgressBar, "pbar");
   142         mContentWidget->mProgressBar = new HbProgressBar(mContentWidget); 
   142     }
   143         HbStyle::setItemName(mContentWidget->mProgressBar, "pbar"); 
   143 
   144         repolish = true; 
   144     if ( !mContentWidget->mTextItem ) {
   145     }
   145         mContentWidget->mTextItem = q->style()->createPrimitive(HbStyle::P_ProgressDialog_text,mContentWidget);
   146     
   146         HbStyle::setItemName(mContentWidget->mTextItem, "text");
   147     if ( !mContentWidget->mTextItem ) { 
       
   148         mContentWidget->mTextItem = q->style()->createPrimitive(HbStyle::PT_TextItem, "text", mContentWidget); 
       
   149         repolish = true;
   147     }
   150     }
   148 
   151 
   149     if ( !mIcon.isNull() ) {
   152     if ( !mIcon.isNull() ) {
   150         if ( !mContentWidget->mIconItem ) {
   153         if ( !mContentWidget->mIconItem ) { 
   151             mContentWidget->mIconItem = q->style()->createPrimitive(HbStyle::P_ProgressDialog_icon, mContentWidget); 
   154             mContentWidget->mIconItem = q->style()->createPrimitive(HbStyle::PT_IconItem, "icon", mContentWidget); 
   152             HbStyle::setItemName(mContentWidget->mIconItem, "icon");
   155             repolish = true; 
   153         }
   156         }
   154     } else {
   157     } else {
   155         if( mContentWidget->mIconItem ){
   158         if( mContentWidget->mIconItem ){
   156             delete mContentWidget->mIconItem;
   159             delete mContentWidget->mIconItem; 
       
   160             repolish = true; 
   157         }
   161         }
   158         mContentWidget->mIconItem = 0;
   162         mContentWidget->mIconItem = 0;
   159     }
   163     }
   160 }
   164 
       
   165     if (repolish)
       
   166         mContentWidget->repolishContent();
       
   167 }
       
   168 
   161 
   169 
   162 /*!
   170 /*!
   163     \internal
   171     \internal
   164 
   172 
   165     Private slot for, when user clicks on cancel button. This stops the timer and 
   173     Private slot for, when user clicks on cancel button. This stops the timer and 
   194         flags |= HbProgressDialogPrivate::Closetimer;
   202         flags |= HbProgressDialogPrivate::Closetimer;
   195     }
   203     }
   196     else if(flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   204     else if(flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   197         flags &= ~HbProgressDialogPrivate::Closetimer;
   205         flags &= ~HbProgressDialogPrivate::Closetimer;
   198         if(flags.testFlag(HbProgressDialogPrivate::Closepending)){
   206         if(flags.testFlag(HbProgressDialogPrivate::Closepending)){
   199             q->close();
   207              flags &= ~HbProgressDialogPrivate::Closepending;
       
   208              q->close();            
   200         }
   209         }
   201     }
   210     }
   202 }
   211 }
   203 
   212 
   204 /*!
   213 /*!
   207     Private slot, for when progress value changes. When maximum value, stop the timer and close the dialog.
   216     Private slot, for when progress value changes. When maximum value, stop the timer and close the dialog.
   208 */
   217 */
   209 void HbProgressDialogPrivate::_q_progressValueChanged(int value)
   218 void HbProgressDialogPrivate::_q_progressValueChanged(int value)
   210 {
   219 {
   211     Q_Q(HbProgressDialog);
   220     Q_Q(HbProgressDialog);
   212     
   221     if(value >= mContentWidget->mProgressBar->maximum() && !(q->autoClose()) && (mAction->text() == hbTrId("txt_common_button_cancel")) ){
       
   222         if(mAction) {
       
   223             if(mAction->text() == hbTrId("txt_common_button_cancel")) {
       
   224                 mAction->setText(hbTrId("txt_common_button_close"));
       
   225             }
       
   226         }
       
   227     }
   213     if(value >= mContentWidget->mProgressBar->maximum() && q->autoClose()){
   228     if(value >= mContentWidget->mProgressBar->maximum() && q->autoClose()){
       
   229         
   214         if(flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   230         if(flags.testFlag(HbProgressDialogPrivate::Closetimer)){
   215             flags |= HbProgressDialogPrivate::Closepending;
   231             flags |= HbProgressDialogPrivate::Closepending;
   216             flags &= ~HbProgressDialogPrivate::Showtimer;
   232             flags &= ~HbProgressDialogPrivate::Showtimer;
   217         }
   233         }
   218         else if(!flags.testFlag(HbProgressDialogPrivate::Showtimer)){
   234         else if(!flags.testFlag(HbProgressDialogPrivate::Showtimer)){
   494     emit cancelled();
   510     emit cancelled();
   495     close();
   511     close();
   496 }
   512 }
   497 
   513 
   498 /*!
   514 /*!
   499 
       
   500     \deprecated HbProgressDialog::primitive(HbStyle::Primitive)
       
   501         is deprecated.
       
   502 
       
   503     Returns the pointer for \a primitive passed.
       
   504     Will return NULL if \a primitive passed is invalid
       
   505 */
       
   506 QGraphicsItem* HbProgressDialog::primitive(HbStyle::Primitive primitive) const
       
   507 {
       
   508     Q_D(const HbProgressDialog);
       
   509 
       
   510     switch (primitive) {
       
   511         case HbStyle::P_ProgressDialog_icon:
       
   512             return d->mContentWidget->mIconItem;
       
   513         case HbStyle::P_ProgressDialog_text:
       
   514             return d->mContentWidget->mTextItem;
       
   515         default:
       
   516             return 0;
       
   517         }
       
   518 }
       
   519 
       
   520 /*!
       
   521     @beta
   515     @beta
   522     Sets the progressdialog type. 
   516     Sets the progressdialog type. 
   523 
   517 
   524     The type of the progress dialog can be specified with one of the values:
   518     The type of the progress dialog can be specified with one of the values:
   525     \li HbProgressDialog::ProgressDialog
   519     \li HbProgressDialog::ProgressDialog
   611     option->iconAlignment = d->mIconAlignment;
   605     option->iconAlignment = d->mIconAlignment;
   612     option->text = d->mTextString;
   606     option->text = d->mTextString;
   613     option->textAlignment = d->mAlign;
   607     option->textAlignment = d->mAlign;
   614 }
   608 }
   615 
   609 
       
   610 void HbProgressDialog::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive)
       
   611 {
       
   612     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   613     QString itemName = HbStyle::itemName(primitive);
       
   614     if (itemName == QLatin1String("text")) {
       
   615         HbStyleTextPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
       
   616         data->text = text();
       
   617         data->textWrapping = Hb::TextWordWrap;
       
   618     }
       
   619 
       
   620     if (itemName == QLatin1String("icon")) {
       
   621         HbStyleIconPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData);
       
   622         data->icon = icon();        
       
   623     }
       
   624 }
       
   625 
   616 /*!
   626 /*!
   617     \reimp
   627     \reimp
   618  */
   628  */
   619 void HbProgressDialog::showEvent(QShowEvent *event)
   629 void HbProgressDialog::showEvent(QShowEvent *event)
   620 {
   630 {
   621     Q_D(HbProgressDialog);
   631     Q_D(HbProgressDialog);
   622     
       
   623     d->mContentWidget->mProgressBar->show();
   632     d->mContentWidget->mProgressBar->show();
       
   633     if(d->mAction) {
       
   634         if(d->mAction->text() == hbTrId("txt_common_button_close")) {
       
   635             d->mAction->setText(hbTrId("txt_common_button_cancel"));
       
   636         }
       
   637     }
   624     HbDialog::showEvent(event);   
   638     HbDialog::showEvent(event);   
   625 }
   639 }
   626 
   640 
   627 /*!
   641 /*!
   628     \reimp
   642     \reimp
   660         d->mTextString = text;
   674         d->mTextString = text;
   661         d->createPrimitives();
   675         d->createPrimitives();
   662 
   676 
   663         if(d->mContentWidget->mTextItem)
   677         if(d->mContentWidget->mTextItem)
   664         {
   678         {
   665             HbStyleOptionProgressDialog progressDialogOption;
   679             HbStyleTextPrimitiveData data;
   666             initStyleOption(&progressDialogOption);
   680             initPrimitiveData(&data, d->mContentWidget->mTextItem);
   667             style()->updatePrimitive(d->mContentWidget->mTextItem, HbStyle::P_ProgressDialog_text, &progressDialogOption);
   681             style()->updatePrimitive(d->mContentWidget->mTextItem, &data, this);
   668         }
   682         }
   669     }
   683     }
   670 }
   684 }
   671 
   685 
   672 /*!
   686 /*!
   698         d->mIcon = icon;
   712         d->mIcon = icon;
   699         d->createPrimitives();
   713         d->createPrimitives();
   700 
   714 
   701         if (d->mContentWidget->mIconItem) {
   715         if (d->mContentWidget->mIconItem) {
   702             d->mContentWidget->setProperty("icon",true);
   716             d->mContentWidget->setProperty("icon",true);
   703 
   717             HbStyleIconPrimitiveData data;
   704             HbStyleOptionProgressDialog progressDialogOption;
   718             initPrimitiveData(&data, d->mContentWidget->mIconItem);
   705             initStyleOption(&progressDialogOption);
   719             style()->updatePrimitive(d->mContentWidget->mIconItem, &data, this);
   706             style()->updatePrimitive(d->mContentWidget->mIconItem, HbStyle::P_ProgressDialog_icon, &progressDialogOption);
   720 
   707         }
   721         }
   708         else
   722         else
   709         {
   723         {
   710             d->mContentWidget->setProperty("icon",false);
   724             d->mContentWidget->setProperty("icon",false);
   711         }
   725         }
   712         d->mContentWidget->repolishContent();
       
   713     }
   726     }
   714 }
   727 }
   715 
   728 
   716 /*!
   729 /*!
   717     @beta
   730     @beta
   724 {
   737 {
   725     Q_D(const HbProgressDialog);
   738     Q_D(const HbProgressDialog);
   726 
   739 
   727     return d->mIcon;
   740     return d->mIcon;
   728 }
   741 }
   729 
   742 /*!
       
   743     updation of pri
       
   744  */
       
   745 void HbProgressDialog::updatePrimitives()
       
   746 {
       
   747     Q_D(HbProgressDialog); 
       
   748     HbDialog::updatePrimitives();
       
   749     if (d->mContentWidget->mIconItem) {
       
   750         HbStyleIconPrimitiveData data;
       
   751         initPrimitiveData(&data, d->mContentWidget->mIconItem);
       
   752         style()->updatePrimitive(d->mContentWidget->mIconItem, &data, this);
       
   753     }    
       
   754     
       
   755     if (d->mContentWidget->mTextItem) {
       
   756         HbStyleTextPrimitiveData data;
       
   757         initPrimitiveData(&data, d->mContentWidget->mTextItem);
       
   758         style()->updatePrimitive(d->mContentWidget->mTextItem, &data, this);
       
   759     }   
       
   760 }
       
   761 /*!
       
   762     Recreaction of all the primitives.
       
   763  */
       
   764 void HbProgressDialog::recreatePrimitives()
       
   765 {
       
   766     Q_D(HbProgressDialog);
       
   767     if (d->mContentWidget->mIconItem) {
       
   768         delete d->mContentWidget->mIconItem;
       
   769         d->mContentWidget->mIconItem = 0;
       
   770         d->mContentWidget->mIconItem = style()->createPrimitive(HbStyle::PT_IconItem, "icon",d->mContentWidget);
       
   771     }
       
   772     if (d->mContentWidget->mTextItem) {
       
   773         delete d->mContentWidget->mTextItem;
       
   774         d->mContentWidget->mTextItem = 0;
       
   775         d->mContentWidget->mTextItem = style()->createPrimitive(HbStyle::PT_TextItem, "text",d->mContentWidget);
       
   776     }
       
   777 }
       
   778 
       
   779 QGraphicsItem *HbProgressDialog::primitive(const QString &itemName) const
       
   780 {
       
   781     Q_D(const HbProgressDialog);
       
   782 
       
   783     if(!itemName.compare(QString("icon"))){
       
   784         return d->mContentWidget->mIconItem;
       
   785     }
       
   786 
       
   787     if(!itemName.compare(QString("text"))){
       
   788         return d->mContentWidget->mTextItem;
       
   789     }
       
   790 
       
   791     return HbDialog::primitive(itemName);
       
   792 }
   730 
   793 
   731 #include "moc_hbprogressdialog.cpp"
   794 #include "moc_hbprogressdialog.cpp"
   732 #include "hbprogressdialog.moc"
   795 #include "hbprogressdialog.moc"