Changeset View
Changeset View
Standalone View
Standalone View
ui/toggleactionmenu.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by David Hurka <david.hurka@mailbox.org> * | ||||
3 | * * | ||||
4 | * Inspired by and replacing toolaction.h by: * | ||||
5 | * Copyright (C) 2004-2006 by Albert Astals Cid <aacid@kde.org> * | ||||
6 | * * | ||||
7 | * This program is free software; you can redistribute it and/or modify * | ||||
8 | * it under the terms of the GNU General Public License as published by * | ||||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||||
10 | * (at your option) any later version. * | ||||
11 | ***************************************************************************/ | ||||
12 | | ||||
13 | #ifndef TOGGLEACTIONMENU_H | ||||
14 | #define TOGGLEACTIONMENU_H | ||||
15 | | ||||
16 | #include <KActionMenu> | ||||
17 | #include <QToolButton> | ||||
18 | #include <QSet> | ||||
19 | | ||||
20 | /** | ||||
21 | * @brief A KActionMenu, with allows to set the default action of its toolbar buttons. | ||||
22 | * | ||||
23 | * Usually, a KActionMenu creates toolbar buttons which reflect its own action properties | ||||
24 | * (icon, text, tooltip, checked state,...), as it is a QAction itself. | ||||
25 | * ToggleActionMenu will use its own action properties only when plugged as submenu in another menu. | ||||
26 | * But the default action of the toolbar buttons can easily be changed with the slot setDefaultAction(). | ||||
27 | * | ||||
28 | * Naming: The user can *Toggle* the checked state of an *Action* by directly clicking the toolbar button, | ||||
29 | * but can also open a *Menu*. | ||||
30 | * | ||||
31 | * @par Intention | ||||
32 | * Setting the default action of the toolbar button can be useful for: | ||||
33 | * * Providing the most propably needed entry of a menu directly on the menu button. | ||||
34 | * * Showing the last used menu entry on the menu button, including its checked state. | ||||
35 | * The advantage is that the user often does not need to open the menu, | ||||
36 | * and that the toolbar button shows additional information | ||||
37 | * like checked state or the user's last selection. | ||||
38 | * | ||||
39 | * This shall replace the former ToolAction in Okular, | ||||
40 | * while beeing flexible enough for other (planned) action menus. | ||||
41 | */ | ||||
42 | class ToggleActionMenu : public KActionMenu | ||||
43 | { | ||||
44 | Q_OBJECT | ||||
45 | | ||||
46 | public: | ||||
47 | explicit ToggleActionMenu( QWidget *parent ); | ||||
48 | ToggleActionMenu( const QString &text, QWidget * parent ); | ||||
49 | /** | ||||
50 | * These are the usual constructors for KActionMenu. | ||||
51 | * | ||||
52 | * @note | ||||
53 | * @p text and @p icon are used only if this menu is a submenu in another menu. | ||||
54 | * To set the appearance of the toolbar buttons, use setDefaultAction. | ||||
55 | */ | ||||
56 | ToggleActionMenu( const QIcon &icon, const QString &text, QWidget *parent ); | ||||
57 | | ||||
58 | QWidget *createWidget( QWidget *parent ) override; | ||||
59 | | ||||
60 | /** | ||||
61 | * Returns the current default action of the toolbar buttons. | ||||
62 | */ | ||||
63 | QAction *defaultAction(); | ||||
64 | | ||||
65 | public slots: | ||||
66 | /** | ||||
67 | * Sets the default action of the toolbar buttons. | ||||
68 | * | ||||
69 | * This action will be triggered by clicking directly on the toolbar buttons. | ||||
70 | * It will also set the text, icon, checked state, etc. of the toolbar buttons. | ||||
71 | * | ||||
72 | * @note | ||||
73 | * The action will not be added to the menu, | ||||
74 | * it usually makes sense to addAction() it before to setDefaultAction() it. | ||||
75 | */ | ||||
76 | void setDefaultAction( QAction *action ); | ||||
77 | | ||||
78 | private: | ||||
79 | QAction *m_defaultAction; | ||||
80 | QList< QPointer< QToolButton > > m_buttons; | ||||
81 | }; | ||||
82 | | ||||
83 | #endif // TOGGLEACTIONMENU_H |