From 28d7a2d7c90dc7264d3cbedd57266a1fcfc9f46a Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 21 Oct 2021 01:33:30 +0200 Subject: [PATCH] Sim: Update tuner dialog values when focus is lost Fixes https://gitlab.com/kicad/code/kicad/issues/7841 --- eeschema/widgets/tuner_slider.cpp | 98 ++++++++++++++++++-------- eeschema/widgets/tuner_slider.h | 8 +++ eeschema/widgets/tuner_slider_base.cpp | 8 ++- eeschema/widgets/tuner_slider_base.fbp | 10 ++- eeschema/widgets/tuner_slider_base.h | 10 ++- 5 files changed, 98 insertions(+), 36 deletions(-) diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp index 15927b5f05..774809f89f 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -131,6 +131,52 @@ void TUNER_SLIDER::updateValueText() } +void TUNER_SLIDER::updateMax() +{ + try + { + SPICE_VALUE newMax( m_maxText->GetValue() ); + SetMax( newMax ); + } + catch( const KI_PARAM_ERROR& ) + { + // Restore the previous value + m_maxText->SetValue( m_max.ToOrigString() ); + } +} + + +void TUNER_SLIDER::updateValue() +{ + try + { + SPICE_VALUE newCur( m_valueText->GetValue() ); + SetValue( newCur ); + m_changed = true; + } + catch( const KI_PARAM_ERROR& ) + { + // Restore the previous value + m_valueText->SetValue( m_value.ToOrigString() ); + } +} + + +void TUNER_SLIDER::updateMin() +{ + try + { + SPICE_VALUE newMin( m_minText->GetValue() ); + SetMin( newMin ); + } + catch( const KI_PARAM_ERROR& ) + { + // Restore the previous value + m_minText->SetValue( m_min.ToOrigString() ); + } +} + + void TUNER_SLIDER::onClose( wxCommandEvent& event ) { m_frame->RemoveTuner( this ); @@ -153,49 +199,39 @@ void TUNER_SLIDER::onSliderChanged( wxScrollEvent& event ) } +void TUNER_SLIDER::onMaxKillFocus( wxFocusEvent& event ) +{ + updateMax(); +} + + +void TUNER_SLIDER::onValueKillFocus( wxFocusEvent& event ) +{ + updateValue(); +} + + +void TUNER_SLIDER::onMinKillFocus( wxFocusEvent& event ) +{ + updateMin(); +} + + void TUNER_SLIDER::onMaxTextEnter( wxCommandEvent& event ) { - try - { - SPICE_VALUE newMax( m_maxText->GetValue() ); - SetMax( newMax ); - } - catch( const KI_PARAM_ERROR& ) - { - // Restore the previous value - m_maxText->SetValue( m_max.ToOrigString() ); - } + updateMax(); } void TUNER_SLIDER::onValueTextEnter( wxCommandEvent& event ) { - try - { - SPICE_VALUE newCur( m_valueText->GetValue() ); - SetValue( newCur ); - m_changed = true; - } - catch( const KI_PARAM_ERROR& ) - { - // Restore the previous value - m_valueText->SetValue( m_value.ToOrigString() ); - } + updateValue(); } void TUNER_SLIDER::onMinTextEnter( wxCommandEvent& event ) { - try - { - SPICE_VALUE newMin( m_minText->GetValue() ); - SetMin( newMin ); - } - catch( const KI_PARAM_ERROR& ) - { - // Restore the previous value - m_minText->SetValue( m_min.ToOrigString() ); - } + updateMin(); } diff --git a/eeschema/widgets/tuner_slider.h b/eeschema/widgets/tuner_slider.h index a8e43671d7..13b300d72e 100644 --- a/eeschema/widgets/tuner_slider.h +++ b/eeschema/widgets/tuner_slider.h @@ -78,10 +78,18 @@ private: void updateSlider(); void updateValueText(); + void updateMax(); + void updateValue(); + void updateMin(); + void onClose( wxCommandEvent& event ) override; void onSave( wxCommandEvent& event ) override; void onSliderChanged( wxScrollEvent& event ) override; + void onMaxKillFocus( wxFocusEvent& event ) override; + void onValueKillFocus( wxFocusEvent& event ) override; + void onMinKillFocus( wxFocusEvent& event ) override; + void onMaxTextEnter( wxCommandEvent& event ) override; void onValueTextEnter( wxCommandEvent& event ) override; void onMinTextEnter( wxCommandEvent& event ) override; diff --git a/eeschema/widgets/tuner_slider_base.cpp b/eeschema/widgets/tuner_slider_base.cpp index a4a2bc3815..5ceed88773 100644 --- a/eeschema/widgets/tuner_slider_base.cpp +++ b/eeschema/widgets/tuner_slider_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -81,8 +81,11 @@ TUNER_SLIDER_BASE::TUNER_SLIDER_BASE( wxWindow* parent, wxWindowID id, const wxP m_slider->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Connect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); + m_maxText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMaxKillFocus ), NULL, this ); m_maxText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this ); + m_valueText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onValueKillFocus ), NULL, this ); m_valueText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this ); + m_minText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMinKillFocus ), NULL, this ); m_minText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this ); m_saveBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this ); } @@ -100,8 +103,11 @@ TUNER_SLIDER_BASE::~TUNER_SLIDER_BASE() m_slider->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Disconnect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); m_slider->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( TUNER_SLIDER_BASE::onSliderChanged ), NULL, this ); + m_maxText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMaxKillFocus ), NULL, this ); m_maxText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMaxTextEnter ), NULL, this ); + m_valueText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onValueKillFocus ), NULL, this ); m_valueText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onValueTextEnter ), NULL, this ); + m_minText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( TUNER_SLIDER_BASE::onMinKillFocus ), NULL, this ); m_minText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( TUNER_SLIDER_BASE::onMinTextEnter ), NULL, this ); m_saveBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( TUNER_SLIDER_BASE::onSave ), NULL, this ); diff --git a/eeschema/widgets/tuner_slider_base.fbp b/eeschema/widgets/tuner_slider_base.fbp index 532aa6c13f..e8fcae89e5 100644 --- a/eeschema/widgets/tuner_slider_base.fbp +++ b/eeschema/widgets/tuner_slider_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ tuner_slider_base 1000 none + 1 TUNER_SLIDER_BASE @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -46,6 +48,7 @@ 126,283 + 0 wxTAB_TRAVERSAL @@ -137,6 +140,7 @@ + 0 @@ -359,6 +363,7 @@ + onMaxKillFocus onMaxTextEnter @@ -424,6 +429,7 @@ + onValueKillFocus onValueTextEnter @@ -489,6 +495,7 @@ + onMinKillFocus onMinTextEnter @@ -509,6 +516,7 @@ + 0 diff --git a/eeschema/widgets/tuner_slider_base.h b/eeschema/widgets/tuner_slider_base.h index 2a01952a06..fb07dba2a7 100644 --- a/eeschema/widgets/tuner_slider_base.h +++ b/eeschema/widgets/tuner_slider_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -16,10 +16,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -44,11 +44,14 @@ class TUNER_SLIDER_BASE : public wxPanel wxTextCtrl* m_minText; wxButton* m_saveBtn; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void onClose( wxCommandEvent& event ) { event.Skip(); } virtual void onSliderChanged( wxScrollEvent& event ) { event.Skip(); } + virtual void onMaxKillFocus( wxFocusEvent& event ) { event.Skip(); } virtual void onMaxTextEnter( wxCommandEvent& event ) { event.Skip(); } + virtual void onValueKillFocus( wxFocusEvent& event ) { event.Skip(); } virtual void onValueTextEnter( wxCommandEvent& event ) { event.Skip(); } + virtual void onMinKillFocus( wxFocusEvent& event ) { event.Skip(); } virtual void onMinTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void onSave( wxCommandEvent& event ) { event.Skip(); } @@ -56,6 +59,7 @@ class TUNER_SLIDER_BASE : public wxPanel public: TUNER_SLIDER_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 126,283 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~TUNER_SLIDER_BASE(); };