2021-05-24 07:25:56 +00:00
|
|
|
|
/*
|
|
|
|
|
SPDX-FileCopyrightText: 2019-2021 David Hurka <david.hurka@mailbox.org>
|
|
|
|
|
|
|
|
|
|
Inspired by and replacing toolaction.h by:
|
|
|
|
|
SPDX-FileCopyrightText: 2004-2006 Albert Astals Cid <aacid@kde.org>
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
|
|
|
|
|
#ifndef TOGGLEACTIONMENU_H
|
|
|
|
|
#define TOGGLEACTIONMENU_H
|
|
|
|
|
|
|
|
|
|
#include <KActionMenu>
|
2021-04-23 01:54:42 +00:00
|
|
|
|
#include <QPointer>
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* @brief A KActionMenu, which allows to set the default action of its toolbar buttons.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* This behaves like a KActionMenu, with the addition of setDefaultAction().
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
|
|
|
|
* @par Intention
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* Setting the default action of toolbar buttons has the advantage that the user
|
|
|
|
|
* can trigger a frequently used action directly without opening the menu.
|
|
|
|
|
* Additionally, the state of the default action is visible in the toolbar.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* @par Example
|
|
|
|
|
* You can make the toolbar button show the last used action with only one connection.
|
|
|
|
|
* You may want to initialize the default action.
|
|
|
|
|
* \code
|
|
|
|
|
* if (myToggleActionMenu->defaultAction() == myToggleActionMenu) {
|
|
|
|
|
* myToggleActionMenu->setDefaultAction(myFirstAction);
|
|
|
|
|
* }
|
|
|
|
|
* connect(myToggleActionMenu->menu(), &QMenu::triggered,
|
|
|
|
|
* myToggleActionMenu, &ToggleActionMenu::setDefaultAction);
|
|
|
|
|
* \endcode
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*/
|
|
|
|
|
class ToggleActionMenu : public KActionMenu
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ToggleActionMenu(QObject *parent);
|
|
|
|
|
ToggleActionMenu(const QString &text, QObject *parent);
|
|
|
|
|
/**
|
|
|
|
|
* Constructs an empty ToggleActionMenu.
|
|
|
|
|
*
|
|
|
|
|
* @param icon The icon of this menu, when plugged into another menu.
|
|
|
|
|
* @param text The name of this menu, when plugged into another menu.
|
|
|
|
|
* @param parent Parent @c QOject.
|
|
|
|
|
*/
|
2021-04-23 01:54:42 +00:00
|
|
|
|
ToggleActionMenu(const QIcon &icon, const QString &text, QObject *parent);
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
|
|
|
|
|
QWidget *createWidget(QWidget *parent) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the current default action of the toolbar buttons.
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* May be @c this.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* This action is set by setDefaultAction().
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*/
|
|
|
|
|
QAction *defaultAction();
|
|
|
|
|
|
2021-04-23 01:54:42 +00:00
|
|
|
|
public Q_SLOTS:
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the default action of the toolbar buttons.
|
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* Toolbar buttons are updated immediately.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* Calling setDefaultAction(nullptr) will reset the default action
|
|
|
|
|
* to this menu itself.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* @note
|
|
|
|
|
* @p action must be present in the menu as direct child action.
|
|
|
|
|
* The default action will be reset to this menu itself
|
|
|
|
|
* when @p action is removed from the menu.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* @note
|
|
|
|
|
* @p action will define all properties of the toolbar buttons.
|
|
|
|
|
* When you disable @p action, the toolbar button will become disabled too.
|
|
|
|
|
* Then the menu can no longer be accessed.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*/
|
|
|
|
|
void setDefaultAction(QAction *action);
|
|
|
|
|
|
2021-04-23 01:54:42 +00:00
|
|
|
|
protected:
|
|
|
|
|
/** Can store @c nullptr, which means this menu itself will be the default action. */
|
|
|
|
|
QPointer<QAction> m_defaultAction;
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
QList<QPointer<QToolButton>> m_buttons;
|
|
|
|
|
|
2022-08-13 21:36:04 +00:00
|
|
|
|
QHash<const QToolButton *, Qt::ToolButtonStyle> m_originalToolButtonStyle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the aproppriate style for @p button.
|
|
|
|
|
* Respects both toolbar settings and settings for this menu action.
|
|
|
|
|
*/
|
|
|
|
|
Qt::ToolButtonStyle styleFor(QToolButton *button) const;
|
|
|
|
|
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
/**
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* Updates the toolbar buttons by setting the current defaultAction() on them.
|
|
|
|
|
*
|
|
|
|
|
* (If the current defaultAction() is invalid, `this` is used instead.)
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*/
|
2021-04-23 01:54:42 +00:00
|
|
|
|
void updateButtons();
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* Updates the event filter, which listens to QMenu’s QActionEvent.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*
|
2021-04-23 01:54:42 +00:00
|
|
|
|
* This is connected to QAction::changed().
|
|
|
|
|
* That signal is emmited when the menu changes, but that’s not documented.
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
*/
|
2021-04-23 01:54:42 +00:00
|
|
|
|
void slotMenuChanged();
|
|
|
|
|
|
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
Replace ToolAction by ToggleActionMenu
Summary:
This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).
Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.
* Menu can be set from outside, not hard coded.
* Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger //anything// now.)
* KActionMenu instead of KSelectAction:
- Pluggable in other menus, thus called “Menu”.
- Doesn’t make the actions exclusive, so //any// actions can be added to the menu.
* ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.
Toolbar buttons use the default action //of// this menu, not this menu itself as action.
Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.
Screenshot:
Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.
{F6884228}
Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:
* Open Okular and look at toolbar button -> has correct tool selected.
* Open a document.
* Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
* Select some selection tools through shortcuts and toolbar button -> behaves correctly.
Usage as submenu:
* Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...
Toolbar buttons:
* Add diverse other actions to the menu -> still works as before.
* Add actions when toolbar buttons are already created -> actions are added to existing buttons.
* setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.
Reviewers: simgunz
Reviewed By: simgunz
Subscribers: aacid, ngraham, simgunz, okular-devel
Tags: #okular
Differential Revision: https://phabricator.kde.org/D21971
2020-02-01 18:54:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TOGGLEACTIONMENU_H
|