Commit 103d92c5 authored by David Jarvie's avatar David Jarvie
Browse files

Show hamburger menu when menu bar is hidden

parent 901046fd
Pipeline #70675 skipped
......@@ -2,6 +2,7 @@ KAlarm Change Log
=== Version 3.3.0 (KDE Applications 21.08) --- 12 July 2021 ===
* Add date selector option to enable alarm list view to be filtered.
* Show hamburger menu when menu bar is hidden, to allow access to all options.
* Fix crash when context menu is requested after toolbar has been edited.
=== Version 3.2.2 (KDE Applications 21.04.2) --- 26 May 2021 ===
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2007-2020 David Jarvie <djarvie@kde.org>
SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
-->
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
......@@ -269,6 +269,12 @@ SPDX-License-Identifier: GPL-2.0-or-later
<whatsthis context="@info:whatsthis">Enter how many minutes before the alarm trigger time to wake the system from suspend. This can be used to ensure that the system is fully restored by the time the alarm triggers.</whatsthis>
<default>2</default>
</entry>
<entry name="ShowMenuBar" type="Bool">
<default>true</default>
<!-- label and whatsthis are already provided by KStandardAction::showMenubar -->
<label></label>
<whatsthis></whatsthis>
</entry>
</group>
<group name="Defaults">
<entry name="DefaultDisplayMethod" key="DisplayMethod" type="Enum">
......
......@@ -7,12 +7,12 @@
<Action name="modify" />
<Action name="delete" />
<Separator/>
<Action name="showResources" />
<Separator/>
<Action name="edit_undo" />
<Action name="edit_redo" />
<Separator/>
<Action name="edit_find"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
<MenuBar>
<Menu name="file" >
......@@ -48,7 +48,7 @@
<Action name="showInSystemTray" />
<Separator/>
<Action name="showResources" />
<Action name="showDateNavigator" />
<Action name="showDateSelector" />
<Separator/>
<Action name="spread" />
</Menu>
......@@ -66,8 +66,8 @@
</Menu>
<Menu noMerge="1" name="settings" >
<text>&amp;Settings</text>
<Merge name="StandardToolBarMenuHandler" />
<Action name="options_show_menubar"/>
<Merge name="StandardToolBarMenuHandler" />
<Separator/>
<Action name="options_configure_keybinding" />
<Action name="options_configure_notifications" />
......
......@@ -502,7 +502,7 @@ void MainWindow::initActions()
connect(mActionToggleResourceSel, &KToggleAction::triggered, this, &MainWindow::slotToggleResourceSelector);
mActionToggleDateNavigator = new KToggleAction(QIcon::fromTheme(QStringLiteral("view-calendar-month")), i18nc("@action", "Show Date Selector"), this);
actions->addAction(QStringLiteral("showDateNavigator"), mActionToggleDateNavigator);
actions->addAction(QStringLiteral("showDateSelector"), mActionToggleDateNavigator);
connect(mActionToggleDateNavigator, &KToggleAction::triggered, this, &MainWindow::slotToggleDateNavigator);
mActionSpreadWindows = KAlarm::createSpreadWindowsAction(this);
......@@ -564,11 +564,19 @@ void MainWindow::initActions()
// be deleted while still processing the action, resulting in a crash.
QAction* act = KStandardAction::quit(nullptr, nullptr, actions);
connect(act, &QAction::triggered, this, &MainWindow::slotQuit, Qt::QueuedConnection);
QAction* actionMenubar = KStandardAction::showMenubar(this, &MainWindow::slotShowMenubar, actions);
KStandardAction::keyBindings(this, &MainWindow::slotConfigureKeys, actions);
KStandardAction::configureNotifications(this, &MainWindow::slotConfigureNotifications, actions);
KStandardAction::configureToolbars(this, &MainWindow::slotConfigureToolbar, actions);
KStandardAction::preferences(this, &MainWindow::slotPreferences, actions);
mActionShowMenuBar = KStandardAction::showMenubar(this, &MainWindow::slotToggleMenubar, actions);
mHamburgerMenu = KStandardAction::hamburgerMenu(nullptr, nullptr, actions);
mHamburgerMenu->setShowMenuBarAction(mActionShowMenuBar);
mHamburgerMenu->setMenuBar(menuBar());
connect(mHamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, [this]() {
slotInitHamburgerMenu();
// Needs to be run on demand, but the contents won't change, so disconnect now.
disconnect(mHamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, nullptr);
});
mResourceSelector->initActions(actions);
setStandardToolBarMenuEnabled(true);
createGUI(UI_FILE);
......@@ -611,12 +619,32 @@ void MainWindow::initActions()
mActionCreateTemplate->setEnabled(false);
mActionExport->setEnabled(false);
const bool menuVisible = !menuBar()->isHidden();
actionMenubar->setChecked(menuVisible);
mActionShowMenuBar->setChecked(Preferences::showMenuBar());
slotToggleMenubar(true);
Undo::emitChanged(); // set the Undo/Redo menu texts
}
/******************************************************************************
* Set up the Hamburger menu, which allows the menu bar to be easily reinstated
* after it has been hidden.
*/
void MainWindow::slotInitHamburgerMenu()
{
QMenu* menu = new QMenu;
KActionCollection* actions = actionCollection();
menu->addAction(actions->action(QStringLiteral("new")));
menu->addAction(actions->action(QStringLiteral("templates")));
menu->addSeparator();
menu->addAction(actions->action(QStringLiteral("edit_find")));
menu->addSeparator();
menu->addAction(actions->action(QStringLiteral("showArchivedAlarms")));
menu->addAction(actions->action(QStringLiteral("showDateSelector")));
menu->addSeparator();
menu->addAction(actions->action(QLatin1String(KStandardAction::name(KStandardAction::Quit))));
mHamburgerMenu->setMenu(menu);
}
/******************************************************************************
* Enable or disable the Templates menu item in every main window instance.
*/
......@@ -1198,10 +1226,28 @@ void MainWindow::slotPreferences()
/******************************************************************************
* Called when the Show Menubar menu item is selected.
*/
void MainWindow::slotShowMenubar()
void MainWindow::slotToggleMenubar(bool dontShowWarning)
{
const bool visible = menuBar()->isVisible();
menuBar()->setVisible(!visible);
if (menuBar())
{
if (mActionShowMenuBar->isChecked())
menuBar()->show();
else
{
if (!dontShowWarning
&& (!toolBar()->isVisible() || !toolBar()->actions().contains(mHamburgerMenu)))
{
const QString accel = mActionShowMenuBar->shortcut().toString();
KMessageBox::information(this,
i18n("<qt>This will hide the menu bar completely."
" You can show it again by typing %1.</qt>", accel),
i18n("Hide menu bar"), QStringLiteral("HideMenuBarWarning"));
}
menuBar()->hide();
}
Preferences::setShowMenuBar(mActionShowMenuBar->isChecked());
Preferences::self()->save();
}
}
/******************************************************************************
......
......@@ -33,6 +33,7 @@ class QMenu;
class QAction;
class KToggleAction;
class KToolBarPopupAction;
class KHamburgerMenu;
class AlarmListModel;
class AlarmListView;
class DatePicker;
......@@ -81,6 +82,7 @@ protected:
void readProperties(const KConfigGroup&) override;
private Q_SLOTS:
void slotInitHamburgerMenu();
void slotNew(EditAlarmDlg::Type);
void slotNewFromTemplate(const KAlarmCal::KAEvent&);
void slotNewTemplate();
......@@ -98,7 +100,7 @@ private Q_SLOTS:
void slotTemplates();
void slotTemplatesEnd();
void slotPreferences();
void slotShowMenubar();
void slotToggleMenubar(bool dontShowWarning);
void slotConfigureKeys();
void slotConfigureNotifications();
void slotConfigureToolbar();
......@@ -153,6 +155,7 @@ private:
QSplitter* mSplitter; // splits window into list and resource selector
QWidget* mPanel; // panel containing resource selector & date navigator
QMap<EditAlarmDlg*, KAEvent> mEditAlarmMap; // edit alarm dialogs to be handled by this window
KToggleAction* mActionShowMenuBar;
KToggleAction* mActionToggleResourceSel;
KToggleAction* mActionToggleDateNavigator;
QAction* mActionImportAlarms;
......@@ -175,6 +178,7 @@ private:
KToggleAction* mActionToggleTrayIcon;
KToggleAction* mActionShowArchived;
KToggleAction* mActionSpreadWindows;
KHamburgerMenu* mHamburgerMenu;
QPointer<QMenu> mContextMenu;
QPointer<QMenu> mResourceContextMenu;
QMap<QAction*, int> mUndoMenuIds; // items in the undo/redo menu, in order of appearance
......
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