Commit 67743a52 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add KHamburgerMenu support

parent d28e0c36
Pipeline #63599 canceled with stage
......@@ -2,7 +2,7 @@
the same menu entries at the same place in KMail and Kontact -->
<!DOCTYPE gui>
<gui version="548" name="kmmainwin" translationDomain="kmail">
<gui version="549" name="kmmainwin" translationDomain="kmail">
<MenuBar>
<Menu noMerge="1" name="file" >
<text>&amp;File</text>
......@@ -347,5 +347,7 @@
<Action name="create_todo"/>
<Separator/>
<ActionList name="kmail_toolbar_actions"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
</gui>
......@@ -15,6 +15,7 @@
#include <PimCommon/BroadcastStatus>
#include <KConfigGroup>
#include <KToolBar>
#include <QApplication>
#include <QStatusBar>
#include <QTimer>
......@@ -55,7 +56,17 @@ KMMainWin::KMMainWin(QWidget *)
KStandardAction::keyBindings(this, &KMMainWin::slotConfigureShortcuts, actionCollection());
mHideMenuBarAction = KStandardAction::showMenubar(this, &KMMainWin::slotToggleMenubar, actionCollection());
mShowMenuBarAction = KStandardAction::showMenubar(this, &KMMainWin::slotToggleMenubar, actionCollection());
mHamburgerMenu = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
mHamburgerMenu->setShowMenuBarAction(mShowMenuBarAction);
mHamburgerMenu->setMenuBar(menuBar());
connect(mHamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, [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);
});
KStandardAction::quit(this, &KMMainWin::slotQuit, actionCollection());
createGUI(QStringLiteral("kmmainwin.rc"));
......@@ -68,7 +79,7 @@ KMMainWin::KMMainWin(QWidget *)
connect(mKMMainWidget, &KMMainWidget::captionChangeRequest, this, qOverload<const QString &>(&KMainWindow::setCaption));
mKMMainWidget->updateQuickSearchLineText();
mHideMenuBarAction->setChecked(KMailSettings::self()->showMenuBar());
mShowMenuBarAction->setChecked(KMailSettings::self()->showMenuBar());
slotToggleMenubar(true);
}
......@@ -79,6 +90,24 @@ KMMainWin::~KMMainWin()
disconnect(PimCommon::BroadcastStatus::instance(), &PimCommon::BroadcastStatus::statusMsg, this, nullptr);
}
void KMMainWin::updateHamburgerMenu()
{
QMenu *menu = new QMenu;
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Open))));
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::OpenRecent))));
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Save))));
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::SaveAs))));
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Print))));
menu->addSeparator();
menu->addAction(actionCollection()->action(QStringLiteral("check_mail")));
menu->addAction(actionCollection()->action(QStringLiteral("check_mail_in")));
menu->addAction(actionCollection()->action(QStringLiteral("send_queued")));
menu->addAction(actionCollection()->action(QStringLiteral("send_queued_via")));
menu->addSeparator();
menu->addAction(actionCollection()->action(QLatin1String(KStandardAction::name(KStandardAction::Quit))));
mHamburgerMenu->setMenu(menu);
}
KMMainWidget *KMMainWin::mainKMWidget() const
{
return mKMMainWidget;
......@@ -106,11 +135,11 @@ void KMMainWin::displayStatusMessage(const QString &aText)
void KMMainWin::slotToggleMenubar(bool dontShowWarning)
{
if (menuBar()) {
if (mHideMenuBarAction->isChecked()) {
if (mShowMenuBarAction->isChecked()) {
menuBar()->show();
} else {
if (!dontShowWarning) {
const QString accel = mHideMenuBarAction->shortcut().toString();
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."
" You can show it again by typing %1.</qt>",
......@@ -120,7 +149,7 @@ void KMMainWin::slotToggleMenubar(bool dontShowWarning)
}
menuBar()->hide();
}
KMailSettings::self()->setShowMenuBar(mHideMenuBarAction->isChecked());
KMailSettings::self()->setShowMenuBar(mShowMenuBarAction->isChecked());
}
}
......
......@@ -14,6 +14,7 @@
class KMMainWidget;
class KToggleAction;
class QLabel;
class KHamburgerMenu;
namespace KPIM
{
class ProgressStatusBarWidget;
......@@ -53,10 +54,12 @@ protected Q_SLOTS:
private:
void slotConfigureShortcuts();
void slotToggleMenubar(bool dontShowWarning);
void updateHamburgerMenu();
KPIM::ProgressStatusBarWidget *mProgressBar = nullptr;
KMMainWidget *mKMMainWidget = nullptr;
KToggleAction *mHideMenuBarAction = nullptr;
KToggleAction *mShowMenuBarAction = nullptr;
QLabel *mMessageLabel = nullptr;
KHamburgerMenu *mHamburgerMenu = nullptr;
bool mReallyClose = false;
};
......@@ -2,7 +2,7 @@
the same menu entries at the same place in KMail and Kontact -->
<!DOCTYPE gui>
<gui version="548" name="kmmainwin" translationDomain="kmail">
<gui version="549" name="kmmainwin" translationDomain="kmail">
<MenuBar>
<Menu noMerge="1" name="file" >
<text>&amp;File</text>
......@@ -347,5 +347,7 @@
<Action name="create_todo"/>
<Separator/>
<ActionList name="kmail_toolbar_actions"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
</gui>
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