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
72 Layout();
73
77 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_TABLECELL_PROPERTIES::onVAlignButton, this );
80
81 // Now all widgets have the size fixed, call FinishDialogSettings
83}
84
85
87{
88 if( !wxDialog::TransferDataToWindow() )
89 return false;
90
91 bool firstCell = true;
92 GR_TEXT_H_ALIGN_T hAlign;
93 GR_TEXT_V_ALIGN_T vAlign;
94
95 for( SCH_TABLECELL* cell : m_cells )
96 {
97 if( firstCell )
98 {
99 m_fontCtrl->SetFontSelection( cell->GetFont() );
100 m_textSize.SetValue( cell->GetTextWidth() );
101
102 m_bold->Set3StateValue( cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
103 m_italic->Set3StateValue( cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED );
104
105 hAlign = cell->GetHorizJustify();
106 vAlign = cell->GetVertJustify();
107
108 m_textColorBook->SetSelection( 1 );
109 m_textColorSwatch->SetSwatchColor( cell->GetTextColor(), false );
110 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
111
112 m_fillColorBook->SetSelection( 1 );
113
114 if( cell->IsFilled() )
115 m_fillColorSwatch->SetSwatchColor( cell->GetFillColor(), false );
116 else
117 m_fillColorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false );
118
119 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
120
121 m_marginLeft.SetValue( cell->GetMarginLeft() );
122 m_marginTop.SetValue( cell->GetMarginTop() );
123 m_marginRight.SetValue( cell->GetMarginRight() );
124 m_marginBottom.SetValue( cell->GetMarginBottom() );
125
126 firstCell = false;
127 }
128 else
129 {
130 if( cell->GetFont() != m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) )
131 m_fontCtrl->SetSelection( -1 );
132
133 if( cell->GetTextWidth() != m_textSize.GetValue() )
135
136 wxCheckBoxState bold = cell->IsBold() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
137
138 if( bold != m_bold->Get3StateValue() )
139 m_bold->Set3StateValue( wxCHK_UNDETERMINED );
140
141 wxCheckBoxState italic = cell->IsItalic() ? wxCHK_CHECKED : wxCHK_UNCHECKED;
142
143 if( italic != m_italic->Get3StateValue() )
144 m_italic->Set3StateValue( wxCHK_UNDETERMINED );
145
146 if( cell->GetHorizJustify() != hAlign )
148
149 if( cell->GetVertJustify() != vAlign )
151
152 if( cell->GetTextColor() != m_textColorSwatch->GetSwatchColor() )
153 {
154 m_textColorBook->SetSelection( 0 );
155 m_textColorPopup->SetSelection( 0 );
156 }
157
158 COLOR4D fillColor = cell->IsFilled() ? cell->GetFillColor() : COLOR4D::UNSPECIFIED;
159
160 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
161 {
162 m_fillColorBook->SetSelection( 0 );
163 m_fillColorPopup->SetSelection( 0 );
164 }
165
166 if( fillColor != m_fillColorSwatch->GetSwatchColor() )
167 fillColor = COLOR4D::UNSPECIFIED;
168
169 if( cell->GetMarginLeft() != m_marginLeft.GetIntValue() )
171
172 if( cell->GetMarginTop() != m_marginTop.GetIntValue() )
174
175 if( cell->GetMarginRight() != m_marginRight.GetIntValue() )
177
178 if( cell->GetMarginBottom() != m_marginBottom.GetIntValue() )
180 }
181
182 switch( hAlign )
183 {
188 }
189
190 switch( vAlign )
191 {
192 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
196 }
197 }
198
199 return true;
200}
201
202
204{
206 {
207 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
208 btn->Check( false );
209 }
210}
211
212
214{
216 {
217 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
218 btn->Check( false );
219 }
220}
221
222
224{
225 if( aEvent.GetSelection() == 1 )
226 {
227 m_textColorBook->SetSelection( 1 );
229 }
230}
231
232
234{
235 if( aEvent.GetSelection() == 1 )
236 {
237 m_fillColorBook->SetSelection( 1 );
239 }
240}
241
242
244{
245 if( !wxDialog::TransferDataFromWindow() )
246 return false;
247
248 SCH_COMMIT commit( m_frame );
249
250 /* save table in undo list if not already in edit */
251 if( m_table->GetEditFlags() == 0 )
252 commit.Modify( m_table, m_frame->GetScreen() );
253
254 for( SCH_TABLECELL* cell : m_cells )
255 {
256 if( m_bold->Get3StateValue() == wxCHK_CHECKED )
257 cell->SetBold( true );
258 else if( m_bold->Get3StateValue() == wxCHK_UNCHECKED )
259 cell->SetBold( false );
260
261 if( m_italic->Get3StateValue() == wxCHK_CHECKED )
262 cell->SetItalic( true );
263 else if( m_italic->Get3StateValue() == wxCHK_UNCHECKED )
264 cell->SetItalic( false );
265
267 cell->SetFont( m_fontCtrl->GetFontSelection( cell->IsBold(), cell->IsItalic() ) );
268
270 cell->SetTextSize( VECTOR2I( m_textSize.GetIntValue(), m_textSize.GetIntValue() ) );
271
272 if( m_hAlignLeft->IsChecked() )
273 cell->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
274 else if( m_hAlignRight->IsChecked() )
275 cell->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
276 else if( m_hAlignCenter->IsChecked() )
277 cell->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
278
279 if( m_vAlignTop->IsChecked() )
280 cell->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
281 else if( m_vAlignBottom->IsChecked() )
282 cell->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
283 else if( m_vAlignCenter->IsChecked() )
284 cell->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
285
286 if( m_textColorBook->GetSelection() == 1 )
287 cell->SetTextColor( m_textColorSwatch->GetSwatchColor() );
288
289 if( m_fillColorBook->GetSelection() == 1 )
290 {
292
293 if( fillColor == COLOR4D::UNSPECIFIED )
294 {
295 cell->SetFillMode( FILL_T::NO_FILL );
296 }
297 else
298 {
299 cell->SetFillMode( FILL_T::FILLED_WITH_COLOR );
300 cell->SetFillColor( fillColor );
301 }
302 }
303
305 cell->SetMarginLeft( m_marginLeft.GetIntValue() );
306
308 cell->SetMarginTop( m_marginTop.GetIntValue() );
309
311 cell->SetMarginRight( m_marginRight.GetIntValue() );
312
314 cell->SetMarginBottom( m_marginBottom.GetIntValue() );
315 }
316
317 if( !commit.Empty() )
318 commit.Push( _( "Edit Table Cell Properties" ) );
319
321 return true;
322}
323
324
325void DIALOG_TABLECELL_PROPERTIES::onEditTable( wxCommandEvent& aEvent )
326{
328 {
330 Close();
331 }
332}
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
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.
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:132
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:403
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)
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:45
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588