diff --git a/eeschema/dialogs/dialog_edit_line_style.cpp b/eeschema/dialogs/dialog_edit_line_style.cpp index 870256e3fc..76ead57caf 100644 --- a/eeschema/dialogs/dialog_edit_line_style.cpp +++ b/eeschema/dialogs/dialog_edit_line_style.cpp @@ -29,6 +29,7 @@ #include #include #include +#include const int BUTT_COLOR_MINSIZE_X = 32; const int BUTT_COLOR_MINSIZE_Y = 20; @@ -64,9 +65,9 @@ DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( SCH_EDIT_FRAME* aParent, SetInitialFocus( m_lineWidth ); for( auto& typeEntry : lineTypeNames ) - { m_typeCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) ); - } + + m_typeCombo->Append( INDETERMINATE_ACTION ); m_sdbSizerOK->SetDefault(); @@ -80,10 +81,10 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataToWindow() auto first_stroke_item = m_strokeItems.front(); if( std::all_of( m_strokeItems.begin() + 1, m_strokeItems.end(), - [&]( const SCH_ITEM* r ) - { - return r->GetPenWidth() == first_stroke_item->GetPenWidth(); - } ) ) + [&]( const SCH_ITEM* r ) + { + return r->GetPenWidth() == first_stroke_item->GetPenWidth(); + } ) ) { m_width.SetValue( first_stroke_item->GetPenWidth() ); } @@ -93,119 +94,51 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataToWindow() } if( std::all_of( m_strokeItems.begin() + 1, m_strokeItems.end(), - [&]( const SCH_ITEM* r ) - { - return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor(); - } ) ) + [&]( const SCH_ITEM* r ) + { + return r->GetStroke().GetColor() == first_stroke_item->GetStroke().GetColor(); + } ) ) { - setColor( first_stroke_item->GetStroke().GetColor() ); + m_colorSwatch->SetSwatchColor( first_stroke_item->GetStroke().GetColor(), false ); } else { - setColor( COLOR4D::UNSPECIFIED ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); } if( std::all_of( m_strokeItems.begin() + 1, m_strokeItems.end(), - [&]( const SCH_ITEM* r ) - { - return r->GetStroke().GetType() == first_stroke_item->GetStroke().GetType(); - } ) ) + [&]( const SCH_ITEM* r ) + { + return r->GetStroke().GetType() == first_stroke_item->GetStroke().GetType(); + } ) ) { int style = static_cast( first_stroke_item->GetStroke().GetType() ); wxCHECK_MSG( style < (int)lineTypeNames.size(), false, - "Line type for first line is not found in the type lookup map" ); + "Line type for first line is not found in the type lookup map" ); m_typeCombo->SetSelection( style ); } else { - m_typeCombo->SetSelection( wxNOT_FOUND ); + m_typeCombo->SetStringSelection( INDETERMINATE_ACTION ); } return true; } -void DIALOG_EDIT_LINE_STYLE::onColorButtonClicked( wxCommandEvent& event ) -{ - COLOR4D newColor = COLOR4D::UNSPECIFIED; - DIALOG_COLOR_PICKER dialog( this, m_selectedColor, false ); - - if( dialog.ShowModal() == wxID_OK ) - newColor = dialog.GetColor(); - - if( m_selectedColor == newColor ) - return; - - setColor( newColor ); -} - - -void DIALOG_EDIT_LINE_STYLE::updateColorButton( COLOR4D& aColor ) -{ - wxMemoryDC iconDC; - - - if( aColor == COLOR4D::UNSPECIFIED ) - { - m_colorButton->SetBitmap( KiBitmap( question_mark_xpm ) ); - } - else - { - wxBitmap bitmap( std::max( m_colorButton->GetSize().x, BUTT_COLOR_MINSIZE_X ), - std::max( m_colorButton->GetSize().y, BUTT_COLOR_MINSIZE_Y ) ); - - iconDC.SelectObject( bitmap ); - iconDC.SetPen( *wxBLACK_PEN ); - - wxBrush brush( aColor.ToColour() ); - iconDC.SetBrush( brush ); - - // Paint the full bitmap in aColor: - iconDC.SetBackground( brush ); - iconDC.Clear(); - - m_colorButton->SetBitmap( bitmap ); - } - - m_colorButton->Refresh(); - - Refresh( false ); -} - - void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event ) { m_width.SetValue( 0 ); - setColor( COLOR4D::UNSPECIFIED ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); - SCH_ITEM* item = dynamic_cast( m_strokeItems.front() ); + // This isn't quite right: they really want to set each stroke to the stroke set by the + // netclass (if any). + m_typeCombo->SetSelection( 0 ); - wxCHECK( item, /* void */ ); - - auto typeIt = lineTypeNames.find( item->GetStroke().GetType() ); - wxCHECK_RET( typeIt != lineTypeNames.end(), - "Default line type not found line dialogs line type lookup map" ); - - m_typeCombo->SetSelection( static_cast( typeIt->first ) ); Refresh(); } -void DIALOG_EDIT_LINE_STYLE::setColor( const COLOR4D& aColor ) -{ - m_selectedColor = aColor; - - if( aColor == COLOR4D::UNSPECIFIED ) - { - COLOR4D defaultColor = Pgm().GetSettingsManager().GetColorSettings()->GetColor( - m_strokeItems.front()->GetLayer() ); - updateColorButton( defaultColor ); - } - else - updateColorButton( m_selectedColor ); -} - - bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow() { PICKED_ITEMS_LIST pickedItems; @@ -225,12 +158,11 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow() strokeItem->SetStroke( stroke ); } - if( m_typeCombo->GetSelection() != wxNOT_FOUND ) + int selection = m_typeCombo->GetSelection(); + + if( selection < (int)lineTypeNames.size() ) { stroke = strokeItem->GetStroke(); - int selection = m_typeCombo->GetSelection(); - wxCHECK_MSG( selection < (int)lineTypeNames.size(), false, - "Selected line type index exceeds size of line type lookup map" ); auto it = lineTypeNames.begin(); std::advance( it, selection ); @@ -240,7 +172,7 @@ bool DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow() } stroke = strokeItem->GetStroke(); - stroke.SetColor( m_selectedColor ); + stroke.SetColor( m_colorSwatch->GetSwatchColor() ); strokeItem->SetStroke( stroke ); m_frame->UpdateItem( strokeItem ); diff --git a/eeschema/dialogs/dialog_edit_line_style.h b/eeschema/dialogs/dialog_edit_line_style.h index 135718ee99..9a19e36ace 100644 --- a/eeschema/dialogs/dialog_edit_line_style.h +++ b/eeschema/dialogs/dialog_edit_line_style.h @@ -45,14 +45,9 @@ private: SCH_EDIT_FRAME* m_frame; std::deque m_strokeItems; - UNIT_BINDER m_width; - COLOR4D m_selectedColor; + UNIT_BINDER m_width; void resetDefaults( wxCommandEvent& event ) override; - void onColorButtonClicked( wxCommandEvent& aEvent ) override; - - void setColor( const COLOR4D& aColor ); - void updateColorButton( COLOR4D& aColor ); }; #endif // __dialog_edit_line_style__ diff --git a/eeschema/dialogs/dialog_edit_line_style_base.cpp b/eeschema/dialogs/dialog_edit_line_style_base.cpp index 15d5ccb5a7..0282c02a73 100644 --- a/eeschema/dialogs/dialog_edit_line_style_base.cpp +++ b/eeschema/dialogs/dialog_edit_line_style_base.cpp @@ -5,12 +5,13 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "widgets/color_swatch.h" + #include "dialog_edit_line_style_base.h" /////////////////////////////////////////////////////////////////////////// BEGIN_EVENT_TABLE( DIALOG_EDIT_LINE_STYLE_BASE, DIALOG_SHIM ) - EVT_BUTTON( idColorBtn, DIALOG_EDIT_LINE_STYLE_BASE::_wxFB_onColorButtonClicked ) EVT_BUTTON( wxID_APPLY, DIALOG_EDIT_LINE_STYLE_BASE::_wxFB_resetDefaults ) END_EVENT_TABLE() @@ -29,43 +30,51 @@ DIALOG_EDIT_LINE_STYLE_BASE::DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWi m_staticTextWidth = new wxStaticText( this, wxID_ANY, _("Width:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextWidth->Wrap( -1 ); - fgSizerGeneral->Add( m_staticTextWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); + fgSizerGeneral->Add( m_staticTextWidth, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 3 ); m_lineWidth = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), 0 ); - fgSizerGeneral->Add( m_lineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 ); + fgSizerGeneral->Add( m_lineWidth, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 3 ); m_staticWidthUnits = new wxStaticText( this, wxID_ANY, _("unit"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticWidthUnits->Wrap( -1 ); m_staticWidthUnits->SetMinSize( wxSize( 40,-1 ) ); - fgSizerGeneral->Add( m_staticWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); + fgSizerGeneral->Add( m_staticWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 3 ); m_staticTextColor = new wxStaticText( this, wxID_ANY, _("Color:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextColor->Wrap( -1 ); - fgSizerGeneral->Add( m_staticTextColor, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + fgSizerGeneral->Add( m_staticTextColor, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); - m_colorButton = new wxBitmapButton( this, idColorBtn, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); + m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE|wxTAB_TRAVERSAL ); + wxBoxSizer* bSizer2; + bSizer2 = new wxBoxSizer( wxVERTICAL ); - m_colorButton->SetBitmap( wxNullBitmap ); - fgSizerGeneral->Add( m_colorButton, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 ); + m_colorSwatch = new COLOR_SWATCH( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + bSizer2->Add( m_colorSwatch, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 ); + + + m_panel1->SetSizer( bSizer2 ); + m_panel1->Layout(); + bSizer2->Fit( m_panel1 ); + fgSizerGeneral->Add( m_panel1, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 2 ); fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); m_staticTextStyle = new wxStaticText( this, wxID_ANY, _("Style:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextStyle->Wrap( -1 ); - fgSizerGeneral->Add( m_staticTextStyle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + fgSizerGeneral->Add( m_staticTextStyle, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); m_typeCombo = new wxBitmapComboBox( this, wxID_ANY, _("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); - m_typeCombo->SetMinSize( wxSize( 140,-1 ) ); + m_typeCombo->SetMinSize( wxSize( 240,-1 ) ); - fgSizerGeneral->Add( m_typeCombo, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 ); + fgSizerGeneral->Add( m_typeCombo, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 3 ); - mainSizer->Add( fgSizerGeneral, 1, wxEXPAND|wxALL, 5 ); + mainSizer->Add( fgSizerGeneral, 1, wxEXPAND|wxALL, 10 ); m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - mainSizer->Add( m_staticline, 0, wxEXPAND | wxALL, 5 ); + mainSizer->Add( m_staticline, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); diff --git a/eeschema/dialogs/dialog_edit_line_style_base.fbp b/eeschema/dialogs/dialog_edit_line_style_base.fbp index eebc13fe1f..6b842f69f4 100644 --- a/eeschema/dialogs/dialog_edit_line_style_base.fbp +++ b/eeschema/dialogs/dialog_edit_line_style_base.fbp @@ -59,7 +59,7 @@ wxVERTICAL none - 5 + 10 wxEXPAND|wxALL 1 @@ -76,7 +76,7 @@ 0 3 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT 0 1 @@ -137,7 +137,7 @@ 3 - wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND + wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT 0 1 @@ -201,7 +201,7 @@ 3 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM 0 1 @@ -262,7 +262,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT 0 1 @@ -322,10 +322,10 @@ - 3 - wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND + 2 + wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -336,31 +336,23 @@ - Load From File; 1 0 1 1 - - 0 0 - Dock 0 Left 1 1 - 0 0 - idColorBtn - MyButton - - 0 + wxID_ANY 0 @@ -368,30 +360,90 @@ 0 1 - m_colorButton + m_panel1 1 protected 1 - - Resizable 1 - - ; forward_declare + ; ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - - onColorButtonClicked + wxBORDER_SIMPLE|wxTAB_TRAVERSAL + + + bSizer2 + wxVERTICAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + COLOR_SWATCH + 1 + + + 1 + + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + + 0 + + + 0 + + 1 + m_colorSwatch + 1 + + + protected + 1 + + Resizable + + 1 + + COLOR_SWATCH; widgets/color_swatch.h; forward_declare + 0 + + + + + + + @@ -406,7 +458,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT 0 1 @@ -467,7 +519,7 @@ 3 - wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND + wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT 0 1 @@ -503,7 +555,7 @@ 0 - 140,-1 + 240,-1 1 m_typeCombo 1 @@ -534,7 +586,7 @@ 5 - wxEXPAND | wxALL + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 1 diff --git a/eeschema/dialogs/dialog_edit_line_style_base.h b/eeschema/dialogs/dialog_edit_line_style_base.h index 6448d04a8e..16f24e0652 100644 --- a/eeschema/dialogs/dialog_edit_line_style_base.h +++ b/eeschema/dialogs/dialog_edit_line_style_base.h @@ -10,6 +10,8 @@ #include #include #include +class COLOR_SWATCH; + #include "dialog_shim.h" #include #include @@ -18,14 +20,11 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include +#include +#include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -39,21 +38,16 @@ class DIALOG_EDIT_LINE_STYLE_BASE : public DIALOG_SHIM private: // Private event handlers - void _wxFB_onColorButtonClicked( wxCommandEvent& event ){ onColorButtonClicked( event ); } void _wxFB_resetDefaults( wxCommandEvent& event ){ resetDefaults( event ); } protected: - enum - { - idColorBtn = 1000 - }; - wxStaticText* m_staticTextWidth; wxTextCtrl* m_lineWidth; wxStaticText* m_staticWidthUnits; wxStaticText* m_staticTextColor; - wxBitmapButton* m_colorButton; + wxPanel* m_panel1; + COLOR_SWATCH* m_colorSwatch; wxStaticText* m_staticTextStyle; wxBitmapComboBox* m_typeCombo; wxStaticLine* m_staticline; @@ -63,7 +57,6 @@ class DIALOG_EDIT_LINE_STYLE_BASE : public DIALOG_SHIM wxButton* m_sdbSizerCancel; // Virtual event handlers, overide them in your derived class - virtual void onColorButtonClicked( wxCommandEvent& event ) { event.Skip(); } virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); }