[utilities/ark] /: port to Hamburger Menu

Andrey Butirsky null at kde.org
Mon Sep 12 13:48:56 BST 2022


Git commit f45da1a6750b2965e5b1e72d6523e65714a878d7 by Andrey Butirsky.
Committed on 12/09/2022 at 12:17.
Pushed by butirsky into branch 'master'.

port to Hamburger Menu

BUG: 444664
GUI:

M  +67   -0    app/mainwindow.cpp
M  +1    -0    app/mainwindow.h
M  +4    -0    kerfuffle/ark.kcfg
M  +3    -1    part/ark_part.rc
M  +3    -0    part/part.cpp

https://invent.kde.org/utilities/ark/commit/f45da1a6750b2965e5b1e72d6523e65714a878d7

diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index fabd19c6..171b2f4f 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -16,6 +16,7 @@
 #include "settingspage.h"
 #include "pluginmanager.h"
 #include "interface.h"
+#include "settings.h"
 
 #include <KParts/ReadWritePart>
 #include <KPluginFactory>
@@ -28,6 +29,8 @@
 #include <KConfigDialog>
 #include <KXMLGUIFactory>
 #include <KConfigSkeleton>
+#include <KToolBar>
+#include <QMenuBar>
 
 #include <QApplication>
 #include <QDragEnterEvent>
@@ -128,10 +131,26 @@ bool MainWindow::loadPart()
     m_part->setObjectName(QStringLiteral("ArkPart"));
     m_windowContents->addWidget(m_part->widget());
 
+    // needs to be above createGUI()
+    KHamburgerMenu * const hamburgerMenu = KStandardAction::hamburgerMenu(nullptr, nullptr, m_part->actionCollection());
+
     setXMLFile(QStringLiteral("arkui.rc"));
     setupGUI(ToolBar | Keys | Save);
     createGUI(m_part);
 
+    connect(hamburgerMenu, &KHamburgerMenu::aboutToShowMenu,
+            this, &MainWindow::updateHamburgerMenu);
+    hamburgerMenu->setMenuBar(menuBar());
+
+    QAction * const showMenuBarAction = actionCollection()->action(
+                                    QLatin1String(KStandardAction::name(KStandardAction::ShowMenubar)));
+    hamburgerMenu->setShowMenuBarAction(showMenuBarAction);
+    if (ArkSettings::version() < 1) {
+        menuBar()->hide();
+    }
+    // FIXME: workaround for BUG 171080
+    showMenuBarAction->setChecked(!menuBar()->isHidden());
+
     statusBar()->hide();
 
     connect(m_part, SIGNAL(ready()), this, SLOT(updateActions()));
@@ -175,6 +194,51 @@ void MainWindow::setupActions()
     // Connect the welcome screen to actions created above
     connect(m_welcomeScreen, &WelcomeScreen::newClicked, m_newAction, &QAction::trigger);
     connect(m_welcomeScreen, &WelcomeScreen::openClicked, m_openAction, &QAction::trigger);
+
+    // add Menubar toggle to 'Settings' menu
+    KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
+    showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
+            "This switches between having a <emphasis>Menubar</emphasis> "
+            "and having a <interface>Hamburger Menu</interface> button. Both "
+            "contain mostly the same commands and configuration options."));
+    connect(showMenuBar, &KToggleAction::triggered,                   // Fixes #286822
+            this, [this]{ menuBar()->setVisible(!menuBar()->isVisible()); }, Qt::QueuedConnection);
+}
+
+void MainWindow::updateHamburgerMenu()
+{
+    const KActionCollection* ac = m_part->actionCollection();
+    auto hamburgerMenu = static_cast<KHamburgerMenu *>(
+                    ac->action(QLatin1String(KStandardAction::name(KStandardAction::HamburgerMenu))));
+    auto menu = hamburgerMenu->menu();
+    if (!menu) {
+        menu = new QMenu(this);
+        hamburgerMenu->setMenu(menu);
+    } else {
+        menu->clear();
+    }
+
+    if (!toolBar()->isVisible()) {
+        // If neither the menu bar nor the toolbar are visible, these actions should be available.
+        menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::ShowMenubar))));
+        menu->addAction(toolBarMenuAction());
+        menu->addSeparator();
+    }
+
+    menu->addAction(m_newAction);
+    menu->addAction(m_openAction);
+    menu->addMenu(m_recentFilesMenu);
+    menu->addSeparator();
+
+    menu->addAction(ac->action(QStringLiteral("extract")));
+    menu->addAction(ac->action(QStringLiteral("add")));
+    menu->addAction(ac->action(QStringLiteral("edit_find")));
+    menu->addSeparator();
+
+    menu->addMenu(static_cast<QMenu *>(factory()->container(QStringLiteral("ark_file"), m_part)));
+    menu->addSeparator();
+
+    menu->addMenu(static_cast<QMenu *>(factory()->container(QStringLiteral("settings"), this)));
 }
 
 void MainWindow::updateActions()
@@ -239,6 +303,9 @@ void MainWindow::closeEvent(QCloseEvent *event)
         }
     }
 
+    ArkSettings::setVersion(1);
+    ArkSettings::self()->save();
+
     KParts::MainWindow::closeEvent(event);
 }
 
diff --git a/app/mainwindow.h b/app/mainwindow.h
index 28a33e14..d3db1ade 100644
--- a/app/mainwindow.h
+++ b/app/mainwindow.h
@@ -55,6 +55,7 @@ private Q_SLOTS:
 
 private:
     void setupActions();
+    void updateHamburgerMenu();
 
     KParts::ReadWritePart *m_part;
     KRecentFilesMenu      *m_recentFilesMenu;
diff --git a/kerfuffle/ark.kcfg b/kerfuffle/ark.kcfg
index 4777bfb6..4fbb2ad4 100644
--- a/kerfuffle/ark.kcfg
+++ b/kerfuffle/ark.kcfg
@@ -17,6 +17,10 @@
 			</choices>
 			<default>Preview</default>
 		</entry>
+		<entry name="Version" type="Int">
+		<label>Internal config version of Ark, mainly used to determine whether an updated version of Ark is running, so as to migrate config entries that were removed/renamed ...etc</label>
+		<default>0</default>
+		</entry>
 	</group>
 	<group name="Extraction">
 		<entry name="openDestinationFolderAfterExtraction" type="Bool">
diff --git a/part/ark_part.rc b/part/ark_part.rc
index 129fcf8c..470dad8e 100644
--- a/part/ark_part.rc
+++ b/part/ark_part.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE gui SYSTEM "kpartgui.dtd">
-<gui name="ark_part" version="24" translationDomain="ark">
+<gui name="ark_part" version="25" translationDomain="ark">
 <MenuBar>
 	<Menu name="archive">
 		<text>&Archive</text>
@@ -39,6 +39,8 @@
 	<Action name="preview"/>
 	<Action name="openfile"/>
 	<Action name="deletefile"/>
+        <Spacer/>
+        <Action name="hamburger_menu" />
 </ToolBar>
 <Menu name="context_menu">
 	<Action name="preview"/>
diff --git a/part/part.cpp b/part/part.cpp
index 90ab3016..35bac861 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -1723,6 +1723,9 @@ void Part::slotShowContextMenu()
     }
 
     QMenu *popup = static_cast<QMenu *>(factory()->container(QStringLiteral("context_menu"), this));
+    if (KHamburgerMenu * const hamburgerMenu = static_cast<KHamburgerMenu *>(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::HamburgerMenu))))) {
+        hamburgerMenu->insertIntoMenuBefore(popup, popup->actions().constFirst());
+    }
     popup->popup(QCursor::pos());
 }
 



More information about the kde-doc-english mailing list