[dolphin] /: Add Reset Zoom Level action inside View menu

Nate Graham null at kde.org
Tue Sep 10 14:09:39 BST 2019


Git commit 7165ea7afdf150600025f9c8ec28dadfe0b28406 by Nate Graham.
Committed on 10/09/2019 at 13:09.
Pushed by ngraham into branch 'master'.

Add Reset Zoom Level action inside View menu

Summary:
FEATURE: 409591
FIXED-IN: 19.12.0

Test Plan: {F7096397}

Reviewers: elvisangelaccio, shubham, #dolphin

Reviewed By: elvisangelaccio, #dolphin

Subscribers: broulik, cfeck, kfm-devel, kde-doc-english

Tags: #dolphin, #documentation

Differential Revision: https://phabricator.kde.org/D22444

M  +11   -0    doc/index.docbook
M  +1    -0    src/dolphinmainwindow.cpp
M  +6    -1    src/dolphinui.rc
M  +15   -0    src/views/dolphinview.cpp
M  +5    -0    src/views/dolphinview.h
M  +15   -1    src/views/dolphinviewactionhandler.cpp
M  +3    -0    src/views/dolphinviewactionhandler.h

https://commits.kde.org/dolphin/7165ea7afdf150600025f9c8ec28dadfe0b28406

diff --git a/doc/index.docbook b/doc/index.docbook
index f2b5c70a37..d5363f2c50 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -1758,6 +1758,17 @@ Selects all unselected items and deselects all selected items in the current fol
 <listitem><para><action>Decreases the size of icons in the view.</action></para></listitem>
 </varlistentry>
 
+<varlistentry>
+<term><menuchoice>
+<shortcut>
+<keycombo action="simul">&Ctrl;<keycap>0</keycap></keycombo>
+</shortcut>
+<guimenu>View</guimenu>
+<guimenuitem>Zoom Reset</guimenuitem>
+</menuchoice></term>
+<listitem><para><action>Resets the size of icons in the view to default.</action></para></listitem>
+</varlistentry>
+
 <varlistentry>
 <term><menuchoice>
 <guimenu>View</guimenu>
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 87d041b873..ec42d33f71 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -1016,6 +1016,7 @@ void DolphinMainWindow::updateControlMenu()
     // Add "View" actions
     if (!GeneralSettings::showZoomSlider()) {
         addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
+        addActionToMenu(ac->action(QStringLiteral("view_zoom_reset")), menu);
         addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
         menu->addSeparator();
     }
diff --git a/src/dolphinui.rc b/src/dolphinui.rc
index 754670a7ef..d52e64edb7 100644
--- a/src/dolphinui.rc
+++ b/src/dolphinui.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="25">
+<kpartgui name="dolphin" version="26">
     <MenuBar>
         <Menu name="file">
             <Action name="new_menu" />
@@ -23,6 +23,10 @@
             <Action name="invert_selection" />
         </Menu>
         <Menu name="view">
+            <Action name="view_zoom_in"/>
+            <Action name="view_zoom_reset"/>
+            <Action name="view_zoom_out"/>
+            <Separator/>
             <Action name="sort" />
             <Action name="view_mode" />
             <Action name="additional_info" />
@@ -116,6 +120,7 @@
         <Action priority="0" name="compact"/>
         <Action priority="0" name="details"/>
         <Action priority="0" name="view_zoom_in"/>
+        <Action priority="0" name="view_zoom_reset"/>
         <Action priority="0" name="view_zoom_out"/>
         <Action priority="0" name="edit_cut"/>
         <Action priority="0" name="edit_copy"/>
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index e6b232dcc1..3597a2aa44 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -66,6 +66,7 @@
 #include <QPixmapCache>
 #include <QPointer>
 #include <QScrollBar>
+#include <QSize>
 #include <QTimer>
 #include <QVBoxLayout>
 
@@ -1338,6 +1339,20 @@ QUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh
     return QUrl();
 }
 
+void DolphinView::resetZoomLevel()
+{
+    ViewModeSettings::ViewMode mode;
+
+    switch (m_mode) {
+    case IconsView:     mode = ViewModeSettings::IconsMode;   break;
+    case CompactView:   mode = ViewModeSettings::CompactMode; break;
+    case DetailsView:   mode = ViewModeSettings::DetailsMode; break;
+    }
+    const ViewModeSettings settings(mode);
+    const QSize iconSize = QSize(settings.iconSize(), settings.iconSize());
+    setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize));
+}
+
 void DolphinView::observeCreatedItem(const QUrl& url)
 {
     if (m_active) {
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index a4da92f2db..ba38d32347 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -196,6 +196,11 @@ public:
     void setZoomLevel(int level);
     int zoomLevel() const;
 
+    /**
+     * Resets the view's icon size to the default value
+     */
+    void resetZoomLevel();
+
     void setSortRole(const QByteArray& role);
     QByteArray sortRole() const;
 
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index 4aa59911be..a520d7e530 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -188,6 +188,14 @@ void DolphinViewActionHandler::createActions()
                             m_actionCollection);
     zoomInAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
 
+    QAction* zoomResetAction = m_actionCollection->addAction(QStringLiteral("view_zoom_reset"));
+    zoomResetAction->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
+    zoomResetAction->setToolTip(i18n("Zoom To Default"));
+    zoomResetAction->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
+    zoomResetAction->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
+    m_actionCollection->setDefaultShortcuts(zoomResetAction, {Qt::CTRL + Qt::Key_0});
+    connect(zoomResetAction, &QAction::triggered, this, &DolphinViewActionHandler::zoomReset);
+
     QAction* zoomOutAction = KStandardAction::zoomOut(this,
                              &DolphinViewActionHandler::zoomOut,
                              m_actionCollection);
@@ -391,7 +399,7 @@ void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
 {
     Q_UNUSED(shown);
     // It is not enough to update the 'Show Preview' action, also
-    // the 'Zoom In' and 'Zoom Out' actions must be adapted.
+    // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
     updateViewActions();
 }
 
@@ -454,6 +462,12 @@ void DolphinViewActionHandler::zoomOut()
     updateViewActions();
 }
 
+void DolphinViewActionHandler::zoomReset()
+{
+    m_currentView->resetZoomLevel();
+    updateViewActions();
+}
+
 void DolphinViewActionHandler::toggleSortFoldersFirst()
 {
     const bool sortFirst = m_currentView->sortFoldersFirst();
diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h
index 7d675b7d49..f931b3b9c5 100644
--- a/src/views/dolphinviewactionhandler.h
+++ b/src/views/dolphinviewactionhandler.h
@@ -131,6 +131,9 @@ private Q_SLOTS:
 
     /** Decreases the size of the current set view mode. */
     void zoomOut();
+    
+    /** Resets the size of the current set view mode to default. */
+    void zoomReset();
 
     /** Switches between a separate sorting and a mixed sorting of files and folders. */
     void toggleSortFoldersFirst();


More information about the kde-doc-english mailing list