From: Peter Penz Date: Tue, 17 Feb 2009 22:24:14 +0000 (+0000) Subject: assure that the size hint calculation and the painting code are consistent X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/93b955c3e634530a1910c522a3c973ba031df6bb assure that the size hint calculation and the painting code are consistent svn path=/trunk/KDE/kdebase/apps/; revision=927623 --- diff --git a/src/panels/information/metatextlabel.cpp b/src/panels/information/metatextlabel.cpp index 017d5e1dc..94ed22666 100644 --- a/src/panels/information/metatextlabel.cpp +++ b/src/panels/information/metatextlabel.cpp @@ -71,9 +71,8 @@ void MetaTextLabel::paintEvent(QPaintEvent* event) const int infoWidth = width() / 2; const int labelWidth = infoWidth - 2 * Spacing; const int infoX = infoWidth; - const int maxHeight = fontMetrics().height() * 5; + const int maxHeight = maxHeightPerLine(); - QRect boundingRect; foreach (const MetaInfo& metaInfo, m_metaInfos) { // draw label (e. g. "Date:") painter.setPen(labelColor); @@ -85,17 +84,27 @@ void MetaTextLabel::paintEvent(QPaintEvent* event) painter.setPen(infoColor); painter.drawText(infoX, y, infoWidth, maxHeight, Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, - metaInfo.info, - &boundingRect); + metaInfo.info); - y += boundingRect.height() + Spacing; + y += requiredHeight(metaInfo); } } +void MetaTextLabel::resizeEvent(QResizeEvent* event) +{ + QWidget::resizeEvent(event); + + int minimumHeight = 0; + foreach (const MetaInfo& metaInfo, m_metaInfos) { + minimumHeight += requiredHeight(metaInfo); + } + setMinimumHeight(minimumHeight); +} + int MetaTextLabel::requiredHeight(const MetaInfo& metaInfo) const { QTextOption textOption; - textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + textOption.setWrapMode(QTextOption::WordWrap); qreal height = 0; const int leading = fontMetrics().leading(); @@ -115,7 +124,17 @@ int MetaTextLabel::requiredHeight(const MetaInfo& metaInfo) const } textLayout.endLayout(); - return static_cast(height) + Spacing; + int adjustedHeight = static_cast(height); + if (adjustedHeight > maxHeightPerLine()) { + adjustedHeight = maxHeightPerLine(); + } + + return adjustedHeight + Spacing; +} + +int MetaTextLabel::maxHeightPerLine() const +{ + return fontMetrics().height() * 100; } #include "metatextlabel.moc" diff --git a/src/panels/information/metatextlabel.h b/src/panels/information/metatextlabel.h index 36ae88e99..e1486c675 100644 --- a/src/panels/information/metatextlabel.h +++ b/src/panels/information/metatextlabel.h @@ -40,6 +40,7 @@ public: protected: virtual void paintEvent(QPaintEvent* event); + virtual void resizeEvent(QResizeEvent* event); private: enum { Spacing = 2 }; @@ -57,6 +58,13 @@ private: * fit into the available width of the widget. */ int requiredHeight(const MetaInfo& metaInfo) const; + + /** + * Returns the maximum height in pixels for the text of + * one added line. The returned value does not contain + * any additional spacing between texts. + */ + int maxHeightPerLine() const; }; #endif