|
|
|
@ -27,13 +27,9 @@
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
static constexpr const auto ArrowOpenExternalLink = Qt::RightArrow;
|
|
|
|
|
static constexpr const auto ArrowLocalLicenseIsCollapsed = Qt::UpArrow;
|
|
|
|
|
static constexpr const auto ArrowLocalLicenseIsExpanded = Qt::DownArrow;
|
|
|
|
|
|
|
|
|
|
static QString
|
|
|
|
|
loadLocalFile( const QUrl& u )
|
|
|
|
|
{
|
|
|
|
@ -56,9 +52,9 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
|
|
|
|
: QWidget( parent )
|
|
|
|
|
, m_entry( std::move( entry ) )
|
|
|
|
|
, m_label( new QLabel( this ) )
|
|
|
|
|
, m_viewLicenseLabel( new QLabel( this ) )
|
|
|
|
|
, m_expandLicenseButton( nullptr )
|
|
|
|
|
, m_fullText( nullptr )
|
|
|
|
|
, m_viewLicenseButton( new QPushButton( this ) )
|
|
|
|
|
, m_licenceTextLabel( new QLabel( this ) )
|
|
|
|
|
, m_isExpanded( m_entry.expandByDefault() )
|
|
|
|
|
{
|
|
|
|
|
QPalette pal( palette() );
|
|
|
|
|
pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) );
|
|
|
|
@ -70,53 +66,47 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
|
|
|
|
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
|
setContentsMargins( 4, 4, 4, 4 );
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* vLayout = new QVBoxLayout;
|
|
|
|
|
QWidget* topPart = new QWidget( this );
|
|
|
|
|
topPart->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
|
|
|
|
|
vLayout->addWidget( topPart );
|
|
|
|
|
|
|
|
|
|
QHBoxLayout* wiLayout = new QHBoxLayout;
|
|
|
|
|
topPart->setLayout( wiLayout );
|
|
|
|
|
|
|
|
|
|
m_label->setWordWrap( true );
|
|
|
|
|
m_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
|
|
|
|
m_label->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
|
|
|
|
|
wiLayout->addWidget( m_label );
|
|
|
|
|
|
|
|
|
|
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|
|
|
|
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
|
|
|
|
wiLayout->addWidget( m_viewLicenseLabel );
|
|
|
|
|
wiLayout->addSpacing( 10 );
|
|
|
|
|
m_viewLicenseButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
|
|
|
|
|
wiLayout->addWidget( m_viewLicenseButton );
|
|
|
|
|
|
|
|
|
|
m_licenceTextLabel->setStyleSheet( "border-top: 1px solid black; margin-top: 0px; padding-top: 1em;" );
|
|
|
|
|
m_licenceTextLabel->setObjectName( "licenseItemFullText" );
|
|
|
|
|
|
|
|
|
|
m_expandLicenseButton = new QToolButton( this );
|
|
|
|
|
wiLayout->addWidget( m_expandLicenseButton );
|
|
|
|
|
if ( m_entry.isLocal() )
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout* vLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
|
|
m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed );
|
|
|
|
|
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
|
|
|
|
|
|
|
|
|
|
vLayout->addLayout( wiLayout );
|
|
|
|
|
m_fullText = new QLabel( this );
|
|
|
|
|
m_fullText->setText( loadLocalFile( m_entry.m_url ) );
|
|
|
|
|
m_fullText->hide();
|
|
|
|
|
m_fullText->setStyleSheet( "border-top: 1px solid black; margin-top: 1em; padding-top: 1em;" );
|
|
|
|
|
m_fullText->setObjectName( "licenseItemFullText" );
|
|
|
|
|
|
|
|
|
|
vLayout->addWidget( m_fullText );
|
|
|
|
|
setLayout( vLayout );
|
|
|
|
|
|
|
|
|
|
if ( m_entry.expandByDefault() )
|
|
|
|
|
m_fullTextContents = loadLocalFile( m_entry.m_url );
|
|
|
|
|
if ( m_isExpanded )
|
|
|
|
|
{
|
|
|
|
|
m_licenceTextLabel->setText( m_fullTextContents );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Since we started in a collapsed state, toggle it to expand.
|
|
|
|
|
// This can only be done once the full text has been added.
|
|
|
|
|
expandClicked();
|
|
|
|
|
m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
|
|
|
|
|
}
|
|
|
|
|
connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_expandLicenseButton->setArrowType( ArrowOpenExternalLink );
|
|
|
|
|
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
|
|
|
|
|
|
|
|
|
|
// Normally setOpenExternalLinks( true ) would do, but we need the
|
|
|
|
|
// open code anyway for the toolbutton, let's share it.
|
|
|
|
|
connect( m_viewLicenseLabel, &QLabel::linkActivated, this, &LicenseWidget::viewClicked );
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
m_licenceTextLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
|
|
|
|
|
|
|
|
|
|
vLayout->addWidget( m_licenceTextLabel );
|
|
|
|
|
setLayout( vLayout );
|
|
|
|
|
|
|
|
|
|
retranslateUi();
|
|
|
|
|
}
|
|
|
|
@ -174,19 +164,18 @@ LicenseWidget::retranslateUi()
|
|
|
|
|
void
|
|
|
|
|
LicenseWidget::expandClicked()
|
|
|
|
|
{
|
|
|
|
|
if ( m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsExpanded )
|
|
|
|
|
{
|
|
|
|
|
m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsExpanded );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_isExpanded = !m_isExpanded;
|
|
|
|
|
// Show/hide based on the new arrow direction.
|
|
|
|
|
if ( m_fullText )
|
|
|
|
|
if ( !m_fullTextContents.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
m_fullText->setHidden( m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsCollapsed );
|
|
|
|
|
if ( m_isExpanded )
|
|
|
|
|
{
|
|
|
|
|
m_licenceTextLabel->setText( m_fullTextContents );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateExpandToolTip();
|
|
|
|
@ -198,17 +187,11 @@ LicenseWidget::updateExpandToolTip()
|
|
|
|
|
{
|
|
|
|
|
if ( m_entry.isLocal() )
|
|
|
|
|
{
|
|
|
|
|
const bool isNowCollapsed = m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsCollapsed;
|
|
|
|
|
|
|
|
|
|
m_expandLicenseButton->setToolTip( isNowCollapsed ? tr( "Shows the complete license text" )
|
|
|
|
|
: tr( "Hide license text" ) );
|
|
|
|
|
m_viewLicenseLabel->setText( isNowCollapsed ? tr( "Show license agreement" ) : tr( "Hide license agreement" ) );
|
|
|
|
|
m_viewLicenseButton->setText( m_isExpanded ? tr( "Hide license text" ) : tr( "Show the license text" ) );
|
|
|
|
|
}
|
|
|
|
|
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() ) );
|
|
|
|
|
m_viewLicenseButton->setText( tr( "Open license agreement in browser." ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|