Debian Codegraph @

src/Gui/MenuManager.h

raw
1 /***************************************************************************
2 * Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_MENUMANAGER_H
24 #define GUI_MENUMANAGER_H
25
26 #include <string>
27 #include <QList>
28 #include <QString>
29 #include <FCGlobal.h>
30
31
32 class QAction;
33 class QMenu;
34
35 namespace Gui
36 {
37
38 class MainWindow;
39
40 class GuiExport MenuItem
41 {
42 public:
43 MenuItem();
44 explicit MenuItem(MenuItem*);
45 ~MenuItem();
46
47 void setCommand(const std::string&);
48 std::string command() const;
49
50 bool hasItems() const;
51 MenuItem* findItem(const std::string&);
52 MenuItem* findParentOf(const std::string&);
53 MenuItem* copy() const;
54 uint count() const;
55
56 void appendItem(MenuItem*);
57 bool insertItem(MenuItem*, MenuItem*);
58 MenuItem* afterItem(MenuItem*) const;
59 void removeItem(MenuItem*);
60 void clear();
61
62 MenuItem& operator<<(MenuItem* item);
63 MenuItem& operator<<(const std::string& command);
64 QList<MenuItem*> getItems() const;
65
66 private:
67 std::string _name;
68 QList<MenuItem*> _items;
69 };
70
71 /**
72 * The MenuManager class is responsible for the creation of menus and context menus and appending
73 * them to the main window.
74 * @see ToolBoxManager
75 * @see ToolBarManager
76 * @author Werner Mayer
77 */
78 class GuiExport MenuManager
79 {
80 public:
81 /** Sets up the menus of a given workbench. */
82 void setup(MenuItem*) const;
83 /// sets up a context menu out of item
84 void setupContextMenu(MenuItem* item, QMenu& menu) const;
85 void retranslate() const;
86
87 /// The one and only instance.
88 static MenuManager* getInstance();
89 static void destruct();
90
91 protected:
92 MenuManager();
93 ~MenuManager();
94
95 private:
96 void setup(MenuItem*, QMenu*) const;
97 void retranslate(QMenu*) const;
98 QAction* findAction(const QList<QAction*>&, const QString&) const;
99 QList<QAction*> findActions(const QList<QAction*>&, const QString&) const;
100
101 private:
102 static MenuManager* _instance;
103
104 friend class MainWindow;
105 };
106
107 } // namespace Gui
108
109
110 #endif // GUI_MENUMANAGER_H