diff --git a/src/filewidgets/kdiroperator.cpp b/src/filewidgets/kdiroperator.cpp --- a/src/filewidgets/kdiroperator.cpp +++ b/src/filewidgets/kdiroperator.cpp @@ -229,6 +229,7 @@ void _k_slotDirectoryCreated(const QUrl &); void updateListViewGrid(); + void updateIconPreviewsState(); int iconSizeForViewType(QAbstractItemView *itemView) const; // private members @@ -282,6 +283,9 @@ KFilePreviewGenerator *previewGenerator; bool showPreviews; + bool calledByPreviewStateUpdate; + bool showPreviewsEnabledBeforeZoom; + int iconsZoom; bool isSaving; @@ -316,6 +320,8 @@ configGroup(nullptr), previewGenerator(nullptr), showPreviews(false), + calledByPreviewStateUpdate(false), + showPreviewsEnabledBeforeZoom(false), iconsZoom(0), isSaving(false), decorationMenu(nullptr), @@ -654,6 +660,10 @@ showPreviews = show; + if (!calledByPreviewStateUpdate) { + showPreviewsEnabledBeforeZoom = show; + } + if (!previewGenerator) { return; } @@ -1633,6 +1643,9 @@ d->previewGenerator->setPreviewShown(previewShown); d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); + // set grid and previews + d->updateListViewGrid(); + // ensure we change everything needed d->_k_slotChangeDecorationPosition(); @@ -2115,7 +2128,7 @@ // DefaultMixDirsAndFiles)) { // d->defaultView |= KFile::SeparateDirs; //} - if (configGroup.readEntry(QStringLiteral("Show Preview"), false)) { + if (configGroup.readEntry(QStringLiteral("Show Preview"), true)) { d->defaultView |= KFile::PreviewContents; } @@ -2150,6 +2163,7 @@ if (d->inlinePreviewState == Private::NotForced) { d->showPreviews = configGroup.readEntry(QStringLiteral("Previews"), false); + d->showPreviewsEnabledBeforeZoom = d->showPreviews; } QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Left); setDecorationPosition(pos); @@ -2213,7 +2227,7 @@ configGroup.writeEntry(QStringLiteral("View Style"), style); if (d->inlinePreviewState == Private::NotForced) { - configGroup.writeEntry(QStringLiteral("Previews"), d->showPreviews); + configGroup.writeEntry(QStringLiteral("Previews"), d->showPreviewsEnabledBeforeZoom); if (qobject_cast(d->itemView)) { configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); } else { @@ -2561,12 +2575,39 @@ completeListDirty = true; } +void KDirOperator::Private::updateIconPreviewsState() +{ + if (!itemView) { + return; + } + + const QFontMetrics metrics(itemView->viewport()->font()); + + // hide icon previews when they are too small + const bool shouldShowInlinePreview = itemView->iconSize().height() > metrics.height() * 2; + + if (showPreviews && shouldShowInlinePreview) { + showPreviewsEnabledBeforeZoom = true; + } + + KToggleAction *previewAction = static_cast(actionCollection->action(QStringLiteral("inline preview"))); + previewAction->setEnabled(shouldShowInlinePreview); + + calledByPreviewStateUpdate = true; + previewAction->setChecked(shouldShowInlinePreview && showPreviewsEnabledBeforeZoom); + calledByPreviewStateUpdate = false; +} + void KDirOperator::Private::updateListViewGrid() { if (!itemView) { return; } + updateIconPreviewsState(); + + const QFontMetrics metrics(itemView->viewport()->font()); + QListView *view = qobject_cast(itemView); if (!view) { @@ -2582,7 +2623,6 @@ delegate->setMaximumSize(QSize()); } } else { - const QFontMetrics metrics(itemView->viewport()->font()); int size = itemView->iconSize().height() + metrics.height() * 2; // some heuristics for good looking. let's guess width = height * (3 / 2) is nice view->setGridSize(QSize(size * (3.0 / 2.0), size + metrics.height()));