Simplify about dialog impl and make it real-time performant.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17213
This commit is contained in:
Jeff Young 2024-03-12 14:31:05 +00:00
parent 463b609993
commit 87121af3c9
4 changed files with 637 additions and 1440 deletions

File diff suppressed because it is too large Load Diff

View File

@ -160,48 +160,27 @@ private:
class CONTRIBUTOR class CONTRIBUTOR
{ {
public: public:
CONTRIBUTOR( const wxString& aName, CONTRIBUTOR( const wxString& aName, const wxString& aCategory,
const wxString& aExtra = wxEmptyString, const wxString& aUrl = wxEmptyString )
const wxString& aUrl = wxEmptyString,
const wxString& aCategory = wxEmptyString,
wxBitmap* aIcon = NULL )
{ {
m_checked = false; m_checked = false;
m_name = aName; m_name = aName;
m_url = aUrl, m_url = aUrl,
m_extra = aExtra;
m_category = aCategory; m_category = aCategory;
m_icon = aIcon;
}
CONTRIBUTOR( const wxString& aName,
const wxString& aCategory,
wxBitmap* aIcon )
{
m_checked = false;
m_name = aName;
m_url = wxEmptyString,
m_extra = wxEmptyString;
m_category = aCategory;
m_icon = aIcon;
} }
virtual ~CONTRIBUTOR() {} virtual ~CONTRIBUTOR() {}
wxString& GetName() { return m_name; } wxString& GetName() { return m_name; }
wxString& GetExtra() { return m_extra; }
wxString& GetUrl() { return m_url; } wxString& GetUrl() { return m_url; }
wxString& GetCategory() { return m_category; } wxString& GetCategory() { return m_category; }
wxBitmap* GetIcon() { return m_icon; }
void SetChecked( bool status ) { m_checked = status; } void SetChecked( bool status ) { m_checked = status; }
bool IsChecked() { return m_checked; } bool IsChecked() { return m_checked; }
private: private:
wxString m_name; wxString m_name;
wxString m_extra;
wxString m_url; wxString m_url;
wxString m_category; wxString m_category;
wxBitmap* m_icon;
bool m_checked; bool m_checked;
}; };

View File

@ -23,11 +23,7 @@
*/ */
#include <config.h>
#include <string>
#include <build_version.h> #include <build_version.h>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/hyperlink.h> #include <wx/hyperlink.h>
@ -43,16 +39,14 @@
* tools_xpm; // Sheet of paper icon for license info tab * tools_xpm; // Sheet of paper icon for license info tab
*/ */
#include <bitmaps.h> #include <bitmaps.h>
#include <build_version.h>
#include <dialogs/html_message_box.h> #include <dialogs/html_message_box.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include "dialog_about.h" #include "dialog_about.h"
DIALOG_ABOUT::DIALOG_ABOUT( EDA_BASE_FRAME *aParent, ABOUT_APP_INFO& aAppInfo ) DIALOG_ABOUT::DIALOG_ABOUT( EDA_BASE_FRAME *aParent, ABOUT_APP_INFO& aAppInfo ) :
: DIALOG_ABOUT_BASE( aParent ), DIALOG_ABOUT_BASE( aParent ),
m_images( nullptr ),
m_info( aAppInfo ) m_info( aAppInfo )
{ {
wxASSERT( aParent != nullptr ); wxASSERT( aParent != nullptr );
@ -128,20 +122,6 @@ DIALOG_ABOUT::DIALOG_ABOUT( EDA_BASE_FRAME *aParent, ABOUT_APP_INFO& aAppInfo )
DIALOG_ABOUT::~DIALOG_ABOUT() DIALOG_ABOUT::~DIALOG_ABOUT()
{ {
#ifndef __WXMAC__
delete m_images;
#endif
}
wxFlexGridSizer* DIALOG_ABOUT::createFlexGridSizer()
{
// three columns with vertical and horizontal extra space of two pixels
wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 3, 2, 2 );
fgSizer->SetFlexibleDirection( wxHORIZONTAL );
fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
return fgSizer;
} }
@ -156,8 +136,8 @@ void DIALOG_ABOUT::createNotebooks()
createNotebookPageByCategory( m_notebook, _( "Developers" ) , IMAGES::DEVELOPERS, createNotebookPageByCategory( m_notebook, _( "Developers" ) , IMAGES::DEVELOPERS,
m_info.GetDevelopers() ); m_info.GetDevelopers() );
createNotebookPage( m_notebook, _( "Doc Writers" ), IMAGES::DOCWRITERS, createNotebookPageByCategory( m_notebook, _( "Doc Writers" ), IMAGES::DOCWRITERS,
m_info.GetDocWriters() ); m_info.GetDocWriters() );
createNotebookPageByCategory( m_notebook, _( "Librarians" ), IMAGES::LIBRARIANS, createNotebookPageByCategory( m_notebook, _( "Librarians" ), IMAGES::LIBRARIANS,
m_info.GetLibrarians() ); m_info.GetLibrarians() );
@ -172,245 +152,54 @@ void DIALOG_ABOUT::createNotebooks()
createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() ); createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() );
} }
void DIALOG_ABOUT::createNotebookPage( wxNotebook* aParent, const wxString& aCaption,
IMAGES aIconIndex, const CONTRIBUTORS& aContributors )
{
wxPanel* outerPanel = new wxPanel( aParent );
wxBoxSizer* outerSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( outerPanel, wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
wxHSCROLL|wxVSCROLL );
m_scrolledWindow1->SetScrollRate( 5, 5 );
/* Panel for additional space at the left,
* but can also be used to show an additional bitmap.
*/
wxPanel* panel1 = new wxPanel( m_scrolledWindow1 );
wxFlexGridSizer* fgSizer1 = createFlexGridSizer();
for( size_t i=0; i<aContributors.GetCount(); ++i )
{
CONTRIBUTOR* contributor = &aContributors.Item( i );
// Icon at first column
wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
// Name of contributor at second column
if ( contributor->GetName() != wxEmptyString )
{
wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
contributor->GetName(),
wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 );
fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
}
else
{
fgSizer1->AddSpacer( 5 );
}
// Email address of contributor at third column
if ( contributor->GetExtra() != wxEmptyString )
{
wxStaticText* hyperlink = wxStaticTextRef( m_scrolledWindow1,
contributor->GetExtra() );
fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
}
else
{
fgSizer1->AddSpacer( 5 );
}
}
bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
m_scrolledWindow1->SetSizer( bSizer );
m_scrolledWindow1->Layout();
bSizer->Fit( m_scrolledWindow1 );
outerSizer->Add( m_scrolledWindow1, 1, wxEXPAND, 0 );
outerPanel->SetSizer( outerSizer );
aParent->AddPage( outerPanel, aCaption, false, static_cast<int>( aIconIndex ) );
}
void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption, void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
IMAGES aIconIndex, IMAGES aIconIndex,
const CONTRIBUTORS& aContributors ) const CONTRIBUTORS& aContributors )
{ {
// The left justification between wxStaticText and wxHyperlinkCtrl is different so wxString html;
// we must pad to make the alignment look decent.
//
// @todo Just make all of the contributor lists HTML so the alignment is consistent.
wxString padding;
// Of course the padding is different depending on the platform so we adjust the
// padding accordingly.
#if defined( __WXGTK__ )
padding += wxS( " " );
#endif
wxPanel* outerPanel = new wxPanel( aParent );
wxBoxSizer* outerSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( outerPanel, wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
wxHSCROLL|wxVSCROLL );
m_scrolledWindow1->SetScrollRate( 5, 5 );
/* Panel for additional space at the left,
* but can also be used to show an additional bitmap.
*/
wxPanel* panel1 = new wxPanel( m_scrolledWindow1 );
wxFlexGridSizer* fgSizer1 = createFlexGridSizer();
for( size_t i=0; i < aContributors.GetCount(); ++i ) for( size_t i=0; i < aContributors.GetCount(); ++i )
{ {
CONTRIBUTOR* contributor = &aContributors.Item( i ); CONTRIBUTOR* contributor = &aContributors.Item( i );
wxString category = contributor->GetCategory();
wxBitmap* icon = contributor->GetIcon(); // to construct the next row we expect to have a category and a contributor that was
wxString category = contributor->GetCategory(); // not considered up to now
if( category == wxEmptyString || contributor->IsChecked() )
continue;
/* to construct the next row we expect to have html += wxString::Format( wxS( "<p><b><u>%s:</u></b><ul>" ),
* a category and a contributor that was not considered up to now contributor->GetCategory() );
*/
if( ( category != wxEmptyString ) && !( contributor->IsChecked() ) ) // Now, all contributors of the same category will follow
for( size_t j=0; j < aContributors.GetCount(); ++j )
{ {
// Icon at first column CONTRIBUTOR* sub_contributor = &aContributors.Item( j );
wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, icon );
fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
// Category name at second column if ( sub_contributor->GetCategory() == category )
wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
contributor->GetCategory() + wxT( ":" ),
wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->SetFont( m_staticText1->GetFont().Bold() );
m_staticText1->Wrap( -1 );
fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM|wxEXPAND, 2 );
// Nothing at third column
fgSizer1->AddSpacer( 5 );
// Now, all contributors of the same category will follow
for( size_t j=0; j < aContributors.GetCount(); ++j )
{ {
CONTRIBUTOR* sub_contributor = &aContributors.Item( j ); // No URL supplied, display normal text control
if( sub_contributor->GetUrl().IsEmpty() )
if ( sub_contributor->GetCategory() == category )
{ {
// First column is empty html += wxString::Format( wxS( "<li>%s</li>" ),
fgSizer1->AddSpacer( 5 ); sub_contributor->GetName() );
wxControl* ctrl;
// No URL supplied, display normal text control
if( sub_contributor->GetUrl().IsEmpty() )
{
ctrl = new wxStaticText( m_scrolledWindow1, wxID_ANY,
padding + wxT( "" ) + sub_contributor->GetName(),
wxDefaultPosition,
wxDefaultSize, 0 );
}
else
{
// Display a hyperlink control instead
ctrl = new wxHyperlinkCtrl( m_scrolledWindow1, wxID_ANY,
wxT( "" ) + sub_contributor->GetName(),
sub_contributor->GetUrl(),
wxDefaultPosition,
wxDefaultSize,
wxBORDER_NONE | wxHL_CONTEXTMENU | wxHL_ALIGN_LEFT );
}
m_staticText1->Wrap( -1 );
fgSizer1->Add( ctrl, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
// Email address of contributor at third column
if( sub_contributor->GetExtra() != wxEmptyString )
{
wxStaticText* mail = wxStaticTextRef( m_scrolledWindow1,
sub_contributor->GetExtra() );
fgSizer1->Add( mail, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
}
else
{
fgSizer1->AddSpacer( 5 );
}
/* this contributor was added to the GUI,
* thus can be ignored next time
*/
sub_contributor->SetChecked( true );
} }
else
{
html += wxString::Format( wxS( "<li><a href='%s'>%s</a></li>" ),
sub_contributor->GetUrl(),
sub_contributor->GetName() );
}
// this contributor was added to the GUI, thus can be ignored next time
sub_contributor->SetChecked( true );
} }
} }
else
{ html += wxS( "</ul></p>" );
continue;
}
} }
/* Now, lets list the remaining contributors that have not been considered createNotebookHtmlPage( aParent, aCaption, aIconIndex, html, true );
* because they were not assigned to any category.
*/
for ( size_t k=0; k < aContributors.GetCount(); ++k )
{
CONTRIBUTOR* contributor = &aContributors.Item( k );
if ( contributor->IsChecked() )
continue;
// Icon at first column
wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
// Name of contributor at second column
if( contributor->GetName() != wxEmptyString )
{
wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
contributor->GetName(),
wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 );
fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
}
else
{
fgSizer1->AddSpacer( 5 );
}
// Email address of contributor at third column
if ( contributor->GetExtra() != wxEmptyString )
{
wxStaticText* mail = wxStaticTextRef( m_scrolledWindow1, contributor->GetExtra() );
fgSizer1->Add( mail, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
}
else
{
fgSizer1->AddSpacer( 5 );
}
}
bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
m_scrolledWindow1->SetSizer( bSizer );
m_scrolledWindow1->Layout();
bSizer->Fit( m_scrolledWindow1 );
outerSizer->Add( m_scrolledWindow1, 1, wxEXPAND, 0 );
outerPanel->SetSizer( outerSizer );
aParent->AddPage( outerPanel, aCaption, false, static_cast<int>( aIconIndex ) );
} }
@ -440,7 +229,8 @@ void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString&
htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this ); wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this );
// no additional space around the HTML window as it is also the case by the other notebook pages // no additional space around the HTML window as it is also the case by the other notebook
// pages
bSizer->Add( htmlWindow, 1, wxEXPAND, 0 ); bSizer->Add( htmlWindow, 1, wxEXPAND, 0 );
panel->SetSizer( bSizer ); panel->SetSizer( bSizer );
@ -448,29 +238,6 @@ void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString&
} }
wxStaticText* DIALOG_ABOUT::wxStaticTextRef( wxScrolledWindow* aParent, const wxString& aReference )
{
wxStaticText* text = new wxStaticText( aParent, wxID_ANY,
wxT( "(" ) + aReference + wxT( ")" ) );
return text;
}
wxStaticBitmap* DIALOG_ABOUT::createStaticBitmap( wxScrolledWindow* aParent, wxBitmap* aIcon )
{
wxStaticBitmap* bitmap = new wxStaticBitmap( aParent, wxID_ANY, wxNullBitmap,
wxDefaultPosition, wxDefaultSize, 0 );
if( aIcon )
bitmap->SetBitmap( *aIcon );
else
bitmap->SetBitmap( KiBitmapBundle( BITMAPS::right ) );
return bitmap;
}
void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event ) void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
{ {
::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() ); ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );

View File

@ -52,13 +52,6 @@ enum class IMAGES {
*/ */
class DIALOG_ABOUT : public DIALOG_ABOUT_BASE class DIALOG_ABOUT : public DIALOG_ABOUT_BASE
{ {
private:
wxImageList* m_images;
wxString m_titleName;
wxString m_untranslatedTitleName;
ABOUT_APP_INFO& m_info;
public: public:
DIALOG_ABOUT( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aAppInfo ); DIALOG_ABOUT( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aAppInfo );
~DIALOG_ABOUT(); ~DIALOG_ABOUT();
@ -76,24 +69,21 @@ private:
void onDonateClick( wxCommandEvent& event ) override; void onDonateClick( wxCommandEvent& event ) override;
// Notebook pages // Notebook pages
wxFlexGridSizer* createFlexGridSizer(); void createNotebooks();
void createNotebooks(); void createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
void createNotebookPage( wxNotebook* aParent, IMAGES aIconIndex, const CONTRIBUTORS& aContributors );
const wxString& aCaption, void createNotebookHtmlPage( wxNotebook* aParent, const wxString& aCaption,
IMAGES aIconIndex, IMAGES aIconIndex, const wxString& aHtmlMessage,
const CONTRIBUTORS& aContributors ); bool aSelection = false );
void createNotebookPageByCategory( wxNotebook* aParent,
const wxString& aCaption,
IMAGES aIconIndex,
const CONTRIBUTORS& aContributors );
void createNotebookHtmlPage( wxNotebook* aParent,
const wxString& aCaption,
IMAGES aIconIndex,
const wxString& aHtmlMessage,
bool aSelection = false );
wxStaticText* wxStaticTextRef( wxScrolledWindow* aParent, const wxString& aReference ); wxStaticText* wxStaticTextRef( wxScrolledWindow* aParent, const wxString& aReference );
wxStaticBitmap* createStaticBitmap( wxScrolledWindow* aParent, wxBitmap* icon ); wxStaticBitmap* createStaticBitmap( wxScrolledWindow* aParent, wxBitmap* icon );
private:
wxString m_titleName;
wxString m_untranslatedTitleName;
ABOUT_APP_INFO& m_info;
}; };
#endif // DIALOG_ABOUT_H #endif // DIALOG_ABOUT_H