]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fixed issue the label texts with spaces might overlap with other labels
authorPeter Penz <peter.penz19@gmail.com>
Sun, 21 Jun 2009 11:23:25 +0000 (11:23 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 21 Jun 2009 11:23:25 +0000 (11:23 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=984673

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

index baa4d03278d7920fa3548d9d83dfc9fc249b7bca..793f72669139176e378ea5b5c970772d12464958 100644 (file)
@@ -81,8 +81,8 @@ void MetaTextLabel::paintEvent(QPaintEvent* event)
     labelColor.setAlpha(128);
 
     int y = 0;
-    const int infoWidth = width() / 2;
-    const int labelWidth = infoWidth - 2 * Spacing;
+    const int infoWidth = infoTextWidth();
+    const int labelWidth = labelTextWidth();
     const int infoX = infoWidth;
     const int maxHeight = maxHeightPerLine();
 
@@ -114,23 +114,29 @@ void MetaTextLabel::resizeEvent(QResizeEvent* event)
     setMinimumHeight(minimumHeight);
 }
 
-int MetaTextLabel::requiredHeight(const MetaInfo& metaInfo) const
+int MetaTextLabel::requiredHeight(const MetaInfo& info) const
+{
+    const int labelTextHeight = requiredHeight(info.label, labelTextWidth());
+    const int infoTextHeight  = requiredHeight(info.info, infoTextWidth());
+    return qMax(labelTextHeight, infoTextHeight);
+}
+
+int MetaTextLabel::requiredHeight(const QString& text, int width) const
 {
     QTextOption textOption;
     textOption.setWrapMode(QTextOption::WordWrap);
 
     qreal height = 0;
     const int leading = fontMetrics().leading();
-    const int availableWidth = width() / 2;
 
-    QTextLayout textLayout(metaInfo.info);
+    QTextLayout textLayout(text);
     textLayout.setFont(font());
     textLayout.setTextOption(textOption);
 
     textLayout.beginLayout();
     QTextLine line = textLayout.createLine();
     while (line.isValid()) {
-        line.setLineWidth(availableWidth);
+        line.setLineWidth(width);
         height += leading;
         height += line.height();
         line = textLayout.createLine();
index e1486c6753538fdfa5d1abe2252554fb47d20e35..500cbca692fc2a998c835fecced1f559c38cbe6f 100644 (file)
@@ -54,10 +54,15 @@ private:
     QList<MetaInfo> m_metaInfos;
 
     /**
-     * Returns the required height in pixels for \a metaInfo to
-     * fit into the available width of the widget.
+     * Returns the required height in pixels for the
+     * label text and information text provided by \a info.
      */
-    int requiredHeight(const MetaInfo& metaInfo) const;
+    int requiredHeight(const MetaInfo& info) const;
+
+    /** Helper method for requiredHeight(const MetaInfo& info). */
+    int requiredHeight(const QString& text, int width) const;
+    int labelTextWidth() const;
+    int infoTextWidth() const;
 
     /**
      * Returns the maximum height in pixels for the text of
@@ -67,4 +72,14 @@ private:
     int maxHeightPerLine() const;
 };
 
+inline int MetaTextLabel::labelTextWidth() const
+{
+    return width() / 2 - 2 * Spacing;
+}
+
+inline int MetaTextLabel::infoTextWidth() const
+{
+    return width() / 2;
+}
+
 #endif