[license] Massage display of buttons

- try to keep them the same height
 - show the URL that will be opened
This commit is contained in:
Adriaan de Groot 2019-12-09 16:49:43 +01:00
parent 6e1504fafc
commit 7330afd96a
2 changed files with 33 additions and 18 deletions

View File

@ -53,7 +53,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
, m_entry( std::move( entry ) ) , m_entry( std::move( entry ) )
, m_label( new QLabel( this ) ) , m_label( new QLabel( this ) )
, m_viewLicenseButton( new QPushButton( this ) ) , m_viewLicenseButton( new QPushButton( this ) )
, m_fullText( nullptr ) , m_licenceTextLabel( new QLabel( this ) )
, m_isExpanded( m_entry.expandByDefault() ) , m_isExpanded( m_entry.expandByDefault() )
{ {
QPalette pal( palette() ); QPalette pal( palette() );
@ -69,33 +69,40 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
QHBoxLayout* wiLayout = new QHBoxLayout; QHBoxLayout* wiLayout = new QHBoxLayout;
m_label->setWordWrap( true ); m_label->setWordWrap( true );
m_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ); m_label->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
wiLayout->addWidget( m_label ); wiLayout->addWidget( m_label );
m_viewLicenseButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ); wiLayout->addSpacing( 1 );
m_viewLicenseButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
wiLayout->addWidget( m_viewLicenseButton ); wiLayout->addWidget( m_viewLicenseButton );
QVBoxLayout* vLayout = new QVBoxLayout;
vLayout->addLayout( wiLayout );
m_licenceTextLabel->setStyleSheet( "border-top: 1px solid black; margin-top: 0px; padding-top: 1em;" );
m_licenceTextLabel->setObjectName( "licenseItemFullText" );
if ( m_entry.isLocal() ) if ( m_entry.isLocal() )
{ {
QVBoxLayout* vLayout = new QVBoxLayout; m_fullTextContents = loadLocalFile( m_entry.m_url );
vLayout->addLayout( wiLayout ); if ( m_isExpanded )
m_fullText = new QLabel( this ); {
m_fullText->setText( loadLocalFile( m_entry.m_url ) ); m_licenceTextLabel->setText( m_fullTextContents );
m_fullText->setStyleSheet( "border-top: 1px solid black; margin-top: 1em; padding-top: 1em;" ); }
m_fullText->setObjectName( "licenseItemFullText" ); else
{
m_fullText->setHidden( !m_isExpanded ); m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
}
vLayout->addWidget( m_fullText );
setLayout( vLayout );
connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked ); connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
} }
else else
{ {
setLayout( wiLayout ); // Only the horizontal layout needed m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked ); connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
} }
vLayout->addWidget( m_licenceTextLabel );
setLayout( vLayout );
retranslateUi(); retranslateUi();
} }
@ -154,9 +161,16 @@ LicenseWidget::expandClicked()
{ {
m_isExpanded = !m_isExpanded; m_isExpanded = !m_isExpanded;
// Show/hide based on the new arrow direction. // Show/hide based on the new arrow direction.
if ( m_fullText ) if ( !m_fullTextContents.isEmpty() )
{ {
m_fullText->setHidden( !m_isExpanded ); if ( m_isExpanded )
{
m_licenceTextLabel->setText( m_fullTextContents );
}
else
{
m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
}
} }
updateExpandToolTip(); updateExpandToolTip();

View File

@ -45,7 +45,8 @@ private:
LicenseEntry m_entry; LicenseEntry m_entry;
QLabel* m_label; QLabel* m_label;
QPushButton* m_viewLicenseButton; QPushButton* m_viewLicenseButton;
QLabel* m_fullText; QLabel* m_licenceTextLabel;
QString m_fullTextContents;
bool m_isExpanded; bool m_isExpanded;
}; };
#endif #endif