TextEdit: Add underline support to text settings

Underlines colors was hard coded to the foreground color of some settings.
With this patch you can set the underline color and the underline style
to your taste.

Change-Id: Ibc64c2d2c89bf1827a2cadaf6aee9d50d08cd1ee
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-09-10 14:18:37 +02:00
committed by David Schulz
parent 0d20d56183
commit 331e9d8878
11 changed files with 318 additions and 72 deletions

View File

@@ -130,6 +130,8 @@ bool FontSettings::fromSettings(const QString &category,
format.setBackground(desc.background());
format.setBold(desc.format().bold());
format.setItalic(desc.format().italic());
format.setUnderlineColor(desc.format().underlineColor());
format.setUnderlineStyle(desc.format().underlineStyle());
} else {
format.fromString(fmt);
}
@@ -152,19 +154,6 @@ bool FontSettings::equals(const FontSettings &f) const
&& m_scheme == f.m_scheme;
}
static bool isDiagnostic(TextStyle textStyle)
{
switch (textStyle) {
case C_ERROR:
case C_ERROR_CONTEXT:
case C_WARNING:
case C_WARNING_CONTEXT: return true;
default: return false;
}
Q_UNREACHABLE();
}
/**
* Returns the QTextCharFormat of the given format category.
*/
@@ -183,34 +172,24 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
}
if (category == C_OCCURRENCES_UNUSED) {
tf.setUnderlineStyle(QTextCharFormat::SingleUnderline);
tf.setUnderlineColor(f.foreground());
tf.setToolTip(QCoreApplication::translate("FontSettings_C_OCCURRENCES_UNUSED",
"Unused variable"));
}
if (isDiagnostic(category)) {
if (category == C_ERROR || category == C_WARNING)
tf.setUnderlineStyle(QTextCharFormat::SingleUnderline);
else
tf.setUnderlineStyle(QTextCharFormat::DotLine);
tf.setUnderlineColor(f.foreground());
}
if (f.foreground().isValid()
&& category != C_OCCURRENCES
&& category != C_OCCURRENCES_RENAME
&& category != C_OCCURRENCES_UNUSED
&& category != C_SEARCH_RESULT
&& category != C_PARENTHESES_MISMATCH
&& !isDiagnostic(category))
&& category != C_PARENTHESES_MISMATCH)
tf.setForeground(f.foreground());
if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background()))
tf.setBackground(f.background());
tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal);
tf.setFontItalic(f.italic());
tf.setUnderlineColor(f.underlineColor());
tf.setUnderlineStyle(f.underlineStyle());
m_formatCache.insert(category, tf);
return tf;
}
@@ -345,6 +324,8 @@ bool FontSettings::loadColorScheme(const QString &fileName,
format.setBackground(desc.background());
format.setBold(desc.format().bold());
format.setItalic(desc.format().italic());
format.setUnderlineColor(desc.format().underlineColor());
format.setUnderlineStyle(desc.format().underlineStyle());
m_scheme.setFormatFor(id, format);
}
}