KiCad PCB EDA Suite
PANEL_COLOR_SETTINGS Class Referenceabstract

#include <panel_color_settings.h>

Inheritance diagram for PANEL_COLOR_SETTINGS:
PANEL_COLOR_SETTINGS_BASE RESETTABLE_PANEL PANEL_EESCHEMA_COLOR_SETTINGS PANEL_FP_EDITOR_COLOR_SETTINGS PANEL_GERBVIEW_COLOR_SETTINGS PANEL_PCBNEW_COLOR_SETTINGS

Public Types

enum  COLOR_CONTEXT_ID { ID_COPY = wxID_HIGHEST + 1 , ID_PASTE , ID_REVERT }
 

Public Member Functions

 PANEL_COLOR_SETTINGS (wxWindow *aParent)
 
 ~PANEL_COLOR_SETTINGS ()=default
 
virtual void ResetPanel () override
 Reset the contents of this panel. More...
 
virtual wxString GetResetTooltip () const override
 Get the tooltip the reset button should display when showing this panel. More...
 
bool Show (bool show) override
 
wxString GetHelpTextAtPoint (const wxPoint &aPt, wxHelpEvent::Origin aOrigin) const override
 Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }. More...
 

Public Attributes

wxCheckBox * m_optOverrideColors
 

Protected Member Functions

void OnBtnOpenThemeFolderClicked (wxCommandEvent &event) override
 
void OnLeftDownTheme (wxMouseEvent &event) override
 
void OnThemeChanged (wxCommandEvent &aEvent) override
 
void ShowColorContextMenu (wxMouseEvent &aEvent, int aLayer)
 
void OnColorChanged (wxCommandEvent &aEvent)
 
virtual void createSwatches ()=0
 
void updateSwatches ()
 
void createThemeList (const wxString &aCurrent)
 Builds the theme listbox and sets the selection to the current theme. More...
 
void createSwatch (int aLayer, const wxString &aName)
 
void updateColor (int aLayer, const KIGFX::COLOR4D &aColor)
 
virtual bool saveCurrentTheme (bool aValidate)
 
virtual bool validateSave (bool aQuiet=false)
 Performs a pre-save validation of the current color theme. More...
 
virtual void onNewThemeSelected ()
 Event fired when a new theme is selected that can be overridden in children. More...
 
virtual void onColorChanged ()
 Event fired when the user changes any color. More...
 
virtual void OnSize (wxSizeEvent &event)
 
virtual void OnOverrideItemColorsClicked (wxCommandEvent &event)
 

Protected Attributes

COLOR_SETTINGSm_currentSettings
 
std::map< int, wxStaticText * > m_labels
 
std::map< int, COLOR_SWATCH * > m_swatches
 
KIGFX::COLOR4D m_copied
 
std::vector< int > m_validLayers
 A list of layer IDs that are valid for the current color settings dialog. More...
 
int m_backgroundLayer
 
std::string m_colorNamespace
 A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings. More...
 
wxBoxSizer * m_mainSizer
 
wxStaticText * m_staticText9
 
wxChoice * m_cbTheme
 
wxButton * m_btnOpenFolder
 
wxStaticLine * m_staticline2
 
wxBoxSizer * m_colorsMainSizer
 
wxScrolledWindow * m_colorsListWindow
 
wxFlexGridSizer * m_colorsGridSizer
 
wxBoxSizer * m_previewPanelSizer
 

Detailed Description

Definition at line 32 of file panel_color_settings.h.

Member Enumeration Documentation

◆ COLOR_CONTEXT_ID

Enumerator
ID_COPY 
ID_PASTE 
ID_REVERT 

Definition at line 39 of file panel_color_settings.h.

Constructor & Destructor Documentation

◆ PANEL_COLOR_SETTINGS()

PANEL_COLOR_SETTINGS::PANEL_COLOR_SETTINGS ( wxWindow *  aParent)

Definition at line 41 of file panel_color_settings.cpp.

41 :
43 m_currentSettings( nullptr ),
44 m_swatches(),
45 m_copied( COLOR4D::UNSPECIFIED ),
49{
50#ifdef __APPLE__
51 m_btnOpenFolder->SetLabel( _( "Reveal Themes in Finder" ) );
52
53 // Simple border is too dark on OSX
54 m_colorsListWindow->SetWindowStyle( wxBORDER_SUNKEN|wxVSCROLL );
55#endif
56}
PANEL_COLOR_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
COLOR_SETTINGS * m_currentSettings
std::map< int, COLOR_SWATCH * > m_swatches
#define _(s)
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220

References _, PANEL_COLOR_SETTINGS_BASE::m_btnOpenFolder, PANEL_COLOR_SETTINGS_BASE::m_colorsListWindow, and UNSPECIFIED.

◆ ~PANEL_COLOR_SETTINGS()

PANEL_COLOR_SETTINGS::~PANEL_COLOR_SETTINGS ( )
default

Member Function Documentation

◆ createSwatch()

void PANEL_COLOR_SETTINGS::createSwatch ( int  aLayer,
const wxString &  aName 
)
protected

Definition at line 239 of file panel_color_settings.cpp.

240{
241 wxStaticText* label = new wxStaticText( m_colorsListWindow, wxID_ANY, aName );
242
243 // The previously selected theme can be deleted and cannot be selected.
244 // so select the default theme (first theme of the list)
245 if( m_cbTheme->GetSelection() < 0 )
246 {
247 m_cbTheme->SetSelection( 0 );
249 }
250
251 void* clientData = m_cbTheme->GetClientData( m_cbTheme->GetSelection() );
252 COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( clientData );
253
254 int id = FIRST_BUTTON_ID + aLayer;
255 COLOR4D defaultColor = selected->GetDefaultColor( aLayer );
258
259 COLOR_SWATCH* swatch = new COLOR_SWATCH( m_colorsListWindow, color, id, backgroundColor,
260 defaultColor, SWATCH_MEDIUM );
261 swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
262
263 m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
264 m_colorsGridSizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3 );
265
266 m_labels[aLayer] = label;
267 m_swatches[aLayer] = swatch;
268
269 swatch->Bind( wxEVT_RIGHT_DOWN,
270 [&, aLayer]( wxMouseEvent& aEvent )
271 {
272 ShowColorContextMenu( aEvent, aLayer );
273 } );
274
275 swatch->Bind( COLOR_SWATCH_CHANGED, &PANEL_COLOR_SETTINGS::OnColorChanged, this );
276}
int color
Definition: DXF_plotter.cpp:57
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
COLOR4D GetDefaultColor(int aLayer)
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:57
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
void OnColorChanged(wxCommandEvent &aEvent)
std::map< int, wxStaticText * > m_labels
virtual void onNewThemeSelected()
Event fired when a new theme is selected that can be overridden in children.
void ShowColorContextMenu(wxMouseEvent &aEvent, int aLayer)
@ SWATCH_MEDIUM
Definition: color_swatch.h:41
constexpr int FIRST_BUTTON_ID

References color, FIRST_BUTTON_ID, COLOR_SETTINGS::GetColor(), COLOR_SETTINGS::GetDefaultColor(), m_backgroundLayer, PANEL_COLOR_SETTINGS_BASE::m_cbTheme, PANEL_COLOR_SETTINGS_BASE::m_colorsGridSizer, PANEL_COLOR_SETTINGS_BASE::m_colorsListWindow, m_currentSettings, m_labels, m_swatches, OnColorChanged(), onNewThemeSelected(), ShowColorContextMenu(), and SWATCH_MEDIUM.

Referenced by PANEL_EESCHEMA_COLOR_SETTINGS::createSwatches(), PANEL_GERBVIEW_COLOR_SETTINGS::createSwatches(), PANEL_FP_EDITOR_COLOR_SETTINGS::createSwatches(), and PANEL_PCBNEW_COLOR_SETTINGS::createSwatches().

◆ createSwatches()

virtual void PANEL_COLOR_SETTINGS::createSwatches ( )
protectedpure virtual

◆ createThemeList()

void PANEL_COLOR_SETTINGS::createThemeList ( const wxString &  aCurrent)
protected

Builds the theme listbox and sets the selection to the current theme.

Parameters
aCurrentis the filename of the current color theme (no extension)

Definition at line 206 of file panel_color_settings.cpp.

207{
208 int width = 0;
209 int height = 0;
210
211 m_cbTheme->GetTextExtent( _( "New Theme..." ), &width, &height );
212 int minwidth = width;
213
214 m_cbTheme->Clear();
215
216 for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
217 {
218 wxString name = settings->GetName();
219
220 if( settings->IsReadOnly() )
221 name += wxS( " " ) + _( "(read-only)" );
222
223 int pos = m_cbTheme->Append( name, static_cast<void*>( settings ) );
224
225 if( settings->GetFilename() == aCurrent )
226 m_cbTheme->SetSelection( pos );
227
228 m_cbTheme->GetTextExtent( name, &width, &height );
229 minwidth = std::max( minwidth, width );
230 }
231
232 m_cbTheme->Append( wxT( "---" ) );
233 m_cbTheme->Append( _( "New Theme..." ) );
234
235 m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
236}
const char * name
Definition: DXF_plotter.cpp:56
SETTINGS_MANAGER * GetSettingsManager()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References _, GetSettingsManager(), PANEL_COLOR_SETTINGS_BASE::m_cbTheme, name, and Pgm().

Referenced by OnLeftDownTheme(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS(), and PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS().

◆ GetHelpTextAtPoint()

wxString RESETTABLE_PANEL::GetHelpTextAtPoint ( const wxPoint &  aPt,
wxHelpEvent::Origin  aOrigin 
) const
inlineoverrideinherited

Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }.

Definition at line 72 of file resettable_panel.h.

73 {
74 if( aPt == wxPoint( -INT_MAX, INT_MAX ) )
75 return GetResetTooltip();
76 else
77 return wxPanel::GetHelpTextAtPoint( aPt, aOrigin );
78 }
virtual wxString GetResetTooltip() const
Get the tooltip the reset button should display when showing this panel.

References RESETTABLE_PANEL::GetResetTooltip().

◆ GetResetTooltip()

virtual wxString PANEL_COLOR_SETTINGS::GetResetTooltip ( ) const
inlineoverridevirtual

Get the tooltip the reset button should display when showing this panel.

Returns
the tooltip

Reimplemented from RESETTABLE_PANEL.

Definition at line 48 of file panel_color_settings.h.

49 {
50 return _( "Reset all colors in this theme to the KiCad defaults" );
51 }

References _.

◆ OnBtnOpenThemeFolderClicked()

void PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 59 of file panel_color_settings.cpp.

60{
62 LaunchExternal( dir );
63}
static wxString GetColorSettingsPath()
Returns the path where color scheme files are stored; creating it if missing (normally .
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
Definition: launch_ext.cpp:25

References SETTINGS_MANAGER::GetColorSettingsPath(), and LaunchExternal().

◆ onColorChanged()

virtual void PANEL_COLOR_SETTINGS::onColorChanged ( )
inlineprotectedvirtual

Event fired when the user changes any color.

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS, and PANEL_PCBNEW_COLOR_SETTINGS.

Definition at line 98 of file panel_color_settings.h.

98{}

Referenced by updateColor().

◆ OnColorChanged()

void PANEL_COLOR_SETTINGS::OnColorChanged ( wxCommandEvent &  aEvent)
protected

Definition at line 324 of file panel_color_settings.cpp.

325{
326 COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
327 COLOR4D newColor = swatch->GetSwatchColor();
328 int layer = static_cast<SCH_LAYER_ID>( swatch->GetId() - FIRST_BUTTON_ID );
329
330 updateColor( layer, newColor );
331}
KIGFX::COLOR4D GetSwatchColor() const
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341

References FIRST_BUTTON_ID, COLOR_SWATCH::GetSwatchColor(), and updateColor().

Referenced by createSwatch().

◆ OnLeftDownTheme()

void PANEL_COLOR_SETTINGS::OnLeftDownTheme ( wxMouseEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 103 of file panel_color_settings.cpp.

104{
105 // Lazy rebuild of theme menu to catch any colour theme changes made in other panels
107
108 event.Skip();
109}
wxString GetFilename() const
Definition: json_settings.h:73
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.

References createThemeList(), JSON_SETTINGS::GetFilename(), and m_currentSettings.

◆ onNewThemeSelected()

virtual void PANEL_COLOR_SETTINGS::onNewThemeSelected ( )
inlineprotectedvirtual

Event fired when a new theme is selected that can be overridden in children.

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS, and PANEL_PCBNEW_COLOR_SETTINGS.

Definition at line 93 of file panel_color_settings.h.

93{}

Referenced by createSwatch(), OnThemeChanged(), and Show().

◆ OnOverrideItemColorsClicked()

virtual void PANEL_COLOR_SETTINGS_BASE::OnOverrideItemColorsClicked ( wxCommandEvent &  event)
inlineprotectedvirtualinherited

◆ OnSize()

virtual void PANEL_COLOR_SETTINGS_BASE::OnSize ( wxSizeEvent &  event)
inlineprotectedvirtualinherited

◆ OnThemeChanged()

void PANEL_COLOR_SETTINGS::OnThemeChanged ( wxCommandEvent &  aEvent)
overrideprotectedvirtual

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 112 of file panel_color_settings.cpp.

113{
114 int idx = m_cbTheme->GetSelection();
115
116 if( idx == static_cast<int>( m_cbTheme->GetCount() ) - 2 )
117 {
118 // separator; re-select active theme
119 m_cbTheme->SetStringSelection( m_currentSettings->GetName() );
120 return;
121 }
122
123 if( idx == (int)m_cbTheme->GetCount() - 1 )
124 {
125 // New Theme...
126
127 if( !saveCurrentTheme( false ) )
128 return;
129
130 FOOTPRINT_NAME_VALIDATOR themeNameValidator;
131 wxTextEntryDialog dlg( this, _( "New theme name:" ), _( "Add Color Theme" ) );
132 dlg.SetTextValidator( themeNameValidator );
133
134 if( dlg.ShowModal() != wxID_OK )
135 return;
136
137 wxString themeName = dlg.GetValue();
138 wxFileName fn( themeName + wxT( ".json" ) );
140
141 if( fn.Exists() )
142 {
143 wxMessageBox( _( "Theme already exists!" ) );
144 return;
145 }
146
147 SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
148 COLOR_SETTINGS* newSettings = settingsMgr.AddNewColorSettings( themeName );
149 newSettings->SetName( themeName );
150 newSettings->SetReadOnly( false );
151
152 for( int layer : m_validLayers )
153 newSettings->SetColor( layer, m_currentSettings->GetColor( layer ) );
154
155 newSettings->SaveToFile( settingsMgr.GetPathForSettingsFile( newSettings ) );
156
157 idx = m_cbTheme->Insert( themeName, idx - 1, static_cast<void*>( newSettings ) );
158 m_cbTheme->SetSelection( idx );
159
160 m_optOverrideColors->SetValue( newSettings->GetOverrideSchItemColors() );
161
162 *m_currentSettings = *newSettings;
165 }
166 else
167 {
168 COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
169
170 if( selected->GetFilename() != m_currentSettings->GetFilename() )
171 {
172 if( !saveCurrentTheme( false ) )
173 return;
174
175 m_optOverrideColors->SetValue( selected->GetOverrideSchItemColors() );
176
177 *m_currentSettings = *selected;
180 }
181 }
182}
void SetName(const wxString &aName)
void SetColor(int aLayer, const COLOR4D &aColor)
bool GetOverrideSchItemColors() const
const wxString & GetName() const
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:64
void SetReadOnly(bool aReadOnly)
Definition: json_settings.h:85
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
virtual bool saveCurrentTheme(bool aValidate)
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Returns the path a given settings file should be loaded from / stored to.
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Registers a new color settings object with the given filename.

References _, SETTINGS_MANAGER::AddNewColorSettings(), COLOR_SETTINGS::GetColor(), SETTINGS_MANAGER::GetColorSettingsPath(), JSON_SETTINGS::GetFilename(), COLOR_SETTINGS::GetName(), COLOR_SETTINGS::GetOverrideSchItemColors(), SETTINGS_MANAGER::GetPathForSettingsFile(), PANEL_COLOR_SETTINGS_BASE::m_cbTheme, m_currentSettings, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, m_validLayers, onNewThemeSelected(), Pgm(), saveCurrentTheme(), JSON_SETTINGS::SaveToFile(), COLOR_SETTINGS::SetColor(), COLOR_SETTINGS::SetName(), JSON_SETTINGS::SetReadOnly(), and updateSwatches().

◆ ResetPanel()

void PANEL_COLOR_SETTINGS::ResetPanel ( )
overridevirtual

Reset the contents of this panel.

Implements RESETTABLE_PANEL.

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS, and PANEL_PCBNEW_COLOR_SETTINGS.

Definition at line 66 of file panel_color_settings.cpp.

67{
69 return;
70
71 for( const std::pair<const int, COLOR_SWATCH*>& pair : m_swatches )
72 {
73 int layer = pair.first;
74 COLOR_SWATCH* button = pair.second;
75
76 COLOR4D defaultColor = m_currentSettings->GetDefaultColor( layer );
77
78 m_currentSettings->SetColor( layer, defaultColor );
79 button->SetSwatchColor( defaultColor, false );
80 }
81}
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
bool IsReadOnly() const
Definition: json_settings.h:84

References COLOR_SETTINGS::GetDefaultColor(), JSON_SETTINGS::IsReadOnly(), m_currentSettings, m_swatches, COLOR_SETTINGS::SetColor(), and COLOR_SWATCH::SetSwatchColor().

Referenced by PANEL_EESCHEMA_COLOR_SETTINGS::ResetPanel(), and PANEL_PCBNEW_COLOR_SETTINGS::ResetPanel().

◆ saveCurrentTheme()

bool PANEL_COLOR_SETTINGS::saveCurrentTheme ( bool  aValidate)
protectedvirtual

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS.

Definition at line 357 of file panel_color_settings.cpp.

358{
360 return true;
361
362 if( aValidate && !validateSave() )
363 return false;
364
365 SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
366 COLOR_SETTINGS* selected = settingsMgr.GetColorSettings( m_currentSettings->GetFilename() );
367
368 selected->SetOverrideSchItemColors( m_optOverrideColors->GetValue() );
369
370 for( int layer : m_validLayers )
371 selected->SetColor( layer, m_currentSettings->GetColor( layer ) );
372
373 settingsMgr.SaveColorSettings( selected, m_colorNamespace );
374
375 return true;
376}
void SetOverrideSchItemColors(bool aFlag)
virtual bool validateSave(bool aQuiet=false)
Performs a pre-save validation of the current color theme.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.

References COLOR_SETTINGS::GetColor(), SETTINGS_MANAGER::GetColorSettings(), JSON_SETTINGS::GetFilename(), JSON_SETTINGS::IsReadOnly(), m_colorNamespace, m_currentSettings, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, m_validLayers, Pgm(), SETTINGS_MANAGER::SaveColorSettings(), COLOR_SETTINGS::SetColor(), COLOR_SETTINGS::SetOverrideSchItemColors(), and validateSave().

Referenced by OnThemeChanged(), PANEL_EESCHEMA_COLOR_SETTINGS::saveCurrentTheme(), and updateColor().

◆ Show()

bool PANEL_COLOR_SETTINGS::Show ( bool  show)
override

Definition at line 84 of file panel_color_settings.cpp.

85{
86 if( show )
87 {
88 // In case changes have been made to the current theme in another panel:
89 int idx = m_cbTheme->GetSelection();
90 COLOR_SETTINGS* settings = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
91
92 if( settings )
93 *m_currentSettings = *settings;
94
97 }
98
99 return PANEL_COLOR_SETTINGS_BASE::Show( show );
100}

References PANEL_COLOR_SETTINGS_BASE::m_cbTheme, m_currentSettings, onNewThemeSelected(), and updateSwatches().

◆ ShowColorContextMenu()

void PANEL_COLOR_SETTINGS::ShowColorContextMenu ( wxMouseEvent &  aEvent,
int  aLayer 
)
protected

Definition at line 279 of file panel_color_settings.cpp.

280{
281 auto selected =
282 static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
283
284 COLOR4D current = m_currentSettings->GetColor( aLayer );
285 COLOR4D saved = selected->GetColor( aLayer );
286 bool readOnly = m_currentSettings->IsReadOnly();
287
288 wxMenu menu;
289
290 AddMenuItem( &menu, ID_COPY, _( "Copy color" ), KiBitmap( BITMAPS::copy ) );
291
292 if( !readOnly && m_copied != COLOR4D::UNSPECIFIED )
293 AddMenuItem( &menu, ID_PASTE, _( "Paste color" ), KiBitmap( BITMAPS::paste ) );
294
295 if( !readOnly && current != saved )
296 AddMenuItem( &menu, ID_REVERT, _( "Revert to saved color" ), KiBitmap( BITMAPS::undo ) );
297
298 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
299 [&]( wxCommandEvent& aCmd )
300 {
301 switch( aCmd.GetId() )
302 {
303 case ID_COPY:
304 m_copied = current;
305 break;
306
307 case ID_PASTE:
308 updateColor( aLayer, m_copied );
309 break;
310
311 case ID_REVERT:
312 updateColor( aLayer, saved );
313 break;
314
315 default:
316 aCmd.Skip();
317 }
318 } );
319
320 PopupMenu( &menu );
321}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
Definition: bitmap.cpp:265

References _, AddMenuItem(), copy, COLOR_SETTINGS::GetColor(), ID_COPY, ID_PASTE, ID_REVERT, JSON_SETTINGS::IsReadOnly(), KiBitmap(), PANEL_COLOR_SETTINGS_BASE::m_cbTheme, m_copied, m_currentSettings, paste, and undo.

Referenced by createSwatch().

◆ updateColor()

void PANEL_COLOR_SETTINGS::updateColor ( int  aLayer,
const KIGFX::COLOR4D aColor 
)
protected

Definition at line 334 of file panel_color_settings.cpp.

335{
337 m_currentSettings->SetColor( aLayer, aColor );
338
339 // Colors must be persisted when edited because multiple PANEL_COLOR_SETTINGS could be
340 // referring to the same theme.
341 saveCurrentTheme( false );
342
343 m_swatches[aLayer]->SetSwatchColor( aColor, false );
344
345 if( m_currentSettings && aLayer == m_backgroundLayer )
346 {
348
349 for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
350 pair.second->SetSwatchBackground( background );
351 }
352
354}
virtual void onColorChanged()
Event fired when the user changes any color.

References COLOR_SETTINGS::GetColor(), m_backgroundLayer, m_currentSettings, m_swatches, onColorChanged(), saveCurrentTheme(), and COLOR_SETTINGS::SetColor().

Referenced by OnColorChanged().

◆ updateSwatches()

void PANEL_COLOR_SETTINGS::updateSwatches ( )
protected

Definition at line 185 of file panel_color_settings.cpp.

186{
187 if( m_swatches.empty() )
188 {
190 }
191 else
192 {
193 bool isReadOnly = m_currentSettings->IsReadOnly();
195
196 for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
197 {
198 pair.second->SetSwatchBackground( background );
199 pair.second->SetSwatchColor( m_currentSettings->GetColor( pair.first ), false );
200 pair.second->SetReadOnly( isReadOnly );
201 }
202 }
203}
virtual void createSwatches()=0

References createSwatches(), COLOR_SETTINGS::GetColor(), JSON_SETTINGS::IsReadOnly(), m_backgroundLayer, m_currentSettings, and m_swatches.

Referenced by OnThemeChanged(), and Show().

◆ validateSave()

virtual bool PANEL_COLOR_SETTINGS::validateSave ( bool  aQuiet = false)
inlineprotectedvirtual

Performs a pre-save validation of the current color theme.

Parameters
aQuietwill suppress any warning output (prompt dialogs)
Returns
true if save is allowed

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS.

Definition at line 85 of file panel_color_settings.h.

86 {
87 return true;
88 }

Referenced by saveCurrentTheme().

Member Data Documentation

◆ m_backgroundLayer

◆ m_btnOpenFolder

wxButton* PANEL_COLOR_SETTINGS_BASE::m_btnOpenFolder
protectedinherited

◆ m_cbTheme

◆ m_colorNamespace

std::string PANEL_COLOR_SETTINGS::m_colorNamespace
protected

◆ m_colorsGridSizer

wxFlexGridSizer* PANEL_COLOR_SETTINGS_BASE::m_colorsGridSizer
protectedinherited

◆ m_colorsListWindow

◆ m_colorsMainSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_colorsMainSizer
protectedinherited

◆ m_copied

KIGFX::COLOR4D PANEL_COLOR_SETTINGS::m_copied
protected

Definition at line 105 of file panel_color_settings.h.

Referenced by ShowColorContextMenu().

◆ m_currentSettings

◆ m_labels

std::map<int, wxStaticText*> PANEL_COLOR_SETTINGS::m_labels
protected

◆ m_mainSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_mainSizer
protectedinherited

◆ m_optOverrideColors

◆ m_previewPanelSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_previewPanelSizer
protectedinherited

◆ m_staticline2

wxStaticLine* PANEL_COLOR_SETTINGS_BASE::m_staticline2
protectedinherited

◆ m_staticText9

wxStaticText* PANEL_COLOR_SETTINGS_BASE::m_staticText9
protectedinherited

◆ m_swatches

std::map<int, COLOR_SWATCH*> PANEL_COLOR_SETTINGS::m_swatches
protected

◆ m_validLayers

std::vector<int> PANEL_COLOR_SETTINGS::m_validLayers
protected

A list of layer IDs that are valid for the current color settings dialog.

Valid colors will be shown for editing and are the set of colors that actions like resetting to defaults will apply to.

This list must be filled in the application-specific color settings panel constructors.

Definition at line 115 of file panel_color_settings.h.

Referenced by PANEL_GERBVIEW_COLOR_SETTINGS::createSwatches(), PANEL_FP_EDITOR_COLOR_SETTINGS::createSwatches(), PANEL_PCBNEW_COLOR_SETTINGS::createSwatches(), OnThemeChanged(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS(), PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS(), saveCurrentTheme(), and PANEL_EESCHEMA_COLOR_SETTINGS::saveCurrentTheme().


The documentation for this class was generated from the following files: