From 3b7e13510b355333c4215d04a731240201401a9d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 9 May 2017 22:49:01 +0200 Subject: Cleanup and unify font handling First of all, move the remaining user requested fonts to ExtraData. This was done for QQuickControl, but not for the controls that do not inherit QQuickControl: QQuickLabel, QQuickTextField & QQuickTextArea. The ExtraData starts really paying off later when introducing palettes that propagate similarly to fonts. Furthermore, give a more explicit name ('font' vs. 'requestedFont') for the user requested fonts. This lets us use 'font' (instead of just 'f') as an argument name in those various font-helper methods in the private classes. Furthermore, sync QQuickLabel|TextField|TextArea's font handling with QQuickControl. It would be best to share the code somehow, but it's quite tricky due to different base classes, font members ('resolvedFont' vs. 'sourceFont'), and notifier signals. Change-Id: I50cc1af160bb033ae604b4239e438c083d83f15d Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktextarea.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/quicktemplates2/qquicktextarea.cpp') diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 21d74dd8..3359f6cb 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -189,18 +189,31 @@ void QQuickTextAreaPrivate::resolveFont() inheritFont(QQuickControlPrivate::parentFont(q)); } -void QQuickTextAreaPrivate::inheritFont(const QFont &f) +void QQuickTextAreaPrivate::inheritFont(const QFont &font) { - Q_Q(QQuickTextArea); - QFont parentFont = font.resolve(f); - parentFont.resolve(font.resolve() | f.resolve()); + QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; + parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); const QFont resolvedFont = parentFont.resolve(defaultFont); - const bool changed = resolvedFont != sourceFont; - q->QQuickTextEdit::setFont(resolvedFont); - if (changed) + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickTextAreaPrivate::updateFont(const QFont &font) +{ + Q_Q(QQuickTextArea); + QFont oldFont = sourceFont; + q->QQuickTextEdit::setFont(font); + + QQuickControlPrivate::updateFontRecur(q, font); + + if (oldFont != font) emit q->fontChanged(); } @@ -419,10 +432,10 @@ QFont QQuickTextArea::font() const void QQuickTextArea::setFont(const QFont &font) { Q_D(QQuickTextArea); - if (d->font.resolve() == font.resolve() && d->font == font) + if (d->extra.value().requestedFont.resolve() == font.resolve() && d->extra.value().requestedFont == font) return; - d->font = font; + d->extra.value().requestedFont = font; d->resolveFont(); } -- cgit v1.2.3