[netinstall] Allow a title above the netinstall tree

- Supports translation via the config file. This is useful
  (like label:sidebar) when displaying more than one netinstall page.
This commit is contained in:
Adriaan de Groot 2020-02-19 09:29:23 +01:00
parent 5b67ca315a
commit f6d8ed85e4
4 changed files with 50 additions and 2 deletions

View File

@ -41,6 +41,7 @@ NetInstallPage::NetInstallPage( QWidget* parent )
, m_groups( nullptr )
{
ui->setupUi( this );
setPageTitle( nullptr );
CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate );
}
@ -50,6 +51,22 @@ NetInstallPage::~NetInstallPage()
delete m_reply;
}
void
NetInstallPage::setPageTitle( CalamaresUtils::Locale::TranslatedString* t )
{
m_title.reset( t );
if ( !m_title )
{
ui->label->hide();
}
else
{
ui->label->show();
}
retranslate();
}
void
NetInstallPage::retranslate()
{
@ -58,6 +75,10 @@ NetInstallPage::retranslate()
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) );
}
if ( ui && m_title )
{
ui->label->setText( m_title->get() ); // That's get() on the TranslatedString
}
}
bool

View File

@ -24,9 +24,13 @@
#include "PackageModel.h"
#include "PackageTreeItem.h"
#include "locale/TranslatableConfiguration.h"
#include <QString>
#include <QWidget>
#include <memory>
class QNetworkReply;
namespace Ui
@ -41,6 +45,17 @@ public:
NetInstallPage( QWidget* parent = nullptr );
virtual ~NetInstallPage();
/** @brief Sets the page title
*
* In situations where there is more than one netinstall page,
* or you want some explanatory title above the treeview,
* set the page title. This page takes ownership of the
* TranslatedString object.
*
* Set to nullptr to remove the title.
*/
void setPageTitle( CalamaresUtils::Locale::TranslatedString* );
void onActivate();
/** @brief Retrieves the groups, with name, description and packages
@ -77,6 +92,8 @@ private:
Ui::Page_NetInst* ui;
std::unique_ptr< CalamaresUtils::Locale::TranslatedString > m_title; // Above the treeview
QNetworkReply* m_reply;
PackageModel* m_groups;
bool m_required;

View File

@ -203,6 +203,6 @@ NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap )
}
if ( label.contains( "title" ) )
{
// Set that label on the page
m_widget->setPageTitle( new CalamaresUtils::Locale::TranslatedString( label, "title" ) );
}
}

View File

@ -14,6 +14,16 @@
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Title of Netinstall Module</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="maximumSize">
@ -31,7 +41,7 @@
<x>0</x>
<y>0</y>
<width>981</width>
<height>434</height>
<height>407</height>
</rect>
</property>
<property name="font">