KiCad PCB EDA Suite
panel_mouse_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 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <bitmaps.h>
23 #include <pgm_base.h>
25 #include <widgets/paged_dialog.h>
26 #include <wx/defs.h>
27 
28 
30  PANEL_MOUSE_SETTINGS_BASE( aParent ),
31  m_dialog( aDialog ),
32  m_currentScrollMod( {} )
33 {
34 #ifdef __WXOSX_MAC__
35  for( wxSizerItem* child : m_zoomSizer->GetChildren() )
36  {
37  if( child->GetWindow() == m_zoomSpeed )
38  child->SetBorder( 14 );
39  }
40 
41  for( wxSizerItem* child : m_panSizer->GetChildren() )
42  {
43  if( child->GetWindow() == m_autoPanSpeed )
44  child->SetBorder( 14 );
45  }
46 
47  m_lblCtrl->SetLabel( _( "Cmd" ) );
48 #endif
49 
50  m_scrollWarning->SetBitmap( KiBitmap( BITMAPS::small_warning ) );
51  m_scrollWarning->Hide();
52 
53  m_checkAutoZoomSpeed->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
54  [&]( wxCommandEvent& aEvt )
55  {
56  m_zoomSpeed->Enable( !m_checkAutoZoomSpeed->GetValue() );
57  } );
58 }
59 
60 
62 {
63 }
64 
65 
67 {
68  const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
69 
70  applySettingsToPanel( *cfg );
71 
72  return true;
73 }
74 
75 
77 {
78  COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
79 
81 
83  {
84  m_dialog->SetError( _( "Only one action can be assigned to each vertical scroll setting" ),
85  this, nullptr );
86  return false;
87  }
88 
89  switch( m_choiceLeftButtonDrag->GetSelection() )
90  {
91  case 0: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::SELECT; break;
93  case 2: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::DRAG_ANY; break;
94  default: break;
95  }
96 
97  switch( m_choiceMiddleButtonDrag->GetSelection() )
98  {
99  case 0: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::PAN; break;
100  case 1: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::ZOOM; break;
101  case 2: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::NONE; break;
102  default: break;
103  }
104 
105  switch( m_choiceRightButtonDrag->GetSelection() )
106  {
107  case 0: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::PAN; break;
108  case 1: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::ZOOM; break;
109  case 2: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::NONE; break;
110  default: break;
111  }
112 
113  cfg->m_Input.center_on_zoom = m_checkZoomCenter->GetValue();
114  cfg->m_Input.auto_pan = m_checkAutoPan->GetValue();
115  cfg->m_Input.auto_pan_acceleration = m_autoPanSpeed->GetValue();
117  cfg->m_Input.zoom_speed = m_zoomSpeed->GetValue();
118  cfg->m_Input.zoom_speed_auto = m_checkAutoZoomSpeed->GetValue();
119  cfg->m_Input.horizontal_pan = m_checkEnablePanH->GetValue();
120 
124 
125  return true;
126 }
127 
128 
130 {
131  COMMON_SETTINGS defaultSettings;
132 
133  defaultSettings.ResetToDefaults();
134 
135  applySettingsToPanel( defaultSettings );
136 }
137 
138 
140 {
141  m_checkZoomCenter->SetValue( aSettings.m_Input.center_on_zoom );
142  m_checkAutoPan->SetValue( aSettings.m_Input.auto_pan );
143  m_checkZoomAcceleration->SetValue( aSettings.m_Input.zoom_acceleration );
144  m_zoomSpeed->SetValue( aSettings.m_Input.zoom_speed );
145  m_checkAutoZoomSpeed->SetValue( aSettings.m_Input.zoom_speed_auto );
146  m_checkEnablePanH->SetValue( aSettings.m_Input.horizontal_pan );
147  m_autoPanSpeed->SetValue( aSettings.m_Input.auto_pan_acceleration );
148 
149  m_zoomSpeed->Enable( !aSettings.m_Input.zoom_speed_auto );
150 
151  switch( aSettings.m_Input.drag_left )
152  {
153  case MOUSE_DRAG_ACTION::SELECT: m_choiceLeftButtonDrag->SetSelection( 0 ); break;
154  case MOUSE_DRAG_ACTION::DRAG_SELECTED: m_choiceLeftButtonDrag->SetSelection( 1 ); break;
155  case MOUSE_DRAG_ACTION::DRAG_ANY: m_choiceLeftButtonDrag->SetSelection( 2 ); break;
156  default: break;
157  }
158 
159  switch( aSettings.m_Input.drag_middle )
160  {
161  case MOUSE_DRAG_ACTION::PAN: m_choiceMiddleButtonDrag->SetSelection( 0 ); break;
162  case MOUSE_DRAG_ACTION::ZOOM: m_choiceMiddleButtonDrag->SetSelection( 1 ); break;
163  case MOUSE_DRAG_ACTION::NONE: m_choiceMiddleButtonDrag->SetSelection( 2 ); break;
164  case MOUSE_DRAG_ACTION::SELECT: break;
165  default: break;
166  }
167 
168  switch( aSettings.m_Input.drag_right )
169  {
170  case MOUSE_DRAG_ACTION::PAN: m_choiceRightButtonDrag->SetSelection( 0 ); break;
171  case MOUSE_DRAG_ACTION::ZOOM: m_choiceRightButtonDrag->SetSelection( 1 ); break;
172  case MOUSE_DRAG_ACTION::NONE: m_choiceRightButtonDrag->SetSelection( 2 ); break;
173  case MOUSE_DRAG_ACTION::SELECT: break;
174  default: break;
175  }
176 
180 
182 }
183 
184 
185 void PANEL_MOUSE_SETTINGS::OnScrollRadioButton( wxCommandEvent& event )
186 {
187  wxRadioButton* btn = dynamic_cast<wxRadioButton*>( event.GetEventObject() );
188 
189  if( !btn )
190  return;
191 
192  SCROLL_MOD_SET newSet = getScrollModSet();
193 
194  m_scrollWarning->Show( !isScrollModSetValid( newSet ) );
195 
196  m_currentScrollMod = newSet;
197 }
198 
199 
201 {
202  SCROLL_MOD_SET ret = {};
203 
204  if( m_rbZoomShift->GetValue() )
205  ret.zoom = WXK_SHIFT;
206  else if( m_rbZoomCtrl->GetValue() )
207  ret.zoom = WXK_CONTROL;
208  else if( m_rbZoomAlt->GetValue() )
209  ret.zoom = WXK_ALT;
210 
211  if( m_rbPanHShift->GetValue() )
212  ret.panh = WXK_SHIFT;
213  else if( m_rbPanHCtrl->GetValue() )
214  ret.panh = WXK_CONTROL;
215  else if( m_rbPanHAlt->GetValue() )
216  ret.panh = WXK_ALT;
217 
218  if( m_rbPanVShift->GetValue() )
219  ret.panv = WXK_SHIFT;
220  else if( m_rbPanVCtrl->GetValue() )
221  ret.panv = WXK_CONTROL;
222  else if( m_rbPanVAlt->GetValue() )
223  ret.panv = WXK_ALT;
224 
225  return ret;
226 }
227 
228 
230 {
231  return ( aSet.zoom != aSet.panh && aSet.panh != aSet.panv && aSet.panv != aSet.zoom );
232 }
233 
234 
236 {
237  auto set_wheel_buttons =
238  []( int aModifier, wxRadioButton* aNoneBtn, wxRadioButton* aCtrlBtn,
239  wxRadioButton* aShiftBtn, wxRadioButton* aAltBtn )
240  {
241  switch( aModifier )
242  {
243  case 0: aNoneBtn->SetValue( true ); break;
244  case WXK_CONTROL: aCtrlBtn->SetValue( true ); break;
245  case WXK_SHIFT: aShiftBtn->SetValue( true ); break;
246  case WXK_ALT: aAltBtn->SetValue( true ); break;
247  }
248  };
249 
251  m_rbZoomAlt );
252 
254  m_rbPanHAlt );
255 
257  m_rbPanVAlt );
258 }
259 
260 
261 void PANEL_MOUSE_SETTINGS::onMouseDefaults( wxCommandEvent& event )
262 {
264  m_currentScrollMod.panh = WXK_CONTROL;
265  m_currentScrollMod.panv = WXK_SHIFT;
266 
268 
269  m_checkEnablePanH->SetValue( false );
270 }
271 
272 
273 void PANEL_MOUSE_SETTINGS::onTrackpadDefaults( wxCommandEvent& event )
274 {
275  m_currentScrollMod.zoom = WXK_CONTROL;
276  m_currentScrollMod.panh = WXK_SHIFT;
278 
280 
281  m_checkEnablePanH->SetValue( true );
282 }
void ResetToDefaults()
Resets all parameters to default values.
MOUSE_DRAG_ACTION drag_left
void applySettingsToPanel(const COMMON_SETTINGS &aSettings)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
MOUSE_DRAG_ACTION drag_right
SCROLL_MOD_SET m_currentScrollMod
void onTrackpadDefaults(wxCommandEvent &event) override
bool TransferDataFromWindow() override
#define _(s)
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
void ResetPanel() override
Reset the contents of this panel.
bool isScrollModSetValid(const SCROLL_MOD_SET &aSet)
see class PGM_BASE
SCROLL_MOD_SET getScrollModSet()
void onMouseDefaults(wxCommandEvent &event) override
PANEL_MOUSE_SETTINGS(PAGED_DIALOG *aDialog, wxWindow *aParent)
void OnScrollRadioButton(wxCommandEvent &event) override
bool TransferDataToWindow() override
MOUSE_DRAG_ACTION drag_middle
Class PANEL_MOUSE_SETTINGS_BASE.