src/hbwidgets/sliders/hbprogressbar.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    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 "hbprogressbar_p.h"
       
    29 #include "hbglobal_p.h"
    28 #include "hbglobal_p.h"
    30 
    29 
    31 #ifdef HB_EFFECTS
    30 #ifdef HB_EFFECTS
    32 #include <hbeffect.h>
    31 #include <hbeffect.h>
    33 #include "hbeffectinternal_p.h"
    32 #include "hbeffectinternal_p.h"
    38     @beta
    37     @beta
    39     @hbwidgets
    38     @hbwidgets
    40     \class HbProgressBar
    39     \class HbProgressBar
    41 
    40 
    42     \brief HbProgressBar widget provides a vertical and horizontal progress bar.
    41     \brief HbProgressBar widget provides a vertical and horizontal progress bar.
    43     An infinite progressbar is also available.
       
    44 
       
    45     A progress bar is used to give the user an indication of the progress of an operation and to 
       
    46     reassure them that the application is still running.
       
    47 
       
    48     The progress bar uses the concept of steps. User can set it up by specifying the minimum and 
       
    49     maximum possible step values, and it will display the percentage of steps that have been completed
       
    50     when you later give it the current step value. 
       
    51     
    42     
    52     The percentage is calculated by dividing the progress (progressValue() - minimum()) divided by maximum() - minimum().
    43     \image html progressbar.png  "A Progress Bar with Min-Max text at bottom"
    53 
    44     \image html infiniteprogressbar.png  "An infinite progres bar"
    54     User can specify the minimum and maximum number of steps with setMinimum() and setMaximum() APIs. 
    45 
    55     The current number of steps is set with setProgressValue(). 
    46     The HbProgressBar widget provides a horizontal or vertical progress bar.
    56 
    47 
    57     If minimum and maximum both are set to 0, the bar shows a busy indicator instead of a percentage of steps.
    48     A progress bar is used to give the user an indication of the progress of an operation and to reassure them that 
    58     This is useful, for example, when using ftp or http to download items when they are unable to 
    49     the application is still running. The progress bar uses the concept of steps. You set it up by specifying the 
    59     determine the size of the item being downloaded.
    50     minimum and maximum possible step values, and it will display the percentage of steps that have been completed 
    60 
    51     when you later give it the current step value. The percentage is calculated by dividing the 
    61     ProgressBar also supports adding text . min max text pair is also supported which is commonly 
    52     progress (value() - minimum()) divided by maximum() - minimum().
    62     used for progress indication for music.
       
    63     
    53     
    64     \image html hbprogressbartext.png Left Aligned Text, Min Max Text.
    54     By default the min value is 0 and max value is 100.If minimum and maximum both are set to 0, the bar shows a busy indicator 
    65 
    55     instead of a percentage of steps.The ProgressBar is always non interactive.
       
    56 
       
    57     ProgressBar also supports adding text . Min-Max text pair is also supported which is commonly 
       
    58     used for progress indication for music. 
       
    59     
    66     Progress bar provides below signal.
    60     Progress bar provides below signal.
    67 
    61 
    68     \li valueChanged(int value) Emitted when the value of the progressbar is changed.
    62     \li valueChanged(int value) Emitted when the value of the progressbar is changed.
    69 */
    63 
    70 
    64 
    71 /*!
    65     Example code for creating normal ProgressBar:
    72     @beta
    66     \code
    73     \fn void HbProgressBar::valueChanged(int value)
    67     HbProgressBar *pb = new HbProgressBar();
    74     
    68     pb->setMinimum(0);
    75     Emitted when the value of the progressbar is changed.
    69     pb->setMaximum(500);
    76 */
    70     pb->setProgressValue(175);
    77 
    71     \endcode
    78 
    72 
    79 /*!
    73     Example code for creating infinite ProgressBar:
    80     @beta
    74     \code
    81     \reimp
    75     HbProgressBar *pb = new HbProgressBar();
    82     \fn int HbProgressBar::type() const
    76     pb->setMinimum(0);
    83  */
    77     pb->setMaximum(0);
    84 
    78     \endcode
    85 /*!
    79 
    86     @beta
    80     Example code for creating normal ProgressBar with Min-Max text at Top:
    87     \enum HbProgressBar::ProgressBarType
    81     \code
    88 
    82     HbProgressBar *pb = new HbProgressBar();
    89     This enum defines available progress bar types.
    83     pb->setMinimum(0);
       
    84     pb->setMaximum(500);
       
    85     pb->setProgressValue(175);
       
    86     pb->setMinMaxTextVisible(true);
       
    87     pb->setMinMaxTextAlignment(Qt::AlignTop);// The possible options are Qt::AlignTop ,Qt::AlignBottom ,Qt::AlignCenter
       
    88     pb->setminText("0");
       
    89     pb->setmaxText("500");
       
    90 
       
    91     \endcode
       
    92 
       
    93     Example code for creating vertical normal ProgressBar:
       
    94     \code
       
    95     HbProgressBar *pb = new HbProgressBar();
       
    96     pb->setOrientation(Qt::Vertical);
       
    97     pb->setMinimum(0);
       
    98     pb->setMaximum(500);
       
    99     pb->setProgressValue(175);
       
   100     \endcode
    90 */
   101 */
    91 
   102 
    92 
   103 
    93 /*
   104 /*
    94     HbProgressBarPrivate
   105     HbProgressBarPrivate
   221 
   232 
   222     if(mProgressValue > mMaximum){
   233     if(mProgressValue > mMaximum){
   223         mProgressValue = mMaximum;
   234         mProgressValue = mMaximum;
   224     }
   235     }
   225 
   236 
       
   237     // update primitve optimization, update only track primitive 
       
   238     // incase of normal as well as in infinite progressbar
       
   239     HbStyleOptionProgressBar progressBarOption;
       
   240     q->initStyleOption(&progressBarOption);
       
   241 
   226     if( (mMinimum == 0) && (mMaximum == 0) ) {
   242     if( (mMinimum == 0) && (mMaximum == 0) ) {
   227         mWaitTrack->setVisible(true);
   243         mWaitTrack->setVisible(true);
   228         mTrack->setVisible(false);
   244         mTrack->setVisible(false);
       
   245 
       
   246         q->style()->updatePrimitive(mWaitTrack, HbStyle::P_ProgressBar_waittrack, &progressBarOption);
   229     } else {
   247     } else {
   230         mWaitTrack->setVisible(false);
   248         mWaitTrack->setVisible(false);
   231         mTrack->setVisible(true);
   249         mTrack->setVisible(true);
   232     }
   250 
   233     q->updatePrimitives();
   251         q->style()->updatePrimitive(mTrack, HbStyle::P_ProgressBar_track, &progressBarOption);
       
   252     }
       
   253     //q->updatePrimitives();
   234 } 
   254 } 
   235 
   255 
   236 /*!
   256 /*!
   237     \internal
   257     \internal
   238     Sets the progressbar orientation.
   258     Sets the progressbar orientation.
   273 }
   293 }
   274 #endif
   294 #endif
   275 
   295 
   276 /*!
   296 /*!
   277     @beta
   297     @beta
   278     Constructor of  Progressbar.
   298    Constructs a progress bar with the given parent.
   279     \param parent. Parent widget
   299    By default, the minimum step value is set to 0, and the maximum to 100.
       
   300    \param parent The parent of ProgressBar
   280 
   301 
   281 */
   302 */
   282 HbProgressBar::HbProgressBar(QGraphicsItem *parent) : 
   303 HbProgressBar::HbProgressBar(QGraphicsItem *parent) : 
   283     HbWidget(*new HbProgressBarPrivate, parent)
   304     HbWidget(*new HbProgressBarPrivate, parent)
   284 {    
   305 {    
   302 {    
   323 {    
   303 }
   324 }
   304 
   325 
   305 /*!
   326 /*!
   306     @beta
   327     @beta
   307     Return the inverted appearence property. 
   328     Return the inverted appearance property. 
   308 
       
   309     \sa setInvertedAppearance()
   329     \sa setInvertedAppearance()
   310 */
   330 */
   311 bool HbProgressBar::invertedAppearance() const 
   331 bool HbProgressBar::invertedAppearance() const 
   312 {
   332 {
   313     Q_D( const HbProgressBar );
   333     Q_D( const HbProgressBar );
   314     return d->mInvertedAppearance;
   334     return d->mInvertedAppearance;
   315 }
   335 }
   316 
   336 
   317 /*!
   337 /*!
   318     @beta
   338     @beta
   319     Sets the inverted appearence. If this is true progress grows from right to 
   339     Sets the inverted Appearance. If this is true progress grows from right to 
   320     left otherwise left to right.
   340     left otherwise left to right.
   321 
   341 
   322     \param inverted true or false.
   342     \param inverted true or false.
   323 
   343 
   324     \sa invertedAppearance()
   344     \sa invertedAppearance()
   344 
   364 
   345 /*!
   365 /*!
   346     @beta
   366     @beta
   347     Sets the maximum value of the progressbar. By default it is 100. 
   367     Sets the maximum value of the progressbar. By default it is 100. 
   348 
   368 
   349     \param maximum the max value
   369     \param maximum the maximum value
   350 
   370 
   351     \sa maximum()
   371     \sa maximum()
   352 */
   372 */
   353 void HbProgressBar::setMaximum(int maximum)
   373 void HbProgressBar::setMaximum(int maximum)
   354 {
   374 {
   370 
   390 
   371 /*!
   391 /*!
   372     @beta
   392     @beta
   373     Sets the minimum value of the progressbar. By default it is 0. 
   393     Sets the minimum value of the progressbar. By default it is 0. 
   374 
   394 
   375     \param maximum the max value
   395     \param minimum the minimum value
   376 
   396 
   377     \sa minimum()
   397     \sa minimum()
   378 */
   398 */
   379 void HbProgressBar::setMinimum(int minimum)
   399 void HbProgressBar::setMinimum(int minimum)
   380 {
   400 {
   408 }
   428 }
   409 
   429 
   410 /*!
   430 /*!
   411     @beta
   431     @beta
   412     This function is provided for convenience.
   432     This function is provided for convenience.
   413 
       
   414     Sets the progress bar's minimum and its maximum.
   433     Sets the progress bar's minimum and its maximum.
   415 
   434 
   416     If  maximum is smaller than minimum, minimum becomes the only valid legal
   435     If  maximum is smaller than minimum, minimum becomes the only valid legal
   417     value.
   436     value.
   418 
   437 
   419      \param minimum the minimum value
   438     \param minimum the minimum value
   420      \param maximum the maximum value
   439     \param maximum the maximum value
   421 */
   440 */
   422 void HbProgressBar::setRange(int minimum, int maximum) 
   441 void HbProgressBar::setRange(int minimum, int maximum) 
   423 {
   442 {
   424     Q_D( HbProgressBar );
   443     Q_D( HbProgressBar );
   425     d->setRange(minimum , maximum);
   444     d->setRange(minimum , maximum);
   426 }
   445 }
   427 
   446 
   428 /*!
   447 /*!
   429     @beta
   448     @beta
   430     Sets the min text string. 
   449     A text can be shown at top,bottom or left-right of the progressbar near minimum and maximum.
       
   450     This will set the text near the minimum point.
   431 
   451 
   432     \param text mintext string
   452     \param text mintext string
   433 
   453 
   434     \sa minText()
   454     \sa minText()
   435 */
   455 */
   455     return d->mMinText;
   475     return d->mMinText;
   456 }
   476 }
   457 
   477 
   458 /*!
   478 /*!
   459     @beta
   479     @beta
   460     Sets the max text string. 
   480     A text can be shown at top,bottom or left-right of the progressbar near minimum and maximum.
       
   481     This will set the text near the minimum point.
   461 
   482 
   462     \param text max text string
   483     \param text max text string
   463 
   484 
   464     \sa maxText()
   485     \sa maxText()
   465 */
   486 */
   486 }
   507 }
   487 
   508 
   488 /*!
   509 /*!
   489     @beta 
   510     @beta 
   490     Set the MinMaxtext visibility. true for showing text,false for hiding the text.
   511     Set the MinMaxtext visibility. true for showing text,false for hiding the text.
   491     The default is  false. Min Max text doesnt have a background and would have a transparent background.
   512     The default is  false. Min Max text does not have a background and would have a transparent background.
   492     \param visible true or false.
   513     \param visible true or false.
   493     \sa isMinMaxTextVisible().
   514     \sa isMinMaxTextVisible().
   494 */
   515 */
   495 void HbProgressBar::setMinMaxTextVisible(bool visible)
   516 void HbProgressBar::setMinMaxTextVisible(bool visible)
   496 {
   517 {
   500 
   521 
   501     if(d->mMinMaxTextVisible) {
   522     if(d->mMinMaxTextVisible) {
   502         if(!d->mMinTextItem && !d->mMaxTextItem){
   523         if(!d->mMinTextItem && !d->mMaxTextItem){
   503             d->createTextPrimitives();
   524             d->createTextPrimitives();
   504         }
   525         }
       
   526         
       
   527     // update primitve optimization, update only text primitives 
       
   528     // incase of with and without min-max text
       
   529     HbStyleOptionProgressBar progressBarOption;
       
   530     initStyleOption(&progressBarOption);
       
   531 
       
   532     style()->updatePrimitive(d->mMinTextItem,HbStyle::P_ProgressBar_mintext,&progressBarOption);    
       
   533     style()->updatePrimitive(d->mMaxTextItem,HbStyle::P_ProgressBar_maxtext,&progressBarOption); 
       
   534 
   505             d->mMinTextItem->show();
   535             d->mMinTextItem->show();
   506             d->mMaxTextItem->show();
   536             d->mMaxTextItem->show();
   507     } else {
   537     } else {
   508         if(d->mMinTextItem && d->mMaxTextItem){
   538         if(d->mMinTextItem && d->mMaxTextItem){
   509             d->mMinTextItem->hide();
   539             d->mMinTextItem->hide();
   510             d->mMaxTextItem->hide();
   540             d->mMaxTextItem->hide();
   511         }
   541         }
   512     }
   542     }
   513     repolish();
   543     repolish();
   514     updatePrimitives();
   544     //updatePrimitives();
   515     }
   545     }
   516 }
   546 }
   517 
   547 
   518 /*!
   548 /*!
   519     @beta
   549     @beta
   537 
   567 
   538     In Vertical orienatation,     
   568     In Vertical orienatation,     
   539     AlignTop is equivalent to Left
   569     AlignTop is equivalent to Left
   540     AlignBottom is equivalent to Right
   570     AlignBottom is equivalent to Right
   541 
   571 
   542     \param alignment alignement for the min max text
   572     \param alignment alignment for the min max text
   543     \sa isMinMaxTextVisible().
   573     \sa isMinMaxTextVisible().
   544 
   574 
   545 */
   575 */
   546 void HbProgressBar::setMinMaxTextAlignment(Qt::Alignment alignment)
   576 void HbProgressBar::setMinMaxTextAlignment(Qt::Alignment alignment)
   547 {
   577 {
   552     if (d->mMinMaxTextAlignment != alignment) {
   582     if (d->mMinMaxTextAlignment != alignment) {
   553         d->mMinMaxTextAlignment = alignment;
   583         d->mMinMaxTextAlignment = alignment;
   554         if (d->mMinMaxTextVisible) {
   584         if (d->mMinMaxTextVisible) {
   555             repolish();
   585             repolish();
   556         }
   586         }
   557         updatePrimitives();
   587         // no need for primitve updation, only layout change is required
       
   588         //updatePrimitives();
   558     }
   589     }
   559 
   590 
   560 }
   591 }
   561 /*!
   592 /*!
   562     @beta
   593     @beta
   594     Q_D(const HbProgressBar);
   625     Q_D(const HbProgressBar);
   595     return d->mOrientation;    
   626     return d->mOrientation;    
   596 }
   627 }
   597 
   628 
   598 /*!
   629 /*!
   599     Returns the pointer for \a primitive passed.
   630     \deprecated HbProgressBar::primitive(HbStyle::Primitive)
   600     Will return NULL if \a primitive passed is invalid
   631         is deprecated.
   601 */
   632 */
   602 QGraphicsItem* HbProgressBar::primitive(HbStyle::Primitive primitive) const
   633 QGraphicsItem* HbProgressBar::primitive(HbStyle::Primitive primitive) const
   603 {
   634 {
   604     Q_D(const HbProgressBar);
   635     Q_D(const HbProgressBar);
   605 
   636 
   651     }
   682     }
   652     HbWidget::updatePrimitives();
   683     HbWidget::updatePrimitives();
   653 }
   684 }
   654 
   685 
   655 /*!
   686 /*!
   656     Initializes \a option with the values from this HbProgressBar. This method 
   687     \reimp
   657     is useful for subclasses when they need a HbStyleOptionProgressBar, but don't
   688 */
   658     want to fill in all the information themselves.
       
   659  */
       
   660 
   689 
   661 void HbProgressBar::initStyleOption(HbStyleOptionProgressBar *option) const
   690 void HbProgressBar::initStyleOption(HbStyleOptionProgressBar *option) const
   662 {
   691 {
   663     Q_D( const HbProgressBar );
   692     Q_D( const HbProgressBar );
   664 
   693 
   671     option->maxText = d->mMaxText;
   700     option->maxText = d->mMaxText;
   672     option->orientation = d->mOrientation;
   701     option->orientation = d->mOrientation;
   673     option->inverted = d->mInvertedAppearance;
   702     option->inverted = d->mInvertedAppearance;
   674     option->stopWaitAnimation = false;
   703     option->stopWaitAnimation = false;
   675     option->minMaxTextAlignment = d->mMinMaxTextAlignment;
   704     option->minMaxTextAlignment = d->mMinMaxTextAlignment;
   676     QRect rect((int)d->mFrame->boundingRect().x(),(int)d->mFrame->boundingRect().y(),(int)d->mFrame->boundingRect().width(),
   705 
   677     (int)d->mFrame->boundingRect().height());
       
   678     option->rect = rect;
       
   679 }
   706 }
   680 
   707 
   681 /*!
   708 /*!
   682     \reimp
   709     \reimp
   683  */
   710  */