[license] Add show-license toggle button

- Non-functional as yet
 - Toggles expand / collapse arrow and tooltip
This commit is contained in:
Adriaan de Groot 2019-04-21 20:36:11 +02:00
parent 32ed3f6db6
commit c696b5c19d
4 changed files with 65 additions and 4 deletions

View File

@ -78,6 +78,14 @@ LicenseEntry::LicenseEntry(const QVariantMap& conf)
cWarning() << "License entry" << m_id << "has unknown type" << typeString << "(using 'software')";
}
bool
LicenseEntry::isLocal() const
{
return ( m_url.scheme() == "file" ) &&
( []( const QString&& r ){ return r.endsWith( ".html" ) || r.endsWith( ".txt" ); }( m_url.toString() ) );
}
LicensePage::LicensePage(QWidget *parent)
: QWidget( parent )
, ui( new Ui::LicensePage )

View File

@ -54,6 +54,7 @@ struct LicenseEntry
bool isValid() const { return !m_id.isEmpty(); }
bool isRequired() const { return m_required; }
bool isLocal() const;
QString m_id;
QString m_prettyName;

View File

@ -23,6 +23,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
@ -30,6 +31,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
, m_entry( std::move( entry ) )
, m_label( new QLabel( this ) )
, m_viewLicenseLabel( new QLabel( this ) )
, m_expandLicenseButton( nullptr )
{
QPalette pal( palette() );
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
@ -47,10 +49,21 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
wiLayout->addWidget( m_label );
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
m_viewLicenseLabel->setOpenExternalLinks( true );
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
wiLayout->addWidget( m_viewLicenseLabel );
if ( m_entry.isLocal() )
{
m_expandLicenseButton = new QToolButton( this );
m_expandLicenseButton->setArrowType( Qt::DownArrow );
wiLayout->addWidget( m_expandLicenseButton );
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
}
else
m_viewLicenseLabel->setOpenExternalLinks( true );
retranslateUi();
}
@ -103,6 +116,39 @@ void LicenseWidget::retranslateUi()
}
m_label->setText( productDescription );
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
LicenseWidget::expandClicked()
{
if ( m_expandLicenseButton->arrowType() == Qt::DownArrow )
{
m_expandLicenseButton->setArrowType( Qt::UpArrow );
}
else
{
m_expandLicenseButton->setArrowType( Qt::DownArrow );
}
updateExpandToolTip();
}
void
LicenseWidget::updateExpandToolTip()
{
if ( !m_expandLicenseButton )
return;
m_expandLicenseButton->setToolTip(
( m_expandLicenseButton->arrowType() == Qt::DownArrow )
? tr( "Show complete license text" )
: tr( "Hide license text" )
) ;
}

View File

@ -27,6 +27,8 @@
#include <QLabel>
#include <QWidget>
class QToolButton;
class LicenseWidget : public QWidget
{
public:
@ -36,8 +38,12 @@ public:
void retranslateUi();
private:
void expandClicked();
void updateExpandToolTip();
LicenseEntry m_entry;
QLabel* m_label;
QLabel* m_viewLicenseLabel;
QToolButton* m_expandLicenseButton;
} ;
#endif