KiCad PCB EDA Suite
PANEL_COLOR_SETTINGS Class Reference

#include <panel_color_settings.h>

Inheritance diagram for PANEL_COLOR_SETTINGS:
PANEL_COLOR_SETTINGS_BASE RESETTABLE_PANEL PANEL_EESCHEMA_COLOR_SETTINGS PANEL_MODEDIT_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 () 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 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)
 
void updateSwatches ()
 
void createThemeList (const wxString &aCurrent)
 
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
 

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

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

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

222 {
223  wxStaticText* label = new wxStaticText( m_colorsListWindow, wxID_ANY, aName );
224 
225  // The previously selected theme can be deleted and cannot be selected.
226  // so select the default theme (first theme of the list)
227  if( m_cbTheme->GetSelection() < 0 )
228  {
229  m_cbTheme->SetSelection( 0 );
231  }
232 
233  void* clientData = m_cbTheme->GetClientData( m_cbTheme->GetSelection() );
234  COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( clientData );
235 
236  int id = FIRST_BUTTON_ID + aLayer;
237  COLOR4D defaultColor = selected->GetDefaultColor( aLayer );
239  COLOR4D backgroundColor = m_currentSettings->GetColor( m_backgroundLayer );
240 
241  COLOR_SWATCH* swatch = new COLOR_SWATCH( m_colorsListWindow, color, id, backgroundColor,
242  defaultColor, SWATCH_MEDIUM );
243  swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
244 
245  m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
246  m_colorsGridSizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3 );
247 
248  m_labels[aLayer] = label;
249  m_swatches[aLayer] = swatch;
250 
251  swatch->Bind( wxEVT_RIGHT_DOWN,
252  [&, aLayer]( wxMouseEvent& aEvent )
253  {
254  ShowColorContextMenu( aEvent, aLayer );
255  } );
256  swatch->Bind( COLOR_SWATCH_CHANGED, &PANEL_COLOR_SETTINGS::OnColorChanged, this );
257 }
int color
Definition: DXF_plotter.cpp:61
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:53
Color settings are a bit different than most of the settings objects in that there can be more than o...
void OnColorChanged(wxCommandEvent &aEvent)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

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_MODEDIT_COLOR_SETTINGS::createSwatches(), PANEL_PCBNEW_COLOR_SETTINGS::createSwatches(), and PANEL_EESCHEMA_COLOR_SETTINGS::createSwatches().

◆ createThemeList()

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

Definition at line 193 of file panel_color_settings.cpp.

194 {
195  int width = 0;
196  int height = 0;
197 
198  m_cbTheme->GetTextExtent( _( "New Theme..." ), &width, &height );
199  int minwidth = width;
200 
201  m_cbTheme->Clear();
202 
203  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
204  {
205  int pos = m_cbTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
206 
207  if( settings->GetName() == aCurrent )
208  m_cbTheme->SetSelection( pos );
209 
210  m_cbTheme->GetTextExtent( settings->GetName(), &width, &height );
211  minwidth = std::max( minwidth, width );
212  }
213 
214  m_cbTheme->Append( wxT( "---" ) );
215  m_cbTheme->Append( _( "New Theme..." ) );
216 
217  m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
218 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
SETTINGS_MANAGER * GetSettingsManager()
#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, and Pgm().

Referenced by OnLeftDownTheme(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_MODEDIT_COLOR_SETTINGS::PANEL_MODEDIT_COLOR_SETTINGS(), and PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS().

◆ GetResetTooltip()

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

References _.

◆ OnBtnOpenThemeFolderClicked()

void PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked ( wxCommandEvent &  event)
overrideprotectedvirtual

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 (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)
protected

Definition at line 304 of file panel_color_settings.cpp.

305 {
306  COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
307  COLOR4D newColor = swatch->GetSwatchColor();
308  LAYER_NUM layer = static_cast<SCH_LAYER_ID>( swatch->GetId() - FIRST_BUTTON_ID );
309 
310  updateColor( layer, newColor );
311 }
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:53
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

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

Referenced by createSwatch().

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

93 {}

Referenced by updateColor().

◆ OnLeftDownTheme()

void PANEL_COLOR_SETTINGS::OnLeftDownTheme ( wxMouseEvent &  event)
overrideprotectedvirtual

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
104  wxString sel = m_cbTheme->GetStringSelection();
105  createThemeList( sel );
106 
107  event.Skip();
108 }
void createThemeList(const wxString &aCurrent)

References createThemeList(), and PANEL_COLOR_SETTINGS_BASE::m_cbTheme.

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

88 {}

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 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  MODULE_NAME_CHAR_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 
149  for( auto layer : m_validLayers )
150  newSettings->SetColor( layer, m_currentSettings->GetColor( layer ) );
151 
152  newSettings->SaveToFile( settingsMgr.GetPathForSettingsFile( newSettings ) );
153 
154  idx = m_cbTheme->Insert( themeName, idx - 1, static_cast<void*>( newSettings ) );
155  m_cbTheme->SetSelection( idx );
156 
157  m_optOverrideColors->SetValue( newSettings->GetOverrideSchItemColors() );
158 
159  *m_currentSettings = *newSettings;
161  }
162  else
163  {
164  COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
165 
166  if( selected->GetFilename() != m_currentSettings->GetFilename() )
167  {
168  if( !saveCurrentTheme( false ) )
169  return;
170 
171  m_optOverrideColors->SetValue( selected->GetOverrideSchItemColors() );
172 
173  *m_currentSettings = *selected;
175  updateSwatches();
176  }
177  }
178 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
virtual bool saveCurrentTheme(bool aValidate)
wxString GetFilename() const
Definition: json_settings.h:64
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.
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
COLOR_SETTINGS * m_currentSettings
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
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 (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, m_currentSettings, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, m_validLayers, onNewThemeSelected(), Pgm(), saveCurrentTheme(), JSON_SETTINGS::SaveToFile(), COLOR_SETTINGS::SetColor(), COLOR_SETTINGS::SetName(), 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 64 of file panel_color_settings.cpp.

65 {
66  if( !m_currentSettings )
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 sendEvent)
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:53
void SetColor(int aLayer, COLOR4D aColor)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References COLOR_SETTINGS::GetDefaultColor(), m_currentSettings, 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)
protectedvirtual

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS.

Definition at line 337 of file panel_color_settings.cpp.

338 {
339  if( aValidate && !validateSave() )
340  return false;
341 
342  SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
343  COLOR_SETTINGS* selected = settingsMgr.GetColorSettings( m_currentSettings->GetFilename() );
344 
345  selected->SetOverrideSchItemColors( m_optOverrideColors->GetValue() );
346 
347  for( auto layer : m_validLayers )
348  selected->SetColor( layer, m_currentSettings->GetColor( layer ) );
349 
350  settingsMgr.SaveColorSettings( selected, m_colorNamespace );
351 
352  return true;
353 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxString GetFilename() const
Definition: json_settings.h:64
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.
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(), 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 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  wxString currentTheme = m_cbTheme->GetStringSelection();
88  COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings( currentTheme );
89 
90  if( settings )
91  *m_currentSettings = *settings;
92 
95  }
96 
97  return PANEL_COLOR_SETTINGS_BASE::Show( show );
98 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
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, m_currentSettings, onNewThemeSelected(), Pgm(), and updateSwatches().

◆ ShowColorContextMenu()

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

Definition at line 260 of file panel_color_settings.cpp.

261 {
262  auto selected =
263  static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
264 
265  COLOR4D current = m_currentSettings->GetColor( aLayer );
266  COLOR4D saved = selected->GetColor( aLayer );
267 
268  wxMenu menu;
269 
270  AddMenuItem( &menu, ID_COPY, _( "Copy color" ), KiBitmap( copy_xpm ) );
271 
272  if( m_copied != COLOR4D::UNSPECIFIED )
273  AddMenuItem( &menu, ID_PASTE, _( "Paste color" ), KiBitmap( paste_xpm ) );
274 
275  if( current != saved )
276  AddMenuItem( &menu, ID_REVERT, _( "Revert to saved color" ), KiBitmap( undo_xpm ) );
277 
278  menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
279  [&]( wxCommandEvent& aCmd )
280  {
281  switch( aCmd.GetId() )
282  {
283  case ID_COPY:
284  m_copied = current;
285  break;
286 
287  case ID_PASTE:
288  updateColor( aLayer, m_copied );
289  break;
290 
291  case ID_REVERT:
292  updateColor( aLayer, saved );
293  break;
294 
295  default:
296  aCmd.Skip();
297  }
298  } );
299 
300  PopupMenu( &menu );
301 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:232
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
COLOR_SETTINGS * m_currentSettings
const BITMAP_OPAQUE copy_xpm[1]
Definition: copy.cpp:67
const BITMAP_OPAQUE paste_xpm[1]
Definition: paste.cpp:69
COLOR4D GetColor(int aLayer) const
#define _(s)
Definition: 3d_actions.cpp:33
const BITMAP_OPAQUE undo_xpm[1]
Definition: undo.cpp:74
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References _, AddMenuItem(), copy_xpm, COLOR_SETTINGS::GetColor(), ID_COPY, ID_PASTE, ID_REVERT, KiBitmap(), PANEL_COLOR_SETTINGS_BASE::m_cbTheme, m_copied, m_currentSettings, paste_xpm, undo_xpm, and updateColor().

Referenced by createSwatch().

◆ updateColor()

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

Definition at line 314 of file panel_color_settings.cpp.

315 {
316  if( m_currentSettings )
317  m_currentSettings->SetColor( aLayer, aColor );
318 
319  // Colors must be persisted when edited because multiple PANEL_COLOR_SETTINGS could be
320  // referring to the same theme.
321  saveCurrentTheme( false );
322 
323  m_swatches[aLayer]->SetSwatchColor( aColor, false );
324 
325  if( m_currentSettings && aLayer == m_backgroundLayer )
326  {
328 
329  for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
330  pair.second->SetSwatchBackground( background );
331  }
332 
333  onColorChanged();
334 }
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)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

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

Referenced by OnColorChanged(), and ShowColorContextMenu().

◆ updateSwatches()

void PANEL_COLOR_SETTINGS::updateSwatches ( )
protected

Definition at line 181 of file panel_color_settings.cpp.

182 {
184 
185  for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
186  {
187  pair.second->SetSwatchBackground( background );
188  pair.second->SetSwatchColor( m_currentSettings->GetColor( pair.first ), false );
189  }
190 }
std::map< int, COLOR_SWATCH * > m_swatches
COLOR_SETTINGS * m_currentSettings
COLOR4D GetColor(int aLayer) const
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References COLOR_SETTINGS::GetColor(), 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 80 of file panel_color_settings.h.

81  {
82  return true;
83  }

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

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

Referenced by PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), PANEL_MODEDIT_COLOR_SETTINGS::PANEL_MODEDIT_COLOR_SETTINGS(), PANEL_PCBNEW_COLOR_SETTINGS::PANEL_PCBNEW_COLOR_SETTINGS(), and saveCurrentTheme().

◆ m_colorsGridSizer

◆ m_colorsListWindow

◆ m_colorsMainSizer

◆ m_copied

KIGFX::COLOR4D PANEL_COLOR_SETTINGS::m_copied
protected

Definition at line 100 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_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 110 of file panel_color_settings.h.

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


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