KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_lib_text_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) 2001 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <widgets/font_choice.h>
28#include <symbol_edit_frame.h>
29#include <lib_text.h>
34#include <scintilla_tricks.h>
35#include "confirm.h"
36
38 LIB_TEXT* aText ) :
40 m_parent( aParent ),
41 m_graphicText( aText ),
42 m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
43{
44 COLOR_SETTINGS* colorSettings = m_parent->GetColorSettings();
45 COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
46
47 m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), false,
48 // onAcceptFn
49 [this]( wxKeyEvent& aEvent )
50 {
51 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
52 } );
53
55
57
59 m_horizontal->SetBitmap( KiBitmapBundle( BITMAPS::text_horizontal ) );
61 m_vertical->SetBitmap( KiBitmapBundle( BITMAPS::text_vertical ) );
62
64
66 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
68 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
69
71
73 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
75 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
77 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
78
80
82 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
84 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
86 m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
87
89
90 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
91 m_textColorSwatch->SetSwatchBackground( schematicBackground );
92
93 m_horizontal->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onOrientButton, this );
94 m_vertical->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onOrientButton, this );
95
96 m_hAlignLeft->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton, this );
99
100 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton, this );
103
105
106 if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
107 {
108 m_sdbSizerButtonsCancel->SetDefault();
109 m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
110 m_sdbSizerButtonsOK->Enable( false );
111 }
112
113 // Now all widgets have the size fixed, call FinishDialogSettings
115}
116
117
119{
120 delete m_scintillaTricks;
121};
122
123
125{
126 wxCHECK( m_commonToAllUnits, false );
127
128 LIB_SYMBOL* symbol = nullptr;
129
130 if( m_graphicText )
131 {
132 symbol = m_graphicText->GetParent();
133
134 wxCHECK( symbol, false );
135
137 m_StyledTextCtrl->SetValue( m_graphicText->GetText() );
138 m_StyledTextCtrl->EmptyUndoBuffer();
139
142
145
147 m_commonToAllUnits->SetValue( symbol && symbol->GetUnitCount() > 1
148 && m_graphicText->GetUnit() == 0 );
150
153 else
154 m_vertical->Check();
155
156 switch ( m_graphicText->GetHorizJustify() )
157 {
158 case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check( true ); break;
159 case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check( true ); break;
160 case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check( true ); break;
162 }
163
164 switch ( m_graphicText->GetVertJustify() )
165 {
166 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check( true ); break;
167 case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check( true ); break;
168 case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check( true ); break;
170 }
171 }
172 else
173 {
176 symbol = m_parent->GetCurSymbol();
177
178 wxCHECK( cfg && symbol && tools, false );
179
181
182 m_commonToAllUnits->SetValue( symbol->GetUnitCount() > 1 && !tools->GetDrawSpecificUnit() );
183 m_commonToAllBodyStyles->SetValue( !tools->GetDrawSpecificBodyStyle() );
184
185 if( tools->GetLastTextAngle().IsHorizontal() )
187 else
188 m_vertical->Check();
189 }
190
191 m_commonToAllUnits->Enable( symbol && symbol->GetUnitCount() > 1 );
192
193 return true;
194}
195
196
197void DIALOG_LIB_TEXT_PROPERTIES::onOrientButton( wxCommandEvent& aEvent )
198{
199 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
200 {
201 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
202 btn->Check( false );
203 }
204}
205
206
207void DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
208{
210 {
211 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
212 btn->Check( false );
213 }
214}
215
216
217void DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
218{
220 {
221 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
222 btn->Check( false );
223 }
224}
225
226
228{
229 if( m_graphicText )
230 {
231 if( m_StyledTextCtrl->GetValue().IsEmpty() )
232 {
233 // Other text items do not have defined extents, and so will disappear if empty
234 DisplayError( this, _( "Text can not be empty." ) );
235 return false;
236 }
237 else
238 {
239 m_graphicText->SetText( m_StyledTextCtrl->GetValue() );
240 }
241
243 {
245 m_italic->IsChecked() ) );
246 }
247
250
251 if( m_horizontal->IsChecked() )
253 else
255
257
258 if( !m_commonToAllUnits->GetValue() )
260 else
262
263 if( !m_commonToAllBodyStyles->GetValue() )
265 else
267
268 // Must come after SetTextSize()
272
273 if( m_hAlignLeft->IsChecked() )
275 else if( m_hAlignCenter->IsChecked() )
277 else
279
280 if( m_vAlignTop->IsChecked() )
282 else if( m_vAlignCenter->IsChecked() )
284 else
286
287 // Record settings used for next time:
289 tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
290 tools->SetDrawSpecificBodyStyle( !m_commonToAllBodyStyles->GetValue() );
291 tools->SetDrawSpecificUnit( !m_commonToAllUnits->GetValue() );
292 }
293
295
296 return true;
297}
298
299
301{
304
305 event.Skip();
306}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
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:41
void SetIsRadioButton()
bool IsChecked() const
void Check(bool aCheck=true)
Check the control.
void SetIsSeparator()
Render button as a toolbar separator.
void SetIsCheckButton()
Setup the control as a two-state button (checked or unchecked).
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
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.
Class DIALOG_LIB_TEXT_PROPERTIES_BASE.
void onMultiLineTCLostFocus(wxFocusEvent &event) override
DIALOG_LIB_TEXT_PROPERTIES(SYMBOL_EDIT_FRAME *aParent, LIB_TEXT *aText)
void onVAlignButton(wxCommandEvent &aEvent)
void onHAlignButton(wxCommandEvent &aEvent)
void onOrientButton(wxCommandEvent &aEvent)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
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...
bool IsHorizontal() const
Definition: eda_angle.h:180
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetTextColor(const COLOR4D &aColor)
Definition: eda_text.h:227
COLOR4D GetTextColor() const
Definition: eda_text.h:228
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:374
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
KIFONT::FONT * GetFont() const
Definition: eda_text.h:208
int GetTextWidth() const
Definition: eda_text.h:222
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:276
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:161
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:145
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:164
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:358
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:268
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
bool IsPrivate() const
Definition: lib_item.h:349
int GetBodyStyle() const
Definition: lib_item.h:346
int GetUnit() const
Definition: lib_item.h:343
void SetPrivate(bool aPrivate)
Definition: lib_item.h:348
void SetBodyStyle(int aBodyStyle)
Definition: lib_item.h:345
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:209
void SetUnit(int aUnit)
Definition: lib_item.h:342
Define a library symbol object.
Definition: lib_symbol.h:99
int GetUnitCount() const override
For items with units, return the number of units.
Define a symbol library graphical text item.
Definition: lib_text.h:40
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
SYMBOL_EDITOR_DRAWING_TOOLS.
The symbol library editor main window.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
int GetBodyStyle() const
SYMBOL_EDITOR_SETTINGS * GetSettings() const
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:432
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:431
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:388
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588