X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/13dfc7fa2b883eaa88d6b4a03f17690d941008f8..8988fc01d01422e596a8c19d45a3bf6d41581c8b:/src/kitemviews/kstandarditemlistview.cpp diff --git a/src/kitemviews/kstandarditemlistview.cpp b/src/kitemviews/kstandarditemlistview.cpp index 79eb86b89..6edbefad8 100644 --- a/src/kitemviews/kstandarditemlistview.cpp +++ b/src/kitemviews/kstandarditemlistview.cpp @@ -1,28 +1,14 @@ -/*************************************************************************** - * Copyright (C) 2012 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2012 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "kstandarditemlistview.h" -#include -#include #include "kstandarditemlistwidget.h" -#include "kstandarditemlistgroupheader.h" + +#include KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) : KItemListView(parent), @@ -30,7 +16,7 @@ KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) : { setAcceptDrops(true); setScrollOrientation(Qt::Vertical); - setVisibleRoles(QList() << "text"); + setVisibleRoles({"text"}); } KStandardItemListView::~KStandardItemListView() @@ -48,23 +34,8 @@ void KStandardItemListView::setItemLayout(ItemLayout layout) const ItemLayout previous = m_itemLayout; m_itemLayout = layout; - switch (layout) { - case IconsLayout: - setScrollOrientation(Qt::Vertical); - setSupportsItemExpanding(false); - break; - case DetailsLayout: - setScrollOrientation(Qt::Vertical); - setSupportsItemExpanding(true); - break; - case CompactLayout: - setScrollOrientation(Qt::Horizontal); - setSupportsItemExpanding(false); - break; - default: - Q_ASSERT(false); - break; - } + setSupportsItemExpanding(itemLayoutSupportsItemExpanding(layout)); + setScrollOrientation(layout == CompactLayout ? Qt::Horizontal : Qt::Vertical); onItemLayoutChanged(layout, previous); @@ -104,36 +75,42 @@ void KStandardItemListView::initializeItemListWidget(KItemListWidget* item) bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet& changedRoles) const { + // The only thing that can modify the item's size hint is the amount of space + // needed to display the text for the visible roles. // Even if the icons have a different size they are always aligned within // the area defined by KItemStyleOption.iconSize and hence result in no // change of the item-size. - const bool containsIconName = changedRoles.contains("iconName"); - const bool containsIconPixmap = changedRoles.contains("iconPixmap"); - const int count = changedRoles.count(); - - const bool iconChanged = (containsIconName && containsIconPixmap && count == 2) || - (containsIconName && count == 1) || - (containsIconPixmap && count == 1); - return !iconChanged; + const auto roles = visibleRoles(); + for (const QByteArray& role : roles) { + if (changedRoles.contains(role)) { + return true; + } + } + return false; +} + +bool KStandardItemListView::itemLayoutSupportsItemExpanding(ItemLayout layout) const +{ + return layout == DetailsLayout; } void KStandardItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) updateLayoutOfVisibleItems(); } void KStandardItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) updateLayoutOfVisibleItems(); } void KStandardItemListView::onSupportsItemExpandingChanged(bool supportsExpanding) { - Q_UNUSED(supportsExpanding); + Q_UNUSED(supportsExpanding) updateLayoutOfVisibleItems(); } @@ -157,36 +134,29 @@ void KStandardItemListView::applyDefaultStyleOption(int iconSize, { KItemListStyleOption option = styleOption(); - bool changed = false; if (option.iconSize < 0) { option.iconSize = iconSize; - changed = true; } if (option.padding < 0) { option.padding = padding; - changed = true; } if (option.horizontalMargin < 0) { option.horizontalMargin = horizontalMargin; - changed = true; } if (option.verticalMargin < 0) { option.verticalMargin = verticalMargin; - changed = true; } - if (changed) { - setStyleOption(option); - } + setStyleOption(option); } void KStandardItemListView::updateLayoutOfVisibleItems() { if (model()) { - foreach (KItemListWidget* widget, visibleItemListWidgets()) { + const auto widgets = visibleItemListWidgets(); + for (KItemListWidget* widget : widgets) { initializeItemListWidget(widget); } } } -#include "kstandarditemlistview.moc"