diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-05-09 22:49:01 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-10 08:43:53 +0000 |
commit | 3b7e13510b355333c4215d04a731240201401a9d (patch) | |
tree | a17c42fedd0c62274c16b606a2bcd2e753a87d77 /src/quicktemplates2/qquicktextfield.cpp | |
parent | 87c1b763147f0dd15e7724fd2a41244dd856613c (diff) |
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 <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicktextfield.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktextfield.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index e6ca2496..241ff922 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -163,18 +163,31 @@ void QQuickTextFieldPrivate::resolveFont() inheritFont(QQuickControlPrivate::parentFont(q)); } -void QQuickTextFieldPrivate::inheritFont(const QFont &f) +void QQuickTextFieldPrivate::inheritFont(const QFont &font) { - Q_Q(QQuickTextField); - 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->QQuickTextInput::setFont(resolvedFont); - if (changed) + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickTextFieldPrivate::updateFont(const QFont &font) +{ + Q_Q(QQuickTextField); + QFont oldFont = sourceFont; + q->QQuickTextInput::setFont(font); + + QQuickControlPrivate::updateFontRecur(q, font); + + if (oldFont != font) emit q->fontChanged(); } @@ -288,10 +301,10 @@ QFont QQuickTextField::font() const void QQuickTextField::setFont(const QFont &font) { Q_D(QQuickTextField); - 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(); } |