KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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_currentScrollMod( {} )
32{
33#ifdef __WXOSX_MAC__
34 for( wxSizerItem* child : m_zoomSizer->GetChildren() )
35 {
36 if( child->GetWindow() == m_zoomSpeed )
37 child->SetBorder( 14 );
38 }
39
40 for( wxSizerItem* child : m_panSizer->GetChildren() )
41 {
42 if( child->GetWindow() == m_autoPanSpeed )
43 child->SetBorder( 14 );
44 }
45
46 m_lblCtrl->SetLabel( _( "Cmd" ) );
47 m_lblAlt->SetLabel( _( "Option" ) );
48#endif
49
50 m_scrollWarning->SetBitmap( KiBitmapBundle( 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
71
72 return true;
73}
74
75
77{
79
81
83 {
84 PAGED_DIALOG::GetDialog( this )->SetError( _( "Only one action can be assigned to each "
85 "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;
93 case 1: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::DRAG_SELECTED; 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
128
129 return true;
130}
131
132
134{
135 COMMON_SETTINGS defaultSettings;
136
137 defaultSettings.ResetToDefaults();
138
139 applySettingsToPanel( defaultSettings );
140}
141
142
144{
145 m_checkZoomCenter->SetValue( aSettings.m_Input.center_on_zoom );
146 m_checkAutoPan->SetValue( aSettings.m_Input.auto_pan );
148 m_zoomSpeed->SetValue( aSettings.m_Input.zoom_speed );
149 m_checkAutoZoomSpeed->SetValue( aSettings.m_Input.zoom_speed_auto );
150 m_checkEnablePanH->SetValue( aSettings.m_Input.horizontal_pan );
151 m_autoPanSpeed->SetValue( aSettings.m_Input.auto_pan_acceleration );
152
153 m_zoomSpeed->Enable( !aSettings.m_Input.zoom_speed_auto );
154
155 switch( aSettings.m_Input.drag_left )
156 {
157 case MOUSE_DRAG_ACTION::SELECT: m_choiceLeftButtonDrag->SetSelection( 0 ); break;
158 case MOUSE_DRAG_ACTION::DRAG_SELECTED: m_choiceLeftButtonDrag->SetSelection( 1 ); break;
159 case MOUSE_DRAG_ACTION::DRAG_ANY: m_choiceLeftButtonDrag->SetSelection( 2 ); break;
160 default: break;
161 }
162
163 switch( aSettings.m_Input.drag_middle )
164 {
165 case MOUSE_DRAG_ACTION::PAN: m_choiceMiddleButtonDrag->SetSelection( 0 ); break;
166 case MOUSE_DRAG_ACTION::ZOOM: m_choiceMiddleButtonDrag->SetSelection( 1 ); break;
167 case MOUSE_DRAG_ACTION::NONE: m_choiceMiddleButtonDrag->SetSelection( 2 ); break;
168 case MOUSE_DRAG_ACTION::SELECT: break;
169 default: break;
170 }
171
172 switch( aSettings.m_Input.drag_right )
173 {
174 case MOUSE_DRAG_ACTION::PAN: m_choiceRightButtonDrag->SetSelection( 0 ); break;
175 case MOUSE_DRAG_ACTION::ZOOM: m_choiceRightButtonDrag->SetSelection( 1 ); break;
176 case MOUSE_DRAG_ACTION::NONE: m_choiceRightButtonDrag->SetSelection( 2 ); break;
177 case MOUSE_DRAG_ACTION::SELECT: break;
178 default: break;
179 }
180
186
188}
189
190
191void PANEL_MOUSE_SETTINGS::OnScrollRadioButton( wxCommandEvent& event )
192{
193 wxRadioButton* btn = dynamic_cast<wxRadioButton*>( event.GetEventObject() );
194
195 if( !btn )
196 return;
197
199
200 m_scrollWarning->Show( !isScrollModSetValid( newSet ) );
201
202 m_currentScrollMod = newSet;
203}
204
205
207{
208 SCROLL_MOD_SET ret = {};
209
210 if( m_rbZoomShift->GetValue() )
211 ret.zoom = WXK_SHIFT;
212 else if( m_rbZoomCtrl->GetValue() )
213 ret.zoom = WXK_CONTROL;
214 else if( m_rbZoomAlt->GetValue() )
215 ret.zoom = WXK_ALT;
216
217 if( m_rbPanHShift->GetValue() )
218 ret.panh = WXK_SHIFT;
219 else if( m_rbPanHCtrl->GetValue() )
220 ret.panh = WXK_CONTROL;
221 else if( m_rbPanHAlt->GetValue() )
222 ret.panh = WXK_ALT;
223
224 if( m_rbPanVShift->GetValue() )
225 ret.panv = WXK_SHIFT;
226 else if( m_rbPanVCtrl->GetValue() )
227 ret.panv = WXK_CONTROL;
228 else if( m_rbPanVAlt->GetValue() )
229 ret.panv = WXK_ALT;
230
231 return ret;
232}
233
234
236{
237 return ( aSet.zoom != aSet.panh && aSet.panh != aSet.panv && aSet.panv != aSet.zoom );
238}
239
240
242{
243 auto set_wheel_buttons =
244 []( int aModifier, wxRadioButton* aNoneBtn, wxRadioButton* aCtrlBtn,
245 wxRadioButton* aShiftBtn, wxRadioButton* aAltBtn )
246 {
247 switch( aModifier )
248 {
249 case 0: aNoneBtn->SetValue( true ); break;
250 case WXK_CONTROL: aCtrlBtn->SetValue( true ); break;
251 case WXK_SHIFT: aShiftBtn->SetValue( true ); break;
252 case WXK_ALT: aAltBtn->SetValue( true ); break;
253 }
254 };
255
257 m_rbZoomAlt );
258
260 m_rbPanHAlt );
261
263 m_rbPanVAlt );
264
267}
268
269
270void PANEL_MOUSE_SETTINGS::onMouseDefaults( wxCommandEvent& event )
271{
273 m_currentScrollMod.panh = WXK_CONTROL;
274 m_currentScrollMod.panv = WXK_SHIFT;
277
279
280 m_checkEnablePanH->SetValue( false );
281}
282
283
284void PANEL_MOUSE_SETTINGS::onTrackpadDefaults( wxCommandEvent& event )
285{
286 m_currentScrollMod.zoom = WXK_CONTROL;
287 m_currentScrollMod.panh = WXK_SHIFT;
291
293
294 m_checkEnablePanH->SetValue( true );
295}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
@ small_warning
void ResetToDefaults()
Resets all parameters to default values.
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
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(wxWindow *aParent)
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:679
#define _(s)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
MOUSE_DRAG_ACTION drag_right
MOUSE_DRAG_ACTION drag_middle
MOUSE_DRAG_ACTION drag_left