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 [this]()
49 {
50 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
51 } );
52
54
56
58 m_horizontal->SetBitmap( KiBitmap( BITMAPS::text_horizontal ) );
60 m_vertical->SetBitmap( KiBitmap( BITMAPS::text_vertical ) );
61
63
65 m_bold->SetBitmap( KiBitmap( BITMAPS::text_bold ) );
67 m_italic->SetBitmap( KiBitmap( BITMAPS::text_italic ) );
68
70
72 m_hAlignLeft->SetBitmap( KiBitmap( BITMAPS::text_align_left ) );
74 m_hAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_align_center ) );
76 m_hAlignRight->SetBitmap( KiBitmap( BITMAPS::text_align_right ) );
77
79
81 m_vAlignTop->SetBitmap( KiBitmap( BITMAPS::text_valign_top ) );
83 m_vAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_valign_center ) );
85 m_vAlignBottom->SetBitmap( KiBitmap( BITMAPS::text_valign_bottom ) );
86
88
89 m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
90 m_textColorSwatch->SetSwatchBackground( schematicBackground );
91
92 m_horizontal->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onOrientButton, this );
93 m_vertical->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onOrientButton, this );
94
95 m_hAlignLeft->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton, this );
98
99 m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton, this );
102
104
105 if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
106 {
107 m_sdbSizerButtonsCancel->SetDefault();
108 m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
109 m_sdbSizerButtonsOK->Enable( false );
110 }
111
112 // Now all widgets have the size fixed, call FinishDialogSettings
114}
115
116
118{
119 delete m_scintillaTricks;
120};
121
122
124{
125 wxCHECK( m_CommonUnit, false );
126
127 LIB_SYMBOL* symbol = nullptr;
128
129 if( m_graphicText )
130 {
131 symbol = m_graphicText->GetParent();
132
133 wxCHECK( symbol, false );
134
136 m_StyledTextCtrl->SetValue( m_graphicText->GetText() );
137 m_StyledTextCtrl->EmptyUndoBuffer();
138
141
144
146 m_CommonUnit->SetValue(
147 symbol && symbol->GetUnitCount() > 1 && m_graphicText->GetUnit() == 0 );
148 m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
149
152 else
153 m_vertical->Check();
154
155 switch ( m_graphicText->GetHorizJustify() )
156 {
157 case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check( true ); break;
158 case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check( true ); break;
159 case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check( true ); break;
160 }
161
162 switch ( m_graphicText->GetVertJustify() )
163 {
164 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check( true ); break;
165 case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check( true ); break;
166 case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check( true ); break;
167 }
168 }
169 else
170 {
173 symbol = m_parent->GetCurSymbol();
174
175 wxCHECK( cfg && symbol && tools, false );
176
178
179 m_CommonUnit->SetValue( symbol->GetUnitCount() > 1 && !tools->GetDrawSpecificUnit() );
180 m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
181
182 if( tools->GetLastTextAngle().IsHorizontal() )
184 else
185 m_vertical->Check();
186 }
187
188 m_CommonUnit->Enable( symbol && symbol->GetUnitCount() > 1 );
189
190 return true;
191}
192
193
194void DIALOG_LIB_TEXT_PROPERTIES::onOrientButton( wxCommandEvent& aEvent )
195{
196 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
197 {
198 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
199 btn->Check( false );
200 }
201}
202
203
204void DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
205{
207 {
208 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
209 btn->Check( false );
210 }
211}
212
213
214void DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
215{
217 {
218 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
219 btn->Check( false );
220 }
221}
222
223
225{
226 if( m_graphicText )
227 {
228 if( m_StyledTextCtrl->GetValue().IsEmpty() )
229 {
230 // Other text items do not have defined extents, and so will disappear if empty
231 DisplayError( this, _( "Text can not be empty." ) );
232 return false;
233 }
234 else
235 {
236 m_graphicText->SetText( m_StyledTextCtrl->GetValue() );
237 }
238
240 {
242 m_italic->IsChecked() ) );
243 }
244
247
248 if( m_horizontal->IsChecked() )
250 else
252
254
255 if( !m_CommonUnit->GetValue() )
257 else
259
260 if( !m_CommonConvert->GetValue() )
262 else
264
268
269 if( m_hAlignLeft->IsChecked() )
271 else if( m_hAlignCenter->IsChecked() )
273 else
275
276 if( m_vAlignTop->IsChecked() )
278 else if( m_vAlignCenter->IsChecked() )
280 else
282
283 // Record settings used for next time:
285 tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
286 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
287 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
288 }
289
291
292 return true;
293}
294
295
297{
300
301 event.Skip();
302}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:106
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 SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
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).
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:174
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:207
COLOR4D GetTextColor() const
Definition: eda_text.h:208
bool IsItalic() const
Definition: eda_text.h:133
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:123
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
KIFONT::FONT * GetFont() const
Definition: eda_text.h:191
int GetTextWidth() const
Definition: eda_text.h:202
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:255
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:152
void SetBold(bool aBold)
Definition: eda_text.cpp:216
bool IsBold() const
Definition: eda_text.h:136
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:155
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:354
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:170
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:200
void SetItalic(bool aItalic)
Definition: eda_text.cpp:208
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:338
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:247
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:103
bool IsPrivate() const
Definition: lib_item.h:299
int GetUnit() const
Definition: lib_item.h:293
void SetPrivate(bool aPrivate)
Definition: lib_item.h:298
int GetConvert() const
Definition: lib_item.h:296
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:188
void SetConvert(int aConvert)
Definition: lib_item.h:295
void SetUnit(int aUnit)
Definition: lib_item.h:292
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.
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:54
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:283
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:425
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:426
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:380
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_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588