34#include <wx/textdlg.h>
42 m_currentSettings( nullptr ),
72 for(
const std::pair<const int, COLOR_SWATCH*>& pair :
m_swatches )
74 int layer = pair.first;
100 return PANEL_COLOR_SETTINGS_BASE::Show( show );
117 if( idx ==
static_cast<int>(
m_cbTheme->GetCount() ) - 2 )
123 if( idx == (
int)
m_cbTheme->GetCount() - 1 )
131 wxTextEntryDialog dlg(
this,
_(
"New theme name:" ),
_(
"Add Color Theme" ) );
132 dlg.SetTextValidator( themeNameValidator );
134 if( dlg.ShowModal() != wxID_OK )
137 wxString themeName = dlg.GetValue();
138 wxFileName fn( themeName + wxT(
".json" ) );
143 wxMessageBox(
_(
"Theme already exists!" ) );
149 newSettings->
SetName( themeName );
157 idx =
m_cbTheme->Insert( themeName, idx - 1,
static_cast<void*
>( newSettings ) );
198 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
200 pair.second->SetSwatchBackground( background );
202 pair.second->SetReadOnly( isReadOnly );
213 m_cbTheme->GetTextExtent(
_(
"New Theme..." ), &width, &height );
214 int minwidth = width;
222 int pos =
m_cbTheme->Append(
name,
static_cast<void*
>( settings ) );
224 if( settings->GetFilename() == aCurrent )
228 minwidth = std::max( minwidth, width );
234 m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
260 swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
266 m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
271 swatch->Bind( wxEVT_RIGHT_DOWN,
272 [&, aLayer]( wxMouseEvent& aEvent )
286 wxCHECK_RET( selected, wxT(
"Invalid color theme selected" ) );
289 COLOR4D saved = selected->GetColor( aLayer );
296 if( !readOnly &&
m_copied != COLOR4D::UNSPECIFIED )
299 if( !readOnly && current != saved )
302 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
303 [&]( wxCommandEvent& aCmd )
305 switch( aCmd.GetId() )
312 updateColor( aLayer, m_copied );
316 updateColor( aLayer, saved );
347 m_swatches[aLayer]->SetSwatchColor( aColor,
false );
353 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
354 pair.second->SetSwatchBackground( background );
388 name += wxS(
" " ) +
_(
"(read-only)" );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetName(const wxString &aName)
void SetColor(int aLayer, const COLOR4D &aColor)
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
COLOR4D GetDefaultColor(int aLayer)
void SetOverrideSchItemColors(bool aFlag)
const wxString & GetName() const
A simple color swatch of the kind used to set layer colors.
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetReadOnly(bool aReadOnly)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
wxString GetFilename() const
A color representation with 4 components: red, green, blue, alpha.
Class PANEL_COLOR_SETTINGS_BASE.
wxCheckBox * m_optOverrideColors
wxFlexGridSizer * m_colorsGridSizer
wxButton * m_btnOpenFolder
wxScrolledWindow * m_colorsListWindow
void createThemeList(const wxString &aCurrent)
Builds the theme listbox and sets the selection to the current theme.
void createSwatch(int aLayer, const wxString &aName)
std::vector< int > m_validLayers
A list of layer IDs that are valid for the current color settings dialog.
void OnThemeChanged(wxCommandEvent &aEvent) override
virtual bool saveCurrentTheme(bool aValidate)
std::string m_colorNamespace
A namespace that will be passed to SETTINGS_MANAGER::SaveColorSettings.
virtual void ResetPanel() override
Reset the contents of this panel.
void OnBtnOpenThemeFolderClicked(wxCommandEvent &event) override
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.
wxString GetSettingsDropdownName(COLOR_SETTINGS *aSettings)
Retrieves the drop down name to be displayed for a color setting.
void updateColor(int aLayer, const KIGFX::COLOR4D &aColor)
COLOR_SETTINGS * m_currentSettings
PANEL_COLOR_SETTINGS(wxWindow *aParent)
void ShowColorContextMenu(wxMouseEvent &aEvent, int aLayer)
void OnLeftDownTheme(wxMouseEvent &event) override
bool Show(bool show) override
virtual void createSwatches()=0
virtual void onColorChanged()
Event fired when the user changes any color.
virtual bool validateSave(bool aQuiet=false)
Performs a pre-save validation of the current color theme.
std::map< int, COLOR_SWATCH * > m_swatches
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Returns the path a given settings file should be loaded from / stored to.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
static wxString GetColorSettingsPath()
Returns the path where color scheme files are stored; creating it if missing (normally .
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Registers a new color settings object with the given filename.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
@ LAYER_PCB_BACKGROUND
PCB background color.
SCH_LAYER_ID
Eeschema drawing layers.
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.
constexpr int FIRST_BUTTON_ID
SETTINGS_MANAGER * GetSettingsManager()
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Custom text control validator definitions.