Commit 6d37029b authored by mae's avatar mae
Browse files

support different selection kinds in basetexteditor.

    enum ExtraSelectionKind {
        CurrentLineSelection,
        ParenthesesMatchingSelection,
        CodeWarningsSelection,
        CodeSemanticsSelection,
        OtherSelection,
        NExtraSelectionKinds
    };
    void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
    QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;

This is mainly for the benefit of the cppmodelmanager.
parent 354fcfc8
...@@ -683,7 +683,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc) ...@@ -683,7 +683,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
sel.cursor = c; sel.cursor = c;
selections.append(sel); selections.append(sel);
} }
ed->setExtraExtraSelections(selections); ed->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection, selections);
break; break;
} }
} }
......
...@@ -2477,6 +2477,9 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e) ...@@ -2477,6 +2477,9 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e)
void BaseTextEditor::slotCursorPositionChanged() void BaseTextEditor::slotCursorPositionChanged()
{ {
QList<QTextEdit::ExtraSelection> extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear
if (d->m_parenthesesMatchingEnabled)
d->m_parenthesesMatchingTimer->start(50);
if (d->m_highlightCurrentLine) { if (d->m_highlightCurrentLine) {
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
...@@ -2487,11 +2490,7 @@ void BaseTextEditor::slotCursorPositionChanged() ...@@ -2487,11 +2490,7 @@ void BaseTextEditor::slotCursorPositionChanged()
extraSelections.append(sel); extraSelections.append(sel);
} }
if (d->m_parenthesesMatchingEnabled) setExtraSelections(CurrentLineSelection, extraSelections);
d->m_parenthesesMatchingTimer->start(50);
d->m_extraSelections = extraSelections;
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections);
} }
QTextBlock TextBlockUserData::testCollapse(const QTextBlock& block) QTextBlock TextBlockUserData::testCollapse(const QTextBlock& block)
...@@ -3133,7 +3132,7 @@ void BaseTextEditor::_q_matchParentheses() ...@@ -3133,7 +3132,7 @@ void BaseTextEditor::_q_matchParentheses()
if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch) if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch)
return; return;
QList<QTextEdit::ExtraSelection> extraSelections = d->m_extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
if (backwardMatch.hasSelection()) { if (backwardMatch.hasSelection()) {
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
...@@ -3186,8 +3185,7 @@ void BaseTextEditor::_q_matchParentheses() ...@@ -3186,8 +3185,7 @@ void BaseTextEditor::_q_matchParentheses()
} }
extraSelections.append(sel); extraSelections.append(sel);
} }
d->m_extraSelections = extraSelections; setExtraSelections(ParenthesesMatchingSelection, extraSelections);
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections);
} }
void BaseTextEditor::setActionHack(QObject *hack) void BaseTextEditor::setActionHack(QObject *hack)
...@@ -3234,15 +3232,21 @@ void BaseTextEditor::deleteLine() ...@@ -3234,15 +3232,21 @@ void BaseTextEditor::deleteLine()
cut(); cut();
} }
void BaseTextEditor::setExtraExtraSelections(const QList<QTextEdit::ExtraSelection> &selections) void BaseTextEditor::setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections)
{ {
d->m_extraExtraSelections = selections; if (selections.isEmpty() && d->m_extraSelections[kind].isEmpty())
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections); return;
d->m_extraSelections[kind] = selections;
QList<QTextEdit::ExtraSelection> all;
for (int i = 0; i < NExtraSelectionKinds; ++i)
all += d->m_extraSelections[i];
QPlainTextEdit::setExtraSelections(all);
} }
QList<QTextEdit::ExtraSelection> BaseTextEditor::extraExtraSelections() const QList<QTextEdit::ExtraSelection> BaseTextEditor::extraSelections(ExtraSelectionKind kind) const
{ {
return d->m_extraExtraSelections; return d->m_extraSelections[kind];
} }
......
...@@ -369,7 +369,6 @@ private: ...@@ -369,7 +369,6 @@ private:
Internal::BaseTextEditorPrivate *d; Internal::BaseTextEditorPrivate *d;
friend class Internal::BaseTextEditorPrivate; friend class Internal::BaseTextEditorPrivate;
public: public:
QWidget *extraArea() const; QWidget *extraArea() const;
virtual int extraAreaWidth(int *markWidthPtr = 0) const; virtual int extraAreaWidth(int *markWidthPtr = 0) const;
...@@ -385,8 +384,16 @@ public: ...@@ -385,8 +384,16 @@ public:
void ensureCursorVisible(); void ensureCursorVisible();
void setExtraExtraSelections(const QList<QTextEdit::ExtraSelection> &selections); enum ExtraSelectionKind {
QList<QTextEdit::ExtraSelection> extraExtraSelections() const; CurrentLineSelection,
ParenthesesMatchingSelection,
CodeWarningsSelection,
CodeSemanticsSelection,
OtherSelection,
NExtraSelectionKinds
};
void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
struct BlockRange { struct BlockRange {
BlockRange():first(0), last(-1){} BlockRange():first(0), last(-1){}
......
...@@ -204,8 +204,7 @@ public: ...@@ -204,8 +204,7 @@ public:
QObject *m_actionHack; QObject *m_actionHack;
QList<QTextEdit::ExtraSelection> m_extraSelections; QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditor::NExtraSelectionKinds];
QList<QTextEdit::ExtraSelection> m_extraExtraSelections;
// block selection mode // block selection mode
bool m_inBlockSelectionMode; bool m_inBlockSelectionMode;
......
...@@ -225,24 +225,13 @@ void VCSBaseEditor::mouseMoveEvent(QMouseEvent *e) ...@@ -225,24 +225,13 @@ void VCSBaseEditor::mouseMoveEvent(QMouseEvent *e)
sel.format.setFontUnderline(true); sel.format.setFontUnderline(true);
change = changeUnderCursor(cursor); change = changeUnderCursor(cursor);
sel.format.setProperty(QTextFormat::UserProperty, change); sel.format.setProperty(QTextFormat::UserProperty, change);
bool found = false; setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>() << sel);
foreach (QTextEdit::ExtraSelection es, extraSelections()) {
if (es.format.stringProperty(QTextFormat::UserProperty) == sel.format.stringProperty(QTextFormat::UserProperty)) {
found = true;
break;
}
}
if (!found) {
setExtraSelections(QList<QTextEdit::ExtraSelection>() << sel);
viewport()->setCursor(Qt::PointingHandCursor); viewport()->setCursor(Qt::PointingHandCursor);
} }
} else { } else {
if (!extraSelections().isEmpty()) { setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>());
setExtraSelections(QList<QTextEdit::ExtraSelection>());
viewport()->setCursor(Qt::IBeamCursor); viewport()->setCursor(Qt::IBeamCursor);
} }
}
}
TextEditor::BaseTextEditor::mouseMoveEvent(e); TextEditor::BaseTextEditor::mouseMoveEvent(e);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment