Merge branch 'issue-1268'

FIXES #1268
main
Adriaan de Groot 5 years ago
commit 41c506cacc

@ -44,6 +44,12 @@
#include <algorithm> #include <algorithm>
static const char mustAccept[] = "#acceptFrame { border: 1px solid red;"
"background-color: #fff6f6;"
"border-radius: 4px;"
"padding: 2px; }";
static const char okAccept[] = "#acceptFrame { padding: 3px }";
const NamedEnumTable< LicenseEntry::Type >& const NamedEnumTable< LicenseEntry::Type >&
LicenseEntry::typeNames() LicenseEntry::typeNames()
{ {
@ -104,13 +110,8 @@ LicensePage::LicensePage( QWidget* parent )
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->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); ui->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;" ui->acceptFrame->setStyleSheet( mustAccept );
"background-color: #fff6f6;"
"border-radius: 4px;"
"padding: 2px; }" );
ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 ); ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
updateGlobalStorage( false ); // Have not agreed yet updateGlobalStorage( false ); // Have not agreed yet
@ -136,6 +137,7 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
m_entries.append( w ); m_entries.append( w );
m_allLicensesOptional &= !entry.isRequired(); m_allLicensesOptional &= !entry.isRequired();
} }
ui->licenseEntriesLayout->addSpacerItem( new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
ui->acceptCheckBox->setChecked( false ); ui->acceptCheckBox->setChecked( false );
checkAcceptance( false ); checkAcceptance( false );
@ -154,7 +156,8 @@ LicensePage::retranslate()
ui->mainText->setText( tr( "This setup procedure will install proprietary " ui->mainText->setText( tr( "This setup procedure will install proprietary "
"software that is subject to licensing terms." ) "software that is subject to licensing terms." )
+ br + review ); + br + review );
ui->additionalText->setText( tr( "If you do not agree with the terms, the setup procedure cannot continue." ) ); QString mustAcceptText( tr( "If you do not agree with the terms, the setup procedure cannot continue." ) );
ui->acceptCheckBox->setToolTip( mustAcceptText );
} }
else else
{ {
@ -163,8 +166,9 @@ LicensePage::retranslate()
"in order to provide additional features and enhance the user " "in order to provide additional features and enhance the user "
"experience." ) "experience." )
+ br + review ); + br + review );
ui->additionalText->setText( tr( "If you do not agree with the terms, proprietary software will not " QString okAcceptText( tr( "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->acceptCheckBox->setToolTip( okAcceptText );
} }
ui->retranslateUi( this ); ui->retranslateUi( this );
@ -195,14 +199,11 @@ LicensePage::checkAcceptance( bool checked )
m_isNextEnabled = checked || m_allLicensesOptional; m_isNextEnabled = checked || m_allLicensesOptional;
if ( !m_isNextEnabled ) if ( !m_isNextEnabled )
{ {
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;" ui->acceptFrame->setStyleSheet( mustAccept );
"background-color: #fff8f8;"
"border-radius: 4px;"
"padding: 2px; }" );
} }
else else
{ {
ui->acceptFrame->setStyleSheet( "#acceptFrame { padding: 3px }" ); ui->acceptFrame->setStyleSheet( okAccept );
} }
emit nextStatusChanged( m_isNextEnabled ); emit nextStatusChanged( m_isNextEnabled );
} }

@ -15,7 +15,7 @@
</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,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0">
<item> <item>
<widget class="QLabel" name="titleLabel"> <widget class="QLabel" name="titleLabel">
<property name="text"> <property name="text">
@ -87,7 +87,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>765</width> <width>765</width>
<height>81</height> <height>89</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="licenseEntriesLayout"/> <layout class="QVBoxLayout" name="licenseEntriesLayout"/>
@ -107,22 +107,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QLabel" name="additionalText">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="text">
<string notr="true">&lt;additionalText&gt;</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing"> <property name="spacing">

@ -27,13 +27,9 @@
#include <QFile> #include <QFile>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QToolButton> #include <QPushButton>
#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 )
{ {
@ -56,9 +52,9 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, m_entry( std::move( entry ) ) , m_entry( std::move( entry ) )
, m_label( new QLabel( this ) ) , m_label( new QLabel( this ) )
, m_viewLicenseLabel( new QLabel( this ) ) , m_viewLicenseButton( new QPushButton( this ) )
, m_expandLicenseButton( nullptr ) , m_licenceTextLabel( new QLabel( this ) )
, m_fullText( nullptr ) , m_isExpanded( m_entry.expandByDefault() )
{ {
QPalette pal( palette() ); QPalette pal( palette() );
pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) ); pal.setColor( QPalette::Background, palette().window().color().lighter( 108 ) );
@ -70,53 +66,47 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
setContentsMargins( 4, 4, 4, 4 ); 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; QHBoxLayout* wiLayout = new QHBoxLayout;
topPart->setLayout( wiLayout );
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_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); wiLayout->addSpacing( 10 );
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); m_viewLicenseButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
wiLayout->addWidget( m_viewLicenseLabel ); 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() ) if ( m_entry.isLocal() )
{ {
QVBoxLayout* vLayout = new QVBoxLayout; m_fullTextContents = loadLocalFile( m_entry.m_url );
if ( m_isExpanded )
m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed ); {
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked ); m_licenceTextLabel->setText( m_fullTextContents );
}
vLayout->addLayout( wiLayout ); else
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() )
{ {
// Since we started in a collapsed state, toggle it to expand. m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
// This can only be done once the full text has been added.
expandClicked();
} }
connect( m_viewLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
} }
else else
{ {
m_expandLicenseButton->setArrowType( ArrowOpenExternalLink ); m_licenceTextLabel->setText( tr( "URL: %1" ).arg( m_entry.m_url.toDisplayString() ) );
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked ); connect( m_viewLicenseButton, &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->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
vLayout->addWidget( m_licenceTextLabel );
setLayout( vLayout );
retranslateUi(); retranslateUi();
} }
@ -174,19 +164,18 @@ LicenseWidget::retranslateUi()
void void
LicenseWidget::expandClicked() LicenseWidget::expandClicked()
{ {
if ( m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsExpanded ) m_isExpanded = !m_isExpanded;
{
m_expandLicenseButton->setArrowType( ArrowLocalLicenseIsCollapsed );
}
else
{
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_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(); updateExpandToolTip();
@ -198,17 +187,11 @@ LicenseWidget::updateExpandToolTip()
{ {
if ( m_entry.isLocal() ) if ( m_entry.isLocal() )
{ {
const bool isNowCollapsed = m_expandLicenseButton->arrowType() == ArrowLocalLicenseIsCollapsed; m_viewLicenseButton->setText( m_isExpanded ? tr( "Hide license text" ) : tr( "Show the license text" ) );
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" ) );
} }
else else
{ {
m_expandLicenseButton->setToolTip( tr( "Opens the license agreement in a browser window." ) ); m_viewLicenseButton->setText( tr( "Open license agreement in browser." ) );
m_viewLicenseLabel->setText(
tr( "<a href=\"%1\">View license agreement</a>" ).arg( m_entry.m_url.toString() ) );
} }
} }

@ -27,7 +27,7 @@
#include <QLabel> #include <QLabel>
#include <QWidget> #include <QWidget>
class QToolButton; class QPushButton;
class LicenseWidget : public QWidget class LicenseWidget : public QWidget
{ {
@ -44,8 +44,9 @@ private:
LicenseEntry m_entry; LicenseEntry m_entry;
QLabel* m_label; QLabel* m_label;
QLabel* m_viewLicenseLabel; QPushButton* m_viewLicenseButton;
QToolButton* m_expandLicenseButton; QLabel* m_licenceTextLabel;
QLabel* m_fullText; QString m_fullTextContents;
bool m_isExpanded;
}; };
#endif #endif

Loading…
Cancel
Save