diff options
Diffstat (limited to 'src/quick/items/qquicktext.cpp')
-rw-r--r-- | src/quick/items/qquicktext.cpp | 438 |
1 files changed, 260 insertions, 178 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 3129bda7cc..5c436d2074 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -40,6 +40,7 @@ #include "qquicktextnode_p.h" #include "qquickimage_p_p.h" #include "qquicktextutil_p.h" +#include "qquicktextdocument_p.h" #include <QtQuick/private/qsgtexture_p.h> @@ -85,7 +86,16 @@ QQuickTextPrivate::QQuickTextPrivate() } QQuickTextPrivate::ExtraData::ExtraData() - : lineHeight(1.0) + : padding(0) + , topPadding(0) + , leftPadding(0) + , rightPadding(0) + , bottomPadding(0) + , explicitTopPadding(false) + , explicitLeftPadding(false) + , explicitRightPadding(false) + , explicitBottomPadding(false) + , lineHeight(1.0) , doc(0) , minimumPixelSize(12) , minimumPointSize(12) @@ -104,180 +114,105 @@ void QQuickTextPrivate::init() q->setFlag(QQuickItem::ItemHasContents); } -QQuickTextDocumentWithImageResources::QQuickTextDocumentWithImageResources(QQuickItem *parent) -: QTextDocument(parent), outstanding(0) -{ - setUndoRedoEnabled(false); - documentLayout()->registerHandler(QTextFormat::ImageObject, this); - connect(this, SIGNAL(baseUrlChanged(QUrl)), this, SLOT(reset())); -} - -QQuickTextDocumentWithImageResources::~QQuickTextDocumentWithImageResources() +QQuickTextPrivate::~QQuickTextPrivate() { - if (!m_resources.isEmpty()) - qDeleteAll(m_resources); -} + delete elideLayout; + delete textLine; textLine = 0; -QVariant QQuickTextDocumentWithImageResources::loadResource(int type, const QUrl &name) -{ - QVariant resource = QTextDocument::loadResource(type, name); - if (resource.isNull() && type == QTextDocument::ImageResource) { - QQmlContext *context = qmlContext(parent()); - QUrl url = baseUrl().resolved(name); - QQuickPixmap *p = loadPixmap(context, url); - resource = p->image(); + if (extra.isAllocated()) { + qDeleteAll(extra->imgTags); + extra->imgTags.clear(); } - - return resource; } -void QQuickTextDocumentWithImageResources::requestFinished() +qreal QQuickTextPrivate::getImplicitWidth() const { - outstanding--; - if (outstanding == 0) { - markContentsDirty(0, characterCount()); - emit imagesLoaded(); + if (!requireImplicitSize) { + // We don't calculate implicitWidth unless it is required. + // We need to force a size update now to ensure implicitWidth is calculated + QQuickTextPrivate *me = const_cast<QQuickTextPrivate*>(this); + me->requireImplicitSize = true; + me->updateSize(); } + return implicitWidth; } -QSizeF QQuickTextDocumentWithImageResources::intrinsicSize( - QTextDocument *, int, const QTextFormat &format) +qreal QQuickTextPrivate::getImplicitHeight() const { - if (format.isImageFormat()) { - QTextImageFormat imageFormat = format.toImageFormat(); - - const int width = qRound(imageFormat.width()); - const bool hasWidth = imageFormat.hasProperty(QTextFormat::ImageWidth) && width > 0; - const int height = qRound(imageFormat.height()); - const bool hasHeight = imageFormat.hasProperty(QTextFormat::ImageHeight) && height > 0; - - QSizeF size(width, height); - if (!hasWidth || !hasHeight) { - QVariant res = resource(QTextDocument::ImageResource, QUrl(imageFormat.name())); - QImage image = res.value<QImage>(); - if (image.isNull()) { - if (!hasWidth) - size.setWidth(16); - if (!hasHeight) - size.setHeight(16); - return size; - } - QSize imgSize = image.size(); - - if (!hasWidth) { - if (!hasHeight) - size.setWidth(imgSize.width()); - else - size.setWidth(qRound(height * (imgSize.width() / (qreal) imgSize.height()))); - } - if (!hasHeight) { - if (!hasWidth) - size.setHeight(imgSize.height()); - else - size.setHeight(qRound(width * (imgSize.height() / (qreal) imgSize.width()))); - } - } - return size; + if (!requireImplicitSize) { + QQuickTextPrivate *me = const_cast<QQuickTextPrivate*>(this); + me->requireImplicitSize = true; + me->updateSize(); } - return QSizeF(); -} - -void QQuickTextDocumentWithImageResources::drawObject( - QPainter *, const QRectF &, QTextDocument *, int, const QTextFormat &) -{ + return implicitHeight; } -QImage QQuickTextDocumentWithImageResources::image(const QTextImageFormat &format) +qreal QQuickTextPrivate::availableWidth() const { - QVariant res = resource(QTextDocument::ImageResource, QUrl(format.name())); - return res.value<QImage>(); + Q_Q(const QQuickText); + return q->width() - q->leftPadding() - q->rightPadding(); } -void QQuickTextDocumentWithImageResources::reset() +qreal QQuickTextPrivate::availableHeight() const { - clearResources(); - markContentsDirty(0, characterCount()); + Q_Q(const QQuickText); + return q->height() - q->topPadding() - q->bottomPadding(); } -QQuickPixmap *QQuickTextDocumentWithImageResources::loadPixmap( - QQmlContext *context, const QUrl &url) +void QQuickTextPrivate::setTopPadding(qreal value, bool reset) { - - QHash<QUrl, QQuickPixmap *>::Iterator iter = m_resources.find(url); - - if (iter == m_resources.end()) { - QQuickPixmap *p = new QQuickPixmap(context->engine(), url); - iter = m_resources.insert(url, p); - - if (p->isLoading()) { - p->connectFinished(this, SLOT(requestFinished())); - outstanding++; - } + Q_Q(QQuickText); + qreal oldPadding = q->topPadding(); + if (!reset || extra.isAllocated()) { + extra.value().topPadding = value; + extra.value().explicitTopPadding = !reset; } - - QQuickPixmap *p = *iter; - if (p->isError()) { - if (!errors.contains(url)) { - errors.insert(url); - qmlInfo(parent()) << p->error(); - } + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) { + updateSize(); + emit q->topPaddingChanged(); } - return p; -} - -void QQuickTextDocumentWithImageResources::clearResources() -{ - foreach (QQuickPixmap *pixmap, m_resources) - pixmap->clear(this); - qDeleteAll(m_resources); - m_resources.clear(); - outstanding = 0; -} - -void QQuickTextDocumentWithImageResources::setText(const QString &text) -{ - clearResources(); - -#ifndef QT_NO_TEXTHTMLPARSER - setHtml(text); -#else - setPlainText(text); -#endif } -QSet<QUrl> QQuickTextDocumentWithImageResources::errors; - -QQuickTextPrivate::~QQuickTextPrivate() +void QQuickTextPrivate::setLeftPadding(qreal value, bool reset) { - delete elideLayout; - delete textLine; textLine = 0; - - if (extra.isAllocated()) { - qDeleteAll(extra->imgTags); - extra->imgTags.clear(); + Q_Q(QQuickText); + qreal oldPadding = q->leftPadding(); + if (!reset || extra.isAllocated()) { + extra.value().leftPadding = value; + extra.value().explicitLeftPadding = !reset; + } + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) { + updateSize(); + emit q->leftPaddingChanged(); } } -qreal QQuickTextPrivate::getImplicitWidth() const +void QQuickTextPrivate::setRightPadding(qreal value, bool reset) { - if (!requireImplicitSize) { - // We don't calculate implicitWidth unless it is required. - // We need to force a size update now to ensure implicitWidth is calculated - QQuickTextPrivate *me = const_cast<QQuickTextPrivate*>(this); - me->requireImplicitSize = true; - me->updateSize(); + Q_Q(QQuickText); + qreal oldPadding = q->rightPadding(); + if (!reset || extra.isAllocated()) { + extra.value().rightPadding = value; + extra.value().explicitRightPadding = !reset; + } + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) { + updateSize(); + emit q->rightPaddingChanged(); } - return implicitWidth; } -qreal QQuickTextPrivate::getImplicitHeight() const +void QQuickTextPrivate::setBottomPadding(qreal value, bool reset) { - if (!requireImplicitSize) { - QQuickTextPrivate *me = const_cast<QQuickTextPrivate*>(this); - me->requireImplicitSize = true; - me->updateSize(); + Q_Q(QQuickText); + qreal oldPadding = q->bottomPadding(); + if (!reset || extra.isAllocated()) { + extra.value().bottomPadding = value; + extra.value().explicitBottomPadding = !reset; + } + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding()))) { + updateSize(); + emit q->bottomPaddingChanged(); } - return implicitHeight; } /*! @@ -323,9 +258,9 @@ void QQuickTextPrivate::updateLayout() formatModifiesFontSize = fontSizeModified; multilengthEos = -1; } else { - layout.clearAdditionalFormats(); + layout.clearFormats(); if (elideLayout) - elideLayout->clearAdditionalFormats(); + elideLayout->clearFormats(); QString tmp = text; multilengthEos = tmp.indexOf(QLatin1Char('\x9c')); if (multilengthEos != -1) { @@ -406,7 +341,7 @@ void QQuickTextPrivate::updateBaseline(qreal baseline, qreal dy) yoff = dy/2; } - q->setBaselineOffset(baseline + yoff); + q->setBaselineOffset(baseline + yoff + q->topPadding()); } void QQuickTextPrivate::updateSize() @@ -426,6 +361,9 @@ void QQuickTextPrivate::updateSize() return; } + qreal hPadding = q->leftPadding() + q->rightPadding(); + qreal vPadding = q->topPadding() + q->bottomPadding(); + if (text.isEmpty() && !isLineLaidOutConnected() && fontSizeMode() == QQuickText::FixedSize) { // How much more expensive is it to just do a full layout on an empty string here? // There may be subtle differences in the height and baseline calculations between @@ -438,8 +376,8 @@ void QQuickTextPrivate::updateSize() ? lineHeight() : fontHeight * lineHeight(); } - updateBaseline(fm.ascent(), q->height() - fontHeight); - q->setImplicitSize(0, fontHeight); + updateBaseline(fm.ascent(), q->height() - fontHeight - vPadding); + q->setImplicitSize(hPadding, fontHeight + vPadding); layedOutTextRect = QRectF(0, 0, 0, fontHeight); emit q->contentSizeChanged(); updateType = UpdatePaintNode; @@ -460,7 +398,7 @@ void QQuickTextPrivate::updateSize() layedOutTextRect = textRect; size = textRect.size(); - updateBaseline(baseline, q->height() - size.height()); + updateBaseline(baseline, q->height() - size.height() - vPadding); } else { widthExceeded = true; // always relayout rich text on width changes.. heightExceeded = false; // rich text layout isn't affected by height changes. @@ -484,15 +422,15 @@ void QQuickTextPrivate::updateSize() naturalWidth = extra->doc->idealWidth(); const bool wasInLayout = internalWidthUpdate; internalWidthUpdate = true; - q->setImplicitWidth(naturalWidth); + q->setImplicitWidth(naturalWidth + hPadding); internalWidthUpdate = wasInLayout; } if (internalWidthUpdate) return; extra->doc->setPageSize(QSizeF()); - if (q->widthValid() && (wrapMode != QQuickText::NoWrap || extra->doc->idealWidth() < q->width())) - extra->doc->setTextWidth(q->width()); + if (q->widthValid() && (wrapMode != QQuickText::NoWrap || extra->doc->idealWidth() < availableWidth())) + extra->doc->setTextWidth(availableWidth()); else extra->doc->setTextWidth(extra->doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) @@ -501,7 +439,7 @@ void QQuickTextPrivate::updateSize() size = QSizeF(extra->doc->idealWidth(),dsize.height()); QFontMetricsF fm(font); - updateBaseline(fm.ascent(), q->height() - size.height()); + updateBaseline(fm.ascent(), q->height() - size.height() - vPadding); //### need to confirm cost of always setting these for richText internalWidthUpdate = true; @@ -509,11 +447,11 @@ void QQuickTextPrivate::updateSize() if (!q->widthValid()) iWidth = size.width(); if (iWidth > -1) - q->setImplicitSize(iWidth, size.height()); + q->setImplicitSize(iWidth + hPadding, size.height() + vPadding); internalWidthUpdate = false; if (iWidth == -1) - q->setImplicitHeight(size.height()); + q->setImplicitHeight(size.height() + vPadding); } if (layedOutTextRect.size() != previousSize) @@ -619,7 +557,7 @@ void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, // use the text item's width by default if it has one and wrap is on or text must be aligned if (q->widthValid() && (q->wrapMode() != QQuickText::NoWrap || q->effectiveHAlign() != QQuickText::AlignLeft)) - textLine->setWidth(q->width()); + textLine->setWidth(availableWidth()); else textLine->setWidth(INT_MAX); if (lineHeight() != 1.0) @@ -631,10 +569,10 @@ void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, } void QQuickTextPrivate::elideFormats( - const int start, const int length, int offset, QList<QTextLayout::FormatRange> *elidedFormats) + const int start, const int length, int offset, QVector<QTextLayout::FormatRange> *elidedFormats) { const int end = start + length; - QList<QTextLayout::FormatRange> formats = layout.additionalFormats(); + const QVector<QTextLayout::FormatRange> formats = layout.formats(); for (int i = 0; i < formats.count(); ++i) { QTextLayout::FormatRange format = formats.at(i); const int formatLength = qMin(format.start + format.length, end) - qMax(format.start, start); @@ -687,10 +625,11 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) && (q->heightValid() || maximumLineCountValid); if ((!requireImplicitSize || (implicitWidthValid && implicitHeightValid)) - && ((singlelineElide && q->width() <= 0.) || (multilineElide && q->heightValid() && q->height() <= 0.))) { + && ((singlelineElide && availableWidth() <= 0.) + || (multilineElide && q->heightValid() && availableHeight() <= 0.))) { // we are elided and we have a zero width or height - widthExceeded = q->widthValid() && q->width() <= 0.; - heightExceeded = q->heightValid() && q->height() <= 0.; + widthExceeded = q->widthValid() && availableWidth() <= 0.; + heightExceeded = q->heightValid() && availableHeight() <= 0.; if (!truncated) { truncated = true; @@ -726,7 +665,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) lineWidth = (q->widthValid() || implicitWidthValid) && q->width() > 0 ? q->width() : FLT_MAX; - qreal maxHeight = q->heightValid() ? q->height() : FLT_MAX; + qreal maxHeight = q->heightValid() ? availableHeight() : FLT_MAX; const bool customLayout = isLineLaidOutConnected(); const bool wasTruncated = truncated; @@ -747,8 +686,8 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) int scaledFontSize = largeFont; bool widthChanged = false; - widthExceeded = q->width() <= 0 && (singlelineElide || canWrap || horizontalFit); - heightExceeded = q->height() <= 0 && (multilineElide || verticalFit); + widthExceeded = availableWidth() <= 0 && (singlelineElide || canWrap || horizontalFit); + heightExceeded = availableHeight() <= 0 && (multilineElide || verticalFit); QRectF br; @@ -918,7 +857,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) bool wasInLayout = internalWidthUpdate; internalWidthUpdate = true; - q->setImplicitSize(naturalWidth, naturalHeight); + q->setImplicitSize(naturalWidth + q->leftPadding() + q->rightPadding(), naturalHeight + q->topPadding() + q->bottomPadding()); internalWidthUpdate = wasInLayout; // Update any variables that are dependent on the validity of the width or height. @@ -935,8 +874,11 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) const qreal oldWidth = lineWidth; const qreal oldHeight = maxHeight; - lineWidth = q->widthValid() && q->width() > 0 ? q->width() : naturalWidth; - maxHeight = q->heightValid() ? q->height() : FLT_MAX; + const qreal availWidth = availableWidth(); + const qreal availHeight = availableHeight(); + + lineWidth = q->widthValid() && availWidth > 0 ? availWidth : naturalWidth; + maxHeight = q->heightValid() ? availHeight : FLT_MAX; // If the width of the item has changed and it's possible the result of wrapping, // eliding, scaling has changed, or the text is not left aligned do another layout. @@ -989,7 +931,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) && (q->heightValid() || (maximumLineCountValid && canWrap)); const qreal oldHeight = maxHeight; - maxHeight = q->heightValid() ? q->height() : FLT_MAX; + maxHeight = q->heightValid() ? availableHeight() : FLT_MAX; // If the height of the item has changed and it's possible the result of eliding, // line count truncation or scaling has changed, do another layout. if ((maxHeight < qMin(oldHeight, naturalHeight) || (heightExceeded && maxHeight > oldHeight)) @@ -1069,7 +1011,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) elideLayout->setCacheEnabled(true); } if (styledText) { - QList<QTextLayout::FormatRange> formats; + QVector<QTextLayout::FormatRange> formats; switch (elideMode) { case QQuickText::ElideRight: elideFormats(elideStart, elideText.length() - 1, 0, &formats); @@ -1092,7 +1034,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) default: break; } - elideLayout->setAdditionalFormats(formats); + elideLayout->setFormats(formats); } elideLayout->setFont(layout.font()); @@ -1283,6 +1225,13 @@ QQuickText::QQuickText(QQuickItem *parent) d->init(); } +QQuickText::QQuickText(QQuickTextPrivate &dd, QQuickItem *parent) +: QQuickImplicitSizeItem(dd, parent) +{ + Q_D(QQuickText); + d->init(); +} + QQuickText::~QQuickText() { } @@ -1357,6 +1306,16 @@ QQuickText::~QQuickText() */ /*! + \qmlproperty string QtQuick::Text::font.styleName + \since 5.6 + + Sets the style name of the font. + + The style name is case insensitive. If set, the font will be matched against style name instead + of the font properties \l font.weight, \l font.bold and \l font.italic. +*/ + +/*! \qmlproperty bool QtQuick::Text::font.bold Sets whether the font weight is bold. @@ -2194,18 +2153,19 @@ void QQuickText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo bool widthMaximum = newGeometry.width() >= oldGeometry.width() && !d->widthExceeded; bool heightMaximum = newGeometry.height() >= oldGeometry.height() && !d->heightExceeded; + bool verticalPositionChanged = heightChanged && d->vAlign != AlignTop; + if ((!widthChanged && !heightChanged) || d->internalWidthUpdate) goto geomChangeDone; - if ((effectiveHAlign() != QQuickText::AlignLeft && widthChanged) - || (vAlign() != QQuickText::AlignTop && heightChanged)) { + if ((effectiveHAlign() != QQuickText::AlignLeft && widthChanged) || verticalPositionChanged) { // If the width has changed and we're not left aligned do an update so the text is // repositioned even if a full layout isn't required. And the same for vertical. d->updateType = QQuickTextPrivate::UpdatePaintNode; update(); } - if (!wrapped && !elide && !scaleFont) + if (!wrapped && !elide && !scaleFont && !verticalPositionChanged) goto geomChangeDone; // left aligned unwrapped text without eliding never needs relayout if (elide // eliding and dimensions were and remain invalid; @@ -2214,7 +2174,7 @@ void QQuickText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo goto geomChangeDone; } - if (widthMaximum && heightMaximum && !d->isLineLaidOutConnected()) // Size is sufficient and growing. + if (widthMaximum && heightMaximum && !d->isLineLaidOutConnected() && !verticalPositionChanged) // Size is sufficient and growing. goto geomChangeDone; if (!(widthChanged || widthMaximum) && !d->isLineLaidOutConnected()) { // only height has changed @@ -2275,7 +2235,7 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data d->updateType = QQuickTextPrivate::UpdateNone; - const qreal dy = QQuickTextUtil::alignedY(d->layedOutTextRect.height() + d->lineHeightOffset(), height(), d->vAlign); + const qreal dy = QQuickTextUtil::alignedY(d->layedOutTextRect.height() + d->lineHeightOffset(), d->availableHeight(), d->vAlign) + topPadding(); QQuickTextNode *node = 0; if (!oldNode) @@ -2292,11 +2252,11 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data const QColor linkColor = QColor::fromRgba(d->linkColor); if (d->richText) { - const qreal dx = QQuickTextUtil::alignedX(d->layedOutTextRect.width(), width(), effectiveHAlign()); + const qreal dx = QQuickTextUtil::alignedX(d->layedOutTextRect.width(), d->availableWidth(), effectiveHAlign()) + leftPadding(); d->ensureDoc(); node->addTextDocument(QPointF(dx, dy), d->extra->doc, color, d->style, styleColor, linkColor); } else if (d->layedOutTextRect.width() > 0) { - const qreal dx = QQuickTextUtil::alignedX(d->lineWidth, width(), effectiveHAlign()); + const qreal dx = QQuickTextUtil::alignedX(d->lineWidth, d->availableWidth(), effectiveHAlign()) + leftPadding(); int unelidedLineCount = d->lineCount; if (d->elideLayout) unelidedLineCount -= 1; @@ -2566,7 +2526,7 @@ QString QQuickTextPrivate::anchorAt(const QTextLayout *layout, const QPointF &mo QTextLine line = layout->lineAt(i); if (line.naturalTextRect().contains(mousePos)) { int charPos = line.xToCursor(mousePos.x(), QTextLine::CursorOnCharacter); - foreach (const QTextLayout::FormatRange &formatRange, layout->additionalFormats()) { + foreach (const QTextLayout::FormatRange &formatRange, layout->formats()) { if (formatRange.format.isAnchor() && charPos >= formatRange.start && charPos < formatRange.start + formatRange.length) { @@ -2583,14 +2543,15 @@ QString QQuickTextPrivate::anchorAt(const QPointF &mousePos) const { Q_Q(const QQuickText); QPointF translatedMousePos = mousePos; - translatedMousePos.ry() -= QQuickTextUtil::alignedY(layedOutTextRect.height() + lineHeightOffset(), q->height(), vAlign); + translatedMousePos.rx() -= q->leftPadding(); + translatedMousePos.ry() -= q->topPadding() + QQuickTextUtil::alignedY(layedOutTextRect.height() + lineHeightOffset(), availableHeight(), vAlign); if (styledText) { QString link = anchorAt(&layout, translatedMousePos); if (link.isEmpty() && elideLayout) link = anchorAt(elideLayout, translatedMousePos); return link; } else if (richText && extra.isAllocated() && extra->doc) { - translatedMousePos.rx() -= QQuickTextUtil::alignedX(layedOutTextRect.width(), q->width(), q->effectiveHAlign()); + translatedMousePos.rx() -= QQuickTextUtil::alignedX(layedOutTextRect.width(), availableWidth(), q->effectiveHAlign()); return extra->doc->documentLayout()->anchorAt(translatedMousePos); } return QString(); @@ -2808,4 +2769,125 @@ void QQuickText::invalidateFontCaches() } } +/*! + \since 5.6 + \qmlproperty real QtQuick::Text::padding + \qmlproperty real QtQuick::Text::topPadding + \qmlproperty real QtQuick::Text::leftPadding + \qmlproperty real QtQuick::Text::bottomPadding + \qmlproperty real QtQuick::Text::rightPadding + + These properties hold the padding around the content. This space is reserved + in addition to the contentWidth and contentHeight. +*/ +qreal QQuickText::padding() const +{ + Q_D(const QQuickText); + return d->padding(); +} + +void QQuickText::setPadding(qreal padding) +{ + Q_D(QQuickText); + if (qFuzzyCompare(d->padding(), padding)) + return; + + d->extra.value().padding = padding; + d->updateSize(); + emit paddingChanged(); + if (!d->extra.isAllocated() || !d->extra->explicitTopPadding) + emit topPaddingChanged(); + if (!d->extra.isAllocated() || !d->extra->explicitLeftPadding) + emit leftPaddingChanged(); + if (!d->extra.isAllocated() || !d->extra->explicitRightPadding) + emit rightPaddingChanged(); + if (!d->extra.isAllocated() || !d->extra->explicitBottomPadding) + emit bottomPaddingChanged(); +} + +void QQuickText::resetPadding() +{ + setPadding(0); +} + +qreal QQuickText::topPadding() const +{ + Q_D(const QQuickText); + if (d->extra.isAllocated() && d->extra->explicitTopPadding) + return d->extra->topPadding; + return d->padding(); +} + +void QQuickText::setTopPadding(qreal padding) +{ + Q_D(QQuickText); + d->setTopPadding(padding); +} + +void QQuickText::resetTopPadding() +{ + Q_D(QQuickText); + d->setTopPadding(0, true); +} + +qreal QQuickText::leftPadding() const +{ + Q_D(const QQuickText); + if (d->extra.isAllocated() && d->extra->explicitLeftPadding) + return d->extra->leftPadding; + return d->padding(); +} + +void QQuickText::setLeftPadding(qreal padding) +{ + Q_D(QQuickText); + d->setLeftPadding(padding); +} + +void QQuickText::resetLeftPadding() +{ + Q_D(QQuickText); + d->setLeftPadding(0, true); +} + +qreal QQuickText::rightPadding() const +{ + Q_D(const QQuickText); + if (d->extra.isAllocated() && d->extra->explicitRightPadding) + return d->extra->rightPadding; + return d->padding(); +} + +void QQuickText::setRightPadding(qreal padding) +{ + Q_D(QQuickText); + d->setRightPadding(padding); +} + +void QQuickText::resetRightPadding() +{ + Q_D(QQuickText); + d->setRightPadding(0, true); +} + +qreal QQuickText::bottomPadding() const +{ + Q_D(const QQuickText); + if (d->extra.isAllocated() && d->extra->explicitBottomPadding) + return d->extra->bottomPadding; + return d->padding(); +} + +void QQuickText::setBottomPadding(qreal padding) +{ + Q_D(QQuickText); + d->setBottomPadding(padding); +} + +void QQuickText::resetBottomPadding() +{ + Q_D(QQuickText); + d->setBottomPadding(0, true); +} + QT_END_NAMESPACE |