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]( wxKeyEvent& aEvent )
49 {
50 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
51 } );
52
54
56
58 m_horizontal->SetBitmap( KiBitmapBundle( BITMAPS::text_horizontal ) );
60 m_vertical->SetBitmap( KiBitmapBundle( BITMAPS::text_vertical ) );
61
63
65 m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
67 m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
68
70
72 m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
74 m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
76 m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
77
79
81 m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
83 m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
85 m_vAlignBottom->SetBitmap( KiBitmapBundle( 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
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: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:226
COLOR4D GetTextColor() const
Definition: eda_text.h:227
void SetTextSize(VECTOR2I aNewSize)
Definition: eda_text.cpp:358
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
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:207
int GetTextWidth() const
Definition: eda_text.h:221
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:260
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:144
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
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:342
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:252
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:342
int GetUnit() const
Definition: lib_item.h:336
void SetPrivate(bool aPrivate)
Definition: lib_item.h:341
int GetConvert() const
Definition: lib_item.h:339
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:202
void SetConvert(int aConvert)
Definition: lib_item.h:338
void SetUnit(int aUnit)
Definition: lib_item.h:335
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: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_HORIZONTAL
Definition: eda_angle.h:433
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:434
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:382
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