X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fda792a1f5a706c4be2d873fa77d504aa90b71e0..ed0df8dc1fc9576e36c920882e7f4b00a2811113:/src/panels/information/metatextlabel.cpp diff --git a/src/panels/information/metatextlabel.cpp b/src/panels/information/metatextlabel.cpp index 017d5e1dc..baa4d0327 100644 --- a/src/panels/information/metatextlabel.cpp +++ b/src/panels/information/metatextlabel.cpp @@ -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(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"