Browse Source

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
Jeff Young 10 months ago
parent
commit
072d8d55fe
  1. 15
      common/string_utils.cpp
  2. 6
      eeschema/sch_painter.cpp
  3. 15
      eeschema/sch_textbox.cpp
  4. 6
      eeschema/sch_textbox.h
  5. 20
      eeschema/tools/ee_selection_tool.cpp
  6. 7
      include/eda_item.h
  7. 3
      include/eda_item_flags.h
  8. 5
      include/string_utils.h

15
common/string_utils.cpp

@ -646,8 +646,8 @@ wxString RemoveHTMLTags( const wxString& aInput )
wxString LinkifyHTML( wxString aStr ) 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>" ); 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 ) bool NoPrintableChars( const wxString& aString )
{ {
wxString tmp = aString; wxString tmp = aString;

6
eeschema/sch_painter.cpp

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

15
eeschema/sch_textbox.cpp

@ -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 void SCH_TEXTBOX::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const
{ {
wxCHECK_MSG( IsHypertext(), /* void */, wxCHECK_MSG( IsHypertext(), /* void */,
wxT( "Calling a hypertext menu on a SCH_TEXTBOX with no hyperlink?" ) ); wxT( "Calling a hypertext menu on a SCH_TEXTBOX with no hyperlink?" ) );
SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>(); 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 ) );
} }

6
eeschema/sch_textbox.h

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

20
eeschema/tools/ee_selection_tool.cpp

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

7
include/eda_item.h

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

3
include/eda_item_flags.h

@ -63,8 +63,7 @@
// 23 is unused // 23 is unused
#define HOLE_PROXY (1 << 24) ///< Indicates the BOARD_ITEM is a proxy for its hole #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 #define BRIGHTENED (1 << 26) ///< item is drawn with a bright contour
// 27 is unused // 27 is unused

5
include/string_utils.h

@ -142,6 +142,11 @@ KICOMMON_API wxString RemoveHTMLTags( const wxString& aInput );
*/ */
KICOMMON_API wxString LinkifyHTML( wxString aStr ); 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. * Read one line line from \a aFile.
* *

Loading…
Cancel
Save