From: Peter Penz Date: Tue, 30 Dec 2008 14:32:45 +0000 (+0000) Subject: optimize the grid size of the icons view to prevent having gaps on the right border... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/5194a032ac75194c67199a8dc2c0edc526f04df1 optimize the grid size of the icons view to prevent having gaps on the right border (= row arrangement) or on the bottom border (= column arrangement) svn path=/trunk/KDE/kdebase/apps/; revision=903417 --- diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index d30ef321e..6af32da9b 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -56,7 +56,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle setLayoutDirection(Qt::LeftToRight); setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); - setSpacing(KDialog::spacingHint()); setMovement(QListView::Static); setDragEnabled(true); setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -323,6 +322,13 @@ void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIn } } +void DolphinIconsView::resizeEvent(QResizeEvent* event) +{ + KCategorizedView::resizeEvent(event); + const DolphinView* view = m_controller->dolphinView(); + updateGridSize(view->showPreview(), view->additionalInfo().count()); +} + void DolphinIconsView::slotShowPreviewChanged() { const DolphinView* view = m_controller->dolphinView(); @@ -396,7 +402,8 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) Q_ASSERT(additionalInfoCount >= 0); itemHeight += additionalInfoCount * m_font.pointSize() * 2; - if (settings->arrangement() == QListView::TopToBottom) { + const bool rowArrangement = (settings->arrangement() == QListView::TopToBottom); + if (rowArrangement) { // The decoration width indirectly defines the maximum // width for the text wrapping. To use the maximum item width // for text wrapping, it is used as decoration width. @@ -409,8 +416,27 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) m_itemSize = QSize(itemWidth, itemHeight); + // optimize the spacing of the grid in a way to prevent large gaps on the + // right border (= row arrangement) or the bottom border (= column arrangement) const int spacing = settings->gridSpacing(); - setGridSize(QSize(itemWidth + spacing * 2, itemHeight + spacing)); + int gridWidth = itemWidth + spacing * 2; + int gridHeight = itemHeight + spacing; + if (rowArrangement) { + const int contentWidth = viewport()->width() - 1 - + style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, horizontalScrollBar()); + const int horizItemCount = contentWidth / gridWidth; + if (horizItemCount > 0) { + gridWidth += (contentWidth - horizItemCount * gridWidth) / horizItemCount; + } + } else { + const int contentHeight = viewport()->height() - 1 - + style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar()); + const int vertItemCount = contentHeight / gridHeight; + if (vertItemCount > 0) { + gridHeight += (contentHeight - vertItemCount * gridHeight) / vertItemCount; + } + } + setGridSize(QSize(gridWidth, gridHeight)); KFileItemDelegate* delegate = dynamic_cast(itemDelegate()); if (delegate != 0) { diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 28d0830fe..cc21e9aad 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -68,6 +68,7 @@ protected: virtual void showEvent(QShowEvent* event); virtual void leaveEvent(QEvent* event); virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); + virtual void resizeEvent(QResizeEvent* event); private slots: void slotShowPreviewChanged();