7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 06:16:56 +00:00

ADDED: support naked hyperlinks in tablecells and textboxes.

Also fix flickering due to IS_ROLLOVER flag getting
nuked.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18832
This commit is contained in:
Jeff Young 2025-02-16 20:38:38 +00:00
parent c8f56f24a8
commit 072d8d55fe
8 changed files with 52 additions and 27 deletions

View File

@ -646,8 +646,8 @@ wxString RemoveHTMLTags( const wxString& aInput )
wxString LinkifyHTML( wxString aStr )
{
wxRegEx regex( wxS( "\\b(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ),
wxRE_ICASE );
static wxRegEx regex( wxS( "\\b(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ),
wxRE_ICASE );
regex.ReplaceAll( &aStr, "<a href=\"\\0\">\\0</a>" );
@ -655,6 +655,17 @@ wxString LinkifyHTML( wxString aStr )
}
bool IsURL( wxString aStr )
{
static wxRegEx regex( wxS( "(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ),
wxRE_ICASE );
regex.ReplaceAll( &aStr, "<a href=\"\\0\">\\0</a>" );
return regex.Matches( aStr );
}
bool NoPrintableChars( const wxString& aString )
{
wxString tmp = aString;

View File

@ -1757,7 +1757,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
}
else
{
if( aText->IsHypertext() && aText->IsRollover() )
if( aText->IsHypertext() && aText->IsRollover() && !aText->IsMoving() )
{
m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
@ -1876,7 +1876,7 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
attrs.m_Angle = aTextBox->GetDrawRotation();
attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
if( aTextBox->IsHypertext() && aTextBox->IsRollover() )
if( aTextBox->IsHypertext() && aTextBox->IsRollover() && !aTextBox->IsMoving() )
{
m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
@ -2390,7 +2390,7 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
if( drawingShadows )
attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
if( aField->IsHypertext() && aField->IsRollover() )
if( aField->IsHypertext() && aField->IsRollover() && !aField->IsMoving() )
{
m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );

View File

@ -407,13 +407,26 @@ bool SCH_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy )
}
bool SCH_TEXTBOX::IsHypertext() const
{
if( HasHyperlink() )
return true;
return IsURL( GetShownText( false ) );
}
void SCH_TEXTBOX::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const
{
wxCHECK_MSG( IsHypertext(), /* void */,
wxT( "Calling a hypertext menu on a SCH_TEXTBOX with no hyperlink?" ) );
SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>();
navTool->HypertextCommand( m_hyperlink );
if( HasHyperlink() )
navTool->HypertextCommand( m_hyperlink );
else
navTool->HypertextCommand( GetShownText( false ) );
}

View File

@ -83,11 +83,7 @@ public:
return GetShownText( sheetPath, aAllowExtraText, aDepth );
}
bool IsHypertext() const override
{
return HasHyperlink();
}
bool IsHypertext() const override;
void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
void SetExcludedFromSim( bool aExclude ) override { m_excludedFromSim = aExclude; }

View File

@ -1000,14 +1000,15 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
evt->SetPassEvent();
}
if( rolloverItem != lastRolloverItem )
if( lastRolloverItem != niluuid && lastRolloverItem != rolloverItem )
{
if( EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ) )
{
item->ClearFlags( IS_ROLLOVER );
lastRolloverItem = niluuid;
EDA_ITEM* item = m_frame->GetItem( lastRolloverItem );
if( item->Type() == SCH_FIELD_T )
if( item->IsRollover() )
{
item->SetIsRollover( false );
if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TABLECELL_T )
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
else
m_frame->GetCanvas()->GetView()->Update( item );
@ -1018,18 +1019,19 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{
EDA_ITEM* item = m_frame->GetItem( rolloverItem );
if( item && !( item->GetFlags() & IS_ROLLOVER ) )
if( !item->IsRollover() )
{
item->SetFlags( IS_ROLLOVER );
lastRolloverItem = rolloverItem;
item->SetIsRollover( true );
if( item->Type() == SCH_FIELD_T )
if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TABLECELL_T )
m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
else
m_frame->GetCanvas()->GetView()->Update( item );
}
}
lastRolloverItem = rolloverItem;
if( m_frame->ToolStackIsEmpty() )
{
if( displayWireCursor )

View File

@ -111,10 +111,8 @@ public:
inline bool IsEntered() const { return m_flags & ENTERED; }
inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
inline bool IsRollover() const
{
return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
}
inline bool IsRollover() const { return m_isRollover; }
inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; }
inline void SetSelected() { SetFlags( SELECTED ); }
inline void SetBrightened() { SetFlags( BRIGHTENED ); }
@ -501,6 +499,7 @@ protected:
EDA_ITEM_FLAGS m_flags;
EDA_ITEM* m_parent; ///< Linked list: Link (parent struct).
bool m_forceVisible;
bool m_isRollover;
};

View File

@ -63,8 +63,7 @@
// 23 is unused
#define HOLE_PROXY (1 << 24) ///< Indicates the BOARD_ITEM is a proxy for its hole
#define IS_ROLLOVER (1 << 25) ///< Rollover active. Used for hyperlink highlighting.
#define SHOW_ELEC_TYPE (1 << 25) ///< Show pin electrical type. Shared with IS_ROLLOVER.
#define SHOW_ELEC_TYPE (1 << 25) ///< Show pin electrical type
#define BRIGHTENED (1 << 26) ///< item is drawn with a bright contour
// 27 is unused

View File

@ -142,6 +142,11 @@ KICOMMON_API wxString RemoveHTMLTags( const wxString& aInput );
*/
KICOMMON_API wxString LinkifyHTML( wxString aStr );
/**
* Performs a URL sniff-test on a string.
*/
KICOMMON_API bool IsURL( wxString aStr );
/**
* Read one line line from \a aFile.
*