Fixed artefact of animated parentheses when the text is modified.

Bug-number: QTCREATOR-154
This commit is contained in:
mae
2009-09-23 12:50:02 +02:00
parent 76d1de0b87
commit 321dbba50f
2 changed files with 20 additions and 10 deletions

View File

@@ -589,6 +589,9 @@ Core::IFile *BaseTextEditor::file()
void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded) void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded)
{ {
if (d->m_animator)
d->m_animator->finish();
d->m_contentsChanged = true; d->m_contentsChanged = true;
// Keep the line numbers and the block information for the text marks updated // Keep the line numbers and the block information for the text marks updated
@@ -2689,7 +2692,8 @@ void BaseTextEditor::slotCursorPositionChanged()
if (d->m_parenthesesMatchingEnabled) { if (d->m_parenthesesMatchingEnabled) {
// Delay update when no matching is displayed yet, to avoid flicker // 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); d->m_parenthesesMatchingTimer->start(50);
} else { } else {
// use 0-timer, not direct call, to give the syntax highlighter a chance // 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()); QTextCursor cursor(textCursor());
cursor.setPosition(position); cursor.setPosition(position);
viewport()->update(QRectF(cursorRect(cursor).topLeft() + rect.topLeft(), rect.size()).toAlignedRect()); 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) void BaseTextEditorAnimator::draw(QPainter *p, const QPointF &pos)
{ {
m_lastDrawPos = pos;
p->setPen(m_palette.text().color()); p->setPen(m_palette.text().color());
QFont f = m_font; QFont f = m_font;
f.setPointSizeF(f.pointSizeF() * (1.0 + m_value/2)); f.setPointSizeF(f.pointSizeF() * (1.0 + m_value/2));
@@ -3809,11 +3816,12 @@ void BaseTextEditorAnimator::step(qreal v)
QRectF before = rect(); QRectF before = rect();
m_value = v; m_value = v;
QRectF after = rect(); QRectF after = rect();
emit updateRequest(m_position, before.united(after)); emit updateRequest(m_position, m_lastDrawPos, before.united(after));
} }
void BaseTextEditorAnimator::finish() void BaseTextEditorAnimator::finish()
{ {
m_timeline->stop();
step(0); step(0);
deleteLater(); deleteLater();
} }
@@ -3912,8 +3920,8 @@ void BaseTextEditor::_q_matchParentheses()
pal.setBrush(QPalette::Text, d->m_matchFormat.foreground()); pal.setBrush(QPalette::Text, d->m_matchFormat.foreground());
pal.setBrush(QPalette::Base, d->m_rangeFormat.background()); pal.setBrush(QPalette::Base, d->m_rangeFormat.background());
d->m_animator->setData(font(), pal, characterAt(d->m_animator->position())); d->m_animator->setData(font(), pal, characterAt(d->m_animator->position()));
connect(d->m_animator, SIGNAL(updateRequest(int,QRectF)), connect(d->m_animator, SIGNAL(updateRequest(int,QPointF,QRectF)),
this, SLOT(_q_animateUpdate(int,QRectF))); this, SLOT(_q_animateUpdate(int,QPointF,QRectF)));
} }
setExtraSelections(ParenthesesMatchingSelection, extraSelections); setExtraSelections(ParenthesesMatchingSelection, extraSelections);

View File

@@ -242,22 +242,23 @@ class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
public: public:
BaseTextEditorAnimator(QObject *parent); BaseTextEditorAnimator(QObject *parent);
void setPosition(int position) { m_position = position; } inline void setPosition(int position) { m_position = position; }
int position() const { return m_position; } inline int position() const { return m_position; }
void setData(QFont f, QPalette pal, const QString &text); void setData(QFont f, QPalette pal, const QString &text);
void draw(QPainter *p, const QPointF &pos); void draw(QPainter *p, const QPointF &pos);
QRectF rect() const; 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(); void finish();
bool isRunning() const; bool isRunning() const;
signals: signals:
void updateRequest(int position, QRectF rect); void updateRequest(int position, QPointF lastPos, QRectF rect);
private slots: private slots:
@@ -267,6 +268,7 @@ private:
QTimeLine *m_timeline; QTimeLine *m_timeline;
qreal m_value; qreal m_value;
int m_position; int m_position;
QPointF m_lastDrawPos;
QFont m_font; QFont m_font;
QPalette m_palette; QPalette m_palette;
QString m_text; QString m_text;
@@ -599,7 +601,7 @@ private slots:
void _q_matchParentheses(); void _q_matchParentheses();
void _q_highlightBlocks(); void _q_highlightBlocks();
void slotSelectionChanged(); void slotSelectionChanged();
void _q_animateUpdate(int position, QRectF rect); void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
}; };