diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-18 00:59:34 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-01-21 07:48:12 (GMT) |
commit | 47f7512133db2954cc739bf9a8734c631008ed38 (patch) | |
tree | 5991276f2045a3d04adbb3f12ef27a74304c7490 | |
parent | 91700dfbd9e3d8e1cbd0536a39becad2e41b1861 (diff) | |
download | Qt-47f7512133db2954cc739bf9a8734c631008ed38.zip Qt-47f7512133db2954cc739bf9a8734c631008ed38.tar.gz Qt-47f7512133db2954cc739bf9a8734c631008ed38.tar.bz2 |
Request font sizes with only 0.5pt resolution.
When animating pointSize avoid generating a huge number of fonts with
slightly different point sizes.
Task-number: QTBUG-13960
Reviewed-by: Aaron Kennedy
(cherry picked from commit f111e97adf93a933351eb5658b33a5820097757a)
6 files changed, 54 insertions, 20 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 2f3c8e5..640965c 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -736,19 +736,28 @@ QDeclarativeText::~QDeclarativeText() QFont QDeclarativeText::font() const { Q_D(const QDeclarativeText); - return d->font; + return d->sourceFont; } void QDeclarativeText::setFont(const QFont &font) { Q_D(QDeclarativeText); - if (d->font == font) + if (d->sourceFont == font) return; + d->sourceFont = font; + QFont oldFont = d->font; d->font = font; - d->updateLayout(); + if (d->font.pointSizeF() != -1) { + // 0.5pt resolution + qreal size = qRound(d->font.pointSizeF()*2.0); + d->font.setPointSizeF(size/2.0); + } + + if (oldFont != d->font) + d->updateLayout(); - emit fontChanged(d->font); + emit fontChanged(d->sourceFont); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h index 67f2289..e749bc9 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h @@ -79,6 +79,7 @@ public: QString text; QFont font; + QFont sourceFont; QColor color; QDeclarativeText::TextStyle style; QColor styleColor; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index d072064..cb62a2c 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -326,22 +326,35 @@ void QDeclarativeTextEdit::setTextFormat(TextFormat format) QFont QDeclarativeTextEdit::font() const { Q_D(const QDeclarativeTextEdit); - return d->font; + return d->sourceFont; } void QDeclarativeTextEdit::setFont(const QFont &font) { Q_D(QDeclarativeTextEdit); + if (d->sourceFont == font) + return; + + d->sourceFont = font; + QFont oldFont = d->font; d->font = font; + if (d->font.pointSizeF() != -1) { + // 0.5pt resolution + qreal size = qRound(d->font.pointSizeF()*2.0); + d->font.setPointSizeF(size/2.0); + } - clearCache(); - d->document->setDefaultFont(d->font); - if(d->cursor){ - d->cursor->setHeight(QFontMetrics(d->font).height()); - moveCursorDelegate(); + if (oldFont != d->font) { + clearCache(); + d->document->setDefaultFont(d->font); + if(d->cursor){ + d->cursor->setHeight(QFontMetrics(d->font).height()); + moveCursorDelegate(); + } + updateSize(); + update(); } - updateSize(); - update(); + emit fontChanged(d->sourceFont); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h index 68a9cc8..3a45541 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h @@ -92,6 +92,7 @@ public: QString text; QFont font; + QFont sourceFont; QColor color; QColor selectionColor; QColor selectedTextColor; diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 57a2177..ef3404f 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -213,24 +213,33 @@ void QDeclarativeTextInput::setText(const QString &s) QFont QDeclarativeTextInput::font() const { Q_D(const QDeclarativeTextInput); - return d->font; + return d->sourceFont; } void QDeclarativeTextInput::setFont(const QFont &font) { Q_D(QDeclarativeTextInput); - if (d->font == font) + if (d->sourceFont == font) return; + d->sourceFont = font; + QFont oldFont = d->font; d->font = font; + if (d->font.pointSizeF() != -1) { + // 0.5pt resolution + qreal size = qRound(d->font.pointSizeF()*2.0); + d->font.setPointSizeF(size/2.0); + } - d->control->setFont(d->font); - if(d->cursorItem){ - d->cursorItem->setHeight(QFontMetrics(d->font).height()); - moveCursor(); + if (oldFont != d->font) { + d->control->setFont(d->font); + if(d->cursorItem){ + d->cursorItem->setHeight(QFontMetrics(d->font).height()); + moveCursor(); + } + updateSize(); } - updateSize(); - emit fontChanged(d->font); + emit fontChanged(d->sourceFont); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index 18e9c81..16827b3 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -107,6 +107,7 @@ public: QLineControl* control; QFont font; + QFont sourceFont; QColor color; QColor selectionColor; QColor selectedTextColor; |