- const QHash<QByteArray, QVariant> values = model()->data(index);
- const KItemListStyleOption& option = styleOption();
- const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
-
- switch (m_itemLayout) {
- case IconsLayout: {
- const QString text = KStringHandler::preProcessWrap(values["name"].toString());
-
- const qreal maxWidth = itemSize().width() - 2 * option.padding;
- int textLinesCount = 0;
- QTextLine line;
-
- // Calculate the number of lines required for wrapping the name
- QTextOption textOption(Qt::AlignHCenter);
- textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
-
- QTextLayout layout(text, option.font);
- layout.setTextOption(textOption);
- layout.beginLayout();
- while ((line = layout.createLine()).isValid()) {
- line.setLineWidth(maxWidth);
- line.naturalTextWidth();
- ++textLinesCount;
- }
- layout.endLayout();
-
- // Add one line for each additional information
- textLinesCount += additionalRolesCount;
-
- const qreal height = textLinesCount * option.fontMetrics.height() +
- option.iconSize +
- option.padding * 3;
- return QSizeF(itemSize().width(), height);
- }
-
- case CompactLayout: {
- // For each row exactly one role is shown. Calculate the maximum required width that is necessary
- // to show all roles without horizontal clipping.
- qreal maximumRequiredWidth = 0.0;
-
- foreach (const QByteArray& role, visibleRoles()) {
- const QString text = KFileItemListWidget::roleText(role, values);
- const qreal requiredWidth = option.fontMetrics.width(text);
- maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
- }
-
- const qreal width = option.padding * 4 + option.iconSize + maximumRequiredWidth;
- const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.height());
- return QSizeF(width, height);
- }
-
- case DetailsLayout: {
- // The width will be determined dynamically by KFileItemListView::visibleRoleSizes()
- const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
- return QSizeF(-1, height);
- }
-
- default:
- Q_ASSERT(false);
- break;
- }
-
- return QSize();
-}
-
-QHash<QByteArray, QSizeF> KFileItemListView::visibleRolesSizes(const KItemRangeList& itemRanges) const
-{
- QElapsedTimer timer;
- timer.start();
-
- QHash<QByteArray, QSizeF> sizes;
-
- int calculatedItemCount = 0;
- bool maxTimeExceeded = false;
- foreach (const KItemRange& itemRange, itemRanges) {
- const int startIndex = itemRange.index;
- const int endIndex = startIndex + itemRange.count - 1;
-
- for (int i = startIndex; i <= endIndex; ++i) {
- foreach (const QByteArray& visibleRole, visibleRoles()) {
- QSizeF maxSize = sizes.value(visibleRole, QSizeF(0, 0));
- const QSizeF itemSize = visibleRoleSizeHint(i, visibleRole);
- maxSize = maxSize.expandedTo(itemSize);
- sizes.insert(visibleRole, maxSize);
- }
-
- if (calculatedItemCount > 100 && timer.elapsed() > 200) {
- // When having several thousands of items calculating the sizes can get
- // very expensive. We accept a possibly too small role-size in favour
- // of having no blocking user interface.
- #ifdef KFILEITEMLISTVIEW_DEBUG
- kDebug() << "Timer exceeded, stopped after" << calculatedItemCount << "items";
- #endif
- maxTimeExceeded = true;
- break;
- }
- ++calculatedItemCount;
- }
- if (maxTimeExceeded) {
- break;
- }
- }
-
-#ifdef KFILEITEMLISTVIEW_DEBUG
- int rangesItemCount = 0;
- foreach (const KItemRange& itemRange, itemRanges) {
- rangesItemCount += itemRange.count;