summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFrerich Raabe <raabe@kde.org>2014-09-16 03:15:39 +0200
committerSlávek Banko <slavek.banko@axis.cz>2014-09-16 03:41:40 +0200
commit0c5a2640a6ab97b1ba97eb2399bd58fb1e890f0c (patch)
treea25e6f2cdec89e052e1ffc5bb631030d4d07a653 /src/widgets
parentb47847259808cc29f6bf98b8c788603d0d21a038 (diff)
downloadtqt3-0c5a2640a6ab97b1ba97eb2399bd58fb1e890f0c.tar.gz
tqt3-0c5a2640a6ab97b1ba97eb2399bd58fb1e890f0c.zip
Add repaint optimization to TQProgressBar
This optimization makes TQProgressBar::setProgress() only repaint itself if stepping to the new progress would cause a graphical change. This means that for a width W and a total number of steps S, it will repaint itself 'W' times (every 'S/W' steps) instead of 'S' times (every step) as it is right now.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/ntqprogressbar.h2
-rw-r--r--src/widgets/qprogressbar.cpp55
2 files changed, 54 insertions, 3 deletions
diff --git a/src/widgets/ntqprogressbar.h b/src/widgets/ntqprogressbar.h
index ca73cd8a..ca90da2a 100644
--- a/src/widgets/ntqprogressbar.h
+++ b/src/widgets/ntqprogressbar.h
@@ -65,6 +65,7 @@ class Q_EXPORT TQProgressBar : public TQFrame
public:
TQProgressBar( TQWidget* parent=0, const char* name=0, WFlags f=0 );
TQProgressBar( int totalSteps, TQWidget* parent=0, const char* name=0, WFlags f=0 );
+ virtual ~TQProgressBar();
int totalSteps() const;
int progress() const;
@@ -95,6 +96,7 @@ protected:
virtual bool setIndicator( TQString & progress_str, int progress,
int totalSteps );
void styleChange( TQStyle& );
+ bool requireRepaint( int newProgress ) const;
private:
int total_steps;
diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp
index d1300d3e..3eb0db0d 100644
--- a/src/widgets/qprogressbar.cpp
+++ b/src/widgets/qprogressbar.cpp
@@ -51,6 +51,14 @@
#endif
#include <limits.h>
+class TQProgressBarPrivate
+{
+ public:
+ TQProgressBarPrivate() : last_painted_progress( 0 ) { }
+
+ int last_painted_progress;
+};
+
/*!
\class TQProgressBar ntqprogressbar.h
\brief The TQProgressBar widget provides a horizontal progress bar.
@@ -103,7 +111,7 @@ TQProgressBar::TQProgressBar( TQWidget *parent, const char *name, WFlags f )
center_indicator( TRUE ),
auto_indicator( TRUE ),
percentage_visible( TRUE ),
- d( 0 ),
+ d( new TQProgressBarPrivate ),
m_orientation( Horizontal )
{
setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
@@ -135,7 +143,7 @@ TQProgressBar::TQProgressBar( int totalSteps,
center_indicator( TRUE ),
auto_indicator( TRUE ),
percentage_visible( TRUE ),
- d( 0 ),
+ d( new TQProgressBarPrivate ),
m_orientation( Horizontal )
{
setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
@@ -144,6 +152,16 @@ TQProgressBar::TQProgressBar( int totalSteps,
/*!
+ Destroys the object and frees any allocated ressources.
+*/
+
+TQProgressBar::~TQProgressBar()
+{
+ delete d;
+}
+
+
+/*!
Reset the progress bar. The progress bar "rewinds" and shows no
progress.
*/
@@ -194,11 +212,16 @@ void TQProgressBar::setProgress( int progress )
progress < 0 || ( ( progress > total_steps ) && total_steps ) )
return;
+ const bool needRepaint = isVisible() && requireRepaint( progress );
+
progress_val = progress;
setIndicator( progress_str, progress_val, total_steps );
- repaint( FALSE );
+ if ( needRepaint ) {
+ repaint( FALSE );
+ d->last_painted_progress = progress;
+ }
#if defined(QT_ACCESSIBILITY_SUPPORT)
TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged );
@@ -330,6 +353,32 @@ void TQProgressBar::styleChange( TQStyle& old )
TQFrame::styleChange( old );
}
+/*!
+ This method returns whether changing the progress to the \a newValue
+ would require a repaint of the progress bar. This allows efficient
+ repainting.
+*/
+bool TQProgressBar::requireRepaint( int newProgress ) const
+{
+ if ( newProgress == progress_val ||
+ newProgress == d->last_painted_progress ) {
+ return false;
+ }
+
+ const int width = contentsRect().width();
+ if ( width == 0 ) {
+ return false;
+ }
+
+ float progressPerPixel = 1.0;
+ if ( total_steps > width ) {
+ progressPerPixel = float( total_steps ) / float( width );
+ }
+
+ const int delta = d->last_painted_progress - newProgress;
+ return TQABS( delta ) >= progressPerPixel;
+}
+
TQt::Orientation TQProgressBar::orientation() const
{
return m_orientation;