Merge branch 'issue-1268'

FIXES #1268
This commit is contained in:
Adriaan de Groot 2019-12-03 13:01:41 +01:00
commit 2d02290b91
5 changed files with 75 additions and 42 deletions

View File

@ -72,6 +72,7 @@ LicenseEntry::LicenseEntry( const QVariantMap& conf )
m_url = QUrl( conf[ "url" ].toString() ); m_url = QUrl( conf[ "url" ].toString() );
m_required = CalamaresUtils::getBool( conf, "required", false ); m_required = CalamaresUtils::getBool( conf, "required", false );
m_expand = CalamaresUtils::getBool( conf, "expand", false );
bool ok = false; bool ok = false;
QString typeString = conf.value( "type", "software" ).toString(); QString typeString = conf.value( "type", "software" ).toString();
@ -97,21 +98,14 @@ LicensePage::LicensePage( QWidget* parent )
{ {
ui->setupUi( this ); ui->setupUi( this );
ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() ); // ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() );
CalamaresUtils::unmarginLayout( ui->verticalLayout );
ui->mainText->setAlignment( Qt::AlignCenter );
ui->mainText->setWordWrap( true ); ui->mainText->setWordWrap( true );
ui->mainText->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); ui->mainText->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
ui->additionalText->setWordWrap( true ); ui->additionalText->setWordWrap( true );
ui->verticalLayout->insertSpacing( 4, CalamaresUtils::defaultFontHeight() / 2 );
ui->verticalLayout->setContentsMargins( CalamaresUtils::defaultFontHeight(),
CalamaresUtils::defaultFontHeight() * 3,
CalamaresUtils::defaultFontHeight(),
CalamaresUtils::defaultFontHeight() );
ui->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); ui->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;" ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
"background-color: #fff6f6;" "background-color: #fff6f6;"
@ -123,54 +117,53 @@ LicensePage::LicensePage( QWidget* parent )
connect( ui->acceptCheckBox, &QCheckBox::toggled, this, &LicensePage::checkAcceptance ); connect( ui->acceptCheckBox, &QCheckBox::toggled, this, &LicensePage::checkAcceptance );
CALAMARES_RETRANSLATE( ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) ); ) CALAMARES_RETRANSLATE_SLOT( &LicensePage::retranslate )
} }
void void
LicensePage::setEntries( const QList< LicenseEntry >& entriesList ) LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
{ {
CalamaresUtils::clearLayout( ui->licenseEntriesLayout ); CalamaresUtils::clearLayout( ui->licenseEntriesLayout );
m_allLicensesOptional = true;
m_entries.clear(); m_entries.clear();
m_entries.reserve( entriesList.count() ); m_entries.reserve( entriesList.count() );
auto isRequired = []( const LicenseEntry& e ) { return e.m_required; };
m_allLicensesOptional = std::none_of( entriesList.cbegin(), entriesList.cend(), isRequired );
checkAcceptance( false );
for ( const LicenseEntry& entry : entriesList ) for ( const LicenseEntry& entry : entriesList )
{ {
LicenseWidget* w = new LicenseWidget( entry ); LicenseWidget* w = new LicenseWidget( entry );
ui->licenseEntriesLayout->addWidget( w ); ui->licenseEntriesLayout->addWidget( w );
m_entries.append( w ); m_entries.append( w );
m_allLicensesOptional &= !entry.isRequired();
} }
ui->licenseEntriesLayout->addStretch();
CALAMARES_RETRANSLATE_SLOT( &LicensePage::retranslate ) ui->acceptCheckBox->setChecked( false );
checkAcceptance( false );
} }
void void
LicensePage::retranslate() LicensePage::retranslate()
{ {
ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) );
QString review = tr( "Please review the End User License Agreements (EULAs)." );
const auto br = QStringLiteral( "<br/>" );
if ( !m_allLicensesOptional ) if ( !m_allLicensesOptional )
{ {
ui->mainText->setText( tr( "<h1>License Agreement</h1>" ui->mainText->setText( tr( "This setup procedure will install proprietary "
"This setup procedure will install proprietary " "software that is subject to licensing terms." )
"software that is subject to licensing terms." ) ); + br + review );
ui->additionalText->setText( tr( "Please review the End User License " ui->additionalText->setText( tr( "If you do not agree with the terms, the setup procedure cannot continue." ) );
"Agreements (EULAs) above.<br/>"
"If you do not agree with the terms, the setup procedure cannot continue." ) );
} }
else else
{ {
ui->mainText->setText( tr( "<h1>License Agreement</h1>" ui->mainText->setText( tr( "This setup procedure can install proprietary "
"This setup procedure can install proprietary "
"software that is subject to licensing terms " "software that is subject to licensing terms "
"in order to provide additional features and enhance the user " "in order to provide additional features and enhance the user "
"experience." ) ); "experience." )
ui->additionalText->setText( tr( "Please review the End User License " + br + review );
"Agreements (EULAs) above.<br/>" ui->additionalText->setText( tr( "If you do not agree with the terms, proprietary software will not "
"If you do not agree with the terms, proprietary software will not "
"be installed, and open source alternatives will be used instead." ) ); "be installed, and open source alternatives will be used instead." ) );
} }
ui->retranslateUi( this ); ui->retranslateUi( this );

View File

@ -56,13 +56,15 @@ struct LicenseEntry
bool isValid() const { return !m_id.isEmpty(); } bool isValid() const { return !m_id.isEmpty(); }
bool isRequired() const { return m_required; } bool isRequired() const { return m_required; }
bool isLocal() const; bool isLocal() const;
bool expandByDefault() const { return m_expand; }
QString m_id; QString m_id;
QString m_prettyName; QString m_prettyName;
QString m_prettyVendor; QString m_prettyVendor;
Type m_type; Type m_type = Type::Software;
QUrl m_url; QUrl m_url;
bool m_required; bool m_required = false;
bool m_expand = false;
}; };
class LicensePage : public QWidget class LicensePage : public QWidget

View File

@ -15,7 +15,17 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0">
<item>
<widget class="QLabel" name="titleLabel">
<property name="text">
<string>&lt;h1&gt;License Agreement&lt;/h1&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="mainText"> <widget class="QLabel" name="mainText">
<property name="sizePolicy"> <property name="sizePolicy">
@ -30,6 +40,12 @@
<property name="text"> <property name="text">
<string notr="true">&lt;Calamares license text&gt;</string> <string notr="true">&lt;Calamares license text&gt;</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -47,6 +63,12 @@
</item> </item>
<item> <item>
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -65,7 +87,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>765</width> <width>765</width>
<height>94</height> <height>81</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="licenseEntriesLayout"/> <layout class="QVBoxLayout" name="licenseEntriesLayout"/>

View File

@ -30,6 +30,10 @@
#include <QToolButton> #include <QToolButton>
#include <QVBoxLayout> #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 static QString
loadLocalFile( const QUrl& u ) loadLocalFile( const QUrl& u )
{ {
@ -57,7 +61,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
, m_fullText( nullptr ) , m_fullText( nullptr )
{ {
QPalette pal( palette() ); QPalette pal( palette() );
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) ); pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) );
setObjectName( "licenseItem" ); setObjectName( "licenseItem" );
@ -82,7 +86,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
{ {
QVBoxLayout* vLayout = new QVBoxLayout; QVBoxLayout* vLayout = new QVBoxLayout;
m_expandLicenseButton->setArrowType( Qt::UpArrow ); m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed );
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked ); connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
vLayout->addLayout( wiLayout ); vLayout->addLayout( wiLayout );
@ -94,10 +98,17 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
vLayout->addWidget( m_fullText ); vLayout->addWidget( m_fullText );
setLayout( vLayout ); setLayout( vLayout );
if ( m_entry.expandByDefault() )
{
// Since we started in a collapsed state, toggle it to expand.
// This can only be done once the full text has been added.
expandClicked();
}
} }
else else
{ {
m_expandLicenseButton->setArrowType( Qt::RightArrow ); m_expandLicenseButton->setArrowType( ArrowOpenExternalLink );
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked ); connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
// Normally setOpenExternalLinks( true ) would do, but we need the // Normally setOpenExternalLinks( true ) would do, but we need the
@ -163,19 +174,19 @@ LicenseWidget::retranslateUi()
void void
LicenseWidget::expandClicked() LicenseWidget::expandClicked()
{ {
if ( m_expandLicenseButton->arrowType() == Qt::DownArrow ) if ( m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsExpanded )
{ {
m_expandLicenseButton->setArrowType( Qt::UpArrow ); m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed );
} }
else else
{ {
m_expandLicenseButton->setArrowType( Qt::DownArrow ); m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsExpanded );
} }
// Show/hide based on the new arrow direction. // Show/hide based on the new arrow direction.
if ( m_fullText ) if ( m_fullText )
{ {
m_fullText->setHidden( m_expandLicenseButton->arrowType() == Qt::UpArrow ); m_fullText->setHidden( m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsCollapsed );
} }
updateExpandToolTip(); updateExpandToolTip();
@ -187,7 +198,7 @@ LicenseWidget::updateExpandToolTip()
{ {
if ( m_entry.isLocal() ) if ( m_entry.isLocal() )
{ {
const bool isNowCollapsed = m_expandLicenseButton->arrowType() == Qt::UpArrow; const bool isNowCollapsed = m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsCollapsed;
m_expandLicenseButton->setToolTip( isNowCollapsed ? tr( "Shows the complete license text" ) m_expandLicenseButton->setToolTip( isNowCollapsed ? tr( "Shows the complete license text" )
: tr( "Hide license text" ) ); : tr( "Hide license text" ) );

View File

@ -14,6 +14,10 @@
# to the URL is provided, which opens in the default web browser. A local # to the URL is provided, which opens in the default web browser. A local
# URL (i.e. file:///) assumes that the contents are HTML or plain text, and # URL (i.e. file:///) assumes that the contents are HTML or plain text, and
# displays the license in-line. YAML: string, mandatory. # displays the license in-line. YAML: string, mandatory.
# - expand A boolean value only relevant for **local** URLs. If true,
# the license text is displayed in "expanded" form by
# default, rather than requiring the user to first open it up.
# YAML: boolean, optional, default is false.
entries: entries:
- id: nvidia - id: nvidia
name: Nvidia name: Nvidia
@ -43,3 +47,4 @@ entries:
type: software type: software
required: true required: true
url: file:../LICENSE url: file:../LICENSE
expand: true