Language selector + focus fix in GreetingPage.
This commit is contained in:
parent
78075d7412
commit
9e9a922498
@ -18,8 +18,16 @@
|
|||||||
|
|
||||||
#include "GreetingPage.h"
|
#include "GreetingPage.h"
|
||||||
|
|
||||||
|
#include "CalamaresVersion.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/CalamaresUtils.h"
|
||||||
|
#include "ViewManager.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QFocusEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QListWidget>
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
|
|
||||||
@ -30,6 +38,45 @@ GreetingPage::GreetingPage( QWidget* parent )
|
|||||||
QBoxLayout *mainLayout = new QHBoxLayout;
|
QBoxLayout *mainLayout = new QHBoxLayout;
|
||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
|
QString defaultLocale = QLocale::system().name();
|
||||||
|
|
||||||
|
m_languageWidget = new QListWidget( this );
|
||||||
|
mainLayout->addWidget( m_languageWidget );
|
||||||
|
{
|
||||||
|
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
|
||||||
|
{
|
||||||
|
QLocale thisLocale = QLocale( locale );
|
||||||
|
QString lang = QLocale::languageToString( thisLocale.language() );
|
||||||
|
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
|
||||||
|
lang.append( QString( " (%1)" )
|
||||||
|
.arg( QLocale::countryToString( thisLocale.country() ) ) );
|
||||||
|
|
||||||
|
m_languageWidget->addItem( lang );
|
||||||
|
m_languageWidget->item( m_languageWidget->count() - 1 )
|
||||||
|
->setData( Qt::UserRole, thisLocale );
|
||||||
|
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
|
||||||
|
thisLocale.country() == QLocale( defaultLocale ).country() )
|
||||||
|
m_languageWidget->setCurrentRow( m_languageWidget->count() - 1 );
|
||||||
|
}
|
||||||
|
m_languageWidget->sortItems();
|
||||||
|
|
||||||
|
connect( m_languageWidget, &QListWidget::currentItemChanged,
|
||||||
|
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
|
||||||
|
{
|
||||||
|
QLocale selectedLocale = current->data( Qt::UserRole ).toLocale();
|
||||||
|
cDebug() << "Selected locale" << selectedLocale.name();
|
||||||
|
|
||||||
|
QLocale::setDefault( selectedLocale );
|
||||||
|
CalamaresUtils::installTranslator( selectedLocale.name(), qApp );
|
||||||
|
} );
|
||||||
|
|
||||||
|
connect( m_languageWidget, &QListWidget::itemActivated,
|
||||||
|
this, []
|
||||||
|
{
|
||||||
|
Calamares::ViewManager::instance()->next();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
QLabel* text = new QLabel( tr( "<h1>Welcome to the %1 installer.</h1><br/>"
|
QLabel* text = new QLabel( tr( "<h1>Welcome to the %1 installer.</h1><br/>"
|
||||||
"This program will ask you some questions and "
|
"This program will ask you some questions and "
|
||||||
"set up %2 on your computer." )
|
"set up %2 on your computer." )
|
||||||
@ -45,3 +92,28 @@ GreetingPage::GreetingPage( QWidget* parent )
|
|||||||
mainLayout->addWidget( text );
|
mainLayout->addWidget( text );
|
||||||
mainLayout->addStretch();
|
mainLayout->addStretch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GreetingPage::changeEvent( QEvent* e )
|
||||||
|
{
|
||||||
|
QWidget::changeEvent( e );
|
||||||
|
switch ( e->type() )
|
||||||
|
{
|
||||||
|
case QEvent::LanguageChange:
|
||||||
|
//TODO: retranslate all widgets
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GreetingPage::focusInEvent( QFocusEvent* e )
|
||||||
|
{
|
||||||
|
if ( m_languageWidget )
|
||||||
|
m_languageWidget->setFocus();
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
|
@ -21,12 +21,20 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QListWidget;
|
||||||
|
|
||||||
class GreetingPage : public QWidget
|
class GreetingPage : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GreetingPage( QWidget* parent = nullptr );
|
explicit GreetingPage( QWidget* parent = nullptr );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent( QEvent* e ) override;
|
||||||
|
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
||||||
|
|
||||||
|
private:
|
||||||
|
QListWidget* m_languageWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GREETINGPAGE_H
|
#endif // GREETINGPAGE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user