X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fa988586bc923b33497cbc97aaac07fc93a4ca83..ca0d0bb322925e2119f13f76d8e9643d24cbf3e0:/src/views/dolphinitemlistview.cpp diff --git a/src/views/dolphinitemlistview.cpp b/src/views/dolphinitemlistview.cpp index 60c8bb97c..5a6987f65 100644 --- a/src/views/dolphinitemlistview.cpp +++ b/src/views/dolphinitemlistview.cpp @@ -1,40 +1,25 @@ -/*************************************************************************** - * Copyright (C) 2011 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: 2011 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "dolphinitemlistview.h" +#include "dolphin_compactmodesettings.h" +#include "dolphin_detailsmodesettings.h" #include "dolphin_generalsettings.h" #include "dolphin_iconsmodesettings.h" -#include "dolphin_detailsmodesettings.h" -#include "dolphin_compactmodesettings.h" #include "dolphinfileitemlistwidget.h" - -#include -#include -#include -#include - - -#include - +#include "kitemviews/kfileitemmodel.h" +#include "kitemviews/kitemlistcontroller.h" +#include "settings/viewmodes/viewmodesettings.h" +#include "views/viewmodecontroller.h" #include "zoomlevelinfo.h" +#include +#include + DolphinItemListView::DolphinItemListView(QGraphicsWidget* parent) : KFileItemListView(parent), @@ -63,7 +48,7 @@ void DolphinItemListView::setZoomLevel(int level) m_zoomLevel = level; - ViewModeSettings settings(viewMode()); + ViewModeSettings settings(itemLayout()); if (previewsShown()) { const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(level); settings.setPreviewSize(previewSize); @@ -82,24 +67,21 @@ int DolphinItemListView::zoomLevel() const void DolphinItemListView::readSettings() { - ViewModeSettings settings(viewMode()); + ViewModeSettings settings(itemLayout()); settings.readConfig(); beginTransaction(); setEnabledSelectionToggles(GeneralSettings::showSelectionToggle()); + setHighlightEntireRow(DetailsModeSettings::sidePadding()); setSupportsItemExpanding(itemLayoutSupportsItemExpanding(itemLayout())); updateFont(); updateGridSize(); const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings"); - const QStringList plugins = globalConfig.readEntry("Plugins", QStringList() - << "directorythumbnail" - << "imagethumbnail" - << "jpegthumbnail"); - setEnabledPlugins(plugins); - + setEnabledPlugins(globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins())); + setLocalFileSizePreviewLimit(globalConfig.readEntry("MaximumSize", 0)); endTransaction(); } @@ -132,7 +114,7 @@ void DolphinItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout pre void DolphinItemListView::onPreviewsShownChanged(bool shown) { - Q_UNUSED(shown); + Q_UNUSED(shown) updateGridSize(); } @@ -145,7 +127,7 @@ void DolphinItemListView::onVisibleRolesChanged(const QList& current void DolphinItemListView::updateFont() { - const ViewModeSettings settings(viewMode()); + const ViewModeSettings settings(itemLayout()); if (settings.useSystemFont()) { KItemListView::updateFont(); @@ -165,7 +147,7 @@ void DolphinItemListView::updateFont() void DolphinItemListView::updateGridSize() { - const ViewModeSettings settings(viewMode()); + const ViewModeSettings settings(itemLayout()); // Calculate the size of the icon const int iconSize = previewsShown() ? settings.previewSize() : settings.iconSize(); @@ -184,19 +166,16 @@ void DolphinItemListView::updateGridSize() switch (itemLayout()) { case KFileItemListView::IconsLayout: { - const int minItemWidth = 48; - itemWidth = minItemWidth + IconsModeSettings::textWidthIndex() * 64; - - if (previewsShown()) { - // Optimize the width for previews with a 3:2 aspect ratio instead - // of a 1:1 ratio to avoid wasting too much vertical space when - // showing photos. - const int minWidth = iconSize * 3 / 2; - itemWidth = qMax(itemWidth, minWidth); - } - if (itemWidth < iconSize + padding * 2) { - itemWidth = iconSize + padding * 2; + // an exponential factor based on zoom, 0 -> 1, 4 -> 1.36 8 -> ~1.85, 16 -> 3.4 + auto zoomFactor = qExp(m_zoomLevel / 13.0); + // 9 is the average char width for 10pt Noto Sans, making fontFactor =1 + // by each pixel the font gets larger the factor increases by 1/9 + auto fontFactor = option.fontMetrics.averageCharWidth() / 9.0; + itemWidth = 48 + IconsModeSettings::textWidthIndex() * 64 * fontFactor * zoomFactor; + + if (itemWidth < iconSize + padding * 2 * zoomFactor) { + itemWidth = iconSize + padding * 2 * zoomFactor; } itemHeight = padding * 3 + iconSize + option.fontMetrics.lineSpacing(); @@ -244,20 +223,3 @@ void DolphinItemListView::updateGridSize() setItemSize(QSizeF(itemWidth, itemHeight)); endTransaction(); } - -ViewModeSettings::ViewMode DolphinItemListView::viewMode() const -{ - ViewModeSettings::ViewMode mode; - - switch (itemLayout()) { - case KFileItemListView::IconsLayout: mode = ViewModeSettings::IconsMode; break; - case KFileItemListView::CompactLayout: mode = ViewModeSettings::CompactMode; break; - case KFileItemListView::DetailsLayout: mode = ViewModeSettings::DetailsMode; break; - default: mode = ViewModeSettings::IconsMode; - Q_ASSERT(false); - break; - } - - return mode; -} -