Commit f45da1a6 authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

port to Hamburger Menu

BUG: 444664
GUI:
parent e6efb7d0
......@@ -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);
}
......
......@@ -55,6 +55,7 @@ private Q_SLOTS:
private:
void setupActions();
void updateHamburgerMenu();
KParts::ReadWritePart *m_part;
KRecentFilesMenu *m_recentFilesMenu;
......
......@@ -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">
......
<!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>&amp;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"/>
......
......@@ -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());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment