┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2014-02-24 21:05:09 +0100
committerFrank Reininghaus <[email protected]>2014-02-24 21:05:09 +0100
commit342822e83de4508a7e32bf9c23ee074c2d584d48 (patch)
tree888ec0bf9a09db0d8adb2e23c8e5caf958ff04dc /src/kitemviews
parent0d37038b407944a9b7ec05127b5b6d41dc1a496f (diff)
Make the handling of the "maximum text lines" setting more robust
If the user sets a maximum number of text lines in the settings, this number was translated into a maximum height in pixels using QFontMetrics::lineSpacing() before this commit. In KStandardItemListWidgetInformant::itemSizeHint(), this maximum height limited the size that is reserved for the item. However, in KStandardItemListWidget::updateIconsLayoutTextCache(), the maximum height was translated back into a maximum number of lines, which limits the number of lines that are created using the QTextLayout. This approach could lead to problems if the real height of the layouted text is 1 pixel more or less than QFontMetrics::lineSpacing() times "number of lines". Now we do not store a "maximum height" inside the "maximum size" explicitly, but store a maximum number of lines and a maximum with (for Compact View) separately, and then use the number of lines also to calculate the required size in KStandardItemListWidgetInformant::itemSizeHint(). This should make sure that the correct height is reserved for each item. Thanks to Christoph Feck and Emmanuel Pescosta for helping to debug this problem and testing the patch. BUG: 323841 FIXED-IN: 4.13 REVIEW: 113871
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kitemliststyleoption.cpp6
-rw-r--r--src/kitemviews/kitemliststyleoption.h3
-rw-r--r--src/kitemviews/kitemlistview.cpp3
-rw-r--r--src/kitemviews/kstandarditemlistwidget.cpp19
4 files changed, 17 insertions, 14 deletions
diff --git a/src/kitemviews/kitemliststyleoption.cpp b/src/kitemviews/kitemliststyleoption.cpp
index ac2587962..edd6363c8 100644
--- a/src/kitemviews/kitemliststyleoption.cpp
+++ b/src/kitemviews/kitemliststyleoption.cpp
@@ -31,7 +31,8 @@ KItemListStyleOption::KItemListStyleOption() :
verticalMargin(-1),
iconSize(-1),
extendedSelectionRegion(false),
- maxTextSize()
+ maxTextLines(0),
+ maxTextWidth(0)
{
}
@@ -45,7 +46,8 @@ KItemListStyleOption::KItemListStyleOption(const KItemListStyleOption& other) :
verticalMargin(other.verticalMargin),
iconSize(other.iconSize),
extendedSelectionRegion(other.extendedSelectionRegion),
- maxTextSize(other.maxTextSize)
+ maxTextLines(other.maxTextLines),
+ maxTextWidth(other.maxTextWidth)
{
}
diff --git a/src/kitemviews/kitemliststyleoption.h b/src/kitemviews/kitemliststyleoption.h
index 1a304fc28..782dd0ec2 100644
--- a/src/kitemviews/kitemliststyleoption.h
+++ b/src/kitemviews/kitemliststyleoption.h
@@ -43,7 +43,8 @@ public:
int verticalMargin;
int iconSize;
bool extendedSelectionRegion;
- QSize maxTextSize;
+ int maxTextLines;
+ int maxTextWidth;
};
#endif
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index ab420cab1..f1b35fa53 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -760,7 +760,8 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option)
updateGroupHeaderHeight();
}
- if (animate && previousOption.maxTextSize != option.maxTextSize) {
+ if (animate &&
+ (previousOption.maxTextLines != option.maxTextLines || previousOption.maxTextWidth != option.maxTextWidth)) {
// Animating a change of the maximum text size just results in expensive
// temporary eliding and clipping operations and does not look good visually.
animate = false;
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp
index 9a9a734ed..9f7b26959 100644
--- a/src/kitemviews/kstandarditemlistwidget.cpp
+++ b/src/kitemviews/kstandarditemlistwidget.cpp
@@ -130,7 +130,6 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
const qreal itemWidth = view->itemSize().width();
const qreal maxWidth = itemWidth - 2 * option.padding;
- const qreal maxTextHeight = option.maxTextSize.height();
const qreal additionalRolesSpacing = additionalRolesCount * option.fontMetrics.lineSpacing();
const qreal spacingAndIconHeight = option.iconSize + option.padding * 3;
@@ -150,20 +149,22 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
layout.setTextOption(textOption);
layout.beginLayout();
QTextLine line;
+ int lineCount = 0;
while ((line = layout.createLine()).isValid()) {
line.setLineWidth(maxWidth);
line.naturalTextWidth();
textHeight += line.height();
+
+ ++lineCount;
+ if (lineCount == option.maxTextLines) {
+ break;
+ }
}
layout.endLayout();
// Add one line for each additional information
textHeight += additionalRolesSpacing;
- if (maxTextHeight > 0 && textHeight > maxTextHeight) {
- textHeight = maxTextHeight;
- }
-
sizeHints[index] = QSizeF(itemWidth, textHeight + spacingAndIconHeight);
}
}
@@ -176,7 +177,7 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
const QList<QByteArray>& visibleRoles = view->visibleRoles();
const bool showOnlyTextRole = (visibleRoles.count() == 1) && (visibleRoles.first() == "text");
- const qreal maxWidth = option.maxTextSize.width();
+ const qreal maxWidth = option.maxTextWidth;
const qreal paddingAndIconWidth = option.padding * 4 + option.iconSize;
const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.lineSpacing());
@@ -1066,9 +1067,6 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
qreal nameHeight = 0;
QTextLine line;
- const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
- const int maxNameLines = (option.maxTextSize.height() / int(lineSpacing)) - additionalRolesCount;
-
QTextLayout layout(nameTextInfo->staticText.text(), m_customizedFont);
layout.setTextOption(nameTextInfo->staticText.textOption());
layout.beginLayout();
@@ -1079,7 +1077,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
nameHeight += line.height();
++nameLineIndex;
- if (nameLineIndex == maxNameLines) {
+ if (nameLineIndex == option.maxTextLines) {
// The maximum number of textlines has been reached. If this is
// the case provide an elided text if necessary.
const int textLength = line.textStart() + line.textLength();
@@ -1101,6 +1099,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
layout.endLayout();
// Use one line for each additional information
+ const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
nameTextInfo->staticText.setTextWidth(maxWidth);
nameTextInfo->pos = QPointF(padding, widgetHeight -
nameHeight -