forked from qt-creator/qt-creator
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.
This commit is contained in:
@@ -683,7 +683,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
||||
sel.cursor = c;
|
||||
selections.append(sel);
|
||||
}
|
||||
ed->setExtraExtraSelections(selections);
|
||||
ed->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection, selections);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2477,6 +2477,9 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e)
|
||||
void BaseTextEditor::slotCursorPositionChanged()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
setExtraSelections(ParenthesesMatchingSelection, extraSelections); // clear
|
||||
if (d->m_parenthesesMatchingEnabled)
|
||||
d->m_parenthesesMatchingTimer->start(50);
|
||||
|
||||
if (d->m_highlightCurrentLine) {
|
||||
QTextEdit::ExtraSelection sel;
|
||||
@@ -2487,11 +2490,7 @@ void BaseTextEditor::slotCursorPositionChanged()
|
||||
extraSelections.append(sel);
|
||||
}
|
||||
|
||||
if (d->m_parenthesesMatchingEnabled)
|
||||
d->m_parenthesesMatchingTimer->start(50);
|
||||
|
||||
d->m_extraSelections = extraSelections;
|
||||
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections);
|
||||
setExtraSelections(CurrentLineSelection, extraSelections);
|
||||
}
|
||||
|
||||
QTextBlock TextBlockUserData::testCollapse(const QTextBlock& block)
|
||||
@@ -3133,7 +3132,7 @@ void BaseTextEditor::_q_matchParentheses()
|
||||
if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch)
|
||||
return;
|
||||
|
||||
QList<QTextEdit::ExtraSelection> extraSelections = d->m_extraSelections;
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
if (backwardMatch.hasSelection()) {
|
||||
QTextEdit::ExtraSelection sel;
|
||||
@@ -3186,8 +3185,7 @@ void BaseTextEditor::_q_matchParentheses()
|
||||
}
|
||||
extraSelections.append(sel);
|
||||
}
|
||||
d->m_extraSelections = extraSelections;
|
||||
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections);
|
||||
setExtraSelections(ParenthesesMatchingSelection, extraSelections);
|
||||
}
|
||||
|
||||
void BaseTextEditor::setActionHack(QObject *hack)
|
||||
@@ -3234,15 +3232,21 @@ void BaseTextEditor::deleteLine()
|
||||
cut();
|
||||
}
|
||||
|
||||
void BaseTextEditor::setExtraExtraSelections(const QList<QTextEdit::ExtraSelection> &selections)
|
||||
void BaseTextEditor::setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections)
|
||||
{
|
||||
d->m_extraExtraSelections = selections;
|
||||
setExtraSelections(d->m_extraSelections + d->m_extraExtraSelections);
|
||||
if (selections.isEmpty() && d->m_extraSelections[kind].isEmpty())
|
||||
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:
|
||||
Internal::BaseTextEditorPrivate *d;
|
||||
friend class Internal::BaseTextEditorPrivate;
|
||||
|
||||
|
||||
public:
|
||||
QWidget *extraArea() const;
|
||||
virtual int extraAreaWidth(int *markWidthPtr = 0) const;
|
||||
@@ -385,8 +384,16 @@ public:
|
||||
|
||||
void ensureCursorVisible();
|
||||
|
||||
void setExtraExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
|
||||
QList<QTextEdit::ExtraSelection> extraExtraSelections() const;
|
||||
enum ExtraSelectionKind {
|
||||
CurrentLineSelection,
|
||||
ParenthesesMatchingSelection,
|
||||
CodeWarningsSelection,
|
||||
CodeSemanticsSelection,
|
||||
OtherSelection,
|
||||
NExtraSelectionKinds
|
||||
};
|
||||
void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
|
||||
QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
|
||||
|
||||
struct BlockRange {
|
||||
BlockRange():first(0), last(-1){}
|
||||
|
||||
@@ -204,8 +204,7 @@ public:
|
||||
|
||||
QObject *m_actionHack;
|
||||
|
||||
QList<QTextEdit::ExtraSelection> m_extraSelections;
|
||||
QList<QTextEdit::ExtraSelection> m_extraExtraSelections;
|
||||
QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditor::NExtraSelectionKinds];
|
||||
|
||||
// block selection mode
|
||||
bool m_inBlockSelectionMode;
|
||||
|
||||
@@ -225,23 +225,12 @@ void VCSBaseEditor::mouseMoveEvent(QMouseEvent *e)
|
||||
sel.format.setFontUnderline(true);
|
||||
change = changeUnderCursor(cursor);
|
||||
sel.format.setProperty(QTextFormat::UserProperty, change);
|
||||
bool found = false;
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
if (!extraSelections().isEmpty()) {
|
||||
setExtraSelections(QList<QTextEdit::ExtraSelection>());
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
}
|
||||
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>() << sel);
|
||||
viewport()->setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
} else {
|
||||
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>());
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
}
|
||||
TextEditor::BaseTextEditor::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user