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
verticalMargin(-1),
iconSize(-1),
extendedSelectionRegion(false),
verticalMargin(-1),
iconSize(-1),
extendedSelectionRegion(false),
+ maxTextLines(0),
+ maxTextWidth(0)
verticalMargin(other.verticalMargin),
iconSize(other.iconSize),
extendedSelectionRegion(other.extendedSelectionRegion),
verticalMargin(other.verticalMargin),
iconSize(other.iconSize),
extendedSelectionRegion(other.extendedSelectionRegion),
- maxTextSize(other.maxTextSize)
+ maxTextLines(other.maxTextLines),
+ maxTextWidth(other.maxTextWidth)
int verticalMargin;
int iconSize;
bool extendedSelectionRegion;
int verticalMargin;
int iconSize;
bool extendedSelectionRegion;
+ int maxTextLines;
+ int maxTextWidth;
updateGroupHeaderHeight();
}
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;
// 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;
const qreal itemWidth = view->itemSize().width();
const qreal maxWidth = itemWidth - 2 * option.padding;
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;
const qreal additionalRolesSpacing = additionalRolesCount * option.fontMetrics.lineSpacing();
const qreal spacingAndIconHeight = option.iconSize + option.padding * 3;
layout.setTextOption(textOption);
layout.beginLayout();
QTextLine line;
layout.setTextOption(textOption);
layout.beginLayout();
QTextLine line;
while ((line = layout.createLine()).isValid()) {
line.setLineWidth(maxWidth);
line.naturalTextWidth();
textHeight += line.height();
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;
}
layout.endLayout();
// Add one line for each additional information
textHeight += additionalRolesSpacing;
- if (maxTextHeight > 0 && textHeight > maxTextHeight) {
- textHeight = maxTextHeight;
- }
-
sizeHints[index] = QSizeF(itemWidth, textHeight + spacingAndIconHeight);
}
}
sizeHints[index] = QSizeF(itemWidth, textHeight + spacingAndIconHeight);
}
}
const QList<QByteArray>& visibleRoles = view->visibleRoles();
const bool showOnlyTextRole = (visibleRoles.count() == 1) && (visibleRoles.first() == "text");
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());
const qreal paddingAndIconWidth = option.padding * 4 + option.iconSize;
const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.lineSpacing());
qreal nameHeight = 0;
QTextLine line;
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();
QTextLayout layout(nameTextInfo->staticText.text(), m_customizedFont);
layout.setTextOption(nameTextInfo->staticText.textOption());
layout.beginLayout();
nameHeight += line.height();
++nameLineIndex;
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();
// 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();
layout.endLayout();
// Use one line for each additional information
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 -
nameTextInfo->staticText.setTextWidth(maxWidth);
nameTextInfo->pos = QPointF(padding, widgetHeight -
nameHeight -
// Calculate the item-width and item-height
int itemWidth;
int itemHeight;
// Calculate the item-width and item-height
int itemWidth;
int itemHeight;
+ int maxTextLines = 0;
+ int maxTextWidth = 0;
switch (itemLayout()) {
case KFileItemListView::IconsLayout: {
switch (itemLayout()) {
case KFileItemListView::IconsLayout: {
}
itemHeight = padding * 3 + iconSize + option.fontMetrics.lineSpacing();
}
itemHeight = padding * 3 + iconSize + option.fontMetrics.lineSpacing();
- if (IconsModeSettings::maximumTextLines() > 0) {
- // A restriction is given for the maximum number of textlines (0 means
- // having no restriction)
- const int additionalInfoCount = visibleRoles().count() - 1;
- const int maxAdditionalLines = additionalInfoCount + IconsModeSettings::maximumTextLines();
- maxTextSize.rheight() = option.fontMetrics.lineSpacing() * maxAdditionalLines;
- }
horizontalMargin = 4;
verticalMargin = 8;
horizontalMargin = 4;
verticalMargin = 8;
+ maxTextLines = IconsModeSettings::maximumTextLines();
break;
}
case KFileItemListView::CompactLayout: {
break;
}
case KFileItemListView::CompactLayout: {
if (CompactModeSettings::maximumTextWidthIndex() > 0) {
// A restriction is given for the maximum width of the text (0 means
// having no restriction)
if (CompactModeSettings::maximumTextWidthIndex() > 0) {
// A restriction is given for the maximum width of the text (0 means
// having no restriction)
- maxTextSize.rwidth() = option.fontMetrics.height() * 10 *
- CompactModeSettings::maximumTextWidthIndex();
+ maxTextWidth = option.fontMetrics.height() * 10 * CompactModeSettings::maximumTextWidthIndex();
option.horizontalMargin = horizontalMargin;
option.verticalMargin = verticalMargin;
option.iconSize = iconSize;
option.horizontalMargin = horizontalMargin;
option.verticalMargin = verticalMargin;
option.iconSize = iconSize;
- option.maxTextSize = maxTextSize;
+ option.maxTextLines = maxTextLines;
+ option.maxTextWidth = maxTextWidth;
beginTransaction();
setStyleOption(option);
setItemSize(QSizeF(itemWidth, itemHeight));
beginTransaction();
setStyleOption(option);
setItemSize(QSizeF(itemWidth, itemHeight));