KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema/dialogs/dialog_tablecell_properties.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <gr_text.h>
25#include <ee_actions.h>
26#include <sch_edit_frame.h>
29#include <widgets/font_choice.h>
31#include <sch_table.h>
32#include <sch_commit.h>
33#include <tool/tool_manager.h>
35
36
38 std::vector<SCH_TABLECELL*> aCells ) :
40 m_frame( aFrame ),
41 m_table( nullptr ),
42 m_cells( std::move( aCells ) ),
43 m_textSize( aFrame, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
44 m_marginLeft( aFrame, nullptr, m_marginLeftCtrl, nullptr ),
45 m_marginTop( aFrame, nullptr, m_marginTopCtrl, m_marginTopUnits ),
46 m_marginRight( aFrame, nullptr, m_marginRightCtrl, nullptr ),
47 m_marginBottom( aFrame, nullptr, m_marginBottomCtrl, nullptr ),
48 m_returnValue( TABLECELL_PROPS_CANCEL )
49{
50 wxASSERT( m_cells.size() > 0 && m_cells[0] );
51
52 m_table = static_cast<SCH_TABLE*>( m_cells[0]->GetParent() );
53
55 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
56
58 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
60 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
62 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
63
65 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
67 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
69 m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
70
74
76 Layout();
77
81 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_TABLECELL_PROPERTIES::onVAlignButton, this );
84
85 // Now all widgets have the size fixed, call FinishDialogSettings
87}
88
89
91{
92 if( !wxDialog::TransferDataToWindow() )
93 return false;
94
95 bool firstCell = true;
98
99 for( SCH_TABLECELL* cell : m_cells )
100 {
101 if( firstCell )
102 {
103 m_fontCtrl->SetFontSelection( cell->GetFont() );
104 m_textSize.SetValue( cell->GetTextWidth() );
105
106 m_bold->Set3StateValue( cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
107 m_italic->Set3StateValue( cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
108
109 hAlign = cell->GetHorizJustify();
110 vAlign = cell->GetVertJustify();
111
112 m_textColorBook->SetSelection( 1 );
113 m_textColorSwatch->SetSwatchColor( cell->GetTextColor(), false );
114 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
115
116 m_fillColorBook->SetSelection( 1 );
117
118 if( cell->IsFilled() )
119 m_fillColorSwatch->SetSwatchColor( cell->GetFillColor(), false );
120 else
121 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
122
123 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
124
125 m_marginLeft.SetValue( cell->GetMarginLeft() );
126 m_marginTop.SetValue( cell->GetMarginTop() );
127 m_marginRight.SetValue( cell->GetMarginRight() );
128 m_marginBottom.SetValue( cell->GetMarginBottom() );
129
130 firstCell = false;
131 }
132 else
133 {
134 if( cell->GetFont() != m_fontCtrl->GetFontSelection( cell->IsBold(),
135 cell->IsItalic() ) )
136 m_fontCtrl->SetSelection( -1 );
137
138 if( cell->GetTextWidth() != m_textSize.GetValue() )
140
141 wxCheckBoxState bold = cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
142
143 if( bold != m_bold->Get3StateValue() )
144 m_bold->Set3StateValue( wxCHK_UNDETERMINED );
145
146 wxCheckBoxState italic = cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
147
148 if( italic != m_italic->Get3StateValue() )
149 m_italic->Set3StateValue( wxCHK_UNDETERMINED );
150
151 if( cell->GetHorizJustify() != hAlign )
153
154 if( cell->GetVertJustify() != vAlign )
156
157 if( cell->GetTextColor() != m_textColorSwatch->GetSwatchColor() )
158 {
159 m_textColorBook->SetSelection( 0 );
160 m_textColorPopup->SetSelection( 0 );
161 }
162
163 COLOR4D fillColor = cell->IsFilled() ? cell->GetFillColor() : COLOR4D::UNSPECIFIED;
164
165 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
166 {
167 m_fillColorBook->SetSelection( 0 );
168 m_fillColorPopup->SetSelection( 0 );
169 }
170
171 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
172 fillColor = COLOR4D::UNSPECIFIED;
173
174 if( cell->GetMarginLeft() != m_marginLeft.GetIntValue() )
176
177 if( cell->GetMarginTop() != m_marginTop.GetIntValue() )
179
180 if( cell->GetMarginRight() != m_marginRight.GetIntValue() )
182
183 if( cell->GetMarginBottom() != m_marginBottom.GetIntValue() )
185 }
186
187 switch( hAlign )
188 {
193 }
194
195 switch( vAlign )
196 {
197 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
201 }
202 }
203
204 return true;
205}
206
207
209{
211 {
212 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
213 btn->Check( false );
214 }
215}
216
217
219{
221 {
222 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
223 btn->Check( false );
224 }
225}
226
227
229{
230 if( aEvent.GetSelection() == 1 )
231 {
232 m_textColorBook->SetSelection( 1 );
234 }
235}
236
237
239{
240 if( aEvent.GetSelection() == 1 )
241 {
242 m_fillColorBook->SetSelection( 1 );
244 }
245}
246
247
249{
250 if( !wxDialog::TransferDataFromWindow() )
251 return false;
252
253 SCH_COMMIT commit( m_frame );
254
255 /* save table in undo list if not already in edit */
256 if( m_table->GetEditFlags() == 0 )
257 commit.Modify( m_table, m_frame->GetScreen() );
258
259 for( SCH_TABLECELL* cell : m_cells )
260 {
261 if( m_bold->Get3StateValue() == wxCHK_CHECKED )
262 cell->SetBold( true );
263 else if( m_bold->Get3StateValue() == wxCHK_UNCHECKED )
264 cell->SetBold( false );
265
266 if( m_italic->Get3StateValue() == wxCHK_CHECKED )
267 cell->SetItalic( true );
268 else if( m_italic->Get3StateValue() == wxCHK_UNCHECKED )
269 cell->SetItalic( false );
270
272 cell->SetFont( m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) );
273
275 cell->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
276
277 if( m_hAlignLeft->IsChecked() )
278 cell->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
279 else if( m_hAlignRight->IsChecked() )
280 cell->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
281 else if( m_hAlignCenter->IsChecked() )
282 cell->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
283
284 if( m_vAlignTop->IsChecked() )
285 cell->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
286 else if( m_vAlignBottom->IsChecked() )
287 cell->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
288 else if( m_vAlignCenter->IsChecked() )
289 cell->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
290
291 if( m_textColorBook->GetSelection() == 1 )
292 cell->SetTextColor( m_textColorSwatch->GetSwatchColor() );
293
294 if( m_fillColorBook->GetSelection() == 1 )
295 {
297
298 if( fillColor == COLOR4D::UNSPECIFIED )
299 {
300 cell->SetFillMode( FILL_T::NO_FILL );
301 }
302 else
303 {
304 cell->SetFillMode( FILL_T::FILLED_WITH_COLOR );
305 cell->SetFillColor( fillColor );
306 }
307 }
308
310 cell->SetMarginLeft( m_marginLeft.GetIntValue() );
311
313 cell->SetMarginTop( m_marginTop.GetIntValue() );
314
316 cell->SetMarginRight( m_marginRight.GetIntValue() );
317
319 cell->SetMarginBottom( m_marginBottom.GetIntValue() );
320 }
321
322 if( !commit.Empty() )
323 commit.Push( _( "Edit Table Cell Properties" ) );
324
326 return true;
327}
328
329
330void DIALOG_TABLECELL_PROPERTIES::onEditTable( wxCommandEvent& aEvent )
331{
333 {
335 Close();
336 }
337}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void SetIsRadioButton()
bool IsChecked() const
void Check(bool aCheck=true)
Check the control.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:108
bool Empty() const
Definition: commit.h:150
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void onTextColorPopup(wxCommandEvent &aEvent) override
void onFillColorPopup(wxCommandEvent &aEvent) override
DIALOG_TABLECELL_PROPERTIES(SCH_EDIT_FRAME *aParentFrame, std::vector< SCH_TABLECELL * > aCells)
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:133
void SetFontSelection(KIFONT::FONT *aFont, bool aSilentMode=false)
Set the selection in wxChoice widget.
Definition: font_choice.cpp:73
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic, bool aForDrawingSheet=false) const
bool HaveFontSelection() const
Definition: font_choice.cpp:95
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Definition: sch_commit.cpp:432
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int GetIntValue()
Definition: unit_binder.h:129
virtual long long int GetValue()
Return the current value in Internal Units.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:153
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:440
STL namespace.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695