ADDED: actions for left-, center-, and right-justifying text items.
(For both PCBNew and EESchema.) Fixes https://gitlab.com/kicad/code/kicad/-/issues/12375
This commit is contained in:
parent
536e7b252d
commit
4a9df1e18e
|
@ -277,6 +277,27 @@ TOOL_ACTION ACTIONS::deleteTool( TOOL_ACTION_ARGS()
|
|||
.Icon( BITMAPS::delete_cursor )
|
||||
.Flags( AF_ACTIVATE ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::leftJustify( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.leftJustify" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Left Justify" ) )
|
||||
.Tooltip( _( "Left-justify fields and text items" ) )
|
||||
.Icon( BITMAPS::text_align_left ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::centerJustify( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.centerJustify" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Center Justify" ) )
|
||||
.Tooltip( _( "Center-justify fields and text items" ) )
|
||||
.Icon( BITMAPS::text_align_center ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::rightJustify( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.rightJustify" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Right Justify" ) )
|
||||
.Tooltip( _( "Right-justify fields and text items" ) )
|
||||
.Icon( BITMAPS::text_align_right ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::activatePointEditor( TOOL_ACTION_ARGS()
|
||||
.Name( "common.Control.activatePointEditor" )
|
||||
.Scope( AS_GLOBAL ) );
|
||||
|
|
|
@ -2347,6 +2347,102 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::JustifyText( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
static std::vector<KICAD_T> justifiableItems = {
|
||||
SCH_FIELD_T,
|
||||
SCH_TEXT_T,
|
||||
SCH_TEXTBOX_T,
|
||||
SCH_LABEL_T
|
||||
};
|
||||
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( justifiableItems );
|
||||
|
||||
if( selection.GetSize() == 0 )
|
||||
return 0;
|
||||
|
||||
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
|
||||
bool moving = item->IsMoving();
|
||||
SCH_COMMIT localCommit( m_toolMgr );
|
||||
SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
|
||||
|
||||
if( !commit )
|
||||
commit = &localCommit;
|
||||
|
||||
auto setJustify =
|
||||
[&]( EDA_TEXT* aTextItem )
|
||||
{
|
||||
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
||||
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
||||
else
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
||||
};
|
||||
|
||||
for( EDA_ITEM* edaItem : selection )
|
||||
{
|
||||
item = static_cast<SCH_ITEM*>( edaItem );
|
||||
|
||||
if( !moving )
|
||||
commit->Modify( item, m_frame->GetScreen() );
|
||||
|
||||
if( item->Type() == SCH_FIELD_T )
|
||||
{
|
||||
setJustify( static_cast<SCH_FIELD*>( item ) );
|
||||
|
||||
// Now that we're re-justifying a field, they're no longer autoplaced.
|
||||
static_cast<SCH_ITEM*>( item->GetParent() )->ClearFieldsAutoplaced();
|
||||
}
|
||||
else if( item->Type() == SCH_TEXT_T )
|
||||
{
|
||||
setJustify( static_cast<SCH_TEXT*>( item ) );
|
||||
}
|
||||
else if( item->Type() == SCH_TEXTBOX_T )
|
||||
{
|
||||
setJustify( static_cast<SCH_TEXTBOX*>( item ) );
|
||||
}
|
||||
else if( item->Type() == SCH_LABEL_T )
|
||||
{
|
||||
SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
|
||||
|
||||
if( label->GetTextAngle() == ANGLE_HORIZONTAL )
|
||||
setJustify( label );
|
||||
}
|
||||
|
||||
m_frame->UpdateItem( item, false, true );
|
||||
}
|
||||
|
||||
// Update R-Tree for modified items
|
||||
for( EDA_ITEM* selected : selection )
|
||||
updateItem( selected, true );
|
||||
|
||||
if( item->IsMoving() )
|
||||
{
|
||||
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
||||
}
|
||||
else
|
||||
{
|
||||
EE_SELECTION selectionCopy = selection;
|
||||
|
||||
if( selection.IsHover() )
|
||||
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
||||
|
||||
if( !localCommit.Empty() )
|
||||
{
|
||||
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
||||
localCommit.Push( _( "Left Justify" ) );
|
||||
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
||||
localCommit.Push( _( "Center Justify" ) );
|
||||
else
|
||||
localCommit.Push( _( "Right Justify" ) );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
bool isSlice = aEvent.Matches( EE_ACTIONS::slice.MakeEvent() );
|
||||
|
@ -2659,6 +2755,9 @@ void SCH_EDIT_TOOL::setTransitions()
|
|||
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toCLabel.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toText.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toTextBox.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::leftJustify.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::centerJustify.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::JustifyText, ACTIONS::rightJustify.MakeEvent() );
|
||||
|
||||
Go( &SCH_EDIT_TOOL::BreakWire, EE_ACTIONS::breakWire.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::BreakWire, EE_ACTIONS::slice.MakeEvent() );
|
||||
|
|
|
@ -69,6 +69,8 @@ public:
|
|||
*/
|
||||
int ChangeTextType( const TOOL_EVENT& aEvent );
|
||||
|
||||
int JustifyText( const TOOL_EVENT& aEvent );
|
||||
|
||||
int BreakWire( const TOOL_EVENT& aEvent );
|
||||
|
||||
int CleanupSheetPins( const TOOL_EVENT& aEvent );
|
||||
|
|
|
@ -74,6 +74,9 @@ public:
|
|||
static TOOL_ACTION duplicate;
|
||||
static TOOL_ACTION doDelete; // sadly 'delete' is a reserved word
|
||||
static TOOL_ACTION deleteTool;
|
||||
static TOOL_ACTION leftJustify;
|
||||
static TOOL_ACTION centerJustify;
|
||||
static TOOL_ACTION rightJustify;
|
||||
|
||||
// Find and Replace
|
||||
static TOOL_ACTION showSearch;
|
||||
|
|
|
@ -2034,6 +2034,81 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
int EDIT_TOOL::JustifyText( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( isRouterActive() )
|
||||
{
|
||||
wxBell();
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOARD_COMMIT localCommit( this );
|
||||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
|
||||
|
||||
if( !commit )
|
||||
commit = &localCommit;
|
||||
|
||||
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
||||
{
|
||||
sTool->FilterCollectorForHierarchy( aCollector, true );
|
||||
},
|
||||
!m_dragging /* prompt user regarding locked items */ );
|
||||
|
||||
if( selection.Empty() )
|
||||
return 0;
|
||||
|
||||
auto setJustify =
|
||||
[&]( EDA_TEXT* aTextItem )
|
||||
{
|
||||
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
||||
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
||||
else
|
||||
aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
||||
};
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( item->Type() == PCB_FIELD_T || item->Type() == PCB_TEXT_T )
|
||||
{
|
||||
if( !item->IsNew() && !item->IsMoving() )
|
||||
commit->Modify( item );
|
||||
|
||||
setJustify( static_cast<PCB_TEXT*>( item ) );
|
||||
}
|
||||
else if( item->Type() == PCB_TEXTBOX_T )
|
||||
{
|
||||
if( !item->IsNew() && !item->IsMoving() )
|
||||
commit->Modify( item );
|
||||
|
||||
setJustify( static_cast<PCB_TEXTBOX*>( item ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( !localCommit.Empty() )
|
||||
{
|
||||
if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
|
||||
localCommit.Push( _( "Left Justify" ) );
|
||||
else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
|
||||
localCommit.Push( _( "Center Justify" ) );
|
||||
else
|
||||
localCommit.Push( _( "Right Justify" ) );
|
||||
}
|
||||
|
||||
if( selection.IsHover() && !m_dragging )
|
||||
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
||||
|
||||
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
||||
|
||||
if( m_dragging )
|
||||
m_toolMgr->PostAction( PCB_ACTIONS::updateLocalRatsnest, VECTOR2I() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( isRouterActive() )
|
||||
|
@ -2871,6 +2946,9 @@ void EDIT_TOOL::setTransitions()
|
|||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::mergePolygons.MakeEvent() );
|
||||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::subtractPolygons.MakeEvent() );
|
||||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::intersectPolygons.MakeEvent() );
|
||||
Go( &EDIT_TOOL::JustifyText, ACTIONS::leftJustify.MakeEvent() );
|
||||
Go( &EDIT_TOOL::JustifyText, ACTIONS::centerJustify.MakeEvent() );
|
||||
Go( &EDIT_TOOL::JustifyText, ACTIONS::rightJustify.MakeEvent() );
|
||||
|
||||
Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
|
||||
Go( &EDIT_TOOL::copyToClipboard, PCB_ACTIONS::copyWithReference.MakeEvent() );
|
||||
|
|
|
@ -103,6 +103,11 @@ public:
|
|||
|
||||
static const std::vector<KICAD_T> MirrorableItems;
|
||||
|
||||
/**
|
||||
* Set the justification on any text items (or fields) in the current selection.
|
||||
*/
|
||||
int JustifyText( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Swap currently selected items' positions. Changes position of each item to the next.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue