Commit f62de2e8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add KHamburgerMenu

parent 4db25290
Pipeline #63645 passed with stage
in 13 minutes and 42 seconds
......@@ -73,10 +73,17 @@
#include <QApplication>
#include <QStandardPaths>
#include <QTimer>
#include <QToolBar>
KOWindowList *ActionManager::mWindowList = nullptr;
ActionManager::ActionManager(KXMLGUIClient *client, CalendarView *widget, QObject *parent, KOrg::MainWindow *mainWindow, bool isPart, QMenuBar *menuBar)
ActionManager::ActionManager(KXMLGUIClient *client,
CalendarView *widget,
QObject *parent,
KOrg::MainWindow *mainWindow,
bool isPart,
QMenuBar *menuBar,
QToolBar *toolBar)
: QObject(parent)
{
new KOrgCalendarAdaptor(this);
......@@ -88,6 +95,7 @@ ActionManager::ActionManager(KXMLGUIClient *client, CalendarView *widget, QObjec
mIsPart = isPart;
mMainWindow = mainWindow;
mMenuBar = menuBar;
mToolBar = toolBar;
}
ActionManager::~ActionManager()
......@@ -112,7 +120,7 @@ void ActionManager::toggleMenubar(bool dontShowWarning)
if (mShowMenuBarAction->isChecked()) {
mMenuBar->show();
} else {
if (!dontShowWarning) {
if (!dontShowWarning && (!mToolBar->isVisible() || !mToolBar->actions().contains(mHamburgerMenu))) {
const QString accel = mShowMenuBarAction->shortcut().toString();
KMessageBox::information(mCalendarView,
i18n("<qt>This will hide the menu bar completely."
......@@ -690,6 +698,25 @@ void ActionManager::initActions()
KStandardAction::preferences(mCalendarView, &CalendarView::edit_options, mACollection);
KStandardAction::keyBindings(this, &ActionManager::keyBindings, mACollection);
}
mHamburgerMenu = KStandardAction::hamburgerMenu(nullptr, nullptr, mACollection);
mHamburgerMenu->setShowMenuBarAction(mShowMenuBarAction);
mHamburgerMenu->setMenuBar(mMenuBar);
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 ActionManager::updateHamburgerMenu()
{
QMenu *menu = new QMenu;
menu->addAction(mACollection->action(QLatin1String(KStandardAction::name(KStandardAction::Print))));
menu->addSeparator();
menu->addAction(mACollection->action(QLatin1String(KStandardAction::name(KStandardAction::Quit))));
mHamburgerMenu->setMenu(menu);
}
void ActionManager::setItems(const QStringList &lst, int idx)
......
......@@ -34,9 +34,11 @@ class ETMViewStateSaver;
class QAction;
class QMenuBar;
class QToolBar;
class KSelectAction;
class QTemporaryFile;
class KToggleAction;
class KHamburgerMenu;
/**
The ActionManager creates all the actions in KOrganizer. This class
......@@ -48,7 +50,13 @@ class KORGANIZERPRIVATE_EXPORT ActionManager : public QObject
{
Q_OBJECT
public:
ActionManager(KXMLGUIClient *client, CalendarView *widget, QObject *parent, KOrg::MainWindow *mainWindow, bool isPart, QMenuBar *menuBar = nullptr);
ActionManager(KXMLGUIClient *client,
CalendarView *widget,
QObject *parent,
KOrg::MainWindow *mainWindow,
bool isPart,
QMenuBar *menuBar = nullptr,
QToolBar *toolBar = nullptr);
~ActionManager() override;
/** Perform initialization that requires this* to be full constructed */
......@@ -284,6 +292,7 @@ private:
/** Create all the actions. */
void initActions();
void enableIncidenceActions(bool enable);
void updateHamburgerMenu();
Akonadi::ETMCalendar::Ptr calendar() const;
Akonadi::Collection selectedCollection() const;
......@@ -343,10 +352,12 @@ private:
KActionCollection *mACollection = nullptr;
CalendarView *mCalendarView = nullptr;
KOrg::MainWindow *mMainWindow = nullptr;
QToolBar *mToolBar = nullptr;
bool mIsPart;
AkonadiCollectionView *mCollectionView = nullptr;
KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionViewStateSaver = nullptr;
KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionSelectionModelStateSaver = nullptr;
KHamburgerMenu *mHamburgerMenu = nullptr;
};
<!DOCTYPE gui>
<gui name="korganizer" version="436" translationDomain="korganizer">
<gui name="korganizer" version="437" translationDomain="korganizer">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Merge/>
......@@ -137,6 +137,8 @@
<Separator/>
<Action name="select_day"/>
<Action name="select_week"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
<ToolBar noMerge="1" name="korganizer_toolbar"><text>Views</text>
......
<!DOCTYPE gui>
<gui name="korganizer" version="435" translationDomain="korganizer">
<gui name="korganizer" version="436" translationDomain="korganizer">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Menu name="import"><text>&amp;Import</text>
......@@ -121,6 +121,8 @@
<Separator/>
<Action name="select_day"/>
<Action name="select_week"/>
<Spacer/>
<Action name="hamburger_menu"/>
</ToolBar>
<ToolBar noMerge="1" name="korganizer_toolbar"><text>Views</text>
......@@ -143,6 +145,7 @@
<ToolBar noMerge="1" name="filter_toolbar" hidden="true"><text>Filters Toolbar</text>
<Action name="filter_select"/>
<Action name="edit_filters"/>
</ToolBar>
<Menu name="rmb_selection_popup">
......
......@@ -28,6 +28,7 @@
#include <KSharedConfig>
#include <KShortcutsDialog>
#include <KStandardAction>
#include <KToolBar>
#include <QLabel>
#include <QStatusBar>
#ifdef WITH_KUSERFEEDBACK
......@@ -51,7 +52,7 @@ KOrganizer::KOrganizer()
mCalendarView->setObjectName(QStringLiteral("KOrganizer::CalendarView"));
setCentralWidget(mCalendarView);
mActionManager = new ActionManager(this, mCalendarView, this, this, false, menuBar());
mActionManager = new ActionManager(this, mCalendarView, this, this, false, menuBar(), toolBar());
(void)new KOrganizerIfaceImpl(mActionManager, this, QStringLiteral("IfaceImpl"));
#ifdef WITH_KUSERFEEDBACK
......
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