Editor: Make parenthese mismatch color configurable.

Task-number: QTCREATORBUG-14357
Change-Id: I92a0d50fb8f3448195f3d38f7544a31eb695733b
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
David Schulz
2015-04-28 11:04:07 +02:00
parent ef56bc6be0
commit f34b32abd5
10 changed files with 17 additions and 6 deletions

View File

@@ -26,6 +26,7 @@
<style name="Occurrences.Rename" foreground="#ffaaaa" background="#553636"/> <style name="Occurrences.Rename" foreground="#ffaaaa" background="#553636"/>
<style name="Operator" foreground="#aaaaaa"/> <style name="Operator" foreground="#aaaaaa"/>
<style name="Parentheses" foreground="#ff5555" background="#333333"/> <style name="Parentheses" foreground="#ff5555" background="#333333"/>
<style name="ParenthesesMismatch" background="#800080"/>
<style name="Preprocessor" foreground="#5555ff"/> <style name="Preprocessor" foreground="#5555ff"/>
<style name="SearchResult" background="#555500"/> <style name="SearchResult" background="#555500"/>
<style name="SearchScope" background="#222200"/> <style name="SearchScope" background="#222200"/>

View File

@@ -24,6 +24,7 @@
<style name="Number" foreground="#3f3f3f"/> <style name="Number" foreground="#3f3f3f"/>
<style name="Operator"/> <style name="Operator"/>
<style name="Parentheses" background="#e3e3e3" bold="true"/> <style name="Parentheses" background="#e3e3e3" bold="true"/>
<style name="ParenthesesMismatch" background="#808080"/>
<style name="Preprocessor" foreground="#5b5b5b" bold="true"/> <style name="Preprocessor" foreground="#5b5b5b" bold="true"/>
<style name="RemovedLine" foreground="#a0a0a4"/> <style name="RemovedLine" foreground="#a0a0a4"/>
<style name="Static" italic="true"/> <style name="Static" italic="true"/>

View File

@@ -32,6 +32,7 @@
<style name="Occurrences.Unused" foreground="#808000"/> <style name="Occurrences.Unused" foreground="#808000"/>
<style name="Operator" foreground="#cfbfad"/> <style name="Operator" foreground="#cfbfad"/>
<style name="Parentheses" foreground="#ffff00" background="#4e4e8f"/> <style name="Parentheses" foreground="#ffff00" background="#4e4e8f"/>
<style name="ParenthesesMismatch" background="#404040"/>
<style name="Preprocessor" foreground="#409090"/> <style name="Preprocessor" foreground="#409090"/>
<style name="RemovedLine" foreground="#ff0000"/> <style name="RemovedLine" foreground="#ff0000"/>
<style name="SearchResult" foreground="#000000" background="#ffef0b"/> <style name="SearchResult" foreground="#000000" background="#ffef0b"/>

View File

@@ -16,6 +16,7 @@
<style name="Number" foreground="#0000ff"/> <style name="Number" foreground="#0000ff"/>
<style name="Operator" foreground="#000000"/> <style name="Operator" foreground="#000000"/>
<style name="Parentheses" foreground="#ff0000" background="#c3e1ff"/> <style name="Parentheses" foreground="#ff0000" background="#c3e1ff"/>
<style name="ParenthesesMismatch" background="#ff00ff"/>
<style name="Preprocessor" foreground="#000080" bold="true"/> <style name="Preprocessor" foreground="#000080" bold="true"/>
<style name="RemovedLine" foreground="#ff0000"/> <style name="RemovedLine" foreground="#ff0000"/>
<style name="String" foreground="#008000" bold="true"/> <style name="String" foreground="#008000" bold="true"/>

View File

@@ -179,7 +179,8 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
&& category != C_OCCURRENCES && category != C_OCCURRENCES
&& category != C_OCCURRENCES_RENAME && category != C_OCCURRENCES_RENAME
&& category != C_OCCURRENCES_UNUSED && category != C_OCCURRENCES_UNUSED
&& category != C_SEARCH_RESULT) && category != C_SEARCH_RESULT
&& category != C_PARENTHESES_MISMATCH)
tf.setForeground(f.foreground()); tf.setForeground(f.foreground());
if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background())) if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background()))
tf.setBackground(f.background()); tf.setBackground(f.background());

View File

@@ -271,6 +271,8 @@ QColor FormatDescription::background() const
return QColor(0xffef0b); return QColor(0xffef0b);
} else if (m_id == C_PARENTHESES) { } else if (m_id == C_PARENTHESES) {
return QColor(0xb4, 0xee, 0xb4); return QColor(0xb4, 0xee, 0xb4);
} else if (m_id == C_PARENTHESES_MISMATCH) {
return QColor(Qt::magenta);
} else if (m_id == C_CURRENT_LINE || m_id == C_SEARCH_SCOPE) { } else if (m_id == C_CURRENT_LINE || m_id == C_SEARCH_SCOPE) {
const QPalette palette = QApplication::palette(); const QPalette palette = QApplication::palette();
const QColor &fg = palette.color(QPalette::Highlight); const QColor &fg = palette.color(QPalette::Highlight);

View File

@@ -341,7 +341,6 @@ public:
// parentheses matcher // parentheses matcher
bool m_formatRange; bool m_formatRange;
QTextCharFormat m_mismatchFormat;
QTimer m_parenthesesMatchingTimer; QTimer m_parenthesesMatchingTimer;
// end parentheses matcher // end parentheses matcher
@@ -660,8 +659,6 @@ void TextEditorWidgetPrivate::ctor(const QSharedPointer<TextDocument> &doc)
// parentheses matcher // parentheses matcher
m_formatRange = true; m_formatRange = true;
m_mismatchFormat.setBackground(q->palette().color(QPalette::Base).value() < 128
? Qt::darkMagenta : Qt::magenta);
m_parenthesesMatchingTimer.setSingleShot(true); m_parenthesesMatchingTimer.setSingleShot(true);
QObject::connect(&m_parenthesesMatchingTimer, &QTimer::timeout, QObject::connect(&m_parenthesesMatchingTimer, &QTimer::timeout,
this, &TextEditorWidgetPrivate::_q_matchParentheses); this, &TextEditorWidgetPrivate::_q_matchParentheses);
@@ -5605,12 +5602,14 @@ void TextEditorWidgetPrivate::_q_matchParentheses()
const QTextCharFormat &matchFormat const QTextCharFormat &matchFormat
= q->textDocument()->fontSettings().toTextCharFormat(C_PARENTHESES); = q->textDocument()->fontSettings().toTextCharFormat(C_PARENTHESES);
const QTextCharFormat &mismatchFormat
= q->textDocument()->fontSettings().toTextCharFormat(C_PARENTHESES_MISMATCH);
int animatePosition = -1; int animatePosition = -1;
if (backwardMatch.hasSelection()) { if (backwardMatch.hasSelection()) {
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
if (backwardMatchType == TextBlockUserData::Mismatch) { if (backwardMatchType == TextBlockUserData::Mismatch) {
sel.cursor = backwardMatch; sel.cursor = backwardMatch;
sel.format = m_mismatchFormat; sel.format = mismatchFormat;
extraSelections.append(sel); extraSelections.append(sel);
} else { } else {
@@ -5634,7 +5633,7 @@ void TextEditorWidgetPrivate::_q_matchParentheses()
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
if (forwardMatchType == TextBlockUserData::Mismatch) { if (forwardMatchType == TextBlockUserData::Mismatch) {
sel.cursor = forwardMatch; sel.cursor = forwardMatch;
sel.format = m_mismatchFormat; sel.format = mismatchFormat;
extraSelections.append(sel); extraSelections.append(sel);
} else { } else {

View File

@@ -46,6 +46,7 @@ const char *nameForStyle(TextStyle style)
case C_SEARCH_RESULT: return "SearchResult"; case C_SEARCH_RESULT: return "SearchResult";
case C_SEARCH_SCOPE: return "SearchScope"; case C_SEARCH_SCOPE: return "SearchScope";
case C_PARENTHESES: return "Parentheses"; case C_PARENTHESES: return "Parentheses";
case C_PARENTHESES_MISMATCH:return "ParenthesesMismatch";
case C_CURRENT_LINE: return "CurrentLine"; case C_CURRENT_LINE: return "CurrentLine";
case C_CURRENT_LINE_NUMBER: return "CurrentLineNumber"; case C_CURRENT_LINE_NUMBER: return "CurrentLineNumber";
case C_OCCURRENCES: return "Occurrences"; case C_OCCURRENCES: return "Occurrences";

View File

@@ -45,6 +45,7 @@ enum TextStyle {
C_SEARCH_RESULT, C_SEARCH_RESULT,
C_SEARCH_SCOPE, C_SEARCH_SCOPE,
C_PARENTHESES, C_PARENTHESES,
C_PARENTHESES_MISMATCH,
C_CURRENT_LINE, C_CURRENT_LINE,
C_CURRENT_LINE_NUMBER, C_CURRENT_LINE_NUMBER,
C_OCCURRENCES, C_OCCURRENCES,

View File

@@ -117,6 +117,9 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
formatDescr.append(FormatDescription(C_PARENTHESES, tr("Parentheses"), formatDescr.append(FormatDescription(C_PARENTHESES, tr("Parentheses"),
tr("Displayed when matching parentheses, square brackets " tr("Displayed when matching parentheses, square brackets "
"or curly brackets are found."))); "or curly brackets are found.")));
formatDescr.append(FormatDescription(C_PARENTHESES_MISMATCH, tr("Mismatched Parentheses"),
tr("Displayed when mismatched parentheses, "
"square brackets, or curly brackets are found.")));
formatDescr.append(FormatDescription(C_CURRENT_LINE, tr("Current Line"), formatDescr.append(FormatDescription(C_CURRENT_LINE, tr("Current Line"),
tr("Line where the cursor is placed in."))); tr("Line where the cursor is placed in.")));