]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemlistview.cpp
Output of licensedigger + manual cleanup afterwards.
[dolphin.git] / src / kitemviews / kfileitemlistview.cpp
index 933518a699d06278fea01dc6f4f48b815c3bbb33..73d6c72e9b5579b83f5fb6c5c6c4fc78c03941b4 100644 (file)
@@ -1,61 +1,43 @@
-/***************************************************************************
- *   Copyright (C) 2011 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: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "kfileitemlistview.h"
 
-#include "kfileitemmodelrolesupdater.h"
 #include "kfileitemlistwidget.h"
 #include "kfileitemmodel.h"
-#include <KLocale>
-#include <KStringHandler>
+#include "kfileitemmodelrolesupdater.h"
 #include "private/kpixmapmodifier.h"
 
-#include <KDebug>
-#include <KIcon>
-#include <KTextEdit>
 #include <KIconLoader>
-#include <KDateTime>
 
+#include <QGraphicsScene>
+#include <QGraphicsView>
 #include <QPainter>
-#include <QTextLine>
 #include <QTimer>
 
 // #define KFILEITEMLISTVIEW_DEBUG
 
 namespace {
     // If the visible index range changes, KFileItemModelRolesUpdater is not
-    // informed immediatetly, but with a short delay. This ensures that scrolling
+    // informed immediately, but with a short delay. This ensures that scrolling
     // always feels smooth and is not interrupted by icon loading (which can be
     // quite expensive if a disk access is required to determine the final icon).
     const int ShortInterval = 50;
 
     // If the icon size changes, a longer delay is used. This prevents that
     // the expensive re-generation of all previews is triggered repeatedly when
-    // chaning the zoom level.
+    // changing the zoom level.
     const int LongInterval = 300;
 }
 
 KFileItemListView::KFileItemListView(QGraphicsWidget* parent) :
     KStandardItemListView(parent),
-    m_modelRolesUpdater(0),
-    m_updateVisibleIndexRangeTimer(0),
-    m_updateIconSizeTimer(0)
+    m_modelRolesUpdater(nullptr),
+    m_updateVisibleIndexRangeTimer(nullptr),
+    m_updateIconSizeTimer(nullptr)
 {
     setAcceptDrops(true);
 
@@ -71,7 +53,7 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) :
     m_updateIconSizeTimer->setInterval(LongInterval);
     connect(m_updateIconSizeTimer, &QTimer::timeout, this, &KFileItemListView::updateIconSize);
 
-    setVisibleRoles(QList<QByteArray>() << "text");
+    setVisibleRoles({"text"});
 }
 
 KFileItemListView::~KFileItemListView()
@@ -121,6 +103,18 @@ QStringList KFileItemListView::enabledPlugins() const
     return m_modelRolesUpdater ? m_modelRolesUpdater->enabledPlugins() : QStringList();
 }
 
+void KFileItemListView::setLocalFileSizePreviewLimit(const qlonglong size)
+{
+    if (m_modelRolesUpdater) {
+        m_modelRolesUpdater->setLocalFileSizePreviewLimit(size);
+    }
+}
+
+qlonglong KFileItemListView::localFileSizePreviewLimit() const
+{
+    return m_modelRolesUpdater ? m_modelRolesUpdater->localFileSizePreviewLimit() : 0;
+}
+
 QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
 {
     if (!model()) {
@@ -160,21 +154,23 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
         yCount = xCount;
     }
 
+    const qreal dpr = scene()->views()[0]->devicePixelRatio();
     // Draw the selected items into the grid cells.
-    QPixmap dragPixmap(xCount * size + xCount, yCount * size + yCount);
+    QPixmap dragPixmap(QSize(xCount * size + xCount, yCount * size + yCount) * dpr);
+    dragPixmap.setDevicePixelRatio(dpr);
     dragPixmap.fill(Qt::transparent);
 
     QPainter painter(&dragPixmap);
     int x = 0;
     int y = 0;
 
-    foreach (int index, indexes) {
+    for (int index : indexes) {
         QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
         if (pixmap.isNull()) {
-            KIcon icon(model()->data(index).value("iconName").toString());
+            QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString());
             pixmap = icon.pixmap(size, size);
         } else {
-            KPixmapModifier::scale(pixmap, QSize(size, size));
+            KPixmapModifier::scale(pixmap, QSize(size, size) * dpr);
         }
 
         painter.drawPixmap(x, y, pixmap);
@@ -210,13 +206,13 @@ void KFileItemListView::initializeItemListWidget(KItemListWidget* item)
 
         const KFileItem fileItem = fileItemModel->fileItem(item->index());
         data.insert("iconName", fileItem.iconName());
-        item->setData(data, QSet<QByteArray>() << "iconName");
+        item->setData(data, {"iconName"});
     }
 }
 
 void KFileItemListView::onPreviewsShownChanged(bool shown)
 {
-    Q_UNUSED(shown);
+    Q_UNUSED(shown)
 }
 
 void KFileItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous)
@@ -231,7 +227,7 @@ void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase*
     KStandardItemListView::onModelChanged(current, previous);
 
     delete m_modelRolesUpdater;
-    m_modelRolesUpdater = 0;
+    m_modelRolesUpdater = nullptr;
 
     if (current) {
         m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this);
@@ -249,8 +245,8 @@ void KFileItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::
 
 void KFileItemListView::onItemSizeChanged(const QSizeF& current, const QSizeF& previous)
 {
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     triggerVisibleIndexRangeUpdate();
 }
 
@@ -398,6 +394,7 @@ void KFileItemListView::applyRolesToModel()
     roles.insert("text");
     roles.insert("isDir");
     roles.insert("isLink");
+    roles.insert("isHidden");
     if (supportsItemExpanding()) {
         roles.insert("isExpanded");
         roles.insert("isExpandable");
@@ -423,4 +420,3 @@ QSize KFileItemListView::availableIconSize() const
     return QSize(iconSize, iconSize);
 }
 
-#include "kfileitemlistview.moc"