KiCad PCB EDA Suite
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-2022 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
61
63
68
70
77
79
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 if( m_graphicText )
126 {
128 m_StyledTextCtrl->SetValue( m_graphicText->GetText() );
129 m_StyledTextCtrl->EmptyUndoBuffer();
130
133
136
138 m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
139 m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
140
143 else
144 m_vertical->Check();
145
146 switch ( m_graphicText->GetHorizJustify() )
147 {
148 case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check( true ); break;
149 case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check( true ); break;
150 case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check( true ); break;
151 }
152
153 switch ( m_graphicText->GetVertJustify() )
154 {
155 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check( true ); break;
156 case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check( true ); break;
157 case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check( true ); break;
158 }
159 }
160 else
161 {
164
166
167 m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
168 m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
169
170 if( tools->GetLastTextAngle().IsHorizontal() )
172 else
173 m_vertical->Check();
174 }
175
176 return true;
177}
178
179
180void DIALOG_LIB_TEXT_PROPERTIES::onOrientButton( wxCommandEvent& aEvent )
181{
182 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
183 {
184 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
185 btn->Check( false );
186 }
187}
188
189
190void DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
191{
193 {
194 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
195 btn->Check( false );
196 }
197}
198
199
200void DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
201{
203 {
204 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
205 btn->Check( false );
206 }
207}
208
209
211{
212 if( m_graphicText )
213 {
214 if( m_StyledTextCtrl->GetValue().IsEmpty() )
215 {
216 // Other text items do not have defined extents, and so will disappear if empty
217 DisplayError( this, _( "Text can not be empty." ) );
218 return false;
219 }
220 else
221 {
222 m_graphicText->SetText( m_StyledTextCtrl->GetValue() );
223 }
224
226 {
228 m_italic->IsChecked() ) );
229 }
230
233
234 if( m_horizontal->IsChecked() )
236 else
238
240
241 if( !m_CommonUnit->GetValue() )
243 else
245
246 if( !m_CommonConvert->GetValue() )
248 else
250
254
255 if( m_hAlignLeft->IsChecked() )
257 else if( m_hAlignCenter->IsChecked() )
259 else
261
262 if( m_vAlignTop->IsChecked() )
264 else if( m_vAlignCenter->IsChecked() )
266 else
268
269 // Record settings used for next time:
271 tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
272 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
273 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
274 }
275
277
278 return true;
279}
280
281
283{
286
287 event.Skip();
288}
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:105
@ text_align_right
@ text_valign_top
@ text_align_left
@ text_valign_center
@ text_vertical
@ text_align_center
@ text_horizontal
@ text_valign_bottom
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:204
COLOR4D GetTextColor() const
Definition: eda_text.h:205
bool IsItalic() const
Definition: eda_text.h:130
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
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:188
int GetTextWidth() const
Definition: eda_text.h:199
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:149
void SetBold(bool aBold)
Definition: eda_text.cpp:209
bool IsBold() const
Definition: eda_text.h:133
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:152
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
void SetFont(KIFONT::FONT *aFont)
Definition: eda_text.cpp:331
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:240
bool HaveFontSelection() const
Definition: font_choice.cpp:88
void SetFontSelection(KIFONT::FONT *aFont)
Definition: font_choice.cpp:67
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:279
int GetUnit() const
Definition: lib_item.h:273
void SetPrivate(bool aPrivate)
Definition: lib_item.h:278
int GetConvert() const
Definition: lib_item.h:276
void SetConvert(int aConvert)
Definition: lib_item.h:275
void SetUnit(int aUnit)
Definition: lib_item.h:272
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.
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:300
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:408
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:409
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
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