From 36c40b985b63b5cb0a8296e07643554d5aeb5f55 Mon Sep 17 00:00:00 2001
From: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Date: Fri, 13 Aug 2010 17:16:58 +0200
Subject: [PATCH] QuickToolBar: optimizing the painting of ColorBox

The painting was visible slow before.
Avoiding QPainter and setting pixels
directly leads to serious speedup.
---
 src/libs/qmleditorwidgets/colorbox.cpp | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/libs/qmleditorwidgets/colorbox.cpp b/src/libs/qmleditorwidgets/colorbox.cpp
index e09cc033405..4b0827bce88 100644
--- a/src/libs/qmleditorwidgets/colorbox.cpp
+++ b/src/libs/qmleditorwidgets/colorbox.cpp
@@ -184,22 +184,21 @@ void ColorBox::paintEvent(QPaintEvent *event)
 
         int fixedHue = clamp(m_lastHue, 0, 359);
 
-        m_cache = QPixmap(120, 120);
+        QImage cache = QImage(120, 120, QImage::Format_RGB32);
 
         int height = 120;
         int width = 120;
 
-        QPainter chacheP(&m_cache);
-
-        for (int y = 0; y < height; y++)
-            for (int x = 0; x < width; x++)
-            {
-            QColor c;
-            c.setHsv(fixedHue, (x*255) / width, 255 - (y*255) / height);
-            chacheP.setPen(c);
-            chacheP.drawPoint(x ,y);
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                QColor c;
+                c.setHsv(fixedHue, (x*255) / width, 255 - (y*255) / height);
+                cache.setPixel(x, y, c.rgb());
+            }
         }
+        m_cache = QPixmap::fromImage(cache);
     }
+    
     p.drawPixmap(5, 5, m_cache);
 
     int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5;
-- 
GitLab