]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistview.cpp
Merge branch 'release/22.04'
[dolphin.git] / src / kitemviews / kstandarditemlistview.cpp
index 00f111053c6d0dc2c14d6f15c8483168345e5c9a..4b7c2d9a42ac84224fd23d55e47aa448fa8faae9 100644 (file)
@@ -1,27 +1,15 @@
-/***************************************************************************
- *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   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 <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "kstandarditemlistview.h"
 
-#include <KIconLoader>
 #include "kstandarditemlistwidget.h"
 
+#include <KIconLoader>
+
 KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) :
     KItemListView(parent),
     m_itemLayout(DetailsLayout)
@@ -29,6 +17,7 @@ KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) :
     setAcceptDrops(true);
     setScrollOrientation(Qt::Vertical);
     setVisibleRoles({"text"});
+    setAlternateBackgrounds(true);
 }
 
 KStandardItemListView::~KStandardItemListView()
@@ -46,6 +35,8 @@ void KStandardItemListView::setItemLayout(ItemLayout layout)
     const ItemLayout previous = m_itemLayout;
     m_itemLayout = layout;
 
+    // keep the leading padding option unchanged here
+    setHighlightEntireRow(layout == DetailsLayout);
     setSupportsItemExpanding(itemLayoutSupportsItemExpanding(layout));
     setScrollOrientation(layout == CompactLayout ? Qt::Horizontal : Qt::Vertical);
 
@@ -81,6 +72,7 @@ void KStandardItemListView::initializeItemListWidget(KItemListWidget* item)
     default:            Q_ASSERT(false); break;
     }
 
+    standardItemListWidget->setHighlightEntireRow(highlightEntireRow());
     standardItemListWidget->setSupportsItemExpanding(supportsItemExpanding());
 }
 
@@ -92,7 +84,8 @@ bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& c
     // 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.
-    foreach (const QByteArray& role, visibleRoles()) {
+    const auto roles = visibleRoles();
+    for (const QByteArray& role : roles) {
         if (changedRoles.contains(role)) {
             return true;
         }
@@ -107,21 +100,21 @@ bool KStandardItemListView::itemLayoutSupportsItemExpanding(ItemLayout layout) c
 
 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();
 }
 
@@ -145,33 +138,27 @@ 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);
         }
     }