From cbf83085bed04638833eab52e39cf61a9f2c42a6 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Mon, 23 Apr 2012 00:23:45 +0200 Subject: [PATCH] Details mode: Fix wrong required column-width calculation BUG: 298577 FIXED-IN: 4.9.0 --- src/kitemviews/kitemlistview.cpp | 11 ++++++++++- src/kitemviews/kstandarditemlistwidget.cpp | 15 +++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index ae86b2842..6d2d98e93 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -693,6 +693,10 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option) m_layouter->markAsDirty(); doLayout(animate ? Animation : NoAnimation); + if (m_itemSize.isEmpty()) { + updatePreferredColumnWidths(); + } + onStyleOptionChanged(option, previousOption); } @@ -1461,6 +1465,11 @@ void KItemListView::setModel(KItemModelBase* model) this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder))); connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)), this, SLOT(slotSortRoleChanged(QByteArray,QByteArray))); + + const int itemCount = m_model->count(); + if (itemCount > 0) { + slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount)); + } } onModelChanged(model, previous); @@ -2130,7 +2139,7 @@ void KItemListView::applyAutomaticColumnWidths() // Stretch the first column to use the whole remaining width firstColumnWidth += availableWidth - requiredWidth; m_headerWidget->setColumnWidth(firstRole, firstColumnWidth); - } else if (requiredWidth > availableWidth) { + } else if (requiredWidth > availableWidth && m_visibleRoles.count() > 1) { // Shrink the first column to be able to show as much other // columns as possible qreal shrinkedFirstColumnWidth = firstColumnWidth - requiredWidth + availableWidth; diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 996d0cb58..43df72f95 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -43,7 +43,7 @@ #include #include -// #define KFILEITEMLISTWIDGET_DEBUG +// #define KSTANDARDITEMLISTWIDGET_DEBUG KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() : KItemListWidgetInformant() @@ -143,9 +143,12 @@ qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArra width += option.fontMetrics.width(text); if (role == "text") { - // Increase the width by the expansion-toggle and the current expansion level - const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); - width += option.padding + (expandedParentsCount + 1) * view->itemSize().height() + KIconLoader::SizeSmall; + if (view->supportsItemExpanding()) { + // Increase the width by the expansion-toggle and the current expansion level + const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); + const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height()); + width += (expandedParentsCount + 1) * height; + } // Increase the width by the required space for the icon width += option.padding * 2 + option.iconSize; @@ -295,7 +298,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic painter->restore(); } -#ifdef KFILEITEMLISTWIDGET_DEBUG +#ifdef KSTANDARDITEMLISTWIDGET_DEBUG painter->setBrush(Qt::NoBrush); painter->setPen(Qt::green); painter->drawRect(m_iconRect); @@ -1130,7 +1133,7 @@ void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixma KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize); painter->drawPixmap(m_pixmapPos, scaledPixmap); -#ifdef KFILEITEMLISTWIDGET_DEBUG +#ifdef KSTANDARDITEMLISTWIDGET_DEBUG painter->setPen(Qt::blue); painter->drawRect(QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize))); #endif -- 2.47.3