[license] Add show-license toggle button
- Non-functional as yet - Toggles expand / collapse arrow and tooltip
This commit is contained in:
parent
32ed3f6db6
commit
c696b5c19d
@ -78,6 +78,14 @@ LicenseEntry::LicenseEntry(const QVariantMap& conf)
|
|||||||
cWarning() << "License entry" << m_id << "has unknown type" << typeString << "(using 'software')";
|
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)
|
LicensePage::LicensePage(QWidget *parent)
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::LicensePage )
|
, ui( new Ui::LicensePage )
|
||||||
|
@ -54,6 +54,7 @@ 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;
|
||||||
|
|
||||||
QString m_id;
|
QString m_id;
|
||||||
QString m_prettyName;
|
QString m_prettyName;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
|
||||||
LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
||||||
@ -30,6 +31,7 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, 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_viewLicenseLabel( new QLabel( this ) )
|
||||||
|
, m_expandLicenseButton( nullptr )
|
||||||
{
|
{
|
||||||
QPalette pal( palette() );
|
QPalette pal( palette() );
|
||||||
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
|
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
|
||||||
@ -47,10 +49,21 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
|||||||
wiLayout->addWidget( m_label );
|
wiLayout->addWidget( m_label );
|
||||||
|
|
||||||
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
||||||
m_viewLicenseLabel->setOpenExternalLinks( true );
|
|
||||||
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
||||||
wiLayout->addWidget( m_viewLicenseLabel );
|
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();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +116,39 @@ void LicenseWidget::retranslateUi()
|
|||||||
}
|
}
|
||||||
m_label->setText( productDescription );
|
m_label->setText( productDescription );
|
||||||
|
|
||||||
m_viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
|
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() ) );
|
.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" )
|
||||||
|
) ;
|
||||||
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QToolButton;
|
||||||
|
|
||||||
class LicenseWidget : public QWidget
|
class LicenseWidget : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -36,8 +38,12 @@ public:
|
|||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void expandClicked();
|
||||||
|
void updateExpandToolTip();
|
||||||
|
|
||||||
LicenseEntry m_entry;
|
LicenseEntry m_entry;
|
||||||
QLabel *m_label;
|
QLabel* m_label;
|
||||||
QLabel *m_viewLicenseLabel;
|
QLabel* m_viewLicenseLabel;
|
||||||
|
QToolButton* m_expandLicenseButton;
|
||||||
} ;
|
} ;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user