]> cloud.milkyroute.net Git - dolphin.git/commitdiff
assure that the size hint calculation and the painting code are consistent
authorPeter Penz <peter.penz19@gmail.com>
Tue, 17 Feb 2009 22:24:14 +0000 (22:24 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 17 Feb 2009 22:24:14 +0000 (22:24 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=927623

src/panels/information/metatextlabel.cpp
src/panels/information/metatextlabel.h

index 017d5e1dce95de3284f00fb9424aaed5cfb4e261..94ed226669fb485d9259794c385d697cd3a09e18 100644 (file)
@@ -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<int>(height) + Spacing;
+    int adjustedHeight = static_cast<int>(height);
+    if (adjustedHeight > maxHeightPerLine()) {
+        adjustedHeight = maxHeightPerLine();
+    }
+
+    return adjustedHeight + Spacing;
+}
+
+int MetaTextLabel::maxHeightPerLine() const
+{
+    return fontMetrics().height() * 100;
 }
 
 #include "metatextlabel.moc"
index 36ae88e9976f79c628e6f11bd08daf381cffecc0..e1486c6753538fdfa5d1abe2252554fb47d20e35 100644 (file)
@@ -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