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 <[email protected]>
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>
26#include <wx/defs.h>
27
28
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 m_lblAlt->SetLabel( _( "Option" ) );
49#endif
50
51 m_scrollWarning->SetBitmap( KiBitmap( BITMAPS::small_warning ) );
52 m_scrollWarning->Hide();
53
54 m_checkAutoZoomSpeed->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
55 [&]( wxCommandEvent& aEvt )
56 {
57 m_zoomSpeed->Enable( !m_checkAutoZoomSpeed->GetValue() );
58 } );
59}
60
61
63{
64}
65
66
68{
69 const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
70
72
73 return true;
74}
75
76
78{
79 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
80
82
84 {
85 m_dialog->SetError( _( "Only one action can be assigned to each vertical scroll setting" ),
86 this, nullptr );
87 return false;
88 }
89
90 switch( m_choiceLeftButtonDrag->GetSelection() )
91 {
92 case 0: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::SELECT; break;
94 case 2: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::DRAG_ANY; break;
95 default: break;
96 }
97
98 switch( m_choiceMiddleButtonDrag->GetSelection() )
99 {
100 case 0: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::PAN; break;
101 case 1: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::ZOOM; break;
102 case 2: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::NONE; break;
103 default: break;
104 }
105
106 switch( m_choiceRightButtonDrag->GetSelection() )
107 {
108 case 0: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::PAN; break;
109 case 1: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::ZOOM; break;
110 case 2: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::NONE; break;
111 default: break;
112 }
113
114 cfg->m_Input.center_on_zoom = m_checkZoomCenter->GetValue();
115 cfg->m_Input.auto_pan = m_checkAutoPan->GetValue();
118 cfg->m_Input.zoom_speed = m_zoomSpeed->GetValue();
120 cfg->m_Input.horizontal_pan = m_checkEnablePanH->GetValue();
121
125
126 return true;
127}
128
129
131{
132 COMMON_SETTINGS defaultSettings;
133
134 defaultSettings.ResetToDefaults();
135
136 applySettingsToPanel( defaultSettings );
137}
138
139
141{
142 m_checkZoomCenter->SetValue( aSettings.m_Input.center_on_zoom );
143 m_checkAutoPan->SetValue( aSettings.m_Input.auto_pan );
145 m_zoomSpeed->SetValue( aSettings.m_Input.zoom_speed );
146 m_checkAutoZoomSpeed->SetValue( aSettings.m_Input.zoom_speed_auto );
147 m_checkEnablePanH->SetValue( aSettings.m_Input.horizontal_pan );
148 m_autoPanSpeed->SetValue( aSettings.m_Input.auto_pan_acceleration );
149
150 m_zoomSpeed->Enable( !aSettings.m_Input.zoom_speed_auto );
151
152 switch( aSettings.m_Input.drag_left )
153 {
154 case MOUSE_DRAG_ACTION::SELECT: m_choiceLeftButtonDrag->SetSelection( 0 ); break;
155 case MOUSE_DRAG_ACTION::DRAG_SELECTED: m_choiceLeftButtonDrag->SetSelection( 1 ); break;
156 case MOUSE_DRAG_ACTION::DRAG_ANY: m_choiceLeftButtonDrag->SetSelection( 2 ); break;
157 default: break;
158 }
159
160 switch( aSettings.m_Input.drag_middle )
161 {
162 case MOUSE_DRAG_ACTION::PAN: m_choiceMiddleButtonDrag->SetSelection( 0 ); break;
163 case MOUSE_DRAG_ACTION::ZOOM: m_choiceMiddleButtonDrag->SetSelection( 1 ); break;
164 case MOUSE_DRAG_ACTION::NONE: m_choiceMiddleButtonDrag->SetSelection( 2 ); break;
165 case MOUSE_DRAG_ACTION::SELECT: break;
166 default: break;
167 }
168
169 switch( aSettings.m_Input.drag_right )
170 {
171 case MOUSE_DRAG_ACTION::PAN: m_choiceRightButtonDrag->SetSelection( 0 ); break;
172 case MOUSE_DRAG_ACTION::ZOOM: m_choiceRightButtonDrag->SetSelection( 1 ); break;
173 case MOUSE_DRAG_ACTION::NONE: m_choiceRightButtonDrag->SetSelection( 2 ); break;
174 case MOUSE_DRAG_ACTION::SELECT: break;
175 default: break;
176 }
177
181
183}
184
185
186void PANEL_MOUSE_SETTINGS::OnScrollRadioButton( wxCommandEvent& event )
187{
188 wxRadioButton* btn = dynamic_cast<wxRadioButton*>( event.GetEventObject() );
189
190 if( !btn )
191 return;
192
194
195 m_scrollWarning->Show( !isScrollModSetValid( newSet ) );
196
197 m_currentScrollMod = newSet;
198}
199
200
202{
203 SCROLL_MOD_SET ret = {};
204
205 if( m_rbZoomShift->GetValue() )
206 ret.zoom = WXK_SHIFT;
207 else if( m_rbZoomCtrl->GetValue() )
208 ret.zoom = WXK_CONTROL;
209 else if( m_rbZoomAlt->GetValue() )
210 ret.zoom = WXK_ALT;
211
212 if( m_rbPanHShift->GetValue() )
213 ret.panh = WXK_SHIFT;
214 else if( m_rbPanHCtrl->GetValue() )
215 ret.panh = WXK_CONTROL;
216 else if( m_rbPanHAlt->GetValue() )
217 ret.panh = WXK_ALT;
218
219 if( m_rbPanVShift->GetValue() )
220 ret.panv = WXK_SHIFT;
221 else if( m_rbPanVCtrl->GetValue() )
222 ret.panv = WXK_CONTROL;
223 else if( m_rbPanVAlt->GetValue() )
224 ret.panv = WXK_ALT;
225
226 return ret;
227}
228
229
231{
232 return ( aSet.zoom != aSet.panh && aSet.panh != aSet.panv && aSet.panv != aSet.zoom );
233}
234
235
237{
238 auto set_wheel_buttons =
239 []( int aModifier, wxRadioButton* aNoneBtn, wxRadioButton* aCtrlBtn,
240 wxRadioButton* aShiftBtn, wxRadioButton* aAltBtn )
241 {
242 switch( aModifier )
243 {
244 case 0: aNoneBtn->SetValue( true ); break;
245 case WXK_CONTROL: aCtrlBtn->SetValue( true ); break;
246 case WXK_SHIFT: aShiftBtn->SetValue( true ); break;
247 case WXK_ALT: aAltBtn->SetValue( true ); break;
248 }
249 };
250
252 m_rbZoomAlt );
253
255 m_rbPanHAlt );
256
258 m_rbPanVAlt );
259}
260
261
262void PANEL_MOUSE_SETTINGS::onMouseDefaults( wxCommandEvent& event )
263{
265 m_currentScrollMod.panh = WXK_CONTROL;
266 m_currentScrollMod.panv = WXK_SHIFT;
267
269
270 m_checkEnablePanH->SetValue( false );
271}
272
273
274void PANEL_MOUSE_SETTINGS::onTrackpadDefaults( wxCommandEvent& event )
275{
276 m_currentScrollMod.zoom = WXK_CONTROL;
277 m_currentScrollMod.panh = WXK_SHIFT;
279
281
282 m_checkEnablePanH->SetValue( true );
283}
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
@ small_warning
void ResetToDefaults()
Resets all parameters to default values.
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
Class PANEL_MOUSE_SETTINGS_BASE.
void onMouseDefaults(wxCommandEvent &event) override
bool TransferDataFromWindow() override
void ResetPanel() override
Reset the contents of this panel.
void applySettingsToPanel(const COMMON_SETTINGS &aSettings)
SCROLL_MOD_SET getScrollModSet()
SCROLL_MOD_SET m_currentScrollMod
bool isScrollModSetValid(const SCROLL_MOD_SET &aSet)
bool TransferDataToWindow() override
void onTrackpadDefaults(wxCommandEvent &event) override
void OnScrollRadioButton(wxCommandEvent &event) override
PANEL_MOUSE_SETTINGS(PAGED_DIALOG *aDialog, wxWindow *aParent)
#define _(s)
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
MOUSE_DRAG_ACTION drag_right
MOUSE_DRAG_ACTION drag_middle
MOUSE_DRAG_ACTION drag_left