KiCad PCB EDA Suite
PANEL_GERBVIEW_COLOR_SETTINGS Class Reference

#include <panel_gerbview_color_settings.h>

Inheritance diagram for PANEL_GERBVIEW_COLOR_SETTINGS:
PANEL_COLOR_SETTINGS PANEL_COLOR_SETTINGS_BASE RESETTABLE_PANEL

Public Types

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

Public Member Functions

 PANEL_GERBVIEW_COLOR_SETTINGS (wxWindow *aParent)
 
 ~PANEL_GERBVIEW_COLOR_SETTINGS () override
 
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

bool TransferDataFromWindow () override
 
bool TransferDataToWindow () override
 
void createSwatches () 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
 
WX_PANELm_panel1
 
wxBoxSizer * m_colorsMainSizer
 
wxScrolledWindow * m_colorsListWindow
 
wxFlexGridSizer * m_colorsGridSizer
 
wxBoxSizer * m_previewPanelSizer
 

Detailed Description

Definition at line 30 of file panel_gerbview_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_GERBVIEW_COLOR_SETTINGS()

PANEL_GERBVIEW_COLOR_SETTINGS::PANEL_GERBVIEW_COLOR_SETTINGS ( wxWindow *  aParent)

Definition at line 29 of file panel_gerbview_color_settings.cpp.

29 :
30 PANEL_COLOR_SETTINGS( aParent )
31{
32 m_colorNamespace = "gerbview";
33
34 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
36 COLOR_SETTINGS* current = mgr.GetColorSettings( app_settings->m_ColorTheme );
37
38 // Colors can also be modified from the LayersManager, so collect last settings if exist
39 // (They can be no yet saved on disk)
40 GERBVIEW_FRAME* gbr_mainframe = dynamic_cast<GERBVIEW_FRAME*>(
41 wxWindow::FindWindowByName( GERBVIEW_FRAME_NAME ) );
42 if( gbr_mainframe )
43 {
44 gbr_mainframe->m_LayersManager->CollectCurrentColorSettings( current );
45 }
46
47 // Saved theme doesn't exist? Reset to default
48 if( current->GetFilename() != app_settings->m_ColorTheme )
49 app_settings->m_ColorTheme = current->GetFilename();
50
51 createThemeList( app_settings->m_ColorTheme );
52
53
54 // Currently this only applies to eeschema
55 m_optOverrideColors->Hide();
56
57
58 m_currentSettings = new COLOR_SETTINGS( *current );
59
61 m_validLayers.push_back( i );
62
63 for( int i = LAYER_DCODES; i < GERBVIEW_LAYER_ID_END; i++ )
64 m_validLayers.push_back( i );
65
67}
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:190
Color settings are a bit different than most of the settings objects in that there can be more than o...
void CollectCurrentColorSettings(COLOR_SETTINGS *aColorSettings)
Collect the current color settings and put it in aColorSettings.
GERBER_LAYER_WIDGET * m_LayersManager
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
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
PANEL_COLOR_SETTINGS(wxWindow *aParent)
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
#define GERBVIEW_FRAME_NAME
The main window used in GerbView.
@ GERBVIEW_LAYER_ID_START
Definition: layer_ids.h:409
@ LAYER_GERBVIEW_BACKGROUND
Definition: layer_ids.h:418
@ LAYER_DCODES
Definition: layer_ids.h:414
@ GERBVIEW_LAYER_ID_END
Definition: layer_ids.h:422
#define GERBER_DRAWLAYERS_COUNT
Definition: layer_ids.h:404
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References GERBER_LAYER_WIDGET::CollectCurrentColorSettings(), PANEL_COLOR_SETTINGS::createThemeList(), GERBER_DRAWLAYERS_COUNT, GERBVIEW_FRAME_NAME, GERBVIEW_LAYER_ID_END, GERBVIEW_LAYER_ID_START, SETTINGS_MANAGER::GetAppSettings(), SETTINGS_MANAGER::GetColorSettings(), LAYER_DCODES, LAYER_GERBVIEW_BACKGROUND, PANEL_COLOR_SETTINGS::m_backgroundLayer, PANEL_COLOR_SETTINGS::m_colorNamespace, APP_SETTINGS_BASE::m_ColorTheme, PANEL_COLOR_SETTINGS::m_currentSettings, GERBVIEW_FRAME::m_LayersManager, PANEL_COLOR_SETTINGS_BASE::m_optOverrideColors, PANEL_COLOR_SETTINGS::m_validLayers, and Pgm().

◆ ~PANEL_GERBVIEW_COLOR_SETTINGS()

PANEL_GERBVIEW_COLOR_SETTINGS::~PANEL_GERBVIEW_COLOR_SETTINGS ( )
override

Definition at line 70 of file panel_gerbview_color_settings.cpp.

71{
72 delete m_currentSettings;
73}

References PANEL_COLOR_SETTINGS::m_currentSettings.

Member Function Documentation

◆ createSwatch()

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

Definition at line 241 of file panel_color_settings.cpp.

242{
243 wxStaticText* label = new wxStaticText( m_colorsListWindow, wxID_ANY, aName );
244
245 // The previously selected theme can be deleted and cannot be selected.
246 // so select the default theme (first theme of the list)
247 if( m_cbTheme->GetSelection() < 0 )
248 {
249 m_cbTheme->SetSelection( 0 );
251 }
252
253 void* clientData = m_cbTheme->GetClientData( m_cbTheme->GetSelection() );
254 COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( clientData );
255
256 int id = FIRST_BUTTON_ID + aLayer;
257 COLOR4D defaultColor = selected->GetDefaultColor( aLayer );
260
261 COLOR_SWATCH* swatch = new COLOR_SWATCH( m_colorsListWindow, color, id, backgroundColor,
262 defaultColor, SWATCH_MEDIUM );
263 swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
264
265 // Display the swatches in the left column and the layer name in the right column
266 // The right column is sometimes (depending on the translation) truncated for long texts.
267 // We cannot allow swatches to be truncated or not shown
268 m_colorsGridSizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3 );
269 m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
270
271 m_labels[aLayer] = label;
272 m_swatches[aLayer] = swatch;
273
274 swatch->Bind( wxEVT_RIGHT_DOWN,
275 [&, aLayer]( wxMouseEvent& aEvent )
276 {
277 ShowColorContextMenu( aEvent, aLayer );
278 } );
279
280 swatch->Bind( COLOR_SWATCH_CHANGED, &PANEL_COLOR_SETTINGS::OnColorChanged, this );
281}
int color
Definition: DXF_plotter.cpp:57
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:102
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)
std::map< int, COLOR_SWATCH * > m_swatches
@ SWATCH_MEDIUM
Definition: color_swatch.h:41
constexpr int FIRST_BUTTON_ID

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

◆ createSwatches()

void PANEL_GERBVIEW_COLOR_SETTINGS::createSwatches ( )
overrideprotectedvirtual

Implements PANEL_COLOR_SETTINGS.

Definition at line 92 of file panel_gerbview_color_settings.cpp.

93{
94 wxString layerName;
95
96 for( int layer : m_validLayers )
97 {
98 switch( layer )
99 {
100 case LAYER_DCODES: layerName = _( "DCodes" ); break;
101 case LAYER_NEGATIVE_OBJECTS: layerName = _( "Negative Objects" ); break;
102 case LAYER_GERBVIEW_GRID: layerName = _( "Grid" ); break;
103 case LAYER_GERBVIEW_AXES: layerName = _( "Axes" ); break;
104 case LAYER_GERBVIEW_DRAWINGSHEET: layerName = _( "Drawing Sheet" ); break;
105 case LAYER_GERBVIEW_PAGE_LIMITS: layerName = _( "Page Limits" ); break;
106 case LAYER_GERBVIEW_BACKGROUND: layerName = _( "Background" ); break;
107
108 default:
109 layerName = wxString::Format( _( "Graphic Layer %d" ), layer + 1 - GERBVIEW_LAYER_ID_START );
110 break;
111 }
112
113 createSwatch( layer, layerName );
114 }
115
116 Layout();
117}
void createSwatch(int aLayer, const wxString &aName)
#define _(s)
@ LAYER_GERBVIEW_DRAWINGSHEET
Definition: layer_ids.h:419
@ LAYER_NEGATIVE_OBJECTS
Definition: layer_ids.h:415
@ LAYER_GERBVIEW_PAGE_LIMITS
Definition: layer_ids.h:420
@ LAYER_GERBVIEW_AXES
Definition: layer_ids.h:417
@ LAYER_GERBVIEW_GRID
Definition: layer_ids.h:416
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, PANEL_COLOR_SETTINGS::createSwatch(), Format(), GERBVIEW_LAYER_ID_START, LAYER_DCODES, LAYER_GERBVIEW_AXES, LAYER_GERBVIEW_BACKGROUND, LAYER_GERBVIEW_DRAWINGSHEET, LAYER_GERBVIEW_GRID, LAYER_GERBVIEW_PAGE_LIMITS, LAYER_NEGATIVE_OBJECTS, and PANEL_COLOR_SETTINGS::m_validLayers.

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

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

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::PANEL_FP_EDITOR_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
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 }

References _.

◆ OnBtnOpenThemeFolderClicked()

void PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked ( wxCommandEvent &  event)
overrideprotectedvirtualinherited

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 61 of file panel_color_settings.cpp.

62{
64 LaunchExternal( dir );
65}
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 ( )
inlineprotectedvirtualinherited

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 PANEL_COLOR_SETTINGS::updateColor().

◆ OnColorChanged()

void PANEL_COLOR_SETTINGS::OnColorChanged ( wxCommandEvent &  aEvent)
protectedinherited

Definition at line 329 of file panel_color_settings.cpp.

330{
331 COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
332 COLOR4D newColor = swatch->GetSwatchColor();
333 int layer = static_cast<SCH_LAYER_ID>( swatch->GetId() - FIRST_BUTTON_ID );
334
335 updateColor( layer, newColor );
336}
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 PANEL_COLOR_SETTINGS::updateColor().

Referenced by PANEL_COLOR_SETTINGS::createSwatch().

◆ OnLeftDownTheme()

void PANEL_COLOR_SETTINGS::OnLeftDownTheme ( wxMouseEvent &  event)
overrideprotectedvirtualinherited

Reimplemented from PANEL_COLOR_SETTINGS_BASE.

Definition at line 105 of file panel_color_settings.cpp.

106{
107 // Lazy rebuild of theme menu to catch any colour theme changes made in other panels
109
110 event.Skip();
111}
wxString GetFilename() const
Definition: json_settings.h:73

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

93{}

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

115{
116 int idx = m_cbTheme->GetSelection();
117
118 if( idx == static_cast<int>( m_cbTheme->GetCount() ) - 2 )
119 {
120 // separator; re-select active theme
121 m_cbTheme->SetStringSelection( m_currentSettings->GetName() );
122 return;
123 }
124
125 if( idx == (int)m_cbTheme->GetCount() - 1 )
126 {
127 // New Theme...
128
129 if( !saveCurrentTheme( false ) )
130 return;
131
132 FOOTPRINT_NAME_VALIDATOR themeNameValidator;
133 wxTextEntryDialog dlg( this, _( "New theme name:" ), _( "Add Color Theme" ) );
134 dlg.SetTextValidator( themeNameValidator );
135
136 if( dlg.ShowModal() != wxID_OK )
137 return;
138
139 wxString themeName = dlg.GetValue();
140 wxFileName fn( themeName + wxT( ".json" ) );
142
143 if( fn.Exists() )
144 {
145 wxMessageBox( _( "Theme already exists!" ) );
146 return;
147 }
148
149 SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
150 COLOR_SETTINGS* newSettings = settingsMgr.AddNewColorSettings( themeName );
151 newSettings->SetName( themeName );
152 newSettings->SetReadOnly( false );
153
154 for( int layer : m_validLayers )
155 newSettings->SetColor( layer, m_currentSettings->GetColor( layer ) );
156
157 newSettings->SaveToFile( settingsMgr.GetPathForSettingsFile( newSettings ) );
158
159 idx = m_cbTheme->Insert( themeName, idx - 1, static_cast<void*>( newSettings ) );
160 m_cbTheme->SetSelection( idx );
161
162 m_optOverrideColors->SetValue( newSettings->GetOverrideSchItemColors() );
163
164 *m_currentSettings = *newSettings;
167 }
168 else
169 {
170 COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( idx ) );
171
172 if( selected->GetFilename() != m_currentSettings->GetFilename() )
173 {
174 if( !saveCurrentTheme( false ) )
175 return;
176
177 m_optOverrideColors->SetValue( selected->GetOverrideSchItemColors() );
178
179 *m_currentSettings = *selected;
182 }
183 }
184}
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, 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 68 of file panel_color_settings.cpp.

69{
71 return;
72
73 for( const std::pair<const int, COLOR_SWATCH*>& pair : m_swatches )
74 {
75 int layer = pair.first;
76 COLOR_SWATCH* button = pair.second;
77
78 COLOR4D defaultColor = m_currentSettings->GetDefaultColor( layer );
79
80 m_currentSettings->SetColor( layer, defaultColor );
81 button->SetSwatchColor( defaultColor, false );
82 }
83}
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(), PANEL_COLOR_SETTINGS::m_currentSettings, PANEL_COLOR_SETTINGS::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)
protectedvirtualinherited

Reimplemented in PANEL_EESCHEMA_COLOR_SETTINGS.

Definition at line 362 of file panel_color_settings.cpp.

363{
365 return true;
366
367 if( aValidate && !validateSave() )
368 return false;
369
370 SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
371 COLOR_SETTINGS* selected = settingsMgr.GetColorSettings( m_currentSettings->GetFilename() );
372
373 selected->SetOverrideSchItemColors( m_optOverrideColors->GetValue() );
374
375 for( int layer : m_validLayers )
376 selected->SetColor( layer, m_currentSettings->GetColor( layer ) );
377
378 settingsMgr.SaveColorSettings( selected, m_colorNamespace );
379
380 return true;
381}
void SetOverrideSchItemColors(bool aFlag)
virtual bool validateSave(bool aQuiet=false)
Performs a pre-save validation of the current color theme.
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(), 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 86 of file panel_color_settings.cpp.

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

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

285{
286 auto selected =
287 static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
288
289 COLOR4D current = m_currentSettings->GetColor( aLayer );
290 COLOR4D saved = selected->GetColor( aLayer );
291 bool readOnly = m_currentSettings->IsReadOnly();
292
293 wxMenu menu;
294
295 AddMenuItem( &menu, ID_COPY, _( "Copy color" ), KiBitmap( BITMAPS::copy ) );
296
297 if( !readOnly && m_copied != COLOR4D::UNSPECIFIED )
298 AddMenuItem( &menu, ID_PASTE, _( "Paste color" ), KiBitmap( BITMAPS::paste ) );
299
300 if( !readOnly && current != saved )
301 AddMenuItem( &menu, ID_REVERT, _( "Revert to saved color" ), KiBitmap( BITMAPS::undo ) );
302
303 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
304 [&]( wxCommandEvent& aCmd )
305 {
306 switch( aCmd.GetId() )
307 {
308 case ID_COPY:
309 m_copied = current;
310 break;
311
312 case ID_PASTE:
313 updateColor( aLayer, m_copied );
314 break;
315
316 case ID_REVERT:
317 updateColor( aLayer, saved );
318 break;
319
320 default:
321 aCmd.Skip();
322 }
323 } );
324
325 PopupMenu( &menu );
326}
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:106
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:266

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, and undo.

Referenced by PANEL_COLOR_SETTINGS::createSwatch().

◆ TransferDataFromWindow()

bool PANEL_GERBVIEW_COLOR_SETTINGS::TransferDataFromWindow ( )
overrideprotected

◆ TransferDataToWindow()

bool PANEL_GERBVIEW_COLOR_SETTINGS::TransferDataToWindow ( )
overrideprotected

Definition at line 86 of file panel_gerbview_color_settings.cpp.

87{
88 return true;
89}

◆ updateColor()

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

Definition at line 339 of file panel_color_settings.cpp.

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

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

◆ updateSwatches()

void PANEL_COLOR_SETTINGS::updateSwatches ( )
protectedinherited

Definition at line 187 of file panel_color_settings.cpp.

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

References PANEL_COLOR_SETTINGS::createSwatches(), 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 85 of file panel_color_settings.h.

86 {
87 return true;
88 }

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

◆ m_colorsGridSizer

◆ m_colorsListWindow

◆ m_colorsMainSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_colorsMainSizer
protectedinherited

◆ m_copied

KIGFX::COLOR4D PANEL_COLOR_SETTINGS::m_copied
protectedinherited

Definition at line 105 of file panel_color_settings.h.

Referenced by PANEL_COLOR_SETTINGS::ShowColorContextMenu().

◆ m_currentSettings

◆ 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_panel1

◆ m_previewPanelSizer

wxBoxSizer* PANEL_COLOR_SETTINGS_BASE::m_previewPanelSizer
protectedinherited

◆ m_staticText9

wxStaticText* PANEL_COLOR_SETTINGS_BASE::m_staticText9
protectedinherited

◆ m_swatches

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

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


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