summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextformat.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2014-01-17 17:38:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-31 00:24:48 +0100
commitf26928cccf7e0fd9f06236476f2a6b52151e5dca (patch)
tree9464f786b5c27d1b5669e0c09eb87414f9529d64 /src/gui/text/qtextformat.cpp
parentf6723cf0d479823a34e874bc4cc9ff43e040793a (diff)
Allow QTextCharFormat::setFont() to skip unresolved font props
This makes the font merging possible and solves an issue with the default font properties inheritance when used in conjunction with QTextFormatCollection. Change-Id: If8b543c011122dde9f086f5d696df3b042f7b90c Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/text/qtextformat.cpp')
-rw-r--r--src/gui/text/qtextformat.cpp103
1 files changed, 80 insertions, 23 deletions
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 641a2ceb8a..d2b91c1f9f 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -1879,36 +1879,93 @@ QStringList QTextCharFormat::anchorNames() const
*/
/*!
+ \enum QTextCharFormat::FontPropertiesInheritanceBehavior
+ \since 5.3
+
+ This enum specifies how the setFont() function should behave with
+ respect to unset font properties.
+
+ \value FontPropertiesSpecifiedOnly If a property is not explicitly set, do not
+ change the text format's property value.
+ \value FontPropertiesAll If a property is not explicitly set, override the
+ text format's property with a default value.
+
+ \sa setFont()
+*/
+
+/*!
+ \overload
+
Sets the text format's \a font.
+
+ \sa font()
*/
void QTextCharFormat::setFont(const QFont &font)
{
- setFontFamily(font.family());
+ setFont(font, FontPropertiesAll);
+}
- const qreal pointSize = font.pointSizeF();
- if (pointSize > 0) {
- setFontPointSize(pointSize);
- } else {
- const int pixelSize = font.pixelSize();
- if (pixelSize > 0)
- setProperty(QTextFormat::FontPixelSize, pixelSize);
+/*!
+ \since 5.3
+
+ Sets the text format's \a font.
+
+ If \a behavior is QTextCharFormat::FontPropertiesAll, the font property that
+ has not been explicitly set is treated like as it were set with default value;
+ If \a behavior is QTextCharFormat::FontPropertiesAll, the font property that
+ has not been explicitly set is ignored and the respective property value
+ remains unchanged.
+
+ \sa font()
+*/
+void QTextCharFormat::setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior)
+{
+ const uint mask = behavior == FontPropertiesAll ? uint(QFont::AllPropertiesResolved)
+ : font.resolve();
+
+ if (mask & QFont::FamilyResolved)
+ setFontFamily(font.family());
+ if (mask & QFont::SizeResolved) {
+ const qreal pointSize = font.pointSizeF();
+ if (pointSize > 0) {
+ setFontPointSize(pointSize);
+ } else {
+ const int pixelSize = font.pixelSize();
+ if (pixelSize > 0)
+ setProperty(QTextFormat::FontPixelSize, pixelSize);
+ }
}
- setFontWeight(font.weight());
- setFontItalic(font.italic());
- setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
- setFontOverline(font.overline());
- setFontStrikeOut(font.strikeOut());
- setFontFixedPitch(font.fixedPitch());
- setFontCapitalization(font.capitalization());
- setFontWordSpacing(font.wordSpacing());
- setFontLetterSpacingType(font.letterSpacingType());
- setFontLetterSpacing(font.letterSpacing());
- setFontStretch(font.stretch());
- setFontStyleHint(font.styleHint());
- setFontStyleStrategy(font.styleStrategy());
- setFontHintingPreference(font.hintingPreference());
- setFontKerning(font.kerning());
+ if (mask & QFont::WeightResolved)
+ setFontWeight(font.weight());
+ if (mask & QFont::StyleResolved)
+ setFontItalic(font.style() != QFont::StyleNormal);
+ if (mask & QFont::UnderlineResolved)
+ setUnderlineStyle(font.underline() ? SingleUnderline : NoUnderline);
+ if (mask & QFont::OverlineResolved)
+ setFontOverline(font.overline());
+ if (mask & QFont::StrikeOutResolved)
+ setFontStrikeOut(font.strikeOut());
+ if (mask & QFont::FixedPitchResolved)
+ setFontFixedPitch(font.fixedPitch());
+ if (mask & QFont::CapitalizationResolved)
+ setFontCapitalization(font.capitalization());
+ if (mask & QFont::LetterSpacingResolved)
+ setFontWordSpacing(font.wordSpacing());
+ if (mask & QFont::LetterSpacingResolved) {
+ setFontLetterSpacingType(font.letterSpacingType());
+ setFontLetterSpacing(font.letterSpacing());
+ }
+ if (mask & QFont::StretchResolved)
+ setFontStretch(font.stretch());
+ if (mask & QFont::StyleHintResolved)
+ setFontStyleHint(font.styleHint());
+ if (mask & QFont::StyleStrategyResolved)
+ setFontStyleStrategy(font.styleStrategy());
+ if (mask & QFont::HintingPreferenceResolved)
+ setFontHintingPreference(font.hintingPreference());
+ if (mask & QFont::KerningResolved)
+ setFontKerning(font.kerning());
}
/*!