KiCad PCB EDA Suite
PANEL_FP_EDITOR_COLOR_SETTINGS Class Reference

#include <panel_fp_editor_color_settings.h>

Inheritance diagram for PANEL_FP_EDITOR_COLOR_SETTINGS:
PANEL_COLOR_SETTINGS PANEL_COLOR_SETTINGS_BASE RESETTABLE_PANEL

Public Member Functions

 PANEL_FP_EDITOR_COLOR_SETTINGS (FOOTPRINT_EDIT_FRAME *aFrame, wxWindow *aParent)
 
 ~PANEL_FP_EDITOR_COLOR_SETTINGS () override
 
virtual void ResetPanel () override
 Reset the contents of this panel. More...
 
virtual wxString GetResetTooltip () override
 Get the tooltip the reset button should display when showing this panel. More...
 
bool Show (bool show) override
 

Public Attributes

wxCheckBox * m_optOverrideColors
 

Protected Types

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

Protected Member Functions

bool TransferDataFromWindow () override
 
bool TransferDataToWindow () override
 
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)
 
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
 

Private Member Functions

void createSwatches ()
 

Private Attributes

FOOTPRINT_EDIT_FRAMEm_frame
 
PAGE_INFOm_page
 
TITLE_BLOCKm_titleBlock
 

Detailed Description

Definition at line 35 of file panel_fp_editor_color_settings.h.

Member Enumeration Documentation

◆ COLOR_CONTEXT_ID

Constructor & Destructor Documentation

◆ PANEL_FP_EDITOR_COLOR_SETTINGS()

PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS ( FOOTPRINT_EDIT_FRAME aFrame,
wxWindow *  aParent 
)

Definition at line 33 of file panel_fp_editor_color_settings.cpp.

35  : PANEL_COLOR_SETTINGS( aParent ),
36  m_frame( aFrame ),
37  m_page( nullptr ),
38  m_titleBlock( nullptr )
39 {
40  // Currently this only applies to eeschema
41  m_optOverrideColors->Hide();
42 
43  m_colorNamespace = "board";
44 
45  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
46 
48  COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
49 
50  // Store the current settings before reloading below
51  current->Store();
52  mgr.SaveColorSettings( current, "board" );
53 
54  m_optOverrideColors->SetValue( current->GetOverrideSchItemColors() );
55 
56  m_currentSettings = new COLOR_SETTINGS( *current );
57 
58  mgr.ReloadColorSettings();
59  createThemeList( settings->m_ColorTheme );
60 
61  m_validLayers.push_back( F_Cu );
62  m_validLayers.push_back( In1_Cu ); // "Internal Layers"
63  m_validLayers.push_back( B_Cu );
64 
65  for( int id = GAL_LAYER_ID_START; id < GAL_LAYER_ID_END; id++ )
66  {
67  if( id == LAYER_VIAS
68  || id == LAYER_VIA_HOLES
69  || id == LAYER_VIA_HOLEWALLS
70  || id == LAYER_PAD_PLATEDHOLES
71  || id == LAYER_PAD_HOLEWALLS )
72  {
73  continue;
74  }
75 
76  m_validLayers.push_back( id );
77  }
78 
80 
81  m_colorsMainSizer->Insert( 0, 10, 0, 0, wxEXPAND, 5 );
82 
84 }
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
to draw via holes (pad holes do not use this layer)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
COLOR_SETTINGS * m_currentSettings
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
PANEL_COLOR_SETTINGS(wxWindow *aParent)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void ReloadColorSettings()
Re-scans the color themes directory, reloading any changes it finds.
Meta control for all vias opacity/visibility.
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
Color settings are a bit different than most of the settings objects in that there can be more than o...
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184

References B_Cu, createSwatches(), PANEL_COLOR_SETTINGS::createThemeList(), F_Cu, GAL_LAYER_ID_END, GAL_LAYER_ID_START, SETTINGS_MANAGER::GetAppSettings(), SETTINGS_MANAGER::GetColorSettings(), In1_Cu, LAYER_PAD_HOLEWALLS, LAYER_PAD_PLATEDHOLES, LAYER_PCB_BACKGROUND, LAYER_VIA_HOLES, LAYER_VIA_HOLEWALLS, LAYER_VIAS, PANEL_COLOR_SETTINGS::m_backgroundLayer, PANEL_COLOR_SETTINGS::m_colorNamespace, PANEL_COLOR_SETTINGS_BASE::m_colorsMainSizer, APP_SETTINGS_BASE::m_ColorTheme, PANEL_COLOR_SETTINGS::m_currentSettings, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, PANEL_COLOR_SETTINGS::m_validLayers, Pgm(), SETTINGS_MANAGER::ReloadColorSettings(), SETTINGS_MANAGER::SaveColorSettings(), and JSON_SETTINGS::Store().

◆ ~PANEL_FP_EDITOR_COLOR_SETTINGS()

PANEL_FP_EDITOR_COLOR_SETTINGS::~PANEL_FP_EDITOR_COLOR_SETTINGS ( )
override

Member Function Documentation

◆ createSwatch()

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

Definition at line 230 of file panel_color_settings.cpp.

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

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

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

◆ createSwatches()

void PANEL_FP_EDITOR_COLOR_SETTINGS::createSwatches ( )
private

Definition at line 111 of file panel_fp_editor_color_settings.cpp.

112 {
113  std::vector<GAL_LAYER_ID> galLayers;
114 
115  // Sort the gal layers by name
116  for( int i : m_validLayers )
117  {
118  if( i >= GAL_LAYER_ID_START && m_currentSettings->GetColor( i ) != COLOR4D::UNSPECIFIED )
119  galLayers.push_back( (GAL_LAYER_ID) i );
120  }
121 
122  std::sort( galLayers.begin(), galLayers.end(),
123  []( int a, int b )
124  {
125  return LayerName( a ) < LayerName( b );
126  } );
127 
128  BOARD* board = m_frame->GetBoard();
129 
130  createSwatch( F_Cu, board ? board->GetLayerName( F_Cu ) : LayerName( F_Cu ) );
131  createSwatch( In1_Cu, _( "Internal Layers" ) );
132  createSwatch( B_Cu, board ? board->GetLayerName( B_Cu ) : LayerName( B_Cu ) );
133 
134  for( GAL_LAYER_ID layer : galLayers )
135  createSwatch( layer, LayerName( layer ) );
136 }
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
COLOR_SETTINGS * m_currentSettings
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:27
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
COLOR4D GetColor(int aLayer) const
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * GetBoard() const
void createSwatch(int aLayer, const wxString &aName)

References _, B_Cu, PANEL_COLOR_SETTINGS::createSwatch(), F_Cu, GAL_LAYER_ID_START, PCB_BASE_FRAME::GetBoard(), COLOR_SETTINGS::GetColor(), In1_Cu, LayerName(), PANEL_COLOR_SETTINGS::m_currentSettings, m_frame, and PANEL_COLOR_SETTINGS::m_validLayers.

Referenced by PANEL_FP_EDITOR_COLOR_SETTINGS().

◆ createThemeList()

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

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 197 of file panel_color_settings.cpp.

198 {
199  int width = 0;
200  int height = 0;
201 
202  m_cbTheme->GetTextExtent( _( "New Theme..." ), &width, &height );
203  int minwidth = width;
204 
205  m_cbTheme->Clear();
206 
207  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
208  {
209  wxString name = settings->GetName();
210 
211  if( settings->IsReadOnly() )
212  name += wxS( " " ) + _( "(read-only)" );
213 
214  int pos = m_cbTheme->Append( name, static_cast<void*>( settings ) );
215 
216  if( settings->GetFilename() == aCurrent )
217  m_cbTheme->SetSelection( pos );
218 
219  m_cbTheme->GetTextExtent( name, &width, &height );
220  minwidth = std::max( minwidth, width );
221  }
222 
223  m_cbTheme->Append( wxT( "---" ) );
224  m_cbTheme->Append( _( "New Theme..." ) );
225 
226  m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
227 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
SETTINGS_MANAGER * GetSettingsManager()
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Definition: 3d_actions.cpp:33
Color settings are a bit different than most of the settings objects in that there can be more than o...

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

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

◆ GetResetTooltip()

virtual wxString PANEL_COLOR_SETTINGS::GetResetTooltip ( )
inlineoverridevirtualinherited

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  }
#define _(s)
Definition: 3d_actions.cpp:33

References _.

◆ OnBtnOpenThemeFolderClicked()

void PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked ( wxCommandEvent &  event)
overrideprotectedvirtualinherited

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 57 of file panel_color_settings.cpp.

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

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

◆ OnColorChanged()

void PANEL_COLOR_SETTINGS::OnColorChanged ( wxCommandEvent &  aEvent)
protectedinherited

Definition at line 315 of file panel_color_settings.cpp.

316 {
317  COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
318  COLOR4D newColor = swatch->GetSwatchColor();
319  LAYER_NUM layer = static_cast<SCH_LAYER_ID>( swatch->GetId() - FIRST_BUTTON_ID );
320 
321  updateColor( layer, newColor );
322 }
KIGFX::COLOR4D GetSwatchColor() const
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
constexpr int FIRST_BUTTON_ID
int LAYER_NUM
This can be replaced with int and removed.
Class representing 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:98

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

Referenced by PANEL_COLOR_SETTINGS::createSwatch().

◆ onColorChanged()

virtual void PANEL_COLOR_SETTINGS::onColorChanged ( )
inlineprotectedvirtualinherited

Event fired when the user changes any color.

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS, and PANEL_PCBNEW_COLOR_SETTINGS.

Definition at line 97 of file panel_color_settings.h.

97 {}

Referenced by PANEL_COLOR_SETTINGS::updateColor().

◆ OnLeftDownTheme()

void PANEL_COLOR_SETTINGS::OnLeftDownTheme ( wxMouseEvent &  event)
overrideprotectedvirtualinherited

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 101 of file panel_color_settings.cpp.

102 {
103  // Lazy rebuild of theme menu to catch any colour theme changes made in other panels
105 
106  event.Skip();
107 }
wxString GetFilename() const
Definition: json_settings.h:66
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
COLOR_SETTINGS * m_currentSettings

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

◆ onNewThemeSelected()

virtual void PANEL_COLOR_SETTINGS::onNewThemeSelected ( )
inlineprotectedvirtualinherited

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 92 of file panel_color_settings.h.

92 {}

Referenced by PANEL_COLOR_SETTINGS::createSwatch(), PANEL_COLOR_SETTINGS::OnThemeChanged(), and PANEL_COLOR_SETTINGS::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)
overrideprotectedvirtualinherited

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 110 of file panel_color_settings.cpp.

111 {
112  int idx = m_cbTheme->GetSelection();
113 
114  if( idx == static_cast<int>( m_cbTheme->GetCount() ) - 2 )
115  {
116  // separator; re-select active theme
117  m_cbTheme->SetStringSelection( m_currentSettings->GetName() );
118  return;
119  }
120 
121  if( idx == (int)m_cbTheme->GetCount() - 1 )
122  {
123  // New Theme...
124 
125  if( !saveCurrentTheme( false ) )
126  return;
127 
128  FOOTPRINT_NAME_VALIDATOR themeNameValidator;
129  wxTextEntryDialog dlg( this, _( "New theme name:" ), _( "Add Color Theme" ) );
130  dlg.SetTextValidator( themeNameValidator );
131 
132  if( dlg.ShowModal() != wxID_OK )
133  return;
134 
135  wxString themeName = dlg.GetValue();
136  wxFileName fn( themeName + wxT( ".json" ) );
138 
139  if( fn.Exists() )
140  {
141  wxMessageBox( _( "Theme already exists!" ) );
142  return;
143  }
144 
145  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
146  COLOR_SETTINGS* newSettings = settingsMgr.AddNewColorSettings( themeName );
147  newSettings->SetName( themeName );
148  newSettings->SetReadOnly( false );
149 
150  for( auto layer : m_validLayers )
151  newSettings->SetColor( layer, m_currentSettings->GetColor( layer ) );
152 
153  newSettings->SaveToFile( settingsMgr.GetPathForSettingsFile( newSettings ) );
154 
155  idx = m_cbTheme->Insert( themeName, idx - 1, static_cast<void*>( newSettings ) );
156  m_cbTheme->SetSelection( idx );
157 
158  m_optOverrideColors->SetValue( newSettings->GetOverrideSchItemColors() );
159 
160  *m_currentSettings = *newSettings;
161  updateSwatches();
163  }
164  else
165  {
166  COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
167 
168  if( selected->GetFilename() != m_currentSettings->GetFilename() )
169  {
170  if( !saveCurrentTheme( false ) )
171  return;
172 
173  m_optOverrideColors->SetValue( selected->GetOverrideSchItemColors() );
174 
175  *m_currentSettings = *selected;
177  updateSwatches();
178  }
179  }
180 }
virtual bool saveCurrentTheme(bool aValidate)
void SetReadOnly(bool aReadOnly)
Definition: json_settings.h:77
wxString GetFilename() const
Definition: json_settings.h:66
virtual void onNewThemeSelected()
Event fired when a new theme is selected that can be overridden in children.
const wxString & GetName() const
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Registers a new color settings object with the given filename.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
COLOR_SETTINGS * m_currentSettings
void SetName(const wxString &aName)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
static wxString GetColorSettingsPath()
Returns the path where color scheme files are stored; creating it if missing (normally .
COLOR4D GetColor(int aLayer) const
#define _(s)
Definition: 3d_actions.cpp:33
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Returns the path a given settings file should be loaded from / stored to.
void SetColor(int aLayer, COLOR4D aColor)

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, PANEL_COLOR_SETTINGS::m_currentSettings, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, PANEL_COLOR_SETTINGS::m_validLayers, PANEL_COLOR_SETTINGS::onNewThemeSelected(), Pgm(), PANEL_COLOR_SETTINGS::saveCurrentTheme(), JSON_SETTINGS::SaveToFile(), COLOR_SETTINGS::SetColor(), COLOR_SETTINGS::SetName(), JSON_SETTINGS::SetReadOnly(), and PANEL_COLOR_SETTINGS::updateSwatches().

◆ ResetPanel()

void PANEL_COLOR_SETTINGS::ResetPanel ( )
overridevirtualinherited

Reset the contents of this panel.

Implements RESETTABLE_PANEL.

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS, and PANEL_PCBNEW_COLOR_SETTINGS.

Definition at line 64 of file panel_color_settings.cpp.

65 {
67  return;
68 
69  for( const std::pair<const int, COLOR_SWATCH*>& pair : m_swatches )
70  {
71  int layer = pair.first;
72  COLOR_SWATCH* button = pair.second;
73 
74  COLOR4D defaultColor = m_currentSettings->GetDefaultColor( layer );
75 
76  m_currentSettings->SetColor( layer, defaultColor );
77  button->SetSwatchColor( defaultColor, false );
78  }
79 }
void SetSwatchColor(KIGFX::COLOR4D aColor, bool aSendEvent)
Set the current swatch color directly.
std::map< int, COLOR_SWATCH * > m_swatches
COLOR_SETTINGS * m_currentSettings
COLOR4D GetDefaultColor(int aLayer)
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:57
bool IsReadOnly() const
Definition: json_settings.h:76
void SetColor(int aLayer, COLOR4D aColor)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

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

◆ saveCurrentTheme()

bool PANEL_COLOR_SETTINGS::saveCurrentTheme ( bool  aValidate)
protectedvirtualinherited

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS.

Definition at line 348 of file panel_color_settings.cpp.

349 {
351  return true;
352 
353  if( aValidate && !validateSave() )
354  return false;
355 
356  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
357  COLOR_SETTINGS* selected = settingsMgr.GetColorSettings( m_currentSettings->GetFilename() );
358 
359  selected->SetOverrideSchItemColors( m_optOverrideColors->GetValue() );
360 
361  for( auto layer : m_validLayers )
362  selected->SetColor( layer, m_currentSettings->GetColor( layer ) );
363 
364  settingsMgr.SaveColorSettings( selected, m_colorNamespace );
365 
366  return true;
367 }
wxString GetFilename() const
Definition: json_settings.h:66
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
COLOR_SETTINGS * m_currentSettings
void SetOverrideSchItemColors(bool aFlag)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
COLOR4D GetColor(int aLayer) const
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
bool IsReadOnly() const
Definition: json_settings.h:76
Color settings are a bit different than most of the settings objects in that there can be more than o...
virtual bool validateSave(bool aQuiet=false)
Performs a pre-save validation of the current color theme.
void SetColor(int aLayer, COLOR4D aColor)

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

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

◆ Show()

bool PANEL_COLOR_SETTINGS::Show ( bool  show)
overrideinherited

Definition at line 82 of file panel_color_settings.cpp.

83 {
84  if( show )
85  {
86  // In case changes have been made to the current theme in another panel:
87  int idx = m_cbTheme->GetSelection();
88  COLOR_SETTINGS* settings = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
89 
90  if( settings )
91  *m_currentSettings = *settings;
92 
95  }
96 
97  return PANEL_COLOR_SETTINGS_BASE::Show( show );
98 }
virtual void onNewThemeSelected()
Event fired when a new theme is selected that can be overridden in children.
COLOR_SETTINGS * m_currentSettings
Color settings are a bit different than most of the settings objects in that there can be more than o...

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

◆ ShowColorContextMenu()

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

Definition at line 270 of file panel_color_settings.cpp.

271 {
272  auto selected =
273  static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
274 
275  COLOR4D current = m_currentSettings->GetColor( aLayer );
276  COLOR4D saved = selected->GetColor( aLayer );
277  bool readOnly = m_currentSettings->IsReadOnly();
278 
279  wxMenu menu;
280 
281  AddMenuItem( &menu, ID_COPY, _( "Copy color" ), KiBitmap( BITMAPS::copy ) );
282 
283  if( !readOnly && m_copied != COLOR4D::UNSPECIFIED )
284  AddMenuItem( &menu, ID_PASTE, _( "Paste color" ), KiBitmap( BITMAPS::paste ) );
285 
286  if( !readOnly && current != saved )
287  AddMenuItem( &menu, ID_REVERT, _( "Revert to saved color" ), KiBitmap( BITMAPS::undo ) );
288 
289  menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
290  [&]( wxCommandEvent& aCmd )
291  {
292  switch( aCmd.GetId() )
293  {
294  case ID_COPY:
295  m_copied = current;
296  break;
297 
298  case ID_PASTE:
299  updateColor( aLayer, m_copied );
300  break;
301 
302  case ID_REVERT:
303  updateColor( aLayer, saved );
304  break;
305 
306  default:
307  aCmd.Skip();
308  }
309  } );
310 
311  PopupMenu( &menu );
312 }
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:245
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
COLOR_SETTINGS * m_currentSettings
COLOR4D GetColor(int aLayer) const
#define _(s)
Definition: 3d_actions.cpp:33
bool IsReadOnly() const
Definition: json_settings.h:76
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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

Referenced by PANEL_COLOR_SETTINGS::createSwatch().

◆ TransferDataFromWindow()

bool PANEL_FP_EDITOR_COLOR_SETTINGS::TransferDataFromWindow ( )
overrideprotected

Definition at line 95 of file panel_fp_editor_color_settings.cpp.

96 {
97  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
100 
101  return true;
102 }
wxString GetFilename() const
Definition: json_settings.h:66
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
COLOR_SETTINGS * m_currentSettings
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:184

References SETTINGS_MANAGER::GetAppSettings(), JSON_SETTINGS::GetFilename(), APP_SETTINGS_BASE::m_ColorTheme, PANEL_COLOR_SETTINGS::m_currentSettings, and Pgm().

◆ TransferDataToWindow()

bool PANEL_FP_EDITOR_COLOR_SETTINGS::TransferDataToWindow ( )
overrideprotected

Definition at line 105 of file panel_fp_editor_color_settings.cpp.

106 {
107  return true;
108 }

◆ updateColor()

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

Definition at line 325 of file panel_color_settings.cpp.

326 {
327  if( m_currentSettings )
328  m_currentSettings->SetColor( aLayer, aColor );
329 
330  // Colors must be persisted when edited because multiple PANEL_COLOR_SETTINGS could be
331  // referring to the same theme.
332  saveCurrentTheme( false );
333 
334  m_swatches[aLayer]->SetSwatchColor( aColor, false );
335 
336  if( m_currentSettings && aLayer == m_backgroundLayer )
337  {
339 
340  for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
341  pair.second->SetSwatchBackground( background );
342  }
343 
344  onColorChanged();
345 }
virtual bool saveCurrentTheme(bool aValidate)
std::map< int, COLOR_SWATCH * > m_swatches
COLOR_SETTINGS * m_currentSettings
virtual void onColorChanged()
Event fired when the user changes any color.
COLOR4D GetColor(int aLayer) const
void SetColor(int aLayer, COLOR4D aColor)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

Referenced by PANEL_COLOR_SETTINGS::OnColorChanged(), and PANEL_COLOR_SETTINGS::ShowColorContextMenu().

◆ updateSwatches()

void PANEL_COLOR_SETTINGS::updateSwatches ( )
protectedinherited

Definition at line 183 of file panel_color_settings.cpp.

184 {
185  bool isReadOnly = m_currentSettings->IsReadOnly();
187 
188  for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
189  {
190  pair.second->SetSwatchBackground( background );
191  pair.second->SetSwatchColor( m_currentSettings->GetColor( pair.first ), false );
192  pair.second->SetReadOnly( isReadOnly );
193  }
194 }
std::map< int, COLOR_SWATCH * > m_swatches
COLOR_SETTINGS * m_currentSettings
COLOR4D GetColor(int aLayer) const
bool IsReadOnly() const
Definition: json_settings.h:76
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

Referenced by PANEL_COLOR_SETTINGS::OnThemeChanged(), and PANEL_COLOR_SETTINGS::Show().

◆ validateSave()

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

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 84 of file panel_color_settings.h.

85  {
86  return true;
87  }

Referenced by PANEL_COLOR_SETTINGS::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
protectedinherited

A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.

This should be set to the appropriate namespace in the application-specific constructor

Definition at line 122 of file panel_color_settings.h.

Referenced by PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_FP_EDITOR_COLOR_SETTINGS(), PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS(), and PANEL_COLOR_SETTINGS::saveCurrentTheme().

◆ m_colorsGridSizer

◆ m_colorsListWindow

◆ m_colorsMainSizer

◆ m_copied

KIGFX::COLOR4D PANEL_COLOR_SETTINGS::m_copied
protectedinherited

Definition at line 104 of file panel_color_settings.h.

Referenced by PANEL_COLOR_SETTINGS::ShowColorContextMenu().

◆ m_currentSettings

◆ m_frame

FOOTPRINT_EDIT_FRAME* PANEL_FP_EDITOR_COLOR_SETTINGS::m_frame
private

Definition at line 55 of file panel_fp_editor_color_settings.h.

Referenced by createSwatches().

◆ m_labels

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

◆ m_mainSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_mainSizer
protectedinherited

◆ m_optOverrideColors

◆ m_page

PAGE_INFO* PANEL_FP_EDITOR_COLOR_SETTINGS::m_page
private

Definition at line 56 of file panel_fp_editor_color_settings.h.

Referenced by ~PANEL_FP_EDITOR_COLOR_SETTINGS().

◆ m_staticline2

wxStaticLine* PANEL_COLOR_SETTINGS_BASE::m_staticline2
protectedinherited

◆ m_staticText9

wxStaticText* PANEL_COLOR_SETTINGS_BASE::m_staticText9
protectedinherited

◆ m_swatches

◆ m_titleBlock

TITLE_BLOCK* PANEL_FP_EDITOR_COLOR_SETTINGS::m_titleBlock
private

Definition at line 57 of file panel_fp_editor_color_settings.h.

Referenced by ~PANEL_FP_EDITOR_COLOR_SETTINGS().

◆ m_validLayers

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

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 114 of file panel_color_settings.h.

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


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