diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-02-07 11:57:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-07 06:36:05 +0100 |
commit | 51b7425329e0fa221c319e8d75595c19f664aedb (patch) | |
tree | 48c2d03edc05da74296a25540f1b8df52389b7ee /src | |
parent | ce3dee765c858a0b573d468ef8fee6b838e576d1 (diff) |
Add contentWidth and contentHeight properties to Text elements.
For Text and TextEdit this is a rename of paintedWidth and paintedHeight
both of which remain as synonyms of the content properties for
compatability. For TextInput this is a new property.
Task-number: QTBUG-23691
Task-number: QTBUG-15160
Change-Id: Idbdc72fad34922be21b649ca45fc39b5e533ed1a
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquicktext.cpp | 26 | ||||
-rw-r--r-- | src/quick/items/qquicktext_p.h | 12 | ||||
-rw-r--r-- | src/quick/items/qquicktext_p_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 20 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit_p.h | 12 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit_p_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 30 | ||||
-rw-r--r-- | src/quick/items/qquicktextinput_p.h | 6 |
8 files changed, 76 insertions, 34 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index f5d1996c93..acf2d17061 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -377,8 +377,8 @@ void QQuickTextPrivate::updateSize() if (text.isEmpty()) { qreal fontHeight = fm.height(); q->setImplicitSize(0, fontHeight); - paintedSize = QSize(0, fontHeight); - emit q->paintedSizeChanged(); + contentSize = QSize(0, fontHeight); + emit q->contentSizeChanged(); updateType = UpdatePaintNode; q->update(); return; @@ -449,9 +449,9 @@ void QQuickTextPrivate::updateSize() if (iWidth == -1) q->setImplicitHeight(size.height()); - if (paintedSize != size) { - paintedSize = size; - emit q->paintedSizeChanged(); + if (contentSize != size) { + contentSize = size; + emit q->contentSizeChanged(); } updateType = UpdatePaintNode; q->update(); @@ -1487,8 +1487,8 @@ void QQuickText::setVAlign(VAlignment align) wrap if an explicit width has been set. wrapMode can be one of: \list - \o Text.NoWrap (default) - no wrapping will be performed. If the text contains insufficient newlines, then \l paintedWidth will exceed a set width. - \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, \l paintedWidth will exceed a set width. + \o Text.NoWrap (default) - no wrapping will be performed. If the text contains insufficient newlines, then \l contentWidth will exceed a set width. + \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, \l contentWidth will exceed a set width. \o Text.WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word. \o Text.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. \endlist @@ -1914,27 +1914,27 @@ void QQuickText::updatePolish() } /*! - \qmlproperty real QtQuick2::Text::paintedWidth + \qmlproperty real QtQuick2::Text::contentWidth Returns the width of the text, including width past the width which is covered due to insufficient wrapping if WrapMode is set. */ -qreal QQuickText::paintedWidth() const +qreal QQuickText::contentWidth() const { Q_D(const QQuickText); - return d->paintedSize.width(); + return d->contentSize.width(); } /*! - \qmlproperty real QtQuick2::Text::paintedHeight + \qmlproperty real QtQuick2::Text::contentHeight Returns the height of the text, including height past the height which is covered due to there being more text than fits in the set height. */ -qreal QQuickText::paintedHeight() const +qreal QQuickText::contentHeight() const { Q_D(const QQuickText); - return d->paintedSize.height(); + return d->contentSize.height(); } /*! diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h index 74339e3b86..ff1f45e605 100644 --- a/src/quick/items/qquicktext_p.h +++ b/src/quick/items/qquicktext_p.h @@ -80,8 +80,10 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode? - Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged) - Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged) + Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged) + Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged) + Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentSizeChanged) // Compatibility + Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentSizeChanged) Q_PROPERTY(qreal lineHeight READ lineHeight WRITE setLineHeight NOTIFY lineHeightChanged) Q_PROPERTY(LineHeightMode lineHeightMode READ lineHeightMode WRITE setLineHeightMode NOTIFY lineHeightModeChanged) Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged) @@ -188,8 +190,8 @@ public: int resourcesLoading() const; // mainly for testing - qreal paintedWidth() const; - qreal paintedHeight() const; + qreal contentWidth() const; + qreal contentHeight() const; QRectF boundingRect() const; Q_INVOKABLE void doLayout(); @@ -209,7 +211,7 @@ Q_SIGNALS: void maximumLineCountChanged(); void textFormatChanged(TextFormat textFormat); void elideModeChanged(TextElideMode mode); - void paintedSizeChanged(); + void contentSizeChanged(); void lineHeightChanged(qreal lineHeight); void lineHeightModeChanged(LineHeightMode mode); void fontSizeModeChanged(); diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h index db84754c64..6c9f22dffa 100644 --- a/src/quick/items/qquicktext_p_p.h +++ b/src/quick/items/qquicktext_p_p.h @@ -124,7 +124,7 @@ public: bool needToUpdateLayout:1; QRect layedOutTextRect; - QSize paintedSize; + QSize contentSize; qreal naturalWidth; virtual qreal getImplicitWidth() const; diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 0ebe5de218..85480cf558 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -271,7 +271,6 @@ void QQuickTextEdit::setText(const QString &text) } else { d->control->setPlainText(text); } - q_textChanged(); } /*! @@ -663,27 +662,27 @@ int QQuickTextEdit::length() const } /*! - \qmlproperty real QtQuick2::TextEdit::paintedWidth + \qmlproperty real QtQuick2::TextEdit::contentWidth Returns the width of the text, including the width past the width which is covered due to insufficient wrapping if \l wrapMode is set. */ -qreal QQuickTextEdit::paintedWidth() const +qreal QQuickTextEdit::contentWidth() const { Q_D(const QQuickTextEdit); - return d->paintedSize.width(); + return d->contentSize.width(); } /*! - \qmlproperty real QtQuick2::TextEdit::paintedHeight + \qmlproperty real QtQuick2::TextEdit::contentHeight Returns the height of the text, including the height past the height that is covered if the text does not fit within the set height. */ -qreal QQuickTextEdit::paintedHeight() const +qreal QQuickTextEdit::contentHeight() const { Q_D(const QQuickTextEdit); - return d->paintedSize.height(); + return d->contentSize.height(); } /*! @@ -1966,8 +1965,11 @@ void QQuickTextEdit::updateSize() else setImplicitHeight(newHeight); - d->paintedSize = QSize(newWidth, newHeight); - emit paintedSizeChanged(); + QSize size(newWidth, newHeight); + if (d->contentSize != size) { + d->contentSize = size; + emit contentSizeChanged(); + } } else { d->dirty = true; } diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h index d74c489d38..d4aeaa5109 100644 --- a/src/quick/items/qquicktextedit_p.h +++ b/src/quick/items/qquicktextedit_p.h @@ -72,8 +72,10 @@ class Q_AUTOTEST_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged) Q_PROPERTY(int length READ length NOTIFY textChanged) - Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged) - Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged) + Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged) + Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged) + Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentSizeChanged) // Compatibility + Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentSizeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged) @@ -212,8 +214,8 @@ public: QVariant inputMethodQuery(Qt::InputMethodQuery property) const; - qreal paintedWidth() const; - qreal paintedHeight() const; + qreal contentWidth() const; + qreal contentHeight() const; QUrl baseUrl() const; void setBaseUrl(const QUrl &url); @@ -233,7 +235,7 @@ public: Q_SIGNALS: void textChanged(); - void paintedSizeChanged(); + void contentSizeChanged(); void cursorPositionChanged(); void cursorRectangleChanged(); void selectionStartChanged(); diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h index 41b64cc567..ead74a282f 100644 --- a/src/quick/items/qquicktextedit_p_p.h +++ b/src/quick/items/qquicktextedit_p_p.h @@ -133,7 +133,7 @@ public: QQuickTextEdit::SelectionMode mouseSelectionMode; int lineCount; int yoff; - QSize paintedSize; + QSize contentSize; enum NodeType { NodeIsNull, diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 39dcc119e0..f8882286ef 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -2251,6 +2251,32 @@ bool QQuickTextInput::canRedo() const return d->canRedo; } +/*! + \qmlproperty real QtQuick2::TextInput::contentWidth + + Returns the width of the text, including the width past the width + which is covered due to insufficient wrapping if \l wrapMode is set. +*/ + +qreal QQuickTextInput::contentWidth() const +{ + Q_D(const QQuickTextInput); + return d->boundingRect.width(); +} + +/*! + \qmlproperty real QtQuick2::TextInput::contentHeight + + Returns the height of the text, including the height past the height + that is covered if the text does not fit within the set height. +*/ + +qreal QQuickTextInput::contentHeight() const +{ + Q_D(const QQuickTextInput); + return d->boundingRect.height(); +} + void QQuickTextInput::moveCursorSelection(int position) { Q_D(QQuickTextInput); @@ -2675,6 +2701,8 @@ void QQuickTextInputPrivate::updateLayout() if (!q->isComponentComplete()) return; + const QRectF previousRect = boundingRect; + QTextOption option = m_textLayout.textOption(); option.setTextDirection(layoutDirection()); option.setFlags(QTextOption::IncludeTrailingSpaces); @@ -2709,6 +2737,8 @@ void QQuickTextInputPrivate::updateLayout() q->update(); q->setImplicitSize(qCeil(boundingRect.width()), qCeil(boundingRect.height())); + if (previousRect != boundingRect) + emit q->contentSizeChanged(); } #ifndef QT_NO_CLIPBOARD diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h index 70a2f0a9a5..b5b3d0f430 100644 --- a/src/quick/items/qquicktextinput_p.h +++ b/src/quick/items/qquicktextinput_p.h @@ -103,6 +103,8 @@ class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged) Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged) Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged) + Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged) + Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged) public: QQuickTextInput(QQuickItem * parent=0); @@ -254,6 +256,9 @@ public: Q_INVOKABLE QString getText(int start, int end) const; + qreal contentWidth() const; + qreal contentHeight() const; + Q_SIGNALS: void textChanged(); void cursorPositionChanged(); @@ -289,6 +294,7 @@ Q_SIGNALS: void canRedoChanged(); void inputMethodComposingChanged(); void effectiveHorizontalAlignmentChanged(); + void contentSizeChanged(); protected: virtual void geometryChanged(const QRectF &newGeometry, |