[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 ) , m_groups( nullptr )
{ {
ui->setupUi( this ); ui->setupUi( this );
setPageTitle( nullptr );
CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate ); CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate );
} }
@ -50,6 +51,22 @@ NetInstallPage::~NetInstallPage()
delete m_reply; 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 void
NetInstallPage::retranslate() NetInstallPage::retranslate()
{ {
@ -58,6 +75,10 @@ NetInstallPage::retranslate()
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) ); m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) ); 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 bool

View File

@ -24,9 +24,13 @@
#include "PackageModel.h" #include "PackageModel.h"
#include "PackageTreeItem.h" #include "PackageTreeItem.h"
#include "locale/TranslatableConfiguration.h"
#include <QString> #include <QString>
#include <QWidget> #include <QWidget>
#include <memory>
class QNetworkReply; class QNetworkReply;
namespace Ui namespace Ui
@ -41,6 +45,17 @@ public:
NetInstallPage( QWidget* parent = nullptr ); NetInstallPage( QWidget* parent = nullptr );
virtual ~NetInstallPage(); 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(); void onActivate();
/** @brief Retrieves the groups, with name, description and packages /** @brief Retrieves the groups, with name, description and packages
@ -77,6 +92,8 @@ private:
Ui::Page_NetInst* ui; Ui::Page_NetInst* ui;
std::unique_ptr< CalamaresUtils::Locale::TranslatedString > m_title; // Above the treeview
QNetworkReply* m_reply; QNetworkReply* m_reply;
PackageModel* m_groups; PackageModel* m_groups;
bool m_required; bool m_required;

View File

@ -203,6 +203,6 @@ NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap )
} }
if ( label.contains( "title" ) ) 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/> <string/>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <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> <item>
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<property name="maximumSize"> <property name="maximumSize">
@ -31,7 +41,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>981</width> <width>981</width>
<height>434</height> <height>407</height>
</rect> </rect>
</property> </property>
<property name="font"> <property name="font">