-QHash<QByteArray, qreal> KFileItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const
-{
- QElapsedTimer timer;
- timer.start();
-
- QHash<QByteArray, qreal> widths;
-
- 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()) {
- qreal maxWidth = widths.value(visibleRole, 0);
- const QSizeF itemSize = visibleRoleSizeHint(i, visibleRole);
- maxWidth = qMax(itemSize.width(), maxWidth);
- widths.insert(visibleRole, maxWidth);
- }
-
- 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;
- }
+qreal KFileItemListView::preferredColumnWidth(int index, const QByteArray& role) const
+{
+ const KItemListStyleOption& option = styleOption();
+
+ qreal width = m_minimumRolesWidths.value(role, 0);
+
+ const QHash<QByteArray, QVariant> values = model()->data(index);
+ const QString text = KFileItemListWidget::roleText(role, values);
+ if (!text.isEmpty()) {
+ const qreal columnPadding = option.padding * 3;
+ width = qMax(width, qreal(2 * columnPadding + option.fontMetrics.width(text)));