From 0ddfcdff434f808b10d414e6a1c1df7d3642f40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 25 Jan 2010 13:46:08 +0100 Subject: Fixed performance issue with scrolling when using X11 graphics system Depending on the XRender driver (probably), drawing a short straight line can take quite a while when this line is transparent. On my laptop's onboard ATI card, this meant that scrolling was unusably slow when this transparent line was being drawn. Fixed by avoiding the issue, since there is no actual need to use transparency here. We can calculate the resulting color in advance instead. --- src/plugins/texteditor/basetexteditor.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index b9bcb9660d..7825941ea5 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1926,6 +1926,13 @@ void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible) q->ensureCursorVisible(); } +static QColor blendColors(const QColor &a, const QColor &b, int alpha) +{ + return QColor((a.red() * (256 - alpha) + b.red() * alpha) / 256, + (a.green() * (256 - alpha) + b.green() * alpha) / 256, + (a.blue() * (256 - alpha) + b.blue() * alpha) / 256); +} + static QColor calcBlendColor(const QColor &baseColor, int level, int count) { QColor color80; @@ -1960,10 +1967,7 @@ static QColor calcBlendColor(const QColor &baseColor, int level, int count) const int blendFactor = level * (256 / (count - 2)); - return QColor( - (color90.red() * blendFactor + color80.red() * (256 - blendFactor)) / 256, - (color90.green() * blendFactor + color80.green() * (256 - blendFactor)) / 256, - (color90.blue() * blendFactor + color80.blue() * (256 - blendFactor)) / 256); + return blendColors(color80, color90, blendFactor); } void BaseTextEditor::paintEvent(QPaintEvent *e) @@ -2379,10 +2383,9 @@ void BaseTextEditor::paintEvent(QPaintEvent *e) if (lineX > 0) { const QColor bg = palette().base().color(); - QColor col = (bg.value() > 128) ? Qt::black : Qt::white; - col.setAlpha(32); - painter.setPen(QPen(col, 0)); - painter.drawLine(QPointF(lineX, 0), QPointF(lineX, viewport()->height())); + const QColor col = (bg.value() > 128) ? Qt::black : Qt::white; + painter.setPen(blendColors(d->m_ifdefedOutFormat.background().color(), col, 32)); + painter.drawLine(QPointF(lineX, er.top()), QPointF(lineX, er.bottom())); } } -- cgit v1.2.3