From 3da48de31b8afa4e92aa5263b1d6e5dfcfa6729b Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jbache@trolltech.com> Date: Fri, 19 Mar 2010 17:47:45 +0100 Subject: [PATCH] Don't cache toolbars twice. Fix flickering. There was a flicker problem with the tool bars because of missing information in the cache key. We added this info and removed the redundant caching of toolbar gradients. Done-with: thorbjorn --- src/libs/utils/stylehelper.cpp | 4 +- src/libs/utils/stylehelper.h | 2 - src/plugins/coreplugin/manhattanstyle.cpp | 48 +++++++---------------- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/libs/utils/stylehelper.cpp b/src/libs/utils/stylehelper.cpp index 42690c190ef..c82abb050ba 100644 --- a/src/libs/utils/stylehelper.cpp +++ b/src/libs/utils/stylehelper.cpp @@ -231,9 +231,9 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c if (StyleHelper::usePixmapCache()) { QString key; QColor keyColor = baseColor(lightColored); - key.sprintf("mh_horizontal %d %d %d %d %d", + key.sprintf("mh_horizontal %d %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(), - clipRect.height(), keyColor.rgb()); + clipRect.height(), keyColor.rgb(), spanRect.x()); QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { diff --git a/src/libs/utils/stylehelper.h b/src/libs/utils/stylehelper.h index 334418816fb..f6d3eba4dac 100644 --- a/src/libs/utils/stylehelper.h +++ b/src/libs/utils/stylehelper.h @@ -78,8 +78,6 @@ public: static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); - - // Pixmap cache should only be enabled for X11 due to slow gradients static bool usePixmapCache() { return true; } static void drawIconWithShadow(const QPixmap &px, const QPoint &pos, QPainter *p, diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 2696fdb7ec1..c9fb0a9cd92 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -763,42 +763,22 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt case CE_ToolBar: { - QString key; - QColor keyColor = Utils::StyleHelper::baseColor(lightColored(widget)); - key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), keyColor.rgb());; - - QPixmap pixmap; - QPainter *p = painter; QRect rect = option->rect; bool horizontal = option->state & State_Horizontal; - if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { - pixmap = QPixmap(option->rect.size()); - p = new QPainter(&pixmap); - rect = QRect(0, 0, option->rect.width(), option->rect.height()); - } - - if (!Utils::StyleHelper::usePixmapCache() || !QPixmapCache::find(key, pixmap)) { - // Map offset for global window gradient - QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - - widget->mapToGlobal(option->rect.topLeft()); - QRect gradientSpan; - if (widget) { - gradientSpan = QRect(offset, widget->window()->size()); - } - bool drawLightColored = lightColored(widget); - if (horizontal) - Utils::StyleHelper::horizontalGradient(p, gradientSpan, rect, drawLightColored); - else - Utils::StyleHelper::verticalGradient(p, gradientSpan, rect, drawLightColored); - } - - if (Utils::StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { - delete p; - QPixmapCache::insert(key, pixmap); - } - if (Utils::StyleHelper::usePixmapCache()) { - painter->drawPixmap(rect.topLeft(), pixmap); - } + rect = option->rect; + + // Map offset for global window gradient + QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - + widget->mapToGlobal(option->rect.topLeft()); + QRect gradientSpan; + if (widget) + gradientSpan = QRect(offset, widget->window()->size()); + + bool drawLightColored = lightColored(widget); + if (horizontal) + Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored); + else + Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored); painter->setPen(Utils::StyleHelper::borderColor()); -- GitLab