src/hbwidgets/sliders/hbprogressbar.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    25 #include "hbprogressbar_p.h"
    25 #include "hbprogressbar_p.h"
    26 #include <hbprogressbar.h>
    26 #include <hbprogressbar.h>
    27 #include <hbstyleoptionprogressbar_p.h>
    27 #include <hbstyleoptionprogressbar_p.h>
    28 #include "hbglobal_p.h"
    28 #include "hbglobal_p.h"
    29 
    29 
       
    30 #include "hbrepeaticonitem_p.h"
       
    31 #include "hbprogresstrackitem_p.h"
    30 #ifdef HB_EFFECTS
    32 #ifdef HB_EFFECTS
    31 #include <hbeffect.h>
    33 #include <hbeffect.h>
    32 #include "hbeffectinternal_p.h"
    34 #include "hbeffectinternal_p.h"
    33 #define HB_PRGRESSBAR_ITEM_TYPE "HB_PROGRESSBAR"
    35 #define HB_PRGRESSBAR_ITEM_TYPE "HB_PROGRESSBAR"
    34 #endif
    36 #endif
   119     mMinMaxTextAlignment(Qt::AlignBottom),
   121     mMinMaxTextAlignment(Qt::AlignBottom),
   120     mMinText(QString()),
   122     mMinText(QString()),
   121     mMaxText(QString()),
   123     mMaxText(QString()),
   122     mOrientation(Qt::Horizontal),
   124     mOrientation(Qt::Horizontal),
   123     mDelayHideInProgress(true),
   125     mDelayHideInProgress(true),
   124     mShowEffectInProgress(false)
   126     mShowEffectInProgress(false),
       
   127     mStopWaitAnimation(false)
   125 {
   128 {
   126 }
   129 }
   127 
   130 
   128 /*
   131 /*
   129     HbProgressBarPrivate
   132     HbProgressBarPrivate
   138     initialises progressbar
   141     initialises progressbar
   139 */
   142 */
   140 void HbProgressBarPrivate::init() 
   143 void HbProgressBarPrivate::init() 
   141 {
   144 {
   142     Q_Q(HbProgressBar);
   145     Q_Q(HbProgressBar);
   143 
   146     
   144     HbStyle *style = qobject_cast<HbStyle*>(q->style());
   147     mFrame = q->style()->createPrimitive(HbStyle::PT_FrameItem, "frame",q);
   145     Q_ASSERT(style);
   148     mFrame->setZValue(-1);
   146 
   149     qgraphicsitem_cast<HbFrameItem*>(mFrame)->frameDrawer().setFillWholeRect(true);
   147     mFrame = style->createPrimitive(HbStyle::P_ProgressBar_frame,q);
   150 
   148     mTrack = style->createPrimitive(HbStyle::P_ProgressBar_track,mFrame);
   151     mTrack = new HbProgressTrackItem(mFrame);
   149     mWaitTrack = style->createPrimitive(HbStyle::P_ProgressBar_waittrack,mFrame);    
   152     HbStyle::setItemName(mTrack, "track");
       
   153     qgraphicsitem_cast<HbProgressTrackItem*>(mTrack)->frameDrawer().setFillWholeRect(true);
       
   154     mTrack->setZValue(-2);
       
   155 
       
   156     mWaitTrack = new HbRepeatIconItem(QLatin1String("qtg_graf_progbar_h_wait"), mFrame);
       
   157     HbStyle::setItemName(mWaitTrack, "wait-track");
   150     mWaitTrack->setVisible(false);
   158     mWaitTrack->setVisible(false);
   151 
   159 
   152     if(q->layoutDirection() == Qt::RightToLeft) {
   160     if(q->layoutDirection() == Qt::RightToLeft) {
   153         q->setInvertedAppearance(true);
   161         q->setInvertedAppearance(true);
   154     }
   162     }
   165 */
   173 */
   166 void HbProgressBarPrivate::createTextPrimitives()
   174 void HbProgressBarPrivate::createTextPrimitives()
   167 {
   175 {
   168     Q_Q(HbProgressBar);
   176     Q_Q(HbProgressBar);
   169 
   177 
   170     mMinTextItem = q->style()->createPrimitive(HbStyle::P_ProgressBar_mintext,q);
   178     mMinTextItem = q->style()->createPrimitive(HbStyle::PT_TextItem, "min-text",q);
   171     mMaxTextItem = q->style()->createPrimitive(HbStyle::P_ProgressBar_maxtext,q);
   179     mMaxTextItem = q->style()->createPrimitive(HbStyle::PT_TextItem, "max-text",q);
   172 }
   180 }
   173 
   181 
   174 void HbProgressBarPrivate::setProgressValue(int value)
   182 void HbProgressBarPrivate::setProgressValue(int value)
   175 {
   183 {
   176    Q_Q(HbProgressBar);
   184    Q_Q(HbProgressBar);
   177    if (mProgressValue == value) {
   185 
   178         return;
   186    // set progress value only for normal progressbar type
   179     }
   187    if( !((mMinimum ==0) && (mMaximum==0))) {
   180     if (value >= mMaximum) {
   188         if (mProgressValue == value) {
   181         value = mMaximum;
   189             return;
   182 #ifdef HB_EFFECTS
   190         }
   183         HbEffect::start(mTrack, HB_PRGRESSBAR_ITEM_TYPE, "progressbar_progress_complete");
   191         if (value >= mMaximum) {
   184 #endif
   192             value = mMaximum;
   185     }
   193     #ifdef HB_EFFECTS
   186     else if (value < mMinimum) {
   194             HbEffect::start(mTrack, HB_PRGRESSBAR_ITEM_TYPE, "progressbar_progress_complete");
   187         value = mMinimum;
   195     #endif
   188     }
   196         }
   189     
   197         else if (value < mMinimum) {
   190     mProgressValue=value;
   198             value = mMinimum;
   191 
   199         }
   192     //redraw track
   200         
   193     HbStyleOptionProgressBar progressBarOption;
   201         mProgressValue=value;
   194     q->initStyleOption(&progressBarOption);
   202 
   195     if(mTrack) {
   203         //redraw track
   196         q->style()->updatePrimitive(mTrack, HbStyle::P_ProgressBar_track, &progressBarOption);
   204         updateProgressTrack();
   197     }
   205 
   198 
   206         emit q->valueChanged(value);
   199     emit q->valueChanged(value);
   207    }
   200     
   208 }
   201 }
   209 
       
   210 /*
       
   211     \internal
       
   212     Update wait track primitive
       
   213 */
       
   214 void HbProgressBarPrivate::updateWaitTrack()
       
   215 {
       
   216     if (mWaitTrack && mWaitTrack->isVisible()) {
       
   217             HbRepeatIconItem *iconItem = qgraphicsitem_cast<HbRepeatIconItem*>(mWaitTrack);
       
   218                 iconItem->setOrientation(mOrientation);
       
   219                 if( !iconItem->isVisible() ) {
       
   220                     //break;
       
   221                 }
       
   222                 if(mOrientation == Qt::Horizontal){
       
   223                     iconItem->setName(QLatin1String("qtg_graf_progbar_h_wait"));
       
   224                 }
       
   225                 else{
       
   226                     iconItem->setName(QLatin1String("qtg_graf_progbar_v_wait"));
       
   227                 }
       
   228                 if(mStopWaitAnimation){
       
   229                     iconItem->stopAnimation();
       
   230                 }
       
   231         }   
       
   232 }
       
   233 
       
   234 /*
       
   235     \internal
       
   236     Update track primitive
       
   237 */
       
   238 void HbProgressBarPrivate::updateProgressTrack()
       
   239 {
       
   240     if (mTrack) {
       
   241             HbProgressTrackItem* frameItem = qgraphicsitem_cast<HbProgressTrackItem*>(mTrack);
       
   242             if(!frameItem->isVisible()) {
       
   243                 //break;
       
   244             }
       
   245 
       
   246             if(mOrientation == Qt::Horizontal){
       
   247                 frameItem->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
       
   248                 frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progbar_h_filled"));
       
   249              }
       
   250              else{
       
   251                frameItem->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical);
       
   252                frameItem->frameDrawer().setFrameGraphicsName(QLatin1String("qtg_fr_progbar_v_filled"));
       
   253              }
       
   254             frameItem->setMaximum(mMaximum);
       
   255             frameItem->setMinimum(mMinimum);
       
   256             frameItem->setValue(mProgressValue);
       
   257             frameItem->setInverted(mInvertedAppearance);
       
   258             frameItem->setOrientation(mOrientation);
       
   259             frameItem->update();
       
   260         }
       
   261 }
       
   262 
   202 
   263 
   203 /*
   264 /*
   204     \internal
   265     \internal
   205     Sets the progressbar enabling/disabling
   266     Sets the progressbar enabling/disabling
   206 */
   267 */
   207 void HbProgressBarPrivate::setEnableFlag(bool flag)
   268 void HbProgressBarPrivate::setEnableFlag(bool flag)
   208 {
   269 {
   209     Q_Q(HbProgressBar);
   270     Q_Q(HbProgressBar);
       
   271     
   210     if(!flag) {
   272     if(!flag) {
   211         q->setProgressValue(q->minimum());
   273         q->setProgressValue(q->minimum());
   212 
       
   213     }
   274     }
   214 }
   275 }
   215 
   276 
   216 /*
   277 /*
   217     \internal
   278     \internal
   218     Sets the progressbar range
   279     Sets the progressbar range
   219 */
   280 */
   220 void HbProgressBarPrivate::setRange(int minimum, int maximum)
   281 void HbProgressBarPrivate::setRange(int minimum, int maximum)
   221 {
   282 {
   222     Q_Q(HbProgressBar);
   283 
   223     if( minimum > maximum ){
   284     if( minimum > maximum ){
   224         maximum = minimum ;
   285         maximum = minimum ;
   225     }
   286     }
   226     mMinimum = minimum;
   287     mMinimum = minimum;
   227     mMaximum = maximum;
   288     mMaximum = maximum;
   234         mProgressValue = mMaximum;
   295         mProgressValue = mMaximum;
   235     }
   296     }
   236 
   297 
   237     // update primitve optimization, update only track primitive 
   298     // update primitve optimization, update only track primitive 
   238     // incase of normal as well as in infinite progressbar
   299     // incase of normal as well as in infinite progressbar
   239     HbStyleOptionProgressBar progressBarOption;
       
   240     q->initStyleOption(&progressBarOption);
       
   241 
   300 
   242     if( (mMinimum == 0) && (mMaximum == 0) ) {
   301     if( (mMinimum == 0) && (mMaximum == 0) ) {
   243         mWaitTrack->setVisible(true);
   302         mWaitTrack->setVisible(true);
   244         mTrack->setVisible(false);
   303         mTrack->setVisible(false);
   245 
   304 
   246         q->style()->updatePrimitive(mWaitTrack, HbStyle::P_ProgressBar_waittrack, &progressBarOption);
   305         updateWaitTrack();
   247     } else {
   306     } else {
   248         mWaitTrack->setVisible(false);
   307         mWaitTrack->setVisible(false);
   249         mTrack->setVisible(true);
   308         mTrack->setVisible(true);
   250 
   309 
   251         q->style()->updatePrimitive(mTrack, HbStyle::P_ProgressBar_track, &progressBarOption);
   310         updateProgressTrack();
   252     }
   311     }
   253     //q->updatePrimitives();
   312     //q->updatePrimitives();
   254 } 
   313 } 
   255 
   314 
   256 /*!
   315 /*!
   456 void HbProgressBar::setMinText(const QString &text)
   515 void HbProgressBar::setMinText(const QString &text)
   457 {
   516 {
   458     Q_D(HbProgressBar);
   517     Q_D(HbProgressBar);
   459     if (d->mMinText != text) {
   518     if (d->mMinText != text) {
   460         d->mMinText = text;
   519         d->mMinText = text;
   461         HbStyleOptionProgressBar progressBarOption;
   520 
   462         progressBarOption.minText = d->mMinText;
   521         if(d->mMinTextItem && d->mMinMaxTextVisible) {
   463         style()->updatePrimitive(d->mMinTextItem,HbStyle::P_ProgressBar_mintext,&progressBarOption);
   522             HbStyleTextPrimitiveData data; 
       
   523             initPrimitiveData(&data, d->mMinTextItem); 
       
   524             style()->updatePrimitive(d->mMinTextItem, &data, this);
       
   525         }
   464      }
   526      }
   465 }
   527 }
   466 
   528 
   467 /*!
   529 /*!
   468     @beta
   530     @beta
   487 void HbProgressBar::setMaxText(const QString &text)
   549 void HbProgressBar::setMaxText(const QString &text)
   488 {
   550 {
   489     Q_D(HbProgressBar);
   551     Q_D(HbProgressBar);
   490     if (d->mMaxText != text) {
   552     if (d->mMaxText != text) {
   491         d->mMaxText = text;
   553         d->mMaxText = text;
   492         HbStyleOptionProgressBar progressBarOption;
   554 
   493         progressBarOption.maxText = d->mMaxText;
   555         if(d->mMaxTextItem && d->mMinMaxTextVisible) {
   494         style()->updatePrimitive(d->mMaxTextItem,HbStyle::P_ProgressBar_maxtext,&progressBarOption);
   556             HbStyleTextPrimitiveData data; 
       
   557             initPrimitiveData(&data, d->mMaxTextItem); 
       
   558             style()->updatePrimitive(d->mMaxTextItem, &data, this);
       
   559         }
   495     }
   560     }
   496 }
   561 }
   497 
   562 
   498 /*!
   563 /*!
   499     @beta
   564     @beta
   524             d->createTextPrimitives();
   589             d->createTextPrimitives();
   525         }
   590         }
   526         
   591         
   527     // update primitve optimization, update only text primitives 
   592     // update primitve optimization, update only text primitives 
   528     // incase of with and without min-max text
   593     // incase of with and without min-max text
   529     HbStyleOptionProgressBar progressBarOption;
   594     if(d->mMinTextItem && d->mMinMaxTextVisible) {
   530     initStyleOption(&progressBarOption);
   595         HbStyleTextPrimitiveData data; 
   531 
   596         initPrimitiveData(&data, d->mMinTextItem); 
   532     style()->updatePrimitive(d->mMinTextItem,HbStyle::P_ProgressBar_mintext,&progressBarOption);    
   597         style()->updatePrimitive(d->mMinTextItem, &data, this);
   533     style()->updatePrimitive(d->mMaxTextItem,HbStyle::P_ProgressBar_maxtext,&progressBarOption); 
   598     }
       
   599 
       
   600     if(d->mMaxTextItem && d->mMinMaxTextVisible) {
       
   601         HbStyleTextPrimitiveData data; 
       
   602         initPrimitiveData(&data, d->mMaxTextItem); 
       
   603         style()->updatePrimitive(d->mMaxTextItem, &data, this);
       
   604     }
   534 
   605 
   535             d->mMinTextItem->show();
   606             d->mMinTextItem->show();
   536             d->mMaxTextItem->show();
   607             d->mMaxTextItem->show();
   537     } else {
   608     } else {
   538         if(d->mMinTextItem && d->mMaxTextItem){
   609         if(d->mMinTextItem && d->mMaxTextItem){
   582     if (d->mMinMaxTextAlignment != alignment) {
   653     if (d->mMinMaxTextAlignment != alignment) {
   583         d->mMinMaxTextAlignment = alignment;
   654         d->mMinMaxTextAlignment = alignment;
   584         if (d->mMinMaxTextVisible) {
   655         if (d->mMinMaxTextVisible) {
   585             repolish();
   656             repolish();
   586         }
   657         }
   587         // no need for primitve updation, only layout change is required
   658         prepareGeometryChange();
   588         //updatePrimitives();
       
   589     }
   659     }
   590 
   660 
   591 }
   661 }
   592 /*!
   662 /*!
   593     @beta
   663     @beta
   625     Q_D(const HbProgressBar);
   695     Q_D(const HbProgressBar);
   626     return d->mOrientation;    
   696     return d->mOrientation;    
   627 }
   697 }
   628 
   698 
   629 /*!
   699 /*!
   630     \deprecated HbProgressBar::primitive(HbStyle::Primitive)
   700    \reimp
   631         is deprecated.
   701 */
   632 */
       
   633 QGraphicsItem* HbProgressBar::primitive(HbStyle::Primitive primitive) const
       
   634 {
       
   635     Q_D(const HbProgressBar);
       
   636 
       
   637     switch (primitive) {
       
   638         case HbStyle::P_ProgressBar_frame:
       
   639             return d->mFrame;
       
   640         case HbStyle::P_ProgressBar_track:
       
   641             return d->mTrack;  
       
   642         case HbStyle::P_ProgressBar_waittrack:
       
   643             return d->mWaitTrack;
       
   644         case HbStyle::P_ProgressBar_mintext:
       
   645             return d->mMinTextItem;
       
   646         case HbStyle::P_ProgressBar_maxtext:
       
   647             return d->mMaxTextItem;
       
   648         default:
       
   649             return 0;
       
   650     }
       
   651 }
       
   652 
       
   653 /*!
       
   654     \reimp
       
   655  */
       
   656 void HbProgressBar::updatePrimitives()
   702 void HbProgressBar::updatePrimitives()
   657 {
   703 {
   658     Q_D(HbProgressBar);
   704     Q_D(HbProgressBar);
   659 
   705 
   660     if(isVisible()){
   706     if(isVisible()){
   661         HbStyleOptionProgressBar progressBarOption;
   707         
   662         initStyleOption(&progressBarOption);
       
   663         if (d->mFrame) {
   708         if (d->mFrame) {
   664             style()->updatePrimitive(d->mFrame, HbStyle::P_ProgressBar_frame, &progressBarOption);          
   709             HbStyleFramePrimitiveData data; 
       
   710             initPrimitiveData(&data, d->mFrame); 
       
   711 
       
   712             style()->updatePrimitive(d->mFrame, &data, this);
   665         }
   713         }
   666      
   714      
   667         if (d->mTrack) {
   715         d->updateProgressTrack();
   668                 style()->updatePrimitive(d->mTrack, HbStyle::P_ProgressBar_track, &progressBarOption);
       
   669         }
       
   670         
   716         
   671         if (d->mWaitTrack) {
   717         d->updateWaitTrack();
   672                 style()->updatePrimitive(d->mWaitTrack, HbStyle::P_ProgressBar_waittrack, &progressBarOption);
       
   673         }
       
   674         
   718         
   675         if(d->mMinTextItem && d->mMinMaxTextVisible) {
   719         if(d->mMinTextItem && d->mMinMaxTextVisible) {
   676             style()->updatePrimitive(d->mMinTextItem,HbStyle::P_ProgressBar_mintext,&progressBarOption);    
   720             HbStyleTextPrimitiveData data; 
       
   721             initPrimitiveData(&data, d->mMinTextItem); 
       
   722 
       
   723             style()->updatePrimitive(d->mMinTextItem, &data, this);
   677         }
   724         }
   678 
   725 
   679         if(d->mMaxTextItem && d->mMinMaxTextVisible) {
   726         if(d->mMaxTextItem && d->mMinMaxTextVisible) {
   680             style()->updatePrimitive(d->mMaxTextItem,HbStyle::P_ProgressBar_maxtext,&progressBarOption);    
   727             HbStyleTextPrimitiveData data; 
       
   728             initPrimitiveData(&data, d->mMaxTextItem); 
       
   729 
       
   730             style()->updatePrimitive(d->mMaxTextItem, &data, this);
   681         }
   731         }
   682     }
   732     }
   683     HbWidget::updatePrimitives();
   733     HbWidget::updatePrimitives();
   684 }
   734 }
   685 
   735 
   705 
   755 
   706 }
   756 }
   707 
   757 
   708 /*!
   758 /*!
   709     \reimp
   759     \reimp
       
   760 */
       
   761 void HbProgressBar::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive)
       
   762 {
       
   763     Q_D(HbProgressBar);
       
   764     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   765     QString itemName = HbStyle::itemName(primitive);
       
   766     if (itemName == QLatin1String("frame")) {
       
   767         HbStyleFramePrimitiveData *data = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData);
       
   768 
       
   769         if (d->mOrientation == Qt::Horizontal) {
       
   770         data->frameType = HbFrameDrawer::ThreePiecesHorizontal;
       
   771         data->frameGraphicsName = QLatin1String("qtg_fr_progbar_h_frame");
       
   772     } else {
       
   773         data->frameType = HbFrameDrawer::ThreePiecesVertical;
       
   774         data->frameGraphicsName = QLatin1String("qtg_fr_progbar_v_frame");
       
   775     }
       
   776 
       
   777     }
       
   778 
       
   779     if (itemName == QLatin1String("min-text")) {
       
   780         HbStyleTextPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
       
   781         if(!d->mMinTextItem) {
       
   782             return;
       
   783         }
       
   784         data->text = d->mMinText;
       
   785         data->textWrapping = Hb::TextWrapAnywhere;
       
   786     }
       
   787     else if(itemName == QLatin1String("max-text")) {
       
   788         HbStyleTextPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData);
       
   789          if(!d->mMaxTextItem) {
       
   790             return;
       
   791         }
       
   792         data->text = d->mMaxText;
       
   793         data->textWrapping = Hb::TextWrapAnywhere;
       
   794     }
       
   795     
       
   796 }
       
   797 
       
   798 /*!
       
   799     \reimp
   710  */
   800  */
   711 void HbProgressBar::closeEvent ( QCloseEvent * event )
   801 void HbProgressBar::closeEvent ( QCloseEvent * event )
   712 {
   802 {
   713     Q_D(HbProgressBar);
   803     Q_D(HbProgressBar);
   714     HbStyleOptionProgressBar progressBarOption;
   804 
   715     initStyleOption(&progressBarOption);
   805     d->mStopWaitAnimation = true;
   716     progressBarOption.stopWaitAnimation = true;
   806 
   717     if (d->mWaitTrack) {
   807     d->updateWaitTrack();
   718         style()->updatePrimitive(d->mWaitTrack, HbStyle::P_ProgressBar_waittrack, &progressBarOption);
       
   719     }
       
   720     event->accept();
   808     event->accept();
   721 }
   809 }
   722 
   810 
   723 /*!
   811 /*!
   724     \reimp
   812     \reimp
   786     }
   874     }
   787 
   875 
   788     HbWidget::changeEvent(event);
   876     HbWidget::changeEvent(event);
   789 }
   877 }
   790 
   878 
       
   879 QGraphicsItem *HbProgressBar::primitive(const QString &itemName) const
       
   880 {
       
   881     Q_D(const HbProgressBar);
       
   882 
       
   883     if(!itemName.compare(QString("frame"))){
       
   884         return d->mFrame;
       
   885     }
       
   886     if(!itemName.compare(QString("track"))){
       
   887         return d->mTrack;
       
   888     }
       
   889     if(!itemName.compare(QString("wait-track"))){
       
   890         return d->mWaitTrack;
       
   891     }
       
   892     if(!itemName.compare(QString("min-text"))){
       
   893         return d->mMinTextItem;
       
   894     }
       
   895     if(!itemName.compare(QString("max-text"))){
       
   896         return d->mMaxTextItem;
       
   897     }
       
   898 
       
   899     return HbWidget::primitive(itemName);
       
   900 }
       
   901 
   791 #include "moc_hbprogressbar.cpp"
   902 #include "moc_hbprogressbar.cpp"