From 633b4b0655bf47b6f5100ee9a6c2f692b0aeb081 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 16 Sep 2009 16:26:46 +1000 Subject: Experiment with implicitWidth and implicitHeight functions. --- src/declarative/fx/qfxitem.cpp | 14 ++++++++++++++ src/declarative/fx/qfxitem.h | 2 ++ src/declarative/fx/qfxitem_p.h | 4 +++- src/declarative/fx/qfxloader.cpp | 6 ++---- src/declarative/fx/qfxtext.cpp | 14 +++----------- src/declarative/fx/qfxtextedit.cpp | 19 +++++++------------ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 962fee2..c7e807c 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -2688,9 +2688,16 @@ void QFxItem::setWidth(qreal w) QRectF(x(), y(), oldWidth, height())); } +qreal QFxItem::implicitWidth() const +{ + Q_D(const QFxItem); + return d->implicitWidth; +} + void QFxItem::setImplicitWidth(qreal w) { Q_D(QFxItem); + d->implicitWidth = w; if (d->width == w || widthValid()) return; @@ -2733,9 +2740,16 @@ void QFxItem::setHeight(qreal h) QRectF(x(), y(), width(), oldHeight)); } +qreal QFxItem::implicitHeight() const +{ + Q_D(const QFxItem); + return d->implicitHeight; +} + void QFxItem::setImplicitHeight(qreal h) { Q_D(QFxItem); + d->implicitHeight = h; if (d->height == h || heightValid()) return; diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 7ec1ab2..9d2113f 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -134,9 +134,11 @@ public: qreal width() const; void setWidth(qreal); + qreal implicitWidth() const; qreal height() const; void setHeight(qreal); + qreal implicitHeight() const; TransformOrigin transformOrigin() const; void setTransformOrigin(TransformOrigin); diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index b2560ee..df75148 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -108,7 +108,7 @@ public: widthValid(false), heightValid(false), _componentComplete(true), _keepMouse(false), smooth(false), keyHandler(0), - width(0), height(0) + width(0), height(0), implicitWidth(0), implicitHeight(0) {} ~QFxItemPrivate() { delete _anchors; } @@ -213,6 +213,8 @@ public: qreal width; qreal height; + qreal implicitWidth; + qreal implicitHeight; QPointF computeTransformOrigin() const; diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index 668faa4..d0c2690 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -361,10 +361,8 @@ void QFxLoaderPrivate::_q_updateSize() return; switch (resizeMode) { case QFxLoader::SizeLoaderToItem: - if (!q->widthValid()) - q->setImplicitWidth(item->width()); - if (!q->heightValid()) - q->setImplicitHeight(item->height()); + q->setImplicitWidth(item->width()); + q->setImplicitHeight(item->height()); break; case QFxLoader::SizeItemToLoader: item->setWidth(q->width()); diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 5b10289..c4e534e 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -513,17 +513,9 @@ void QFxTextPrivate::updateSize() } q->setBaselineOffset(fm.ascent() + yoff); - if (!q->widthValid()) { - int newWidth = (richText ? (int)doc->idealWidth() : size.width()); - q->setImplicitWidth(newWidth); - } - if (!q->heightValid()) { - if (richText) { - q->setImplicitHeight((int)doc->size().height()); - } else { - q->setImplicitHeight(size.height()); - } - } + //### need to comfirm cost of always setting these for richText + q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width()); + q->setImplicitHeight(richText ? (int)doc->size().height() : size.height()); } else { dirty = true; } diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 72f12cc..0185ce0 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -1044,18 +1044,13 @@ void QFxTextEdit::updateSize() yoff = dy/2; } setBaselineOffset(fm.ascent() + yoff + d->textMargin); - if (!widthValid()) { - int newWidth = (int)d->document->idealWidth(); - d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set - setImplicitWidth(newWidth); - } - if (!heightValid()) { - if (d->text.isEmpty()) { - setImplicitHeight(fm.height()); - } else { - setImplicitHeight((int)d->document->size().height()); - } - } + + //### need to comfirm cost of always setting these + int newWidth = (int)d->document->idealWidth(); + d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well? + setImplicitWidth(newWidth); + setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height()); + setContentsSize(QSize(width(), height())); } else { d->dirty = true; -- cgit v0.12