KiCad PCB EDA Suite
panel_common_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) 2018 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 <pgm_base.h>
25 #include <dialog_shim.h>
26 #include <kiface_i.h>
27 #include <bitmap_types.h>
28 #include <bitmaps.h>
29 #include <wx/graphics.h>
30 #include "panel_common_settings.h"
31 
33  PANEL_COMMON_SETTINGS_BASE( aParent ),
34  m_dialog( aDialog ),
35  m_last_scale( -1 )
36 {
37  m_scaleSlider->SetStep( 25 );
38 
39  m_textEditorBtn->SetBitmap( KiBitmap( folder_xpm ) );
40  m_pdfViewerBtn->SetBitmap( KiBitmap( folder_xpm ) );
41 }
42 
43 
45 {
46  wxConfigBase* commonSettings = Pgm().CommonSettings();
47 
48  int timevalue;
49  wxString msg;
50 
51  commonSettings->Read( AUTOSAVE_INTERVAL_KEY, &timevalue );
52  msg << timevalue / 60;
53  m_SaveTime->SetValue( msg );
54 
55  int fileHistorySize;
56  commonSettings->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
57  m_fileHistorySize->SetValue( fileHistorySize );
58 
59  int antialiasingMode;
60  commonSettings->Read( GAL_ANTIALIASING_MODE_KEY, &antialiasingMode, 0 );
61  m_antialiasing->SetSelection( antialiasingMode );
62 
63  commonSettings->Read( CAIRO_ANTIALIASING_MODE_KEY, &antialiasingMode, 0 );
64  m_antialiasingFallback->SetSelection( antialiasingMode );
65 
66  int scale_fourths;
67  commonSettings->Read( ICON_SCALE_KEY, &scale_fourths );
68 
69  if( scale_fourths <= 0 )
70  {
71  m_scaleAuto->SetValue( true );
72  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
73  }
74  else
75  {
76  m_scaleAuto->SetValue( false );
77  m_scaleSlider->SetValue( scale_fourths * 25 );
78  }
79 
80  bool option;
81  commonSettings->Read( USE_ICONS_IN_MENUS_KEY, &option );
82  m_checkBoxIconsInMenus->SetValue( option );
83 
84  commonSettings->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
85  m_ZoomCenterOpt->SetValue( !option );
86 
87  commonSettings->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
88  m_MousewheelPANOpt->SetValue( option );
89 
90  commonSettings->Read( ENBL_AUTO_PAN_KEY, &option );
91  m_AutoPANOpt->SetValue( option );
92 
93  m_textEditorPath->SetValue( Pgm().GetEditorName( false ) );
94  m_defaultPDFViewer->SetValue( Pgm().UseSystemPdfBrowser() );
95  m_otherPDFViewer->SetValue( !Pgm().UseSystemPdfBrowser() );
96  m_PDFViewerPath->SetValue( Pgm().GetPdfBrowserName() );
97 
98  return true;
99 }
100 
101 
103 {
104  wxConfigBase* commonSettings = Pgm().CommonSettings();
105 
106  commonSettings->Write( AUTOSAVE_INTERVAL_KEY, m_SaveTime->GetValue() * 60 );
107 
108  commonSettings->Write( FILE_HISTORY_SIZE_KEY, m_fileHistorySize->GetValue() );
109 
110  commonSettings->Write( GAL_ANTIALIASING_MODE_KEY, m_antialiasing->GetSelection() );
111 
112  commonSettings->Write( CAIRO_ANTIALIASING_MODE_KEY, m_antialiasingFallback->GetSelection() );
113 
114  const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
115  commonSettings->Write( ICON_SCALE_KEY, scale_fourths );
116 
117  commonSettings->Write( USE_ICONS_IN_MENUS_KEY, m_checkBoxIconsInMenus->GetValue() );
118  commonSettings->Write( ENBL_ZOOM_NO_CENTER_KEY, !m_ZoomCenterOpt->GetValue() );
119  commonSettings->Write( ENBL_MOUSEWHEEL_PAN_KEY, m_MousewheelPANOpt->GetValue() );
120  commonSettings->Write( ENBL_AUTO_PAN_KEY, m_AutoPANOpt->GetValue() );
121 
122  Pgm().SetEditorName( m_textEditorPath->GetValue() );
123 
124  Pgm().SetPdfBrowserName( m_PDFViewerPath->GetValue() );
127 
128  return true;
129 }
130 
131 
132 void PANEL_COMMON_SETTINGS::OnScaleSlider( wxScrollEvent& aEvent )
133 {
134  m_scaleAuto->SetValue( false );
135 }
136 
137 
138 void PANEL_COMMON_SETTINGS::OnScaleAuto( wxCommandEvent& aEvent )
139 {
140  if( m_scaleAuto->GetValue() )
141  {
142  m_last_scale = m_scaleSlider->GetValue();
143  m_scaleSlider->SetValue( 25 * KiIconScale( GetParent() ) );
144  }
145  else
146  {
147  if( m_last_scale >= 0 )
148  m_scaleSlider->SetValue( m_last_scale );
149  }
150 }
151 
152 
153 void PANEL_COMMON_SETTINGS::OnTextEditorClick( wxCommandEvent& event )
154 {
155  // Ask the user to select a new editor, but suggest the current one as the default.
156  wxString editorname = Pgm().AskUserForPreferredEditor( m_textEditorPath->GetValue() );
157 
158  // If we have a new editor name request it to be copied to m_editor_name and saved
159  // to the preferences file. If the user cancelled the dialog then the previous
160  // value will be retained.
161  if( !editorname.IsEmpty() )
162  m_textEditorPath->SetValue( editorname );
163 }
164 
165 
166 void PANEL_COMMON_SETTINGS::OnPDFViewerClick( wxCommandEvent& event )
167 {
168  wxString mask( wxT( "*" ) );
169 
170 #ifdef __WINDOWS__
171  mask += wxT( ".exe" );
172 #endif
173 
174  wxString wildcard = _( "Executable files (" ) + mask + wxT( ")|" ) + mask;
175 
177  wxFileName fn = Pgm().GetPdfBrowserName();
178 
179  wxFileDialog dlg( this, _( "Select Preferred PDF Browser" ), fn.GetPath(), fn.GetFullPath(),
180  wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
181 
182  if( dlg.ShowModal() == wxID_CANCEL )
183  return;
184 
185  m_otherPDFViewer->SetValue( true );
186  m_PDFViewerPath->SetValue( dlg.GetPath() );
187 }
188 
189 
190 void PANEL_COMMON_SETTINGS::onUpdateUIPdfPath( wxUpdateUIEvent& event )
191 {
192  bool enabled = m_otherPDFViewer->GetValue();
193  m_PDFViewerPath->Enable( enabled );
194  m_pdfViewerBtn->Enable( enabled );
195 }
196 
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:192
void OnScaleAuto(wxCommandEvent &aEvent) override
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:240
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:221
void OnScaleSlider(wxScrollEvent &aEvent) override
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:89
void OnPDFViewerClick(wxCommandEvent &event) override
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:82
VTBL_ENTRY void WritePdfBrowserInfos()
Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:55
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:237
Class PANEL_COMMON_SETTINGS_BASE.
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:48
bool TransferDataFromWindow() override
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void OnTextEditorClick(wxCommandEvent &event) override
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:51
#define DEFAULT_FILE_HISTORY_SIZE
The default file history size is 9.
Definition: pgm_base.h:60
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:223
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:49
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:52
void onUpdateUIPdfPath(wxUpdateUIEvent &event) override
#define ICON_SCALE_KEY
Definition: pgm_base.h:46
int m_last_scale
saved icon scale when Auto selected
#define AUTOSAVE_INTERVAL_KEY
Definition: pgm_base.h:47
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:54
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
see class PGM_BASE
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:45
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:55
bool TransferDataToWindow() override
PANEL_COMMON_SETTINGS(DIALOG_SHIM *aDialog, wxWindow *aParent)
void SetStep(int aSize)
Set the step size.