1 /***************************************************************************
2 			  MenuRoot.h  -  root node of a menu structure
3 			     -------------------
4     begin                : Mon Jan 10 2000
5     copyright            : (C) 2000 by Thomas Eschenbacher
6     email                : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef MENU_ROOT_H
19 #define MENU_ROOT_H
20 
21 #include "config.h"
22 
23 #include <QList>
24 
25 #include "libgui/MenuNode.h"
26 
27 class QMenuBar;
28 
29 namespace Kwave
30 {
31 
32     class MenuSub;
33 
34     /**
35      * This is the class for the root of a Menu (e.g. a MenuBar) that contains
36      * all toplevel menus of a menu hierarchy.
37      * @author Thomas Eschenbacher
38      */
39     class MenuRoot: public Kwave::MenuNode
40     {
41 	Q_OBJECT
42 
43     public:
44 
45 	/**
46 	 * Constructor.
47 	 * @param bar reference to a QMenuBar
48 	 */
49 	explicit MenuRoot(QMenuBar &bar);
50 
51 	/** Destructor */
52         virtual ~MenuRoot() Q_DECL_OVERRIDE;
53 
54 	/**
55 	 * overloaded version from MenuNode, which does a cleanup of
56 	 * the "garbage collector" afterwards.
57 	 *
58 	 * @see MenuNode::insertNode()
59 	 *
60 	 * @param name non-localized name of the first node (might be 0)
61 	 * @param position path consiting of several node names separated
62 	 *        by a '/'. All strings are non-localized.
63 	 * @param command the command to be sent when the node is
64 	 *                selected (might be 0)
65 	 * @param shortcut keyboard shortcut, 0 if unused
66 	 * @param uid unique id string (might be 0)
67 	 */
68         virtual void insertNode(const QString &name,
69 	                        const QString &position,
70 	                        const QString &command,
71 	                        const QKeySequence &shortcut,
72 	                        const QString &uid) Q_DECL_OVERRIDE;
73 
74 	/**
75 	 * Inserts a new branch node into the menu structure.
76 	 *
77 	 * @param name non-localized name of the node
78 	 * @param command the command template used for creating commands of
79 	 *                submenus (leafes) that don't have an own command
80 	 *                but contain data for their parent's command.
81 	 *                Should contain a %s that will be replaced by some
82 	 *                data from a child entry. (this is used for
83 	 *                menus with data selection lists like "recent files)
84 	 *                If not used, pass 0.
85 	 * @param shortcut keyboard shortcut, 0 if unused
86 	 * @param uid unique id string (might be 0)
87 	 * @return pointer to the new branch node
88 	 */
89         virtual Kwave::MenuSub *insertBranch(const QString &name,
90 	                                     const QString &command,
91 	                                     const QKeySequence &shortcut,
92 	                                     const QString &uid) Q_DECL_OVERRIDE;
93 
94 	/**
95 	 * Inserts a new leaf node into the menu structure. The new node
96 	 * normally is (derived from) MenuItem.
97 	 * @param name non-localized name of the node
98 	 * @param command the command to be sent when the node is
99 	 *                selected (might be 0)
100 	 * @param shortcut keyboard shortcut, 0 if unused
101 	 * @param uid unique id string (might be 0)
102 	 * @return pointer to the new leaf node
103 	 */
104         virtual Kwave::MenuNode *insertLeaf(const QString &name,
105 	                                    const QString &command,
106 	                                    const QKeySequence &shortcut,
107 	                                    const QString &uid) Q_DECL_OVERRIDE;
108 
109 	/**
110 	 * Removes a child node of the current node. If the child
111 	 * was not found or is already removed this does nothing.
112 	 * @param child pointer to the child node
113 	 */
114         virtual void removeChild(Kwave::MenuNode *child) Q_DECL_OVERRIDE;
115 
116 	/**
117 	 * Handles/interprets special menu commands.
118 	 * @param command name of a menu node or command
119 	 * @return true if the name was recognized as a command and handled
120 	 */
121         virtual bool specialCommand(const QString &command) Q_DECL_OVERRIDE;
122 
123 	/**
124 	 * Returns a pointer to the list of groups
125 	 */
126         virtual QHash<QString, Kwave::MenuGroup *> &groupList() Q_DECL_OVERRIDE;
127 
128 	/**
129 	 * replacement for QObject::deleteLater(...), which does not work
130 	 * in this context
131 	 */
132 	static void deleteLater(Kwave::MenuNode *node);
133 
134     protected:
135 	friend class MenuSub;
136 
137 	/**
138 	 * Makes a child node visible, by adding it to the menu bar
139 	 * @param child pointer to the child node (normally a MenuSub)
140 	 */
141 	void showChild(Kwave::MenuSub *child);
142 
143 	/**
144 	 * Makes a child node invisible, by removing it from the menu bar
145 	 * @param child pointer to the child node (normally a MenuSub)
146 	 */
147 	void hideChild(Kwave::MenuSub *child);
148 
149     private:
150 
151 	/** reference to a QMenuBar */
152 	QMenuBar &m_menu_bar;
153 
154 	/** list of menu groups */
155 	QHash<QString, Kwave::MenuGroup *> m_group_list;
156 
157 	/** list of nodes to delete, as deleteLater() does not work :-( */
158 	static QList <Kwave::MenuNode *> m_garbage;
159 
160     };
161 }
162 
163 #endif // _MENU_ROOT_H_
164 
165 //***************************************************************************
166 //***************************************************************************
167