QuickToolBar: optimizing the painting of ColorBox

The painting was visible slow before.
Avoiding QPainter and setting pixels
directly leads to serious speedup.
This commit is contained in:
Thomas Hartmann
2010-08-13 17:16:58 +02:00
parent 502ac08edb
commit 36c40b985b

View File

@@ -184,22 +184,21 @@ void ColorBox::paintEvent(QPaintEvent *event)
int fixedHue = clamp(m_lastHue, 0, 359); int fixedHue = clamp(m_lastHue, 0, 359);
m_cache = QPixmap(120, 120); QImage cache = QImage(120, 120, QImage::Format_RGB32);
int height = 120; int height = 120;
int width = 120; int width = 120;
QPainter chacheP(&m_cache); for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
QColor c; QColor c;
c.setHsv(fixedHue, (x*255) / width, 255 - (y*255) / height); c.setHsv(fixedHue, (x*255) / width, 255 - (y*255) / height);
chacheP.setPen(c); cache.setPixel(x, y, c.rgb());
chacheP.drawPoint(x ,y);
} }
} }
m_cache = QPixmap::fromImage(cache);
}
p.drawPixmap(5, 5, m_cache); p.drawPixmap(5, 5, m_cache);
int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5; int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5;