Commit 2b547147 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add KHamburgerMenu when we hide menubar

parent 6f1d3582
<!DOCTYPE gui>
<gui name="kaddressbook" version="42" translationDomain="kaddressbook">
<gui name="kaddressbook" version="43" translationDomain="kaddressbook">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
......@@ -118,6 +118,8 @@
<Action name="category_filter"/>
<Separator/>
<ActionList name="kaddressbook_toolbar_actions"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
</gui>
......@@ -72,6 +72,30 @@ void MainWindow::initActions()
"the application-wide shortcuts."));
KStandardAction::configureToolbars(this, &MainWindow::configureToolbars, actionCollection());
KStandardAction::preferences(this, &MainWindow::configure, actionCollection());
mHamburgerMenu = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
mHamburgerMenu->setShowMenuBarAction(mShowMenuBarAction);
mHamburgerMenu->setMenuBar(menuBar());
connect(mHamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, [this]() {
updateHamburgerMenu();
// Immediately disconnect. We only need to run this once, but on demand.
// NOTE: The nullptr at the end disconnects all connections between
// q and mHamburgerMenu's aboutToShowMenu signal.
disconnect(mHamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, nullptr);
});
}
void MainWindow::updateHamburgerMenu()
{
QMenu *menu = new QMenu;
menu->addAction(actionCollection()->action(QStringLiteral("akonadi_contact_create")));
menu->addAction(actionCollection()->action(QStringLiteral("akonadi_contact_group_create")));
menu->addSeparator();
menu->addAction(actionCollection()->action(QStringLiteral("akonadi_contact_item_edit")));
menu->addSeparator();
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Print))));
menu->addSeparator();
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Quit))));
mHamburgerMenu->setMenu(menu);
}
void MainWindow::configure()
......@@ -110,7 +134,7 @@ void MainWindow::slotToggleMenubar(bool dontShowWarning)
if (mShowMenuBarAction->isChecked()) {
menuBar()->show();
} else {
if (!dontShowWarning) {
if (!dontShowWarning && (!toolBar()->isVisible() || !toolBar()->actions().contains(mHamburgerMenu))) {
const QString accel = mShowMenuBarAction->shortcut().toString();
KMessageBox::information(this,
i18n("<qt>This will hide the menu bar completely."
......
......@@ -12,6 +12,7 @@
class MainWidget;
class KToggleAction;
class KHamburgerMenu;
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
......@@ -30,8 +31,10 @@ private:
void slotToggleMenubar(bool dontShowWarning);
void initActions();
void updateHamburgerMenu();
MainWidget *mMainWidget = nullptr;
KToggleAction *mShowMenuBarAction = nullptr;
KHamburgerMenu *mHamburgerMenu = nullptr;
};
Markdown is supported
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