forked from qt-creator/qt-creator
TextEditor: Add mixins for font settings
You can only set one text style but in many cases like Function and Declaration it would be nice if they could be merged. Change-Id: Icda892057b79eef1bea2fa8b2c5f0f7cbc5f518a Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -139,8 +139,9 @@ bool FontSettings::equals(const FontSettings &f) const
|
||||
*/
|
||||
QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
|
||||
{
|
||||
if (m_formatCache.contains(category))
|
||||
return m_formatCache.value(category);
|
||||
auto textCharFormatIterator = m_formatCache.find(category);
|
||||
if (textCharFormatIterator != m_formatCache.end())
|
||||
return *textCharFormatIterator;
|
||||
|
||||
const Format &f = m_scheme.formatFor(category);
|
||||
QTextCharFormat tf;
|
||||
@@ -174,6 +175,60 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
|
||||
return tf;
|
||||
}
|
||||
|
||||
uint qHash(const TextStyles &textStyles)
|
||||
{
|
||||
uint hash = ::qHash(quint8(textStyles.mainStyle));
|
||||
|
||||
hash ^= ::qHashRange(textStyles.mixinStyles.cbegin(), textStyles.mixinStyles.cend());
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool operator==(const TextStyles &first, const TextStyles &second)
|
||||
{
|
||||
return first.mainStyle == second.mainStyle
|
||||
&& first.mixinStyles == second.mixinStyles;
|
||||
}
|
||||
|
||||
void FontSettings::addMixinStyle(QTextCharFormat &textCharFormat,
|
||||
const MixinTextStyles &mixinStyles) const
|
||||
{
|
||||
for (TextStyle mixinStyle : mixinStyles) {
|
||||
const QTextCharFormat mixinTextCharFormat = toTextCharFormat(mixinStyle);
|
||||
if (!textCharFormat.hasProperty(QTextFormat::ForegroundBrush))
|
||||
textCharFormat.setForeground(mixinTextCharFormat.foreground());
|
||||
|
||||
if (!textCharFormat.hasProperty(QTextFormat::BackgroundBrush))
|
||||
textCharFormat.setBackground(mixinTextCharFormat.background());
|
||||
|
||||
if (!textCharFormat.fontItalic())
|
||||
textCharFormat.setFontItalic(mixinTextCharFormat.fontItalic());
|
||||
|
||||
if (textCharFormat.fontWeight() == QFont::Normal)
|
||||
textCharFormat.setFontWeight(mixinTextCharFormat.fontWeight());
|
||||
|
||||
if (textCharFormat.underlineStyle() == QTextCharFormat::NoUnderline) {
|
||||
textCharFormat.setUnderlineStyle(mixinTextCharFormat.underlineStyle());
|
||||
textCharFormat.setUnderlineColor(mixinTextCharFormat.underlineColor());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
QTextCharFormat FontSettings::toTextCharFormat(const TextStyles textStyles) const
|
||||
{
|
||||
auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
|
||||
if (textCharFormatIterator != m_textCharFormatCache.end())
|
||||
return *textCharFormatIterator;
|
||||
|
||||
QTextCharFormat textCharFormat = toTextCharFormat(textStyles.mainStyle);
|
||||
|
||||
addMixinStyle(textCharFormat, textStyles.mixinStyles);
|
||||
|
||||
m_textCharFormatCache.insert(textStyles, textCharFormat);
|
||||
|
||||
return textCharFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of QTextCharFormats that corresponds to the list of
|
||||
* requested format categories.
|
||||
|
||||
Reference in New Issue
Block a user