Skip to content

Commit

Permalink
Add contentWidth and contentHeight properties to Text elements.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Feb 7, 2012
1 parent ce3dee7 commit 51b7425
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 145 deletions.
26 changes: 13 additions & 13 deletions src/quick/items/qquicktext.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

/*!
Expand Down
12 changes: 7 additions & 5 deletions src/quick/items/qquicktext_p.h
Expand Up @@ -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)
Expand Down Expand Up @@ -188,8 +190,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem

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();
Expand All @@ -209,7 +211,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem
void maximumLineCountChanged();
void textFormatChanged(TextFormat textFormat);
void elideModeChanged(TextElideMode mode);
void paintedSizeChanged();
void contentSizeChanged();
void lineHeightChanged(qreal lineHeight);
void lineHeightModeChanged(LineHeightMode mode);
void fontSizeModeChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/quick/items/qquicktext_p_p.h
Expand Up @@ -124,7 +124,7 @@ class Q_AUTOTEST_EXPORT QQuickTextPrivate : public QQuickImplicitSizeItemPrivate
bool needToUpdateLayout:1;

QRect layedOutTextRect;
QSize paintedSize;
QSize contentSize;
qreal naturalWidth;
virtual qreal getImplicitWidth() const;

Expand Down
20 changes: 11 additions & 9 deletions src/quick/items/qquicktextedit.cpp
Expand Up @@ -271,7 +271,6 @@ void QQuickTextEdit::setText(const QString &text)
} else {
d->control->setPlainText(text);
}
q_textChanged();
}

/*!
Expand Down Expand Up @@ -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();
}

/*!
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 7 additions & 5 deletions src/quick/items/qquicktextedit_p.h
Expand Up @@ -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)
Expand Down Expand Up @@ -212,8 +214,8 @@ class Q_AUTOTEST_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem

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);
Expand All @@ -233,7 +235,7 @@ class Q_AUTOTEST_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem

Q_SIGNALS:
void textChanged();
void paintedSizeChanged();
void contentSizeChanged();
void cursorPositionChanged();
void cursorRectangleChanged();
void selectionStartChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/quick/items/qquicktextedit_p_p.h
Expand Up @@ -133,7 +133,7 @@ class QQuickTextEditPrivate : public QQuickImplicitSizeItemPrivate
QQuickTextEdit::SelectionMode mouseSelectionMode;
int lineCount;
int yoff;
QSize paintedSize;
QSize contentSize;

enum NodeType {
NodeIsNull,
Expand Down
30 changes: 30 additions & 0 deletions src/quick/items/qquicktextinput.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/quick/items/qquicktextinput_p.h
Expand Up @@ -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);
Expand Down Expand Up @@ -254,6 +256,9 @@ class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem

Q_INVOKABLE QString getText(int start, int end) const;

qreal contentWidth() const;
qreal contentHeight() const;

Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
Expand Down Expand Up @@ -289,6 +294,7 @@ class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
void canRedoChanged();
void inputMethodComposingChanged();
void effectiveHorizontalAlignmentChanged();
void contentSizeChanged();

protected:
virtual void geometryChanged(const QRectF &newGeometry,
Expand Down

0 comments on commit 51b7425

Please sign in to comment.