summaryrefslogtreecommitdiff
path: root/src/libs/utils/stylehelper.cpp
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2009-11-09 11:47:05 +0100
committerhjk <qtc-committer@nokia.com>2009-11-09 11:59:50 +0100
commit9033749198baffbe5ddf4449bf1059ee7a45aa44 (patch)
tree801c5850bafdc74ee7c2e3a3d07f6a69e81e2a9e /src/libs/utils/stylehelper.cpp
parenta253a6998055b33fedb72943101f94342cfb55a7 (diff)
downloadqt-creator-9033749198baffbe5ddf4449bf1059ee7a45aa44.tar.gz
actually use pixmap cache for toolbar drawing if requested to do so
Diffstat (limited to 'src/libs/utils/stylehelper.cpp')
-rw-r--r--src/libs/utils/stylehelper.cpp137
1 files changed, 77 insertions, 60 deletions
diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp
index 3087894c8d..3236d74821 100644
--- a/src/libs/utils/stylehelper.cpp
+++ b/src/libs/utils/stylehelper.cpp
@@ -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();
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
- grad.setColorAt(0, highlightColor());
+ grad.setColorAt(0, StyleHelper::highlightColor());
grad.setColorAt(0.301, base);
- grad.setColorAt(1, shadowColor());
+ grad.setColorAt(1, StyleHelper::shadowColor());
p->fillRect(rect, grad);
QColor light(255, 255, 255, 80);
p->setPen(light);
p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
+}
+
+void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
+{
+ if (StyleHelper::usePixmapCache()) {
+ 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);
+ }
- if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
painter->drawPixmap(clipRect.topLeft(), pixmap);
- p->end();
- delete p;
- QPixmapCache::insert(key, 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();
QLinearGradient grad(rect.topLeft(), rect.bottomLeft());
- grad.setColorAt(0, highlightColor().lighter(120));
- if (rect.height() == navigationWidgetHeight()) {
- grad.setColorAt(0.4, highlightColor());
+ grad.setColorAt(0, StyleHelper::highlightColor().lighter(120));
+ if (rect.height() == StyleHelper::navigationWidgetHeight()) {
+ grad.setColorAt(0.4, StyleHelper::highlightColor());
grad.setColorAt(0.401, base);
}
- grad.setColorAt(1, shadowColor());
+ grad.setColorAt(1, StyleHelper::shadowColor());
p->fillRect(rect, grad);
QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
- QColor highlight = highlightColor().lighter(130);
+ QColor highlight = StyleHelper::highlightColor().lighter(130);
highlight.setAlpha(100);
shadowGradient.setColorAt(0.7, highlight);
shadowGradient.setColorAt(1, QColor(0, 0, 0, 40));
p->fillRect(rect, shadowGradient);
- if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
- painter->drawPixmap(clipRect.topLeft(), pixmap);
- p->end();
- delete p;
- QPixmapCache::insert(key, pixmap);
- }
}
-void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
+void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{
- 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());
+ 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);
+ }
+
+ 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 = mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25);
+ 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)
+{
+ if (StyleHelper::usePixmapCache()) {
+ QString key;
+ key.sprintf("mh_menu %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());
+ menuGradientHelper(&p, spanRect, rect);
+ p.end();
+ QPixmapCache::insert(key, pixmap);
+ }
- if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
painter->drawPixmap(clipRect.topLeft(), pixmap);
- p->end();
- delete p;
- QPixmapCache::insert(key, pixmap);
+ } else {
+ menuGradientHelper(painter, spanRect, clipRect);
}
}