From 265c6fa3b74dd38854b7c2bbc69b027db2144605 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Mon, 10 Aug 2020 02:29:15 +0100 Subject: [PATCH] Improve color theme support in the footprint preview widget This ensures the colors used by the status text pane in the preview widget are the same as the canvas, so there is a seemless transition between the two. Additionally, remove the scrollbars from the symbol preview widget in the place symbol dialog - they are pointless. --- common/widgets/footprint_preview_widget.cpp | 44 ++++++++++++--------- eeschema/widgets/symbol_preview_widget.cpp | 2 + include/widgets/footprint_preview_widget.h | 16 +++++++- pcbnew/footprint_preview_panel.cpp | 18 +++++++++ pcbnew/footprint_preview_panel.h | 4 ++ 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/common/widgets/footprint_preview_widget.cpp b/common/widgets/footprint_preview_widget.cpp index 368020d6e4..34201ae6db 100644 --- a/common/widgets/footprint_preview_widget.cpp +++ b/common/widgets/footprint_preview_widget.cpp @@ -28,38 +28,46 @@ FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aK wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ), m_prev_panel( nullptr ), - m_status_label( nullptr ), - m_sizer( nullptr ) + m_status( nullptr ), + m_statusPanel( nullptr ), + m_statusSizer( nullptr ), + m_outerSizer( nullptr ) { m_prev_panel = FOOTPRINT_PREVIEW_PANEL_BASE::Create( this, aKiway ); if( !m_prev_panel ) return; - SetBackgroundColour( *wxBLACK ); - SetForegroundColour( *wxWHITE ); + m_statusPanel = new wxPanel( this ); + m_status = new wxStaticText( m_statusPanel, wxID_ANY, wxEmptyString ); + m_statusSizer = new wxBoxSizer( wxVERTICAL ); + m_statusSizer->Add( 0, 0, 1 ); // add a spacer + m_statusSizer->Add( m_status, 0, wxALIGN_CENTER ); + m_statusSizer->Add( 0, 0, 1 ); // add a spacer + m_statusPanel->SetSizer( m_statusSizer ); - m_status_label = new wxStaticText( this, -1, wxEmptyString ); - m_sizer = new wxBoxSizer( wxVERTICAL ); - m_sizer->Add( 0, 0, 1 ); - m_sizer->Add( m_status_label, 0, wxALL | wxALIGN_CENTER, 0 ); - m_sizer->Add( 0, 0, 1 ); + // Give the status panel the same color scheme as the canvas so it isn't jarring when switched to + m_statusPanel->SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() ); + m_statusPanel->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() ); - auto outer_sizer = new wxBoxSizer( wxVERTICAL ); - outer_sizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 ); - outer_sizer->Add( m_sizer, 1, wxALL | wxALIGN_CENTER, 0 ); + m_outerSizer = new wxBoxSizer( wxVERTICAL ); + m_outerSizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 ); + m_outerSizer->Add( m_statusPanel, 1, wxALL | wxEXPAND, 0 ); + + // Hide the status panel to start + m_statusPanel->Hide(); - m_sizer->ShowItems( false ); m_prev_panel->SetStatusHandler( [this]( FOOTPRINT_STATUS s ){ this->OnStatusChange( s ); } ); - SetSizer( outer_sizer ); + SetSizer( m_outerSizer ); + Layout(); } void FOOTPRINT_PREVIEW_WIDGET::SetStatusText( wxString const& aText ) { - m_status_label->SetLabel( aText ); - m_sizer->ShowItems( true ); + m_status->SetLabel( aText ); + m_statusPanel->Show(); m_prev_panel->GetWindow()->Hide(); Layout(); } @@ -67,9 +75,9 @@ void FOOTPRINT_PREVIEW_WIDGET::SetStatusText( wxString const& aText ) void FOOTPRINT_PREVIEW_WIDGET::ClearStatus() { - m_status_label->SetLabel( wxEmptyString ); + m_status->SetLabel( wxEmptyString ); + m_statusPanel->Hide(); m_prev_panel->GetWindow()->Show(); - m_sizer->ShowItems( false ); Layout(); } diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp index 0214a30707..65ec96c792 100644 --- a/eeschema/widgets/symbol_preview_widget.cpp +++ b/eeschema/widgets/symbol_preview_widget.cpp @@ -55,6 +55,8 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway, m_preview = new SCH_PREVIEW_PANEL( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ), m_galDisplayOptions, canvasType ); m_preview->SetStealsFocus( false ); + m_preview->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER ); + m_preview->GetGAL()->SetAxesEnabled( false ); // Do not display the grid: the look is not good for a small canvas area. // But mainly, due to some strange bug I (JPC) was unable to fix, the grid creates diff --git a/include/widgets/footprint_preview_widget.h b/include/widgets/footprint_preview_widget.h index d5d06085fa..bf9612351c 100644 --- a/include/widgets/footprint_preview_widget.h +++ b/include/widgets/footprint_preview_widget.h @@ -25,6 +25,8 @@ #include #include +#include + class FOOTPRINT_LOAD_EVENT; class FOOTPRINT_PREVIEW_PANEL_BASE; class LIB_ID; @@ -89,8 +91,12 @@ private: void OnStatusChange( FOOTPRINT_STATUS aStatus ); FOOTPRINT_PREVIEW_PANEL_BASE* m_prev_panel; - wxStaticText* m_status_label; - wxSizer* m_sizer; + + wxStaticText* m_status; + wxPanel* m_statusPanel; + wxSizer* m_statusSizer; + wxSizer* m_outerSizer; + }; @@ -128,6 +134,12 @@ public: */ virtual wxWindow* GetWindow() = 0; + /** + * Get the colors to use in a preview widget to match the preview panel. + */ + virtual const KIGFX::COLOR4D& GetBackgroundColor() = 0; + virtual const KIGFX::COLOR4D& GetForegroundColor() = 0; + /** * Return a footprint preview panel instance via Kiface. May return null * if Kiway is not available or there is any error on load. diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 1e84eafc13..6d56c6d342 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -291,6 +291,24 @@ FOOTPRINT_PREVIEW_PANEL::~FOOTPRINT_PREVIEW_PANEL( ) } +const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetBackgroundColor() +{ + KIGFX::PAINTER* painter = GetView()->GetPainter(); + auto settings = static_cast( painter->GetSettings() ); + + return settings->GetBackgroundColor(); +} + + +const COLOR4D& FOOTPRINT_PREVIEW_PANEL::GetForegroundColor() +{ + KIGFX::PAINTER* painter = GetView()->GetPainter(); + auto settings = static_cast( painter->GetSettings() ); + + return settings->GetCursorColor(); +} + + FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY FOOTPRINT_PREVIEW_PANEL::CacheAndReturn( const LIB_ID& aFPID ) { auto opt_ent = m_iface->GetFromCache( aFPID ); diff --git a/pcbnew/footprint_preview_panel.h b/pcbnew/footprint_preview_panel.h index d6ff4d3c09..691baa4ad2 100644 --- a/pcbnew/footprint_preview_panel.h +++ b/pcbnew/footprint_preview_panel.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,9 @@ public: virtual void SetStatusHandler( FOOTPRINT_STATUS_HANDLER aHandler ) override; + virtual const KIGFX::COLOR4D& GetBackgroundColor() override; + virtual const KIGFX::COLOR4D& GetForegroundColor() override; + virtual wxWindow* GetWindow() override; BOARD* GetBoard() { return m_dummyBoard.get(); }