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 (C) 2023-2024 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(), cell->IsItalic() ) )
135 m_fontCtrl->SetSelection( -1 );
136
137 if( cell->GetTextWidth() != m_textSize.GetValue() )
139
140 wxCheckBoxState bold = cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
141
142 if( bold != m_bold->Get3StateValue() )
143 m_bold->Set3StateValue( wxCHK_UNDETERMINED );
144
145 wxCheckBoxState italic = cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
146
147 if( italic != m_italic->Get3StateValue() )
148 m_italic->Set3StateValue( wxCHK_UNDETERMINED );
149
150 if( cell->GetHorizJustify() != hAlign )
152
153 if( cell->GetVertJustify() != vAlign )
155
156 if( cell->GetTextColor() != m_textColorSwatch->GetSwatchColor() )
157 {
158 m_textColorBook->SetSelection( 0 );
159 m_textColorPopup->SetSelection( 0 );
160 }
161
162 COLOR4D fillColor = cell->IsFilled() ? cell->GetFillColor() : COLOR4D::UNSPECIFIED;
163
164 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
165 {
166 m_fillColorBook->SetSelection( 0 );
167 m_fillColorPopup->SetSelection( 0 );
168 }
169
170 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
171 fillColor = COLOR4D::UNSPECIFIED;
172
173 if( cell->GetMarginLeft() != m_marginLeft.GetIntValue() )
175
176 if( cell->GetMarginTop() != m_marginTop.GetIntValue() )
178
179 if( cell->GetMarginRight() != m_marginRight.GetIntValue() )
181
182 if( cell->GetMarginBottom() != m_marginBottom.GetIntValue() )
184 }
185
186 switch( hAlign )
187 {
192 }
193
194 switch( vAlign )
195 {
196 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
200 }
201 }
202
203 return true;
204}
205
206
208{
210 {
211 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
212 btn->Check( false );
213 }
214}
215
216
218{
220 {
221 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
222 btn->Check( false );
223 }
224}
225
226
228{
229 if( aEvent.GetSelection() == 1 )
230 {
231 m_textColorBook->SetSelection( 1 );
233 }
234}
235
236
238{
239 if( aEvent.GetSelection() == 1 )
240 {
241 m_fillColorBook->SetSelection( 1 );
243 }
244}
245
246
248{
249 if( !wxDialog::TransferDataFromWindow() )
250 return false;
251
252 SCH_COMMIT commit( m_frame );
253
254 /* save table in undo list if not already in edit */
255 if( m_table->GetEditFlags() == 0 )
256 commit.Modify( m_table, m_frame->GetScreen() );
257
258 for( SCH_TABLECELL* cell : m_cells )
259 {
260 if( m_bold->Get3StateValue() == wxCHK_CHECKED )
261 cell->SetBold( true );
262 else if( m_bold->Get3StateValue() == wxCHK_UNCHECKED )
263 cell->SetBold( false );
264
265 if( m_italic->Get3StateValue() == wxCHK_CHECKED )
266 cell->SetItalic( true );
267 else if( m_italic->Get3StateValue() == wxCHK_UNCHECKED )
268 cell->SetItalic( false );
269
271 cell->SetFont( m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) );
272
274 cell->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
275
276 if( m_hAlignLeft->IsChecked() )
277 cell->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
278 else if( m_hAlignRight->IsChecked() )
279 cell->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
280 else if( m_hAlignCenter->IsChecked() )
281 cell->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
282
283 if( m_vAlignTop->IsChecked() )
284 cell->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
285 else if( m_vAlignBottom->IsChecked() )
286 cell->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
287 else if( m_vAlignCenter->IsChecked() )
288 cell->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
289
290 if( m_textColorBook->GetSelection() == 1 )
291 cell->SetTextColor( m_textColorSwatch->GetSwatchColor() );
292
293 if( m_fillColorBook->GetSelection() == 1 )
294 {
296
297 if( fillColor == COLOR4D::UNSPECIFIED )
298 {
299 cell->SetFillMode( FILL_T::NO_FILL );
300 }
301 else
302 {
303 cell->SetFillMode( FILL_T::FILLED_WITH_COLOR );
304 cell->SetFillColor( fillColor );
305 }
306 }
307
309 cell->SetMarginLeft( m_marginLeft.GetIntValue() );
310
312 cell->SetMarginTop( m_marginTop.GetIntValue() );
313
315 cell->SetMarginRight( m_marginRight.GetIntValue() );
316
318 cell->SetMarginBottom( m_marginBottom.GetIntValue() );
319 }
320
321 if( !commit.Empty() )
322 commit.Push( _( "Edit Table Cell Properties" ) );
323
325 return true;
326}
327
328
329void DIALOG_TABLECELL_PROPERTIES::onEditTable( wxCommandEvent& aEvent )
330{
332 {
334 Close();
335 }
336}
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)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
bool Empty() const
Returns status of an item.
Definition: commit.h:144
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
bool HaveFontSelection() const
Definition: font_choice.cpp:94
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:73
KIFONT::FONT * GetFontSelection(bool aBold, bool aItalic) const
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
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:406
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:127
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:154
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:392
STL namespace.
GR_TEXT_H_ALIGN_T
@ 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
@ 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:673