[license] Adjust tooltip and button texts

- Handle various states of the link and tool buttons,
   give them appropriate texts and tooltips.
This commit is contained in:
Adriaan de Groot 2019-04-24 06:53:31 -04:00
parent 4ce6fdbd90
commit 3608f62ec0

View File

@ -74,14 +74,13 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
wiLayout->addWidget( m_viewLicenseLabel ); wiLayout->addWidget( m_viewLicenseLabel );
m_expandLicenseButton = new QToolButton( this );
wiLayout->addWidget( m_expandLicenseButton );
if ( m_entry.isLocal() ) if ( m_entry.isLocal() )
{ {
QVBoxLayout* vLayout = new QVBoxLayout; QVBoxLayout* vLayout = new QVBoxLayout;
m_expandLicenseButton = new QToolButton( this );
m_expandLicenseButton->setArrowType( Qt::UpArrow ); m_expandLicenseButton->setArrowType( Qt::UpArrow );
wiLayout->addWidget( m_expandLicenseButton );
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked ); connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
vLayout->addLayout( wiLayout ); vLayout->addLayout( wiLayout );
@ -96,11 +95,9 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
} }
else else
{ {
auto* button = new QToolButton( this ); m_expandLicenseButton->setArrowType( Qt::RightArrow );
button->setArrowType( Qt::RightArrow ); connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
wiLayout->addWidget( button );
connect( button, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
// Normally setOpenExternalLinks( true ) would do, but we need the // Normally setOpenExternalLinks( true ) would do, but we need the
// open code anyway for the toolbutton, let's share it. // open code anyway for the toolbutton, let's share it.
connect( m_viewLicenseLabel, &QLabel::linkActivated, this, &LicenseWidget::viewClicked ); connect( m_viewLicenseLabel, &QLabel::linkActivated, this, &LicenseWidget::viewClicked );
@ -159,15 +156,7 @@ void LicenseWidget::retranslateUi()
.arg( m_entry.m_prettyVendor ); .arg( m_entry.m_prettyVendor );
} }
m_label->setText( productDescription ); m_label->setText( productDescription );
updateExpandToolTip();
if ( m_entry.isLocal() )
{
m_viewLicenseLabel->setText( tr( "Show license agreement" ) );
updateExpandToolTip();
}
else
m_viewLicenseLabel->setText( tr( "<a href=\"%1\">View license agreement</a>" )
.arg( m_entry.m_url.toString() ) );
} }
void void
@ -189,17 +178,30 @@ LicenseWidget::expandClicked()
updateExpandToolTip(); updateExpandToolTip();
} }
/** @brief Called on retranslate and when button state changes. */
void void
LicenseWidget::updateExpandToolTip() LicenseWidget::updateExpandToolTip()
{ {
if ( !m_expandLicenseButton ) if ( m_entry.isLocal() )
return; {
const bool isNowCollapsed = m_expandLicenseButton->arrowType() == Qt::UpArrow;
m_expandLicenseButton->setToolTip( m_expandLicenseButton->setToolTip(
( m_expandLicenseButton->arrowType() == Qt::UpArrow ) isNowCollapsed
? tr( "Show complete license text" ) ? tr( "Shows the complete license text" )
: tr( "Hide license text" ) : tr( "Hide license text" )
) ; ) ;
m_viewLicenseLabel->setText(
isNowCollapsed
? tr( "Show license agreement" )
: tr( "Hide license agreement" ) );
}
else
{
m_expandLicenseButton->setToolTip( tr( "Opens the license agreement in a browser window." ) );
m_viewLicenseLabel->setText( tr( "<a href=\"%1\">View license agreement</a>" )
.arg( m_entry.m_url.toString() ) );
}
} }
void void