From 42319e57c654a7a4c3cad87594a065490469dfe8 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 16 May 2020 09:23:51 -0400 Subject: [PATCH] Clean up libedit color settings Fixes https://gitlab.com/kicad/code/kicad/-/issues/4433 --- .../dialogs/panel_libedit_color_settings.cpp | 38 ++- .../dialogs/panel_libedit_color_settings.h | 3 + .../panel_libedit_color_settings_base.cpp | 28 +- .../panel_libedit_color_settings_base.fbp | 258 ++++++++---------- .../panel_libedit_color_settings_base.h | 11 +- eeschema/eeschema_config.cpp | 2 +- eeschema/libedit/lib_edit_frame.cpp | 6 +- 7 files changed, 186 insertions(+), 160 deletions(-) diff --git a/eeschema/dialogs/panel_libedit_color_settings.cpp b/eeschema/dialogs/panel_libedit_color_settings.cpp index 863cada7f2..c2030589d9 100644 --- a/eeschema/dialogs/panel_libedit_color_settings.cpp +++ b/eeschema/dialogs/panel_libedit_color_settings.cpp @@ -47,33 +47,65 @@ bool PANEL_LIBEDIT_COLOR_SETTINGS::TransferDataToWindow() COLOR_SETTINGS* current = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme ); + int width = 0; + int height = 0; + int minwidth = width; + + m_themeSelection->Clear(); + for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() ) { int pos = m_themeSelection->Append( settings->GetName(), static_cast( settings ) ); if( settings == current ) m_themeSelection->SetSelection( pos ); + + m_themeSelection->GetTextExtent( settings->GetName(), &width, &height ); + minwidth = std::max( minwidth, width ); } + m_themeSelection->SetMinSize( wxSize( minwidth + 50, -1 ) ); + + m_txtTheme->Enable( !m_useEeschemaTheme->GetValue() ); + m_themeSelection->Enable( !m_useEeschemaTheme->GetValue() ); + + Fit(); + return true; } bool PANEL_LIBEDIT_COLOR_SETTINGS::TransferDataFromWindow() { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + auto selected = static_cast( m_themeSelection->GetClientData( m_themeSelection->GetSelection() ) ); - auto cfg = Pgm().GetSettingsManager().GetAppSettings(); + LIBEDIT_SETTINGS* cfg = mgr.GetAppSettings(); cfg->m_UseEeschemaColorSettings = m_useEeschemaTheme->GetValue(); - cfg->m_ColorTheme = selected->GetFilename(); + + if( !cfg->m_UseEeschemaColorSettings ) + cfg->m_ColorTheme = selected->GetFilename(); if( cfg->m_UseEeschemaColorSettings ) - selected = m_frame->GetColorSettings(); + { + EESCHEMA_SETTINGS* eecfg = mgr.GetAppSettings(); + selected = mgr.GetColorSettings( eecfg->m_ColorTheme ); + } auto settings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings(); settings->LoadColors( selected ); return true; } + + +void PANEL_LIBEDIT_COLOR_SETTINGS::OnUseEeschemaThemeChanged( wxCommandEvent& event ) +{ + bool useEeschema = m_useEeschemaTheme->GetValue(); + + m_txtTheme->Enable( !useEeschema ); + m_themeSelection->Enable( !useEeschema ); +} diff --git a/eeschema/dialogs/panel_libedit_color_settings.h b/eeschema/dialogs/panel_libedit_color_settings.h index 7f4c8a1796..3c591ff429 100644 --- a/eeschema/dialogs/panel_libedit_color_settings.h +++ b/eeschema/dialogs/panel_libedit_color_settings.h @@ -36,6 +36,9 @@ class PANEL_LIBEDIT_COLOR_SETTINGS : public PANEL_LIBEDIT_COLOR_SETTINGS_BASE public: PANEL_LIBEDIT_COLOR_SETTINGS( LIB_EDIT_FRAME* aFrame, wxWindow* aWindow ); +protected: + void OnUseEeschemaThemeChanged( wxCommandEvent& event ) override; + private: bool TransferDataToWindow() override; diff --git a/eeschema/dialogs/panel_libedit_color_settings_base.cpp b/eeschema/dialogs/panel_libedit_color_settings_base.cpp index 9631606871..e901a72d04 100644 --- a/eeschema/dialogs/panel_libedit_color_settings_base.cpp +++ b/eeschema/dialogs/panel_libedit_color_settings_base.cpp @@ -9,38 +9,38 @@ /////////////////////////////////////////////////////////////////////////// +BEGIN_EVENT_TABLE( PANEL_LIBEDIT_COLOR_SETTINGS_BASE, wxPanel ) + EVT_CHECKBOX( wxID_ANY, PANEL_LIBEDIT_COLOR_SETTINGS_BASE::_wxFB_OnUseEeschemaThemeChanged ) +END_EVENT_TABLE() + PANEL_LIBEDIT_COLOR_SETTINGS_BASE::PANEL_LIBEDIT_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) { wxBoxSizer* p1mainSizer; p1mainSizer = new wxBoxSizer( wxHORIZONTAL ); wxStaticBoxSizer* sbSizer1; - sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Color Theme") ), wxVERTICAL ); + sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Color Theme") ), wxHORIZONTAL ); sbSizer1->SetMinSize( wxSize( 250,-1 ) ); m_useEeschemaTheme = new wxCheckBox( sbSizer1->GetStaticBox(), wxID_ANY, _("Use Eeschema color theme"), wxDefaultPosition, wxDefaultSize, 0 ); + m_useEeschemaTheme->SetValue(true); sbSizer1->Add( m_useEeschemaTheme, 0, wxALL|wxEXPAND, 10 ); - wxBoxSizer* bSizer3; - bSizer3 = new wxBoxSizer( wxHORIZONTAL ); + m_txtTheme = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("Theme:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_txtTheme->Wrap( -1 ); + m_txtTheme->Enable( false ); - m_staticText16 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("Theme:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText16->Wrap( -1 ); - bSizer3->Add( m_staticText16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + sbSizer1->Add( m_txtTheme, 0, wxALIGN_CENTER_VERTICAL|wxALL, 10 ); wxArrayString m_themeSelectionChoices; m_themeSelection = new wxChoice( sbSizer1->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_themeSelectionChoices, 0 ); m_themeSelection->SetSelection( 0 ); - bSizer3->Add( m_themeSelection, 1, wxALL, 5 ); + m_themeSelection->Enable( false ); + + sbSizer1->Add( m_themeSelection, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 10 ); - sbSizer1->Add( bSizer3, 0, wxALL|wxEXPAND, 5 ); - - - sbSizer1->Add( 0, 0, 1, wxEXPAND, 5 ); - - - p1mainSizer->Add( sbSizer1, 0, 0, 5 ); + p1mainSizer->Add( sbSizer1, 0, wxALL, 5 ); p1mainSizer->Add( 0, 0, 1, wxEXPAND, 5 ); diff --git a/eeschema/dialogs/panel_libedit_color_settings_base.fbp b/eeschema/dialogs/panel_libedit_color_settings_base.fbp index a872609f70..335f5c5f5b 100644 --- a/eeschema/dialogs/panel_libedit_color_settings_base.fbp +++ b/eeschema/dialogs/panel_libedit_color_settings_base.fbp @@ -56,14 +56,14 @@ none 5 - + wxALL 0 wxID_ANY Color Theme 250,-1 sbSizer1 - wxVERTICAL + wxHORIZONTAL 1 none @@ -84,7 +84,7 @@ 1 0 - 0 + 1 1 1 @@ -128,152 +128,132 @@ + OnUseEeschemaThemeChanged - 5 - wxALL|wxEXPAND + 10 + wxALIGN_CENTER_VERTICAL|wxALL 0 - + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + + 1 + + 0 + 0 + wxID_ANY + Theme: + 0 + + 0 + + + 0 - bSizer3 - wxHORIZONTAL - none - - 5 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Theme: - 0 - - 0 - - - 0 - - 1 - m_staticText16 - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - - - 5 - wxALL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_themeSelection - 1 - - - protected - 1 - - Resizable - 0 - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - + 1 + m_txtTheme + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 - 5 - wxEXPAND + 10 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP 1 - - 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 0 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_themeSelection + 1 + + protected - 0 + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + diff --git a/eeschema/dialogs/panel_libedit_color_settings_base.h b/eeschema/dialogs/panel_libedit_color_settings_base.h index 7e027fa3c5..ed7dbbdd04 100644 --- a/eeschema/dialogs/panel_libedit_color_settings_base.h +++ b/eeschema/dialogs/panel_libedit_color_settings_base.h @@ -30,13 +30,22 @@ /////////////////////////////////////////////////////////////////////////////// class PANEL_LIBEDIT_COLOR_SETTINGS_BASE : public wxPanel { + DECLARE_EVENT_TABLE() private: + // Private event handlers + void _wxFB_OnUseEeschemaThemeChanged( wxCommandEvent& event ){ OnUseEeschemaThemeChanged( event ); } + + protected: wxCheckBox* m_useEeschemaTheme; - wxStaticText* m_staticText16; + wxStaticText* m_txtTheme; wxChoice* m_themeSelection; + // Virtual event handlers, overide them in your derived class + virtual void OnUseEeschemaThemeChanged( wxCommandEvent& event ) { event.Skip(); } + + public: PANEL_LIBEDIT_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index afe19af5ba..dae6f910a8 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -500,7 +500,7 @@ void LIB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) ); book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) ); book->AddSubPage( new PANEL_LIBEDIT_SETTINGS( this, book ), _( "Editing Options" ) ); - book->AddSubPage( new PANEL_LIBEDIT_COLOR_SETTINGS( this, book ), _( "Color Options" ) ); + book->AddSubPage( new PANEL_LIBEDIT_COLOR_SETTINGS( this, book ), _( "Colors" ) ); aHotkeysPanel->AddHotKeys( GetToolManager() ); } diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index d38396c204..5595417988 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -242,10 +242,12 @@ void LIB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) COLOR_SETTINGS* LIB_EDIT_FRAME::GetColorSettings() { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + if( GetSettings()->m_UseEeschemaColorSettings ) - return m_colorSettings; + return mgr.GetColorSettings( mgr.GetAppSettings()->m_ColorTheme ); else - return Pgm().GetSettingsManager().GetColorSettings( GetSettings()->m_ColorTheme ); + return mgr.GetColorSettings( GetSettings()->m_ColorTheme ); }