LibrePCB Developers Documentation
menubuilder.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_MENUBUILDER_H
21#define LIBREPCB_EDITOR_MENUBUILDER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27#include <QtWidgets>
28
29/*******************************************************************************
30 * Namespace / Forward Declarations
31 ******************************************************************************/
32namespace librepcb {
33namespace editor {
34
35/*******************************************************************************
36 * Class MenuBuilder
37 ******************************************************************************/
38
42class MenuBuilder final {
43 Q_DECLARE_TR_FUNCTIONS(MenuBuilder)
44
45public:
46 // Types
47 typedef QMenu* (*MenuFactory)(QWidget*);
48
49 enum class Flag {
50 DefaultAction = (1 << 0),
51 };
52 Q_DECLARE_FLAGS(Flags, Flag)
53
54 // Constructors / Destructor
55 MenuBuilder() = delete;
56 MenuBuilder(const MenuBuilder& other) = delete;
57 explicit MenuBuilder(QMenuBar* menuBar) noexcept;
58 explicit MenuBuilder(QMenu* menu) noexcept;
59 ~MenuBuilder() noexcept;
60
61 // General Methods
62 QMenu* newMenu(MenuFactory factory) noexcept;
63 QMenu* addSubMenu(MenuFactory factory) noexcept;
64 QMenu* addSubMenu(const QString& objectName, const QString& title,
65 const QIcon& icon = QIcon()) noexcept;
66 void addAction(QAction* action, Flags flags = Flags()) noexcept;
67 void addAction(const QScopedPointer<QAction>& action,
68 Flags flags = Flags()) noexcept;
69 void addSection(const QString& text, const QIcon& icon = QIcon()) noexcept;
70 void addSeparator() noexcept;
71
72 // Operator Overloadings
73 MenuBuilder& operator=(const MenuBuilder& rhs) = delete;
74
75 // Static Methods
76 static QMenu* createFileMenu(QWidget* parent) noexcept;
77 static QMenu* createEditMenu(QWidget* parent) noexcept;
78 static QMenu* createViewMenu(QWidget* parent) noexcept;
79 static QMenu* createSchematicMenu(QWidget* parent) noexcept;
80 static QMenu* createBoardMenu(QWidget* parent) noexcept;
81 static QMenu* createProjectMenu(QWidget* parent) noexcept;
82 static QMenu* createToolsMenu(QWidget* parent) noexcept;
83 static QMenu* createExtrasMenu(QWidget* parent) noexcept;
84 static QMenu* createHelpMenu(QWidget* parent) noexcept;
85 static QMenu* createGoToDockMenu(QWidget* parent) noexcept;
86 static QMenu* createDocksVisibilityMenu(QWidget* parent) noexcept;
87 static QMenu* createImportMenu(QWidget* parent) noexcept;
88 static QMenu* createExportMenu(QWidget* parent) noexcept;
89 static QMenu* createProductionDataMenu(QWidget* parent) noexcept;
90 static QMenu* createLineWidthMenu(QWidget* parent) noexcept;
91 static QMenu* createChangeDeviceMenu(QWidget* parent) noexcept;
92 static QMenu* createChangeFootprintMenu(QWidget* parent) noexcept;
93 static QMenu* createChangeModelMenu(QWidget* parent) noexcept;
94 static QMenu* createMoveToOtherLibraryMenu(QWidget* parent) noexcept;
95 static QMenu* createMoreResourcesMenu(QWidget* parent) noexcept;
96
97private: // Methods
98 static QMenu* createMenu(const QString& objectName, const QString& text,
99 const QIcon& icon, QWidget* parent) noexcept;
100
101private: // Data
102 QMenuBar* mMenuBar;
103 QPointer<QMenu> mMenu;
104};
105
106} // namespace editor
107} // namespace librepcb
108
109Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::MenuBuilder::Flags)
110
111/*******************************************************************************
112 * End of File
113 ******************************************************************************/
114
115#endif
Helper to easily create a QMenu.
Definition: menubuilder.h:42
static QMenu * createMenu(const QString &objectName, const QString &text, const QIcon &icon, QWidget *parent) noexcept
Definition: menubuilder.cpp:205
QMenu * addSubMenu(MenuFactory factory) noexcept
Definition: menubuilder.cpp:61
static QMenu * createFileMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:110
QMenuBar * mMenuBar
Definition: menubuilder.h:102
static QMenu * createMoveToOtherLibraryMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:189
static QMenu * createBoardMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:126
static QMenu * createExtrasMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:138
static QMenu * createSchematicMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:122
static QMenu * createMoreResourcesMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:197
Flag
Definition: menubuilder.h:49
static QMenu * createHelpMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:142
QMenu * newMenu(MenuFactory factory) noexcept
Definition: menubuilder.cpp:53
void addAction(QAction *action, Flags flags=Flags()) noexcept
Definition: menubuilder.cpp:80
static QMenu * createChangeDeviceMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:174
static QMenu * createImportMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:155
QMenu *(* MenuFactory)(QWidget *)
Definition: menubuilder.h:47
static QMenu * createChangeModelMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:184
static QMenu * createEditMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:114
static QMenu * createLineWidthMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:170
void addSection(const QString &text, const QIcon &icon=QIcon()) noexcept
Definition: menubuilder.cpp:94
static QMenu * createProjectMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:130
static QMenu * createExportMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:160
static QMenu * createDocksVisibilityMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:150
static QMenu * createChangeFootprintMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:179
static QMenu * createViewMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:118
static QMenu * createToolsMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:134
static QMenu * createProductionDataMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:165
QPointer< QMenu > mMenu
Definition: menubuilder.h:103
void addSeparator() noexcept
Definition: menubuilder.cpp:100
static QMenu * createGoToDockMenu(QWidget *parent) noexcept
Definition: menubuilder.cpp:146
Definition: occmodel.cpp:77