KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 { }
50
52 m_Type( aType )
53 { }
54
55 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, int aSize ) :
56 m_Type( aType ),
57 m_Size( aSize )
58 {
59 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
60 }
61
62 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, std::string aName ) :
63 m_Type( aType )
64 {
65 if( aType == TOOLBAR_ITEM_TYPE::CONTROL )
66 m_ControlName = aName;
67 else if( aType == TOOLBAR_ITEM_TYPE::TOOL )
68 m_ActionName = aName;
69 }
70
71public:
73
74 // Control properties
75 std::string m_ControlName;
76
77 // Tool properties
78 std::string m_ActionName;
79
80 // Spacer properties
81 int m_Size;
82
83 // Group properties
84 wxString m_GroupName;
85 std::vector<TOOLBAR_ITEM> m_GroupItems;
86};
87
89{
90public:
91 TOOLBAR_GROUP_CONFIG( wxString aName ) :
92 m_groupName( aName )
93 {
94 }
95
96 const wxString& GetName() const
97 {
98 return m_groupName;
99 }
100
101 TOOLBAR_GROUP_CONFIG& AddAction( std::string aActionName )
102 {
103
104 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
105 return *this;
106 }
107
109 {
110 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
111 return *this;
112 }
113
114 std::vector<TOOLBAR_ITEM> GetGroupItems() const
115 {
116 return m_groupItems;
117 }
118
119public:
120 // These are public to write the JSON, but are lower-cased to encourage people not to directly
121 // access them and treat them as private.
122 wxString m_groupName;
123 std::vector<TOOLBAR_ITEM> m_groupItems;
124};
125
127{
128public:
129
132
133 TOOLBAR_CONFIGURATION& AppendAction( std::string aActionName )
134 {
135 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
136 return *this;
137 }
138
140 {
141 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
142 return *this;
143 }
144
146 {
147 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SEPARATOR );
148 return *this;
149 }
150
152 {
153 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SPACER, aSize );
154 return *this;
155 }
156
158 {
159 TOOLBAR_ITEM item( TOOLBAR_ITEM_TYPE::TB_GROUP );
160 item.m_GroupName = aGroup.GetName();
161 item.m_GroupItems = aGroup.GetGroupItems();
162
163 m_toolbarItems.push_back( item );
164 return *this;
165 }
166
167 TOOLBAR_CONFIGURATION& AppendControl( std::string aControlName )
168 {
169 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName );
170 return *this;
171 }
172
174 {
175 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControl.GetName() );
176 return *this;
177 }
178
179 std::vector<TOOLBAR_ITEM> GetToolbarItems() const
180 {
181 return m_toolbarItems;
182 }
183
184 void Clear()
185 {
186 m_toolbarItems.clear();
187 }
188
189public:
190 // These are public to write the JSON, but are lower-cased to encourage people not to directly
191 // access them and treat them as private.
192 std::vector<TOOLBAR_ITEM> m_toolbarItems;
193};
194
195
196enum class TOOLBAR_LOC
197{
198 LEFT = 0,
199 RIGHT,
200 TOP_MAIN,
201 TOP_AUX
202};
203
205{
206public:
207 TOOLBAR_SETTINGS( const wxString& aFilename );
208
209 virtual ~TOOLBAR_SETTINGS() {}
210
214 virtual std::optional<TOOLBAR_CONFIGURATION> DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
215 {
216 return std::nullopt;
217 }
218
224 std::optional<TOOLBAR_CONFIGURATION> GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aAllowCustom = true );
225
229 std::optional<TOOLBAR_CONFIGURATION> GetStoredToolbarConfig( TOOLBAR_LOC aToolbar );
230
235 {
236 m_toolbars[aToolbar] = aConfig;
237 }
238
239protected:
240 // The toolbars
241 std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;
242};
243
244#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