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();
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);
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();
}
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"