From f4e22a9264e3722b5d3658c3e2de43002a77773b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 9 Apr 2020 17:15:57 +0100 Subject: [PATCH] Add ability to override individual item colors. Fixes https://gitlab.com/kicad/code/kicad/issues/4167 --- common/dialogs/dialog_color_picker.cpp | 34 ++++++--- common/dialogs/dialog_color_picker.h | 2 +- common/dialogs/dialog_color_picker_base.cpp | 2 +- common/dialogs/dialog_color_picker_base.fbp | 2 +- common/dialogs/panel_color_settings_base.cpp | 10 +++ common/dialogs/panel_color_settings_base.fbp | 75 +++++++++++++++++++ common/dialogs/panel_color_settings_base.h | 3 + common/settings/color_settings.cpp | 6 +- eeschema/dialogs/dialog_sch_sheet_props.cpp | 35 +++++++-- .../dialogs/dialog_sch_sheet_props_base.cpp | 14 ++-- .../dialogs/dialog_sch_sheet_props_base.fbp | 4 +- .../dialogs/dialog_sch_sheet_props_base.h | 4 +- .../dialogs/panel_eeschema_color_settings.cpp | 17 +++++ .../dialogs/panel_eeschema_color_settings.h | 5 +- eeschema/sch_base_frame.cpp | 11 ++- eeschema/sch_base_frame.h | 2 + eeschema/sch_painter.cpp | 7 +- eeschema/sch_painter.h | 2 + include/settings/color_settings.h | 20 ++--- 19 files changed, 204 insertions(+), 51 deletions(-) diff --git a/common/dialogs/dialog_color_picker.cpp b/common/dialogs/dialog_color_picker.cpp index f4daa7cb71..7eb28077f5 100644 --- a/common/dialogs/dialog_color_picker.cpp +++ b/common/dialogs/dialog_color_picker.cpp @@ -145,7 +145,7 @@ bool DIALOG_COLOR_PICKER::TransferDataToWindow() { // Draw all bitmaps, with colors according to the color 4D setIconColor( m_OldColorRect, m_previousColor4D ); - SetEditVals( ALL_CHANGED ); + SetEditVals( ALL_CHANGED, false ); drawAll(); // Configure the spin control sizes @@ -525,8 +525,16 @@ void DIALOG_COLOR_PICKER::drawHSVPalette() } -void DIALOG_COLOR_PICKER::SetEditVals( CHANGED_COLOR aChanged ) +void DIALOG_COLOR_PICKER::SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransparency ) { + if( aCheckTransparency ) + { + // If they've changed the color, they probably don't want it to remain 100% transparent, + // and it looks like a bug when it changing the color has no effect. + if( m_newColor4D.a == 0.0 ) + m_newColor4D.a = 1.0; + } + m_sliderTransparency->SetValue( normalizeToInt( m_newColor4D.a, ALPHA_MAX ) ); if( aChanged == RED_CHANGED || aChanged == GREEN_CHANGED || aChanged == BLUE_CHANGED ) @@ -578,9 +586,10 @@ void DIALOG_COLOR_PICKER::buttColorClick( wxCommandEvent& event ) m_newColor4D.r = color.r; m_newColor4D.g = color.g; m_newColor4D.b = color.b; + m_newColor4D.a = color.a; m_newColor4D.ToHSV( m_hue, m_sat, m_val, true ); - SetEditVals( ALL_CHANGED ); + SetEditVals( ALL_CHANGED, false ); drawAll(); @@ -680,7 +689,7 @@ void DIALOG_COLOR_PICKER::onRGBMouseDrag( wxMouseEvent& event ) } m_newColor4D.ToHSV( m_hue, m_sat, m_val, true ); - SetEditVals( ALL_CHANGED ); + SetEditVals( ALL_CHANGED, true ); drawAll(); } @@ -737,7 +746,7 @@ bool DIALOG_COLOR_PICKER::setHSvaluesFromCursor( wxPoint aMouseCursor ) m_hue += 360.0; m_newColor4D.FromHSV( m_hue, m_sat, m_val ); - SetEditVals( ALL_CHANGED ); + SetEditVals( ALL_CHANGED, true ); return true; } @@ -758,7 +767,7 @@ void DIALOG_COLOR_PICKER::OnChangeEditRed( wxSpinEvent& event ) { double val = (double)event.GetPosition() / 255.0; m_newColor4D.r = val; - SetEditVals( RED_CHANGED ); + SetEditVals( RED_CHANGED, true ); drawAll(); } @@ -768,7 +777,7 @@ void DIALOG_COLOR_PICKER::OnChangeEditGreen( wxSpinEvent& event ) { double val = (double)event.GetPosition() / 255.0; m_newColor4D.g = val; - SetEditVals( GREEN_CHANGED ); + SetEditVals( GREEN_CHANGED, true ); drawAll(); } @@ -778,7 +787,7 @@ void DIALOG_COLOR_PICKER::OnChangeEditBlue( wxSpinEvent& event ) { double val = (double)event.GetPosition() / 255.0; m_newColor4D.b = val; - SetEditVals( BLUE_CHANGED ); + SetEditVals( BLUE_CHANGED, true ); drawAll(); } @@ -790,7 +799,7 @@ void DIALOG_COLOR_PICKER::OnChangeEditHue( wxSpinEvent& event ) m_newColor4D.FromHSV( m_hue, m_sat, m_val ); - SetEditVals( HUE_CHANGED ); + SetEditVals( HUE_CHANGED, true ); drawAll(); } @@ -802,7 +811,7 @@ void DIALOG_COLOR_PICKER::OnChangeEditSat( wxSpinEvent& event ) m_newColor4D.FromHSV( m_hue, m_sat, m_val ); - SetEditVals( SAT_CHANGED ); + SetEditVals( SAT_CHANGED, true ); drawAll(); } @@ -814,7 +823,7 @@ void DIALOG_COLOR_PICKER::OnChangeBrightness( wxScrollEvent& event ) m_newColor4D.FromHSV( m_hue, m_sat, m_val ); - SetEditVals( VAL_CHANGED ); + SetEditVals( VAL_CHANGED, true ); drawAll(); } @@ -825,9 +834,10 @@ void DIALOG_COLOR_PICKER::OnResetButton( wxCommandEvent& aEvent ) m_newColor4D.r = m_defaultColor.r; m_newColor4D.g = m_defaultColor.g; m_newColor4D.b = m_defaultColor.b; + m_newColor4D.a = m_defaultColor.a; m_newColor4D.ToHSV( m_hue, m_sat, m_val, true ); - SetEditVals( ALL_CHANGED ); + SetEditVals( ALL_CHANGED, false ); drawAll(); } diff --git a/common/dialogs/dialog_color_picker.h b/common/dialogs/dialog_color_picker.h index a647adb0e3..551dbfbbe5 100644 --- a/common/dialogs/dialog_color_picker.h +++ b/common/dialogs/dialog_color_picker.h @@ -117,7 +117,7 @@ private: std::vector m_buttonsColor; ///< list of defined colors buttons - void SetEditVals( CHANGED_COLOR aChanged ); + void SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransparency ); void drawAll(); void createHSVBitmap(); ///< generate the bitmap that shows the HSV color circle diff --git a/common/dialogs/dialog_color_picker_base.cpp b/common/dialogs/dialog_color_picker_base.cpp index 37d7890200..01741be4db 100644 --- a/common/dialogs/dialog_color_picker_base.cpp +++ b/common/dialogs/dialog_color_picker_base.cpp @@ -164,7 +164,7 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID m_opacityLabel->Wrap( -1 ); m_SizerTransparency->Add( m_opacityLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxLEFT, 5 ); - m_sliderTransparency = new wxSlider( this, wxID_ANY, 80, 20, 100, wxDefaultPosition, wxDefaultSize, wxSL_INVERSE|wxSL_LABELS|wxSL_LEFT|wxSL_VERTICAL ); + m_sliderTransparency = new wxSlider( this, wxID_ANY, 80, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_INVERSE|wxSL_LABELS|wxSL_LEFT|wxSL_VERTICAL ); m_SizerTransparency->Add( m_sliderTransparency, 1, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_HORIZONTAL, 10 ); diff --git a/common/dialogs/dialog_color_picker_base.fbp b/common/dialogs/dialog_color_picker_base.fbp index a3e2f57a7d..47907131ab 100644 --- a/common/dialogs/dialog_color_picker_base.fbp +++ b/common/dialogs/dialog_color_picker_base.fbp @@ -1350,7 +1350,7 @@ 0 - 20 + 0 0 diff --git a/common/dialogs/panel_color_settings_base.cpp b/common/dialogs/panel_color_settings_base.cpp index 6a83d2741c..ca50edfcc5 100644 --- a/common/dialogs/panel_color_settings_base.cpp +++ b/common/dialogs/panel_color_settings_base.cpp @@ -29,6 +29,14 @@ PANEL_COLOR_SETTINGS_BASE::PANEL_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindow bControlSizer->Add( m_cbTheme, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + bControlSizer->Add( 0, 0, 1, wxEXPAND, 5 ); + + m_optOverrideColors = new wxCheckBox( this, wxID_ANY, _("Override individual item colors"), wxDefaultPosition, wxDefaultSize, 0 ); + m_optOverrideColors->SetToolTip( _("Show all items in their default color even if they have specific colors set in their properties.") ); + + bControlSizer->Add( m_optOverrideColors, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bControlSizer->Add( 0, 0, 1, wxEXPAND, 5 ); m_btnReset = new wxButton( this, wxID_ANY, _("&Reset to Defaults"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -74,6 +82,7 @@ PANEL_COLOR_SETTINGS_BASE::PANEL_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindow // Connect Events this->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_COLOR_SETTINGS_BASE::OnSize ) ); m_cbTheme->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeChanged ), NULL, this ); + m_optOverrideColors->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnOverrideItemColorsClicked ), NULL, this ); m_btnReset->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnResetClicked ), NULL, this ); m_btnOpenFolder->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnOpenThemeFolderClicked ), NULL, this ); } @@ -83,6 +92,7 @@ PANEL_COLOR_SETTINGS_BASE::~PANEL_COLOR_SETTINGS_BASE() // Disconnect Events this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_COLOR_SETTINGS_BASE::OnSize ) ); m_cbTheme->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnThemeChanged ), NULL, this ); + m_optOverrideColors->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnOverrideItemColorsClicked ), NULL, this ); m_btnReset->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnResetClicked ), NULL, this ); m_btnOpenFolder->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COLOR_SETTINGS_BASE::OnBtnOpenThemeFolderClicked ), NULL, this ); diff --git a/common/dialogs/panel_color_settings_base.fbp b/common/dialogs/panel_color_settings_base.fbp index 1f590f5252..aa823d21d3 100644 --- a/common/dialogs/panel_color_settings_base.fbp +++ b/common/dialogs/panel_color_settings_base.fbp @@ -200,6 +200,81 @@ 0 + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Override individual item colors + + 0 + + + 0 + + 1 + m_optOverrideColors + 1 + + + public + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Show all items in their default color even if they have specific colors set in their properties. + + wxFILTER_NONE + wxDefaultValidator + + + + + OnOverrideItemColorsClicked + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + 5 wxALIGN_CENTER_VERTICAL|wxALL diff --git a/common/dialogs/panel_color_settings_base.h b/common/dialogs/panel_color_settings_base.h index 555c7ccdce..3fdf8b1c0e 100644 --- a/common/dialogs/panel_color_settings_base.h +++ b/common/dialogs/panel_color_settings_base.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -49,11 +50,13 @@ class PANEL_COLOR_SETTINGS_BASE : public wxPanel // Virtual event handlers, overide them in your derived class virtual void OnSize( wxSizeEvent& event ) { event.Skip(); } virtual void OnThemeChanged( wxCommandEvent& event ) { event.Skip(); } + virtual void OnOverrideItemColorsClicked( wxCommandEvent& event ) { event.Skip(); } virtual void OnBtnResetClicked( wxCommandEvent& event ) { event.Skip(); } virtual void OnBtnOpenThemeFolderClicked( wxCommandEvent& event ) { event.Skip(); } public: + wxCheckBox* m_optOverrideColors; 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 ); ~PANEL_COLOR_SETTINGS_BASE(); diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index b00eeebb52..b08b64908e 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -29,7 +29,8 @@ const int colorsSchemaVersion = 0; COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) : JSON_SETTINGS( std::move( aFilename ), SETTINGS_LOC::COLORS, colorsSchemaVersion ), - m_Palette(), m_colors(), m_color_context( COLOR_CONTEXT::PCB ) + m_overrideSchItemColors( false ), + m_color_context( COLOR_CONTEXT::PCB ) { m_params.emplace_back( new PARAM( "meta.name", &m_displayName, "KiCad Default" ) ); @@ -56,6 +57,9 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) : // TODO(JE) in actual usage, how long does the default palette need to be? m_params.emplace_back( new PARAM_LIST( "palette", &m_Palette, default_palette ) ); + m_params.emplace_back( new PARAM( "schematic.override_item_colors", + &m_overrideSchItemColors, false ) ); + #define CLR( x, y, z ) m_params.emplace_back( new COLOR_MAP_PARAM( x, y, z, &m_colors ) ) CLR( "schematic.background", LAYER_SCHEMATIC_BACKGROUND, COLOR4D( WHITE ) ); diff --git a/eeschema/dialogs/dialog_sch_sheet_props.cpp b/eeschema/dialogs/dialog_sch_sheet_props.cpp index 38c04a2357..51a9654ce3 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props.cpp +++ b/eeschema/dialogs/dialog_sch_sheet_props.cpp @@ -35,7 +35,7 @@ #include #include #include - +#include "panel_eeschema_color_settings.h" DIALOG_SCH_SHEET_PROPS::DIALOG_SCH_SHEET_PROPS( SCH_EDIT_FRAME* aParent, SCH_SHEET* aSheet, bool* aClearAnnotationNewItems ) : @@ -159,12 +159,12 @@ bool DIALOG_SCH_SHEET_PROPS::TransferDataToWindow() if( backgroundColor == COLOR4D::UNSPECIFIED ) backgroundColor = colorSettings->GetColor( LAYER_SHEET_BACKGROUND ); - m_borderColorSwatch->SetSwatchColor( borderColor, false ); - m_backgroundColorSwatch->SetSwatchColor( backgroundColor, false ); + m_borderSwatch->SetSwatchColor( borderColor, false ); + m_backgroundSwatch->SetSwatchColor( backgroundColor, false ); KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ); - m_borderColorSwatch->SetSwatchBackground( canvas ); - m_backgroundColorSwatch->SetSwatchBackground( canvas ); + m_borderSwatch->SetSwatchBackground( canvas ); + m_backgroundSwatch->SetSwatchBackground( canvas ); // set up the read-only fields m_heirarchyPath->SetValue( g_CurrentSheet->PathHumanReadable() ); @@ -286,8 +286,29 @@ bool DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow() m_sheet->SetFields( *m_fields ); m_sheet->SetBorderWidth( m_borderWidth.GetValue() ); - m_sheet->SetBorderColor( m_borderColorSwatch->GetSwatchColor() ); - m_sheet->SetBackgroundColor( m_backgroundColorSwatch->GetSwatchColor() ); + + COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings(); + + if( colorSettings->GetOverrideSchItemColors() + && ( m_sheet->GetBorderColor() != m_borderSwatch->GetSwatchColor() || + m_sheet->GetBackgroundColor() != m_backgroundSwatch->GetSwatchColor() ) ) + { + wxPanel temp( this ); + temp.Hide(); + PANEL_EESCHEMA_COLOR_SETTINGS prefs( m_frame, &temp ); + wxString checkboxLabel = prefs.m_optOverrideColors->GetLabel(); + + KIDIALOG dlg( this, _( "Note: item colors are overridden in the current color theme." ), + KIDIALOG::KD_WARNING ); + dlg.ShowDetailedText( wxString::Format( _( "To see individual item colors uncheck '%s'\n" + "in Preferences > Eeschema > Colors." ), + checkboxLabel ) ); + dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); + dlg.ShowModal(); + } + + m_sheet->SetBorderColor( m_borderSwatch->GetSwatchColor() ); + m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() ); m_frame->TestDanglingEnds(); m_frame->RefreshItem( m_sheet ); diff --git a/eeschema/dialogs/dialog_sch_sheet_props_base.cpp b/eeschema/dialogs/dialog_sch_sheet_props_base.cpp index 171077fc4a..4f3f6bf680 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props_base.cpp +++ b/eeschema/dialogs/dialog_sch_sheet_props_base.cpp @@ -136,11 +136,11 @@ DIALOG_SCH_SHEET_PROPS_BASE::DIALOG_SCH_SHEET_PROPS_BASE( wxWindow* parent, wxWi m_borderColorLabel->Wrap( -1 ); sbSizer2->Add( m_borderColorLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - m_borderColorSwatch = new COLOR_SWATCH( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - m_borderColorSwatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); - m_borderColorSwatch->SetMinSize( wxSize( 48,24 ) ); + m_borderSwatch = new COLOR_SWATCH( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_borderSwatch->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + m_borderSwatch->SetMinSize( wxSize( 48, 24 ) ); - sbSizer2->Add( m_borderColorSwatch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + sbSizer2->Add( m_borderSwatch, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 ); sbSizer2->Add( 40, 0, 1, wxEXPAND, 5 ); @@ -149,10 +149,10 @@ DIALOG_SCH_SHEET_PROPS_BASE::DIALOG_SCH_SHEET_PROPS_BASE( wxWindow* parent, wxWi m_backgroundColorLabel->Wrap( -1 ); sbSizer2->Add( m_backgroundColorLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - m_backgroundColorSwatch = new COLOR_SWATCH( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - m_backgroundColorSwatch->SetMinSize( wxSize( 48,24 ) ); + m_backgroundSwatch = new COLOR_SWATCH( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_backgroundSwatch->SetMinSize( wxSize( 48, 24 ) ); - sbSizer2->Add( m_backgroundColorSwatch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + sbSizer2->Add( m_backgroundSwatch, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 ); bSizer5->Add( sbSizer2, 1, wxEXPAND|wxBOTTOM, 5 ); diff --git a/eeschema/dialogs/dialog_sch_sheet_props_base.fbp b/eeschema/dialogs/dialog_sch_sheet_props_base.fbp index 0739e74452..1a0eb8e926 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props_base.fbp +++ b/eeschema/dialogs/dialog_sch_sheet_props_base.fbp @@ -816,7 +816,7 @@ 0 48,24 1 - m_borderColorSwatch + m_borderSwatch 1 @@ -949,7 +949,7 @@ 0 48,24 1 - m_backgroundColorSwatch + m_backgroundSwatch 1 diff --git a/eeschema/dialogs/dialog_sch_sheet_props_base.h b/eeschema/dialogs/dialog_sch_sheet_props_base.h index 53ad7f0dff..e6a89eb31d 100644 --- a/eeschema/dialogs/dialog_sch_sheet_props_base.h +++ b/eeschema/dialogs/dialog_sch_sheet_props_base.h @@ -53,9 +53,9 @@ class DIALOG_SCH_SHEET_PROPS_BASE : public DIALOG_SHIM wxTextCtrl* m_borderWidthCtrl; wxStaticText* m_borderWidthUnits; wxStaticText* m_borderColorLabel; - COLOR_SWATCH* m_borderColorSwatch; + COLOR_SWATCH* m_borderSwatch; wxStaticText* m_backgroundColorLabel; - COLOR_SWATCH* m_backgroundColorSwatch; + COLOR_SWATCH* m_backgroundSwatch; wxStaticLine* m_staticline1; wxStaticText* m_hiearchicalPathLabel; wxTextCtrl* m_heirarchyPath; diff --git a/eeschema/dialogs/panel_eeschema_color_settings.cpp b/eeschema/dialogs/panel_eeschema_color_settings.cpp index 9d268b0acd..d82e3754a7 100644 --- a/eeschema/dialogs/panel_eeschema_color_settings.cpp +++ b/eeschema/dialogs/panel_eeschema_color_settings.cpp @@ -91,6 +91,8 @@ PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS( SCH_BASE_FRAME* aF m_cbTheme->Append( wxT( "---" ) ); m_cbTheme->Append( _( "New Theme..." ) ); + m_optOverrideColors->SetValue( current->GetOverrideSchItemColors() ); + m_currentSettings = new COLOR_SETTINGS( *current ); KIGFX::GAL_DISPLAY_OPTIONS options; @@ -132,6 +134,8 @@ PANEL_EESCHEMA_COLOR_SETTINGS::~PANEL_EESCHEMA_COLOR_SETTINGS() bool PANEL_EESCHEMA_COLOR_SETTINGS::TransferDataFromWindow() { + m_currentSettings->SetOverrideSchItemColors( m_optOverrideColors->GetValue() ); + if( !saveCurrentTheme( true ) ) return false; @@ -178,6 +182,8 @@ bool PANEL_EESCHEMA_COLOR_SETTINGS::saveCurrentTheme( bool aValidate ) SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager(); COLOR_SETTINGS* selected = settingsMgr.GetColorSettings( m_currentSettings->GetFilename() ); + selected->SetOverrideSchItemColors( m_optOverrideColors->GetValue() ); + for( SCH_LAYER_ID layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; ++layer ) { COLOR4D color; @@ -535,6 +541,9 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event ) idx = m_cbTheme->Insert( themeName, idx - 1, static_cast( newSettings ) ); m_cbTheme->SetSelection( idx ); + + m_optOverrideColors->SetValue( newSettings->GetOverrideSchItemColors() ); + *m_currentSettings = *newSettings; } else @@ -546,6 +555,8 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event ) if( !saveCurrentTheme( false ) ) return; + m_optOverrideColors->SetValue( selected->GetOverrideSchItemColors() ); + *m_currentSettings = *selected; updatePreview(); @@ -556,6 +567,12 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event ) } +void PANEL_EESCHEMA_COLOR_SETTINGS::OnOverrideItemColorsClicked( wxCommandEvent& aEvent ) +{ + // JEY TODO: hide/show extra color buttons +} + + void PANEL_EESCHEMA_COLOR_SETTINGS::ShowColorContextMenu( wxMouseEvent& aEvent, SCH_LAYER_ID aLayer ) { diff --git a/eeschema/dialogs/panel_eeschema_color_settings.h b/eeschema/dialogs/panel_eeschema_color_settings.h index 37053bd9ce..c40559dc34 100644 --- a/eeschema/dialogs/panel_eeschema_color_settings.h +++ b/eeschema/dialogs/panel_eeschema_color_settings.h @@ -51,10 +51,9 @@ protected: void SetColor( wxCommandEvent& aEvent ); - void OnBtnResetClicked( wxCommandEvent& aEvent ) override; - void OnThemeChanged( wxCommandEvent& aEvent ) override; - + void OnOverrideItemColorsClicked( wxCommandEvent& aEvent ) override; + void OnBtnResetClicked( wxCommandEvent& aEvent ) override; void OnSize( wxSizeEvent& aEvent ) override; void ShowColorContextMenu( wxMouseEvent& aEvent, SCH_LAYER_ID aLayer ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index cf193c23b6..c733af22c4 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -522,11 +522,20 @@ COLOR4D SCH_BASE_FRAME::GetLayerColor( SCH_LAYER_ID aLayer ) } +void SCH_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) +{ + EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged ); + + EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + m_colorSettings = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme ); +} + + COLOR_SETTINGS* SCH_BASE_FRAME::GetColorSettings() { if( !m_colorSettings ) { - auto cfg = Pgm().GetSettingsManager().GetAppSettings(); + EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); m_colorSettings = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme ); } diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 55bd0e1a9d..3cd263af13 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -374,6 +374,8 @@ public: */ virtual void OnModify() {} + void CommonSettingsChanged( bool aEnvVarsChanged ) override; + /** * Helper to retrieve a layer color from the global color settings */ diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index acf21b7966..c225d56c56 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -73,6 +73,7 @@ SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : m_ShowPinsElectricalType( true ), m_ShowDisabled( false ), m_ShowUmbilicals( true ), + m_OverrideItemColors( false ), m_DefaultLineWidth( 0 ), m_DefaultWireThickness( 0 ), m_DefaultBusThickness( 0 ) @@ -88,6 +89,8 @@ void SCH_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings ) m_layerColors[ layer ] = aSettings->GetColor( layer ); m_backgroundColor = aSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND ); + + m_OverrideItemColors = aSettings->GetOverrideSchItemColors(); } @@ -256,7 +259,9 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr if( sheet->GetBackgroundColor() == COLOR4D::UNSPECIFIED ) sheet->SetBackgroundColor( m_schSettings.GetLayerColor( LAYER_SHEET_BACKGROUND ) ); - if( aLayer == LAYER_SHEET ) + if( m_schSettings.m_OverrideItemColors ) + color = m_schSettings.GetLayerColor( aLayer ); + else if( aLayer == LAYER_SHEET ) color = sheet->GetBorderColor(); else if( aLayer == LAYER_SHEET_BACKGROUND ) color = sheet->GetBackgroundColor(); diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index fca3936115..f2ddd966ee 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -108,6 +108,8 @@ public: bool m_ShowDisabled; bool m_ShowUmbilicals; + bool m_OverrideItemColors; + int m_DefaultLineWidth; int m_DefaultWireThickness; int m_DefaultBusThickness; diff --git a/include/settings/color_settings.h b/include/settings/color_settings.h index bff375615f..6cdc69e04e 100644 --- a/include/settings/color_settings.h +++ b/include/settings/color_settings.h @@ -63,9 +63,9 @@ class COLOR_SETTINGS : public JSON_SETTINGS { public: /** - * m_Pallete stores a list of colors that are used, in order, when a list of colors needs to be - * generated for an application. For example, layer colors in GerbView, or default layer colors - * in PcbNew. + * m_Pallete stores a list of colors that are used, in order, when a list of colors needs to + * be generated for an application. For example, layer colors in GerbView, or default layer + * colors in PcbNew. */ std::vector m_Palette; @@ -87,19 +87,15 @@ public: m_color_context = aContext; } - const wxString& GetName() - { - return m_displayName; - } + const wxString& GetName() const { return m_displayName; } + void SetName( const wxString& aName ) { m_displayName = aName; } - void SetName( const wxString& aName ) - { - m_displayName = aName; - } + bool GetOverrideSchItemColors() const { return m_overrideSchItemColors; } + void SetOverrideSchItemColors( bool aFlag ) { m_overrideSchItemColors = aFlag; } private: - wxString m_displayName; + bool m_overrideSchItemColors; /** * Map of all layer colors.