KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
toolbar_configuration.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Ian McInerney
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef TOOLBAR_CONFIGURATION_H_
26#define TOOLBAR_CONFIGURATION_H_
27
28#include <string>
29#include <vector>
30
32#include <settings/parameters.h>
33#include <tool/action_toolbar.h>
34#include <tool/tool_action.h>
35
37{
38 TOOL,
40 SPACER,
41 CONTROL,
43};
44
46{
47public:
49 m_Type( TOOLBAR_ITEM_TYPE::TOOL ),
50 m_Size( 0 )
51 { }
52
54 m_Type( aType ),
55 m_Size( 0 )
56 { }
57
58 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, int aSize ) :
59 m_Type( aType ),
60 m_Size( aSize )
61 {
62 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
63 }
64
65 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, std::string aName ) :
66 m_Type( aType ),
67 m_Size( 0 )
68 {
69 if( aType == TOOLBAR_ITEM_TYPE::CONTROL )
70 m_ControlName = aName;
71 else if( aType == TOOLBAR_ITEM_TYPE::TOOL )
72 m_ActionName = aName;
73 }
74
75public:
77
78 // Control properties
79 std::string m_ControlName;
80
81 // Tool properties
82 std::string m_ActionName;
83
84 // Spacer properties
85 int m_Size;
86
87 // Group properties
88 wxString m_GroupName;
89 std::vector<TOOLBAR_ITEM> m_GroupItems;
90};
91
93{
94public:
95 TOOLBAR_GROUP_CONFIG( wxString aName ) :
96 m_groupName( aName )
97 {
98 }
99
100 const wxString& GetName() const
101 {
102 return m_groupName;
103 }
104
105 TOOLBAR_GROUP_CONFIG& AddAction( std::string aActionName )
106 {
107
108 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
109 return *this;
110 }
111
113 {
114 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
115 return *this;
116 }
117
118 std::vector<TOOLBAR_ITEM> GetGroupItems() const
119 {
120 return m_groupItems;
121 }
122
123public:
124 // These are public to write the JSON, but are lower-cased to encourage people not to directly
125 // access them and treat them as private.
126 wxString m_groupName;
127 std::vector<TOOLBAR_ITEM> m_groupItems;
128};
129
131{
132public:
133
136
137 TOOLBAR_CONFIGURATION& AppendAction( std::string aActionName )
138 {
139 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
140 return *this;
141 }
142
144 {
145 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
146 return *this;
147 }
148
150 {
151 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SEPARATOR );
152 return *this;
153 }
154
156 {
157 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SPACER, aSize );
158 return *this;
159 }
160
162 {
163 TOOLBAR_ITEM item( TOOLBAR_ITEM_TYPE::TB_GROUP );
164 item.m_GroupName = aGroup.GetName();
165 item.m_GroupItems = aGroup.GetGroupItems();
166
167 m_toolbarItems.push_back( item );
168 return *this;
169 }
170
171 TOOLBAR_CONFIGURATION& AppendControl( std::string aControlName )
172 {
173 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName );
174 return *this;
175 }
176
178 {
179 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControl.GetName() );
180 return *this;
181 }
182
183 std::vector<TOOLBAR_ITEM> GetToolbarItems() const
184 {
185 return m_toolbarItems;
186 }
187
188 void Clear()
189 {
190 m_toolbarItems.clear();
191 }
192
193public:
194 // These are public to write the JSON, but are lower-cased to encourage people not to directly
195 // access them and treat them as private.
196 std::vector<TOOLBAR_ITEM> m_toolbarItems;
197};
198
199
200enum class TOOLBAR_LOC
201{
202 LEFT = 0,
203 RIGHT,
204 TOP_MAIN,
205 TOP_AUX
206};
207
209{
210public:
211 TOOLBAR_SETTINGS( const wxString& aFilename );
212
213 virtual ~TOOLBAR_SETTINGS() {}
214
218 virtual std::optional<TOOLBAR_CONFIGURATION> DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
219 {
220 return std::nullopt;
221 }
222
228 std::optional<TOOLBAR_CONFIGURATION> GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aAllowCustom = true );
229
233 std::optional<TOOLBAR_CONFIGURATION> GetStoredToolbarConfig( TOOLBAR_LOC aToolbar );
234
239 {
240 m_toolbars[aToolbar] = aConfig;
241 }
242
243protected:
244 // The toolbars
245 std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;
246};
247
248#endif /* TOOLBAR_CONFIGURATION_H_ */
Class to hold basic information about controls that can be added to the toolbars.
const std::string & GetName() const
TOOLBAR_CONFIGURATION & AppendControl(const ACTION_TOOLBAR_CONTROL &aControl)
TOOLBAR_CONFIGURATION & AppendGroup(const TOOLBAR_GROUP_CONFIG &aGroup)
TOOLBAR_CONFIGURATION & AppendControl(std::string aControlName)
TOOLBAR_CONFIGURATION & AppendAction(const TOOL_ACTION &aAction)
TOOLBAR_CONFIGURATION & AppendSpacer(int aSize)
std::vector< TOOLBAR_ITEM > m_toolbarItems
std::vector< TOOLBAR_ITEM > GetToolbarItems() const
TOOLBAR_CONFIGURATION & AppendAction(std::string aActionName)
TOOLBAR_CONFIGURATION & AppendSeparator()
TOOLBAR_GROUP_CONFIG & AddAction(std::string aActionName)
std::vector< TOOLBAR_ITEM > GetGroupItems() const
TOOLBAR_GROUP_CONFIG(wxString aName)
TOOLBAR_GROUP_CONFIG & AddAction(const TOOL_ACTION &aAction)
const wxString & GetName() const
std::vector< TOOLBAR_ITEM > m_groupItems
std::vector< TOOLBAR_ITEM > m_GroupItems
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType, int aSize)
std::string m_ActionName
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType, std::string aName)
TOOLBAR_ITEM_TYPE m_Type
std::string m_ControlName
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType)
virtual std::optional< TOOLBAR_CONFIGURATION > DefaultToolbarConfig(TOOLBAR_LOC aToolbar)
Get the default tools to show on the specified canvas toolbar.
void SetStoredToolbarConfig(TOOLBAR_LOC aToolbar, TOOLBAR_CONFIGURATION &aConfig)
Set the stored configuration for the given toolbar.
std::map< TOOLBAR_LOC, TOOLBAR_CONFIGURATION > m_toolbars
Represent a single user action.
Definition: tool_action.h:304
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:337
#define KICOMMON_API
Definition: kicommon.h:28
@ RIGHT
Toolbar on the right side of the canvas.
@ LEFT
Toolbar on the left side of the canvas.
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.
TOOLBAR_ITEM_TYPE