36#include <wx/textdlg.h>
44 m_currentSettings( nullptr ),
77 for(
const std::pair<const int, COLOR_SWATCH*>& pair :
m_swatches )
79 int layer = pair.first;
105 return PANEL_COLOR_SETTINGS_BASE::Show( show );
122 if( idx ==
static_cast<int>(
m_cbTheme->GetCount() ) - 2 )
128 if( idx == (
int)
m_cbTheme->GetCount() - 1 )
136 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"New theme name:" ),
137 _(
"Add Color Theme" ) );
138 dlg.SetTextValidator( themeNameValidator );
140 if( dlg.ShowModal() != wxID_OK )
143 wxString themeName = dlg.GetValue();
144 wxFileName fn( themeName + wxT(
".json" ) );
149 wxMessageBox(
_(
"Theme already exists!" ) );
155 newSettings->
SetName( themeName );
163 idx =
m_cbTheme->Insert( themeName, idx - 1,
static_cast<void*
>( newSettings ) );
204 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
206 pair.second->SetSwatchBackground( background );
208 pair.second->SetReadOnly( isReadOnly );
219 m_cbTheme->GetTextExtent(
_(
"New Theme..." ), &width, &height );
220 int minwidth = width;
228 int pos =
m_cbTheme->Append(
name,
static_cast<void*
>( settings ) );
230 if( settings->GetFilename() == aCurrent )
234 minwidth = std::max( minwidth, width );
240 m_cbTheme->SetMinSize( wxSize( minwidth + 50, -1 ) );
266 swatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
272 m_colorsGridSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxLEFT, 5 );
277 swatch->Bind( wxEVT_RIGHT_DOWN,
278 [&, aLayer]( wxMouseEvent& aEvent )
292 wxCHECK_RET( selected, wxT(
"Invalid color theme selected" ) );
295 COLOR4D saved = selected->GetColor( aLayer );
302 if( !readOnly &&
m_copied != COLOR4D::UNSPECIFIED )
305 if( !readOnly && current != saved )
308 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
309 [&]( wxCommandEvent& aCmd )
311 switch( aCmd.GetId() )
318 updateColor( aLayer, m_copied );
322 updateColor( aLayer, saved );
353 m_swatches[aLayer]->SetSwatchColor( aColor,
false );
359 for( std::pair<int, COLOR_SWATCH*> pair :
m_swatches )
360 pair.second->SetSwatchBackground( background );
394 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)
Calls Store() and then writes the contents of the JSON document to a file.
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
virtual SETTINGS_MANAGER & GetSettingsManager() const
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.
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
constexpr int FIRST_BUTTON_ID
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global Program "get" accessor.
Functions to provide common constants and other functions to assist in making a consistent UI.
Custom text control validator definitions.