]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Add Reset Zoom Level action inside View menu
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 27321f63a6b2ede7d578272aeee194674c4605a3..a520d7e5303c5e1ba3f5e9e49dc388d084058dad 100644 (file)
@@ -188,10 +188,18 @@ 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);
-    zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This reduces the icon size."));
+    zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
 
     KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
     showPreview->setText(i18nc("@action:intoolbar", "Preview"));
@@ -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();
@@ -535,11 +549,11 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
 
     // #374508: don't overwrite custom icons.
     const QString iconName = showHiddenFilesAction->icon().name();
-    if (!iconName.isEmpty() && iconName != QLatin1String("visibility") && iconName != QLatin1String("hint")) {
+    if (!iconName.isEmpty() && iconName != QLatin1String("view-visible") && iconName != QLatin1String("view-hidden")) {
         return;
     }
 
-    showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("visibility") : QStringLiteral("hint")));
+    showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
 }
 
 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
@@ -637,9 +651,10 @@ void DolphinViewActionHandler::slotSortTriggered(QAction* action)
     // and several sub-menus. Because of this they don't have a common
     // action-group that assures an exclusive toggle-state between the main-menu
     // actions and the sub-menu-actions. If an action gets checked, it must
-    // be assured that all other actions get unchecked.
+    // be assured that all other actions get unchecked, except the ascending/
+    // descending actions
     QAction* sortByMenu =  m_actionCollection->action(QStringLiteral("sort"));
-    foreach (QAction* groupAction, sortByMenu->menu()->actions()) {
+    for (QAction *groupAction : qAsConst(m_sortByActions)) {
         KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
         if (actionMenu) {
             foreach (QAction* subAction, actionMenu->menu()->actions()) {