Branch: master

d9d3dd45 2014-09-16 13:10:59 Slávek Banko
Improve TQProgressBar repaint optimization
M src/widgets/ntqprogressbar.h
M src/widgets/qprogressbar.cpp
diff --git a/src/widgets/ntqprogressbar.h b/src/widgets/ntqprogressbar.h
index ca90da2..4ca7b9e 100644
--- a/src/widgets/ntqprogressbar.h
+++ b/src/widgets/ntqprogressbar.h
@@ -96,7 +96,7 @@
     virtual bool setIndicator( TQString & progress_str, int progress,
 			       int totalSteps );
     void styleChange( TQStyle& );
-    bool	requireRepaint( int newProgress ) const;
+    bool	repaintRequired() const;
 
 private:
     int		total_steps;
diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp
index 3eb0db0..ec5424c 100644
--- a/src/widgets/qprogressbar.cpp
+++ b/src/widgets/qprogressbar.cpp
@@ -212,13 +212,11 @@
 	 progress < 0 || ( ( progress > total_steps ) && total_steps ) )
 	return;
 
-    const bool needRepaint = isVisible() && requireRepaint( progress );
-
     progress_val = progress;
 
     setIndicator( progress_str, progress_val, total_steps );
 
-    if ( needRepaint ) {
+    if ( isVisible() && repaintRequired() ) {
         repaint( FALSE );
         d->last_painted_progress = progress;
     }
@@ -358,10 +356,9 @@
     would require a repaint of the progress bar. This allows efficient
     repainting.
 */
-bool TQProgressBar::requireRepaint( int newProgress ) const
+bool TQProgressBar::repaintRequired() const
 {
-    if ( newProgress == progress_val ||
-         newProgress == d->last_painted_progress ) {
+    if ( progress_val == d->last_painted_progress ) {
         return false;
     }
 
@@ -375,7 +372,7 @@
         progressPerPixel = float( total_steps ) / float( width );
     }
 
-    const int delta = d->last_painted_progress - newProgress;
+    const int delta = d->last_painted_progress - progress_val;
     return TQABS( delta ) >= progressPerPixel;
 }