actually use pixmap cache for toolbar drawing if requested to do so

This commit is contained in:
hjk
2009-11-09 11:47:05 +01:00
parent a253a69980
commit 9033749198

View File

@@ -132,105 +132,122 @@ void StyleHelper::setBaseColor(const QColor &color)
} }
} }
void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect)
{ {
QString key;
key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb());;
QPixmap pixmap;
QPainter *p = painter;
QRect rect = clipRect;
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size());
p = new QPainter(&pixmap);
rect = QRect(0, 0, clipRect.width(), clipRect.height());
}
QColor base = StyleHelper::baseColor(); QColor base = StyleHelper::baseColor();
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, highlightColor()); grad.setColorAt(0, StyleHelper::highlightColor());
grad.setColorAt(0.301, base); grad.setColorAt(0.301, base);
grad.setColorAt(1, shadowColor()); grad.setColorAt(1, StyleHelper::shadowColor());
p->fillRect(rect, grad); p->fillRect(rect, grad);
QColor light(255, 255, 255, 80); QColor light(255, 255, 255, 80);
p->setPen(light); p->setPen(light);
p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
}
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
painter->drawPixmap(clipRect.topLeft(), pixmap); {
p->end(); if (StyleHelper::usePixmapCache()) {
delete p; QString key;
key.sprintf("mh_vertical %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb());;
QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size());
QPainter p(&pixmap);
QRect rect(0, 0, clipRect.width(), clipRect.height());
verticalGradientHelper(&p, spanRect, rect);
p.end();
QPixmapCache::insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
painter->drawPixmap(clipRect.topLeft(), pixmap);
} else {
verticalGradientHelper(painter, spanRect, clipRect);
}
} }
void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const
QRect &rect)
{ {
QString key;
key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(),
clipRect.width(), clipRect.height(), StyleHelper::baseColor().rgb());
QPixmap pixmap;
QPainter *p = painter;
QRect rect = clipRect;
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size());
p = new QPainter(&pixmap);
rect = QRect(0, 0, clipRect.width(), clipRect.height());
}
QColor base = StyleHelper::baseColor(); QColor base = StyleHelper::baseColor();
QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); QLinearGradient grad(rect.topLeft(), rect.bottomLeft());
grad.setColorAt(0, highlightColor().lighter(120)); grad.setColorAt(0, StyleHelper::highlightColor().lighter(120));
if (rect.height() == navigationWidgetHeight()) { if (rect.height() == StyleHelper::navigationWidgetHeight()) {
grad.setColorAt(0.4, highlightColor()); grad.setColorAt(0.4, StyleHelper::highlightColor());
grad.setColorAt(0.401, base); grad.setColorAt(0.401, base);
} }
grad.setColorAt(1, shadowColor()); grad.setColorAt(1, StyleHelper::shadowColor());
p->fillRect(rect, grad); p->fillRect(rect, grad);
QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
QColor highlight = highlightColor().lighter(130); QColor highlight = StyleHelper::highlightColor().lighter(130);
highlight.setAlpha(100); highlight.setAlpha(100);
shadowGradient.setColorAt(0.7, highlight); shadowGradient.setColorAt(0.7, highlight);
shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); shadowGradient.setColorAt(1, QColor(0, 0, 0, 40));
p->fillRect(rect, shadowGradient); p->fillRect(rect, shadowGradient);
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { }
painter->drawPixmap(clipRect.topLeft(), pixmap);
p->end(); void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
delete p; {
if (StyleHelper::usePixmapCache()) {
QString key;
key.sprintf("mh_horizontal %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb());
QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size());
QPainter p(&pixmap);
QRect rect = QRect(0, 0, clipRect.width(), clipRect.height());
horizontalGradientHelper(&p, spanRect, rect);
p.end();
QPixmapCache::insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
painter->drawPixmap(clipRect.topLeft(), pixmap);
} else {
horizontalGradientHelper(painter, spanRect, clipRect);
}
}
static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect)
{
QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft());
QColor menuColor = StyleHelper::mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25);
grad.setColorAt(0, menuColor.lighter(112));
grad.setColorAt(1, menuColor);
p->fillRect(rect, grad);
} }
void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{ {
if (StyleHelper::usePixmapCache()) {
QString key; QString key;
key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(), key.sprintf("mh_menu %d %d %d %d %d",
clipRect.height(), StyleHelper::baseColor().rgb());; spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb());
QPixmap pixmap; QPixmap pixmap;
QPainter *p = painter; if (!QPixmapCache::find(key, pixmap)) {
QRect rect = clipRect;
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
pixmap = QPixmap(clipRect.size()); pixmap = QPixmap(clipRect.size());
p = new QPainter(&pixmap); QPainter p(&pixmap);
rect = QRect(0, 0, clipRect.width(), clipRect.height()); QRect rect = QRect(0, 0, clipRect.width(), clipRect.height());
menuGradientHelper(&p, spanRect, rect);
p.end();
QPixmapCache::insert(key, pixmap);
} }
QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft());
QColor menuColor = mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25);
grad.setColorAt(0, menuColor.lighter(112));
grad.setColorAt(1, menuColor);
p->fillRect(rect, grad);
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
painter->drawPixmap(clipRect.topLeft(), pixmap); painter->drawPixmap(clipRect.topLeft(), pixmap);
p->end(); } else {
delete p; menuGradientHelper(painter, spanRect, clipRect);
QPixmapCache::insert(key, pixmap);
} }
} }