KiCad PCB EDA Suite
panel_libedit_color_settings.cpp
Go to the documentation of this file.
1 /*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23 
24 #include <fctsys.h>
25 #include <eeschema_settings.h>
26 #include <lib_edit_frame.h>
27 #include <libedit_settings.h>
28 #include <pgm_base.h>
29 #include <sch_painter.h>
31 #include <view/view.h>
32 
34 
35 
37  wxWindow* aWindow )
38  : PANEL_LIBEDIT_COLOR_SETTINGS_BASE( aWindow ), m_frame( aFrame )
39 {
40 }
41 
42 
44 {
45  auto cfg = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
46 
47  m_useEeschemaTheme->SetValue( cfg->m_UseEeschemaColorSettings );
48 
49  COLOR_SETTINGS* current = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme );
50 
51  int width = 0;
52  int height = 0;
53  int minwidth = width;
54 
55  m_themeSelection->Clear();
56 
57  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
58  {
59  int pos = m_themeSelection->Append( settings->GetName(), static_cast<void*>( settings ) );
60 
61  if( settings == current )
62  m_themeSelection->SetSelection( pos );
63 
64  m_themeSelection->GetTextExtent( settings->GetName(), &width, &height );
65  minwidth = std::max( minwidth, width );
66  }
67 
68  m_themeSelection->SetMinSize( wxSize( minwidth + 50, -1 ) );
69 
70  m_txtTheme->Enable( !m_useEeschemaTheme->GetValue() );
71  m_themeSelection->Enable( !m_useEeschemaTheme->GetValue() );
72 
73  Fit();
74 
75  return true;
76 }
77 
78 
80 {
81  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
82 
83  auto selected = static_cast<COLOR_SETTINGS*>(
84  m_themeSelection->GetClientData( m_themeSelection->GetSelection() ) );
85 
87 
89 
90  if( !cfg->m_UseEeschemaColorSettings )
91  cfg->m_ColorTheme = selected->GetFilename();
92 
94  {
96  selected = mgr.GetColorSettings( eecfg->m_ColorTheme );
97  }
98 
99  auto settings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
100  settings->LoadColors( selected );
101 
102  return true;
103 }
104 
105 
107 {
108  bool useEeschema = m_useEeschemaTheme->GetValue();
109 
110  m_txtTheme->Enable( !useEeschema );
111  m_themeSelection->Enable( !useEeschema );
112 }
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
AppSettings * 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.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
The symbol library editor main window.
see class PGM_BASE
void OnUseEeschemaThemeChanged(wxCommandEvent &event) override
PANEL_LIBEDIT_COLOR_SETTINGS(LIB_EDIT_FRAME *aFrame, wxWindow *aWindow)
Color settings are a bit different than most of the settings objects in that there can be more than o...
Class PANEL_LIBEDIT_COLOR_SETTINGS_BASE.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:136