From 321dbba50fc4b9cb24765eaf68e1451fce553898 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Wed, 23 Sep 2009 12:50:02 +0200
Subject: [PATCH] Fixed artefact of animated parentheses when the text is
 modified.

Bug-number: QTCREATOR-154
---
 src/plugins/texteditor/basetexteditor.cpp | 18 +++++++++++++-----
 src/plugins/texteditor/basetexteditor.h   | 12 +++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index fb34d45174c..b5e47fa6be3 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -589,6 +589,9 @@ Core::IFile *BaseTextEditor::file()
 
 void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded)
 {
+    if (d->m_animator)
+        d->m_animator->finish();
+
     d->m_contentsChanged = true;
 
     // Keep the line numbers and the block information for the text marks updated
@@ -2689,7 +2692,8 @@ void BaseTextEditor::slotCursorPositionChanged()
 
     if (d->m_parenthesesMatchingEnabled) {
         // Delay update when no matching is displayed yet, to avoid flicker
-        if (extraSelections(ParenthesesMatchingSelection).isEmpty()) {
+        if (extraSelections(ParenthesesMatchingSelection).isEmpty()
+            && d->m_animator == 0) {
             d->m_parenthesesMatchingTimer->start(50);
         } else {
              // use 0-timer, not direct call, to give the syntax highlighter a chance
@@ -3747,11 +3751,13 @@ void BaseTextEditor::setFindScope(const QTextCursor &scope)
     }
 }
 
-void BaseTextEditor::_q_animateUpdate(int position, QRectF rect)
+void BaseTextEditor::_q_animateUpdate(int position, QPointF lastPos, QRectF rect)
 {
     QTextCursor cursor(textCursor());
     cursor.setPosition(position);
     viewport()->update(QRectF(cursorRect(cursor).topLeft() + rect.topLeft(), rect.size()).toAlignedRect());
+    if (!lastPos.isNull())
+        viewport()->update(QRectF(lastPos + rect.topLeft(), rect.size()).toAlignedRect());
 }
 
 
@@ -3778,6 +3784,7 @@ void BaseTextEditorAnimator::setData(QFont f, QPalette pal, const QString &text)
 
 void BaseTextEditorAnimator::draw(QPainter *p, const QPointF &pos)
 {
+    m_lastDrawPos = pos;
     p->setPen(m_palette.text().color());
     QFont f = m_font;
     f.setPointSizeF(f.pointSizeF() * (1.0 + m_value/2));
@@ -3809,11 +3816,12 @@ void BaseTextEditorAnimator::step(qreal v)
     QRectF before = rect();
     m_value = v;
     QRectF after = rect();
-    emit updateRequest(m_position, before.united(after));
+    emit updateRequest(m_position, m_lastDrawPos, before.united(after));
 }
 
 void BaseTextEditorAnimator::finish()
 {
+    m_timeline->stop();
     step(0);
     deleteLater();
 }
@@ -3912,8 +3920,8 @@ void BaseTextEditor::_q_matchParentheses()
         pal.setBrush(QPalette::Text, d->m_matchFormat.foreground());
         pal.setBrush(QPalette::Base, d->m_rangeFormat.background());
         d->m_animator->setData(font(), pal, characterAt(d->m_animator->position()));
-        connect(d->m_animator, SIGNAL(updateRequest(int,QRectF)),
-                this, SLOT(_q_animateUpdate(int,QRectF)));
+        connect(d->m_animator, SIGNAL(updateRequest(int,QPointF,QRectF)),
+                this, SLOT(_q_animateUpdate(int,QPointF,QRectF)));
     }
 
     setExtraSelections(ParenthesesMatchingSelection, extraSelections);
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 2015a10fcb5..ad2b022b0a3 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -242,22 +242,23 @@ class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
 public:
     BaseTextEditorAnimator(QObject *parent);
 
-    void setPosition(int position) { m_position = position; }
-    int position() const { return m_position; }
+    inline void setPosition(int position) { m_position = position; }
+    inline int position() const { return m_position; }
 
     void setData(QFont f, QPalette pal, const QString &text);
 
     void draw(QPainter *p, const QPointF &pos);
     QRectF rect() const;
 
-    qreal value() const { return m_value; }
+    inline qreal value() const { return m_value; }
+    inline QPointF lastDrawPos() const { return m_lastDrawPos; }
 
     void finish();
 
     bool isRunning() const;
 
 signals:
-    void updateRequest(int position, QRectF rect);
+    void updateRequest(int position, QPointF lastPos, QRectF rect);
 
 
 private slots:
@@ -267,6 +268,7 @@ private:
     QTimeLine *m_timeline;
     qreal m_value;
     int m_position;
+    QPointF m_lastDrawPos;
     QFont m_font;
     QPalette m_palette;
     QString m_text;
@@ -599,7 +601,7 @@ private slots:
     void _q_matchParentheses();
     void _q_highlightBlocks();
     void slotSelectionChanged();
-    void _q_animateUpdate(int position, QRectF rect);
+    void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
 };
 
 
-- 
GitLab