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
132
135
137 m_CommonUnit->SetValue( m_graphicText->GetUnit() == 0 );
138 m_CommonConvert->SetValue( m_graphicText->GetConvert() == 0 );
139
142 else
143 m_vertical->Check();
144
145 switch ( m_graphicText->GetHorizJustify() )
146 {
147 case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check( true ); break;
148 case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check( true ); break;
149 case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check( true ); break;
150 }
151
152 switch ( m_graphicText->GetVertJustify() )
153 {
154 case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check( true ); break;
155 case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check( true ); break;
156 case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check( true ); break;
157 }
158 }
159 else
160 {
163
165
166 m_CommonUnit->SetValue( !tools->GetDrawSpecificUnit() );
167 m_CommonConvert->SetValue( !tools->GetDrawSpecificConvert() );
168
169 if( tools->GetLastTextAngle().IsHorizontal() )
171 else
172 m_vertical->Check();
173 }
174
175 return true;
176}
177
178
179void DIALOG_LIB_TEXT_PROPERTIES::onOrientButton( wxCommandEvent& aEvent )
180{
181 for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
182 {
183 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
184 btn->Check( false );
185 }
186}
187
188
189void DIALOG_LIB_TEXT_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
190{
192 {
193 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
194 btn->Check( false );
195 }
196}
197
198
199void DIALOG_LIB_TEXT_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
200{
202 {
203 if( btn->IsChecked() && btn != aEvent.GetEventObject() )
204 btn->Check( false );
205 }
206}
207
208
210{
211 if( m_graphicText )
212 {
213 if( m_StyledTextCtrl->GetValue().IsEmpty() )
214 {
215 // Other text items do not have defined extents, and so will disappear if empty
216 DisplayError( this, _( "Text can not be empty." ) );
217 return false;
218 }
219 else
220 {
221 m_graphicText->SetText( m_StyledTextCtrl->GetValue() );
222 }
223
225 {
227 m_italic->IsChecked() ) );
228 }
229
232
233 if( m_horizontal->IsChecked() )
235 else
237
239
240 if( !m_CommonUnit->GetValue() )
242 else
244
245 if( !m_CommonConvert->GetValue() )
247 else
249
253
254 if( m_hAlignLeft->IsChecked() )
256 else if( m_hAlignCenter->IsChecked() )
258 else
260
261 if( m_vAlignTop->IsChecked() )
263 else if( m_vAlignCenter->IsChecked() )
265 else
267
268 // Record settings used for next time:
270 tools->SetLastTextAngle( m_graphicText->GetTextAngle() );
271 tools->SetDrawSpecificConvert( !m_CommonConvert->GetValue() );
272 tools->SetDrawSpecificUnit( !m_CommonUnit->GetValue() );
273 }
274
276
277 return true;
278}
279
280
282{
285
286 event.Skip();
287}
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:194
COLOR4D GetTextColor() const
Definition: eda_text.h:195
bool IsItalic() const
Definition: eda_text.h:120
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:117
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:178
int GetTextWidth() const
Definition: eda_text.h:189
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:139
void SetBold(bool aBold)
Definition: eda_text.cpp:209
bool IsBold() const
Definition: eda_text.h:123
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:142
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:280
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