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 <eeschema_settings.h>
25 #include <lib_edit_frame.h>
26 #include <libedit_settings.h>
27 #include <pgm_base.h>
28 #include <sch_painter.h>
30 #include <view/view.h>
31 
33 
34 
36  wxWindow* aWindow )
37  : PANEL_LIBEDIT_COLOR_SETTINGS_BASE( aWindow ), m_frame( aFrame )
38 {
39 }
40 
41 
43 {
44  auto cfg = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
45 
46  m_useEeschemaTheme->SetValue( cfg->m_UseEeschemaColorSettings );
47 
48  COLOR_SETTINGS* current = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme );
49 
50  int width = 0;
51  int height = 0;
52  int minwidth = width;
53 
54  m_themeSelection->Clear();
55 
56  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
57  {
58  int pos = m_themeSelection->Append( settings->GetName(), static_cast<void*>( settings ) );
59 
60  if( settings == current )
61  m_themeSelection->SetSelection( pos );
62 
63  m_themeSelection->GetTextExtent( settings->GetName(), &width, &height );
64  minwidth = std::max( minwidth, width );
65  }
66 
67  m_themeSelection->SetMinSize( wxSize( minwidth + 50, -1 ) );
68 
69  m_txtTheme->Enable( !m_useEeschemaTheme->GetValue() );
70  m_themeSelection->Enable( !m_useEeschemaTheme->GetValue() );
71 
72  Fit();
73 
74  return true;
75 }
76 
77 
79 {
80  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
81 
82  auto selected = static_cast<COLOR_SETTINGS*>(
83  m_themeSelection->GetClientData( m_themeSelection->GetSelection() ) );
84 
86 
88 
89  if( !cfg->m_UseEeschemaColorSettings )
90  cfg->m_ColorTheme = selected->GetFilename();
91 
93  {
95  selected = mgr.GetColorSettings( eecfg->m_ColorTheme );
96  }
97 
98  auto settings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
99  settings->LoadColors( selected );
100 
101  return true;
102 }
103 
104 
106 {
107  bool useEeschema = m_useEeschemaTheme->GetValue();
108 
109  m_txtTheme->Enable( !useEeschema );
110  m_themeSelection->Enable( !useEeschema );
111 }
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:102
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
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,...
SETTINGS_MANAGER * GetSettingsManager()
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:176