7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 14:50:11 +00:00

Sym/Fp diff panels: add a quick switch hotkey

Then you can just toggle back and forth with '/'.

One day, these frames should use a tool manager for this
kind of thing (also for the ruler tool, but lots of other
things on top), but for now just bind a char hook.
This commit is contained in:
John Beard 2024-10-31 21:42:09 +08:00
parent 8a6910d96f
commit e53281a71b
4 changed files with 124 additions and 13 deletions

View File

@ -17,13 +17,18 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <widgets/footprint_diff_widget.h>
#include <pcb_painter.h>
#include <footprint.h>
#include <settings/settings_manager.h>
#include "widgets/footprint_diff_widget.h"
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/slider.h>
#include <wx/bmpbuttn.h>
#include <bitmaps.h>
#include <footprint.h>
#include <hotkeys_basic.h>
#include <pcb_painter.h>
#include <settings/settings_manager.h>
FOOTPRINT_DIFF_WIDGET::FOOTPRINT_DIFF_WIDGET( wxWindow* aParent, KIWAY& aKiway ) :
@ -41,6 +46,13 @@ FOOTPRINT_DIFF_WIDGET::FOOTPRINT_DIFF_WIDGET( wxWindow* aParent, KIWAY& aKiway )
bottomSizer->Add( m_slider, 1, wxLEFT | wxRIGHT | wxALIGN_BOTTOM, 30 );
bottomSizer->Add( libLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
m_toggleButton = new wxBitmapButton( this, wxID_ANY, KiBitmapBundle( BITMAPS::swap ) );
wxString toggleTooltip = _( "Toggle between A and B display" );
toggleTooltip = AddHotkeyName( toggleTooltip, '/', HOTKEY_ACTION_TYPE::IS_COMMENT );
m_toggleButton->SetToolTip( toggleTooltip );
bottomSizer->Add( m_toggleButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL, 6 );
m_outerSizer->Add( bottomSizer, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
Layout();
@ -54,6 +66,15 @@ FOOTPRINT_DIFF_WIDGET::FOOTPRINT_DIFF_WIDGET( wxWindow* aParent, KIWAY& aKiway )
m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
m_slider->Bind( wxEVT_SCROLL_CHANGED, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
// Bind keys
Bind( wxEVT_CHAR_HOOK, &FOOTPRINT_DIFF_WIDGET::onCharHook, this );
m_toggleButton->Bind( wxEVT_BUTTON,
[&]( wxCommandEvent& aEvent )
{
ToggleAB();
} );
}
@ -88,6 +109,20 @@ void FOOTPRINT_DIFF_WIDGET::DisplayDiff( FOOTPRINT* aBoardFootprint,
}
void FOOTPRINT_DIFF_WIDGET::ToggleAB()
{
const int val = m_slider->GetValue();
if( val == 0 )
m_slider->SetValue( 100 );
else
m_slider->SetValue( 0 );
wxScrollEvent dummy;
onSlider( dummy );
}
void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
{
double pct = (double) m_slider->GetValue() / 100.0;
@ -130,4 +165,17 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
RefreshAll();
aEvent.Skip();
}
void FOOTPRINT_DIFF_WIDGET::onCharHook( wxKeyEvent& aEvent )
{
if( aEvent.GetKeyCode() == '/' )
{
ToggleAB();
}
else
{
aEvent.Skip();
}
}

View File

@ -17,15 +17,20 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <widgets/symbol_diff_widget.h>
#include "widgets/symbol_diff_widget.h"
#include <wx/bmpbuttn.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/stattext.h>
#include <bitmaps.h>
#include <hotkeys_basic.h>
#include <lib_symbol.h>
#include <sch_painter.h>
#include <eeschema_settings.h>
#include <settings/settings_manager.h>
#include <lib_symbol.h>
#include <sch_view.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/slider.h>
SYMBOL_DIFF_WIDGET::SYMBOL_DIFF_WIDGET( wxWindow* aParent,
@ -44,6 +49,13 @@ SYMBOL_DIFF_WIDGET::SYMBOL_DIFF_WIDGET( wxWindow* aParent,
bottomSizer->Add( m_slider, 1, wxLEFT | wxRIGHT | wxALIGN_BOTTOM, 30 );
bottomSizer->Add( libLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
m_toggleButton = new wxBitmapButton( this, wxID_ANY, KiBitmapBundle( BITMAPS::swap ) );
wxString toggleTooltip = _( "Toggle between A and B display" );
toggleTooltip = AddHotkeyName( toggleTooltip, '/', HOTKEY_ACTION_TYPE::IS_COMMENT );
m_toggleButton->SetToolTip( toggleTooltip );
bottomSizer->Add( m_toggleButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL, 6 );
m_outerSizer->Add( bottomSizer, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
Layout();
@ -57,6 +69,14 @@ SYMBOL_DIFF_WIDGET::SYMBOL_DIFF_WIDGET( wxWindow* aParent,
m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &SYMBOL_DIFF_WIDGET::onSlider, this );
m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &SYMBOL_DIFF_WIDGET::onSlider, this );
m_slider->Bind( wxEVT_SCROLL_CHANGED, &SYMBOL_DIFF_WIDGET::onSlider, this );
Bind( wxEVT_CHAR_HOOK, &SYMBOL_DIFF_WIDGET::onCharHook, this );
m_toggleButton->Bind( wxEVT_BUTTON,
[this]( wxCommandEvent& aEvent )
{
ToggleAB();
} );
}
@ -117,6 +137,20 @@ void SYMBOL_DIFF_WIDGET::DisplayDiff( LIB_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSy
}
void SYMBOL_DIFF_WIDGET::ToggleAB()
{
const int val = m_slider->GetValue();
if( val == 0 )
m_slider->SetValue( 100 );
else
m_slider->SetValue( 0 );
wxScrollEvent dummy;
onSlider( dummy );
}
void SYMBOL_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
{
KIGFX::VIEW* view = m_preview->GetView();
@ -163,4 +197,17 @@ void SYMBOL_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
m_preview->ForceRefresh();
aEvent.Skip();
}
void SYMBOL_DIFF_WIDGET::onCharHook( wxKeyEvent& aEvent )
{
if( aEvent.GetKeyCode() == '/' )
{
ToggleAB();
}
else
{
aEvent.Skip();
}
}

View File

@ -24,6 +24,7 @@
class LIB_SYMBOL;
class wxBitmapButton;
class wxSlider;
@ -46,12 +47,19 @@ public:
*/
void DisplayDiff( LIB_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSymbol, int aUnit, int aConvert );
private:
void onSlider( wxScrollEvent& aEvent );
/**
* Toggle between full-A and full-B display.
*/
void ToggleAB();
private:
LIB_SYMBOL* m_libraryItem;
wxSlider* m_slider;
void onSlider( wxScrollEvent& aEvent );
void onCharHook( wxKeyEvent& aEvent );
private:
LIB_SYMBOL* m_libraryItem;
wxSlider* m_slider;
wxBitmapButton* m_toggleButton;
};

View File

@ -24,6 +24,7 @@
class FOOTPRINT;
class wxBitmapButton;
class wxSlider;
@ -44,13 +45,20 @@ public:
*/
void DisplayDiff( FOOTPRINT* aBoardFootprint, std::shared_ptr<FOOTPRINT>& aLibFootprint );
/**
* Toggle between full-A and full-B display.
*/
void ToggleAB();
private:
void onSlider( wxScrollEvent& aEvent );
void onCharHook( wxKeyEvent& aEvent );
private:
std::shared_ptr<FOOTPRINT> m_boardItemCopy;
std::shared_ptr<FOOTPRINT> m_libraryItem;
wxSlider* m_slider;
wxBitmapButton* m_toggleButton;
};