KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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
25
26#include <advanced_config.h>
27#include <bitmaps.h>
28#include <dialog_shim.h>
29#include <dpi_scaling_common.h>
30#include <kiface_base.h>
31#include <kiplatform/ui.h>
32#include <pgm_base.h>
33#include <id.h>
38#include <wx/filedlg.h>
39
40/*
41 * What follows is a whole lot of ugly to handle various platform GUI deficiences with respect
42 * to light/dark mode, DPI scaling, and other foibles.
43 *
44 * Ugly as it all is, it does improve our usability on various platforms.
45 */
46
49{
50 /*
51 * Cairo canvas doesn't work on Mac, so no need for fallback anti-aliasing options
52 */
53#ifdef __WXMAC__
54 m_antialiasingFallback->Show( false );
55 m_antialiasingFallbackLabel->Show( false );
56#endif
57
58 m_textEditorBtn->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
59 m_pdfViewerBtn->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
60
61 /*
62 * Automatic dark mode detection works fine on Mac, so no need for the explicit options.
63 */
64#ifdef __WXMAC__
65 m_stIconTheme->Show( false );
66 m_rbIconThemeLight->Show( false );
67 m_rbIconThemeDark->Show( false );
68 m_rbIconThemeAuto->Show( false );
69#endif
70
71 /*
72 * Automatic canvas scaling works fine on all supported platforms, so manual scaling is disabled
73 */
74 if( ADVANCED_CFG::GetCfg().m_AllowManualCanvasScale )
75 {
76 static constexpr int dpi_scaling_precision = 1;
77 static constexpr double dpi_scaling_increment = 0.5;
78
81 m_canvasScaleCtrl->SetDigits( dpi_scaling_precision );
82 m_canvasScaleCtrl->SetIncrement( dpi_scaling_increment );
84
85 m_canvasScaleCtrl->SetToolTip(
86 _( "Set the scale for the canvas."
87 "\n\n"
88 "On high-DPI displays on some platforms, KiCad cannot determine the "
89 "scaling factor. In this case you may need to set this to a value to "
90 "match your system's DPI scaling. 2.0 is a common value. "
91 "\n\n"
92 "If this does not match the system DPI scaling, the canvas will "
93 "not match the window size and cursor position." ) );
94
95 m_canvasScaleAuto->SetToolTip(
96 _( "Use an automatic value for the canvas scale."
97 "\n\n"
98 "On some platforms, the automatic value is incorrect and should be "
99 "set manually." ) );
100 }
101 else
102 {
103 m_staticTextCanvasScale->Show( false );
104 m_canvasScaleCtrl->Show( false );
105 m_canvasScaleCtrl = nullptr;
106 m_canvasScaleAuto->Show( false );
107 }
108
109 // Hide the option of icons in menus for platforms that do not support them
111
112 m_scaleFonts->Show( false );
113 m_fontScalingHelp->Show( false );
114
116 {
117 m_canvasScaleCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED,
118 wxCommandEventHandler( PANEL_COMMON_SETTINGS::OnCanvasScaleChange ),
119 nullptr, this );
120 }
121
122 wxSize minSize = m_highContrastCtrl->GetMinSize();
123 int minWidth = m_highContrastCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
124
125 m_highContrastCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
126}
127
128
130{
132 {
133 m_canvasScaleCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED,
134 wxCommandEventHandler( PANEL_COMMON_SETTINGS::OnCanvasScaleChange ),
135 nullptr, this );
136 }
137}
138
139
141{
142 COMMON_SETTINGS* commonSettings = Pgm().GetCommonSettings();
143
144 applySettingsToPanel( *commonSettings );
145
146 // TODO(JE) Move these into COMMON_SETTINGS probably
147 m_textEditorPath->SetValue( Pgm().GetTextEditor( false ) );
148 m_defaultPDFViewer->SetValue( Pgm().UseSystemPdfBrowser() );
149 m_otherPDFViewer->SetValue( !Pgm().UseSystemPdfBrowser() );
150 m_PDFViewerPath->SetValue( Pgm().GetPdfBrowserName() );
152
153 return true;
154}
155
156
158{
159 COMMON_SETTINGS* commonSettings = Pgm().GetCommonSettings();
160
161 commonSettings->m_System.autosave_interval = m_SaveTime->GetValue() * 60;
162 commonSettings->m_System.file_history_size = m_fileHistorySize->GetValue();
163 commonSettings->m_System.clear_3d_cache_interval = m_Clear3DCacheFilesOlder->GetValue();
164
165 commonSettings->m_Graphics.opengl_aa_mode = m_antialiasing->GetSelection();
166 commonSettings->m_Graphics.cairo_aa_mode = m_antialiasingFallback->GetSelection();
167
169 {
170 DPI_SCALING_COMMON dpi( commonSettings, this );
171 dpi.SetDpiConfig( m_canvasScaleAuto->GetValue(), m_canvasScaleCtrl->GetValue() );
172 }
173
174 if( m_rbIconThemeLight->GetValue() )
175 commonSettings->m_Appearance.icon_theme = ICON_THEME::LIGHT;
176 else if( m_rbIconThemeDark->GetValue() )
177 commonSettings->m_Appearance.icon_theme = ICON_THEME::DARK;
178 else if( m_rbIconThemeAuto->GetValue() )
179 commonSettings->m_Appearance.icon_theme = ICON_THEME::AUTO;
180
181 if( m_rbIconSizeSmall->GetValue() )
182 commonSettings->m_Appearance.toolbar_icon_size = 16;
183 else if( m_rbIconSizeNormal->GetValue() )
184 commonSettings->m_Appearance.toolbar_icon_size = 24;
185 else if( m_rbIconSizeLarge->GetValue() )
186 commonSettings->m_Appearance.toolbar_icon_size = 32;
187
188 commonSettings->m_Appearance.use_icons_in_menus = m_checkBoxIconsInMenus->GetValue();
189 commonSettings->m_Appearance.apply_icon_scale_to_fonts = m_scaleFonts->GetValue();
190
191 commonSettings->m_Appearance.show_scrollbars = m_showScrollbars->GetValue();
192
193 commonSettings->m_Appearance.grid_striping = m_gridStriping->GetValue();
194
195 double dimmingPercent = 80;
196 m_highContrastCtrl->GetValue().ToDouble( &dimmingPercent );
197 commonSettings->m_Appearance.hicontrast_dimming_factor = dimmingPercent / 100.0f;
198
199 commonSettings->m_Input.focus_follow_sch_pcb = m_focusFollowSchPcb->GetValue();
200 commonSettings->m_Input.hotkey_feedback = m_hotkeyFeedback->GetValue();
201 commonSettings->m_Input.immediate_actions = !m_NonImmediateActions->GetValue();
202 commonSettings->m_Input.warp_mouse_on_move = m_warpMouseOnMove->GetValue();
203
204 commonSettings->m_Backup.enabled = m_cbBackupEnabled->GetValue();
205 commonSettings->m_Backup.backup_on_autosave = m_cbBackupAutosave->GetValue();
206 commonSettings->m_Backup.limit_total_files = m_backupLimitTotalFiles->GetValue();
207 commonSettings->m_Backup.limit_daily_files = m_backupLimitDailyFiles->GetValue();
208 commonSettings->m_Backup.min_interval = m_backupMinInterval->GetValue() * 60;
209 commonSettings->m_Backup.limit_total_size = m_backupLimitTotalSize->GetValue() * 1024 * 1024;
210
211 commonSettings->m_Session.remember_open_files = m_cbRememberOpenFiles->GetValue();
212
213 Pgm().SetTextEditor( m_textEditorPath->GetValue());
214
215 Pgm().SetPdfBrowserName( m_PDFViewerPath->GetValue() );
218
219 Pgm().GetSettingsManager().Save( commonSettings );
220
221 return true;
222}
223
224
226{
227 COMMON_SETTINGS defaultSettings;
228
229 defaultSettings.ResetToDefaults();
230
231 applySettingsToPanel( defaultSettings );
232
233 // TODO(JE) Move these into COMMON_SETTINGS probably
234 m_textEditorPath->SetValue( defaultSettings.m_System.text_editor );
235 m_defaultPDFViewer->SetValue( defaultSettings.m_System.use_system_pdf_viewer );
236 m_otherPDFViewer->SetValue( !defaultSettings.m_System.use_system_pdf_viewer );
237 m_PDFViewerPath->SetValue( defaultSettings.m_System.pdf_viewer_name );
239}
240
241
243{
244 int timevalue = aSettings.m_System.autosave_interval;
245 wxString msg;
246
247 msg << timevalue / 60;
248 m_SaveTime->SetValue( msg );
249
250 m_fileHistorySize->SetValue( aSettings.m_System.file_history_size );
251
252 m_antialiasing->SetSelection( aSettings.m_Graphics.opengl_aa_mode );
253 m_antialiasingFallback->SetSelection( aSettings.m_Graphics.cairo_aa_mode );
254
256
258 {
259 const DPI_SCALING_COMMON dpi( &aSettings, this );
260 m_canvasScaleCtrl->SetValue( dpi.GetScaleFactor() );
261 m_canvasScaleAuto->SetValue( dpi.GetCanvasIsAutoScaled() );
262 }
263
264 switch( aSettings.m_Appearance.icon_theme )
265 {
266 case ICON_THEME::LIGHT: m_rbIconThemeLight->SetValue( true ); break;
267 case ICON_THEME::DARK: m_rbIconThemeDark->SetValue( true ); break;
268 case ICON_THEME::AUTO: m_rbIconThemeAuto->SetValue( true ); break;
269 }
270
271 switch( aSettings.m_Appearance.toolbar_icon_size )
272 {
273 case 16: m_rbIconSizeSmall->SetValue( true ); break;
274 case 24: m_rbIconSizeNormal->SetValue( true ); break;
275 case 32: m_rbIconSizeLarge->SetValue( true ); break;
276 }
277
280
281 m_gridStriping->SetValue( aSettings.m_Appearance.grid_striping );
282
283 double dimmingPercent = aSettings.m_Appearance.hicontrast_dimming_factor * 100.0f;
284 m_highContrastCtrl->SetValue( wxString::Format( "%.0f", dimmingPercent ) );
285
286 m_focusFollowSchPcb->SetValue( aSettings.m_Input.focus_follow_sch_pcb );
287 m_hotkeyFeedback->SetValue( aSettings.m_Input.hotkey_feedback );
288 m_warpMouseOnMove->SetValue( aSettings.m_Input.warp_mouse_on_move );
289 m_NonImmediateActions->SetValue( !aSettings.m_Input.immediate_actions );
290
292
293 m_cbBackupEnabled->SetValue( aSettings.m_Backup.enabled );
294 m_cbBackupAutosave->SetValue( aSettings.m_Backup.backup_on_autosave );
297 m_backupMinInterval->SetValue( aSettings.m_Backup.min_interval / 60 );
298 m_backupLimitTotalSize->SetValue( aSettings.m_Backup.limit_total_size / ( 1024 * 1024 ) );
299
300 m_showScrollbars->SetValue( aSettings.m_Appearance.show_scrollbars );
301}
302
303
304void PANEL_COMMON_SETTINGS::OnCanvasScaleChange( wxCommandEvent& aEvent )
305{
306 m_canvasScaleAuto->SetValue( false );
307}
308
309
310void PANEL_COMMON_SETTINGS::OnCanvasScaleAuto( wxCommandEvent& aEvent )
311{
312 const bool automatic = m_canvasScaleAuto->GetValue();
313
314 if( automatic && m_canvasScaleCtrl )
315 {
316 // set the scale to the auto value, without consulting the config
317 DPI_SCALING_COMMON dpi( nullptr, this );
318
319 // update the field (no events sent)
320 m_canvasScaleCtrl->SetValue( dpi.GetScaleFactor() );
321 }
322}
323
324
325void PANEL_COMMON_SETTINGS::OnTextEditorClick( wxCommandEvent& event )
326{
327 // Ask the user to select a new editor, but suggest the current one as the default.
328 wxString editorname = Pgm().AskUserForPreferredEditor( m_textEditorPath->GetValue() );
329
330 // If we have a new editor name request it to be copied to m_text_editor and saved
331 // to the preferences file. If the user cancelled the dialog then the previous
332 // value will be retained.
333 if( !editorname.IsEmpty() )
334 m_textEditorPath->SetValue( editorname );
335}
336
337
338void PANEL_COMMON_SETTINGS::OnPDFViewerClick( wxCommandEvent& event )
339{
340 wxString mask( wxT( "*" ) );
341
342#ifdef __WINDOWS__
343 mask += wxT( ".exe" );
344#endif
345
346 wxString wildcard = _( "Executable files (" ) + mask + wxT( ")|" ) + mask;
347
349 wxFileName fn = Pgm().GetPdfBrowserName();
350
351 wxWindow* topLevelParent = wxGetTopLevelParent( this );
352
353 wxFileDialog dlg( topLevelParent, _( "Select Preferred PDF Viewer" ), fn.GetPath(),
354 fn.GetFullPath(), wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
355
356 if( dlg.ShowModal() == wxID_CANCEL )
357 return;
358
359 m_otherPDFViewer->SetValue( true );
360 m_PDFViewerPath->SetValue( dlg.GetPath() );
361}
362
363
365{
367}
368
369
371{
372 m_PDFViewerPath->Enable( m_otherPDFViewer->GetValue() );
373 m_pdfViewerBtn->Enable( m_otherPDFViewer->GetValue() );
374}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APPEARANCE m_Appearance
AUTO_BACKUP m_Backup
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
bool GetCanvasIsAutoScaled() const override
Is the current value auto scaled, or is it user-set in the config.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
void SetDpiConfig(bool aAuto, double aValue) override
Set the common DPI config in a given config object.
static double GetDefaultScaleFactor()
Get the "default" scaling factor to use if not other config is available.
Definition: dpi_scaling.cpp:42
static double GetMaxScaleFactor()
Definition: dpi_scaling.cpp:27
static double GetMinScaleFactor()
Definition: dpi_scaling.cpp:35
void ResetToDefaults()
Resets all parameters to default values.
Class PANEL_COMMON_SETTINGS_BASE.
void OnTextEditorClick(wxCommandEvent &event) override
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
void OnCanvasScaleChange(wxCommandEvent &aEvent)
Event fired when the canvas scale field is modified.
PANEL_COMMON_SETTINGS(wxWindow *aParent)
void applySettingsToPanel(COMMON_SETTINGS &aSettings)
void OnPDFViewerClick(wxCommandEvent &event) override
void OnCanvasScaleAuto(wxCommandEvent &aEvent) override
Event fired when the canvas auto-scale option is changed.
void ResetPanel() override
Reset the contents of this panel.
void OnRadioButtonPdfViewer(wxCommandEvent &event) override
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:678
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:189
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: pgm_base.cpp:1044
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:187
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:188
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:204
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
virtual void WritePdfBrowserInfos()
Save the PDF browser choice to the common configuration.
Definition: pgm_base.cpp:1051
virtual const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:231
bool Enable(bool aEnable=true) override
void SetBitmap(const wxBitmapBundle &aBmp)
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
bool AllowIconsInMenus()
If the user has disabled icons system-wide, we check that here.
Definition: gtk/ui.cpp:209
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
int min_interval
Minimum time, in seconds, between subsequent backups.
bool backup_on_autosave
Trigger a backup on autosave.
unsigned long long limit_total_size
Maximum total size of backups (bytes), 0 for unlimited.
int limit_total_files
Maximum number of backup archives to retain.
int limit_daily_files
Maximum files to keep per day, 0 for unlimited.
bool enabled
Automatically back up the project when files are saved.