Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qsyntaxhighlighter.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6060    Q_DECLARE_PUBLIC(QSyntaxHighlighter)
    6161public:
    62     inline QSyntaxHighlighterPrivate() : rehighlightPending(false) {}
     62    inline QSyntaxHighlighterPrivate()
     63        : rehighlightPending(false), inReformatBlocks(false)
     64    {}
    6365
    6466    QPointer<QTextDocument> doc;
    6567
    6668    void _q_reformatBlocks(int from, int charsRemoved, int charsAdded);
    67     void reformatBlock(QTextBlock block);
    68    
     69    void reformatBlocks(int from, int charsRemoved, int charsAdded);
     70    void reformatBlock(const QTextBlock &block);
     71
    6972    inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) {
    70         QObject::disconnect(doc, SIGNAL(contentsChange(int,int,int)),
    71                             q_func(), SLOT(_q_reformatBlocks(int,int,int)));
     73        inReformatBlocks = true;
    7274        cursor.beginEditBlock();
    7375        int from = cursor.position();
    7476        cursor.movePosition(operation);
    75         _q_reformatBlocks(from, 0, cursor.position() - from);
     77        reformatBlocks(from, 0, cursor.position() - from);
    7678        cursor.endEditBlock();
    77         QObject::connect(doc, SIGNAL(contentsChange(int,int,int)),
    78                          q_func(), SLOT(_q_reformatBlocks(int,int,int)));
     79        inReformatBlocks = false;
    7980    }
    8081
     
    8485        rehighlightPending = false;
    8586        q_func()->rehighlight();
    86         return;
    8787    }
    8888
     
    9191    QTextBlock currentBlock;
    9292    bool rehighlightPending;
     93
    9394};
    9495
    9596void QSyntaxHighlighterPrivate::applyFormatChanges()
    9697{
     98
     99
    97100    QTextLayout *layout = currentBlock.layout();
    98101
     
    102105    const int preeditAreaLength = layout->preeditAreaText().length();
    103106
    104     QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
    105     while (it != ranges.end()) {
    106         if (it->start >= preeditAreaStart
    107             && it->start + it->length <= preeditAreaStart + preeditAreaLength)
    108             ++it;
    109         else
    110             it = ranges.erase(it);
     107    if (preeditAreaLength != 0) {
     108        QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
     109        while (it != ranges.end()) {
     110            if (it->start >= preeditAreaStart
     111                && it->start + it->length <= preeditAreaStart + preeditAreaLength) {
     112                ++it;
     113            } else {
     114                it = ranges.erase(it);
     115                formatsChanged = true;
     116            }
     117        }
     118    } else if (!ranges.isEmpty()) {
     119        ranges.clear();
     120        formatsChanged = true;
    111121    }
    112122
     
    114124
    115125    QTextLayout::FormatRange r;
    116     r.start = r.length = -1;
     126    r.start = -1;
    117127
    118128    int i = 0;
     
    136146        r.length = i - r.start;
    137147
    138         if (r.start >= preeditAreaStart) {
    139             r.start += preeditAreaLength;
    140         } else if (r.start + r.length >= preeditAreaStart) {
    141             r.length += preeditAreaLength;
     148        if (preeditAreaLength != 0) {
     149            if (r.start >= preeditAreaStart)
     150                r.start += preeditAreaLength;
     151            else if (r.start + r.length >= preeditAreaStart)
     152                r.length += preeditAreaLength;
    142153        }
    143154
    144155        ranges << r;
    145         r.start = r.length = -1;
     156        formatsChanged = true;
     157        r.start = -1;
    146158    }
    147159
     
    149161        r.length = formatChanges.count() - r.start;
    150162
    151         if (r.start >= preeditAreaStart) {
    152             r.start += preeditAreaLength;
    153         } else if (r.start + r.length >= preeditAreaStart) {
    154             r.length += preeditAreaLength;
     163        if (preeditAreaLength != 0) {
     164            if (r.start >= preeditAreaStart)
     165                r.start += preeditAreaLength;
     166            else if (r.start + r.length >= preeditAreaStart)
     167                r.length += preeditAreaLength;
    155168        }
    156169
    157170        ranges << r;
    158     }
    159 
    160     layout->setAdditionalFormats(ranges);
     171        formatsChanged = true;
     172    }
     173
     174    if (formatsChanged) {
     175        layout->setAdditionalFormats(ranges);
     176        doc->markContentsDirty(currentBlock.position(), currentBlock.length());
     177    }
    161178}
    162179
    163180void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int charsAdded)
    164181{
    165     Q_UNUSED(charsRemoved);
     182    if (!inReformatBlocks)
     183        reformatBlocks(from, charsRemoved, charsAdded);
     184}
     185
     186void QSyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int charsAdded)
     187{
    166188    rehighlightPending = false;
    167189
     
    192214}
    193215
    194 void QSyntaxHighlighterPrivate::reformatBlock(QTextBlock block)
     216void QSyntaxHighlighterPrivate::reformatBlock(block)
    195217{
    196218    Q_Q(QSyntaxHighlighter);
     
    199221
    200222    currentBlock = block;
    201     QTextBlock previous = block.previous();
    202223
    203224    formatChanges.fill(QTextCharFormat(), block.length() - 1);
    204225    q->highlightBlock(block.text());
    205226    applyFormatChanges();
    206 
    207     doc->markContentsDirty(block.position(), block.length());
    208227
    209228    currentBlock = QTextBlock();
     
    350369        connect(d->doc, SIGNAL(contentsChange(int,int,int)),
    351370                this, SLOT(_q_reformatBlocks(int,int,int)));
     371
    352372        QTimer::singleShot(0, this, SLOT(_q_delayedRehighlight()));
    353         d->rehighlightPending = true;
    354373    }
    355374}
     
    392411{
    393412    Q_D(QSyntaxHighlighter);
    394     if (!d->doc)
     413    if (!d->doc)
    395414        return;
     415
     416
    396417
    397418    QTextCursor cursor(block);
    398419    d->rehighlight(cursor, QTextCursor::EndOfBlock);
     420
     421
     422
    399423}
    400424
     
    461485{
    462486    Q_D(QSyntaxHighlighter);
    463 
    464487    if (start < 0 || start >= d->formatChanges.count())
    465488        return;
     
    629652
    630653    Returns the current text block.
    631  */
     654*/
    632655QTextBlock QSyntaxHighlighter::currentBlock() const
    633656{
Note: See TracChangeset for help on using the changeset viewer.