]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/metatextlabel.cpp
fixed issue that the video preview size was wrong during resizing the information...
[dolphin.git] / src / panels / information / metatextlabel.cpp
index 017d5e1dce95de3284f00fb9424aaed5cfb4e261..baa4d03278d7920fa3548d9d83dfc9fc249b7bca 100644 (file)
@@ -51,7 +51,20 @@ void MetaTextLabel::add(const QString& labelText, const QString& infoText)
     MetaInfo metaInfo;
     metaInfo.label = labelText;
     metaInfo.info = infoText;
-    m_metaInfos.append(metaInfo);
+
+    // add the meta information alphabetically sorted
+    bool inserted = false;
+    const int count = m_metaInfos.size();
+    for (int i = 0; i < count; ++i) {
+        if (m_metaInfos[i].label > labelText) {
+            m_metaInfos.insert(i, metaInfo);
+            inserted = true;
+            break;
+        }
+    }
+    if (!inserted) {
+        m_metaInfos.append(metaInfo);
+    }
 
     setMinimumHeight(minimumHeight() + requiredHeight(metaInfo));
     update();
@@ -71,9 +84,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 +97,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 += requiredHeight(metaInfo);
+    }
+}
+
+void MetaTextLabel::resizeEvent(QResizeEvent* event)
+{
+    QWidget::resizeEvent(event);
 
-        y += boundingRect.height() + Spacing;
+    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 +137,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"