KiCad PCB EDA Suite
panel_pl_editor_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 modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <fctsys.h>
21 #include <pl_editor_settings.h>
22 #include <pl_editor_frame.h>
23 #include <pgm_base.h>
25 #include <view/view.h>
26 
28 
29 
31  wxWindow* aWindow )
33  m_frame( aFrame )
34 {
35 }
36 
37 
39 {
40  PL_EDITOR_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PL_EDITOR_SETTINGS>();
41 
42  COLOR_SETTINGS* current = Pgm().GetSettingsManager().GetColorSettings( cfg->m_ColorTheme );
43 
44  int width = 0;
45  int height = 0;
46  int minwidth = width;
47 
48  m_themeSelection->Clear();
49 
50  for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
51  {
52  int pos = m_themeSelection->Append( settings->GetName(), static_cast<void*>( settings ) );
53 
54  if( settings == current )
55  m_themeSelection->SetSelection( pos );
56 
57  m_themeSelection->GetTextExtent( settings->GetName(), &width, &height );
58  minwidth = std::max( minwidth, width );
59  }
60 
61  m_themeSelection->SetMinSize( wxSize( minwidth + 50, -1 ) );
62 
63  Fit();
64 
65  return true;
66 }
67 
68 
70 {
71  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
72 
73  auto selected = static_cast<COLOR_SETTINGS*>(
74  m_themeSelection->GetClientData( m_themeSelection->GetSelection() ) );
75 
77 
78  cfg->m_ColorTheme = selected->GetFilename();
79 
80  auto settings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
81  settings->LoadColors( selected );
82 
83  return true;
84 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PL_EDITOR_FRAME is the main window used in the page layout editor.
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
Class PANEL_PL_EDITOR_COLOR_SETTINGS_BASE.
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
PANEL_PL_EDITOR_COLOR_SETTINGS(PL_EDITOR_FRAME *aFrame, wxWindow *aWindow)
SETTINGS_MANAGER * GetSettingsManager()
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
see class PGM_BASE
Color settings are a bit different than most of the settings objects in that there can be more than o...
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:157