[welcome] Introduce a delegate for drawing the languages list

- Show the native name left, English name right
main
Adriaan de Groot 6 years ago
parent 0b833b1e75
commit 81acc496dc

@ -16,9 +16,9 @@ include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( CHECKER_SOURCES
checker/CheckerContainer.cpp
checker/GeneralRequirements.cpp
checker/ResultWidget.cpp
checker/ResultsListWidget.cpp
checker/GeneralRequirements.cpp
${PARTMAN_SRC}
)

@ -41,18 +41,18 @@ LocaleModel::rowCount( const QModelIndex& ) const
QVariant
LocaleModel::data( const QModelIndex& index, int role ) const
{
if ( role != Qt::DisplayRole )
if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) )
return QVariant();
if ( !index.isValid() )
return QVariant();
const auto& locale = m_locales.at( index.row() );
switch ( index.column() )
switch ( role )
{
case 0:
case LabelRole:
return locale.label();
case 1:
case EnglishLabelRole:
return locale.englishLabel();
default:
return QVariant();
@ -100,3 +100,10 @@ LocaleModel::find( const QLocale& locale ) const
return locale == l.locale();
} );
}
void
LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyledItemDelegate::paint( painter, option, index );
option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( LocaleModel::EnglishLabelRole ).toString() );
}

@ -20,9 +20,9 @@
#define WELCOME_LOCALEMODEL_H
#include <QAbstractListModel>
#include <QStyledItemDelegate>
#include <QVector>
#include "utils/LocaleLabel.h"
class LocaleModel : public QAbstractListModel
@ -30,6 +30,12 @@ class LocaleModel : public QAbstractListModel
public:
using LocaleLabel = CalamaresUtils::LocaleLabel;
enum
{
LabelRole = Qt::DisplayRole,
EnglishLabelRole = Qt::UserRole + 1
};
LocaleModel( const QStringList& locales, QObject* parent = nullptr );
virtual ~LocaleModel() override;
@ -56,4 +62,12 @@ private:
QVector< LocaleLabel > m_locales;
} ;
class LocaleTwoColumnDelegate : public QStyledItemDelegate
{
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
} ;
#endif

@ -36,10 +36,10 @@
#include <QApplication>
#include <QBoxLayout>
#include <QComboBox>
#include <QDesktopServices>
#include <QFocusEvent>
#include <QLabel>
#include <QComboBox>
#include <QMessageBox>
WelcomePage::WelcomePage( QWidget* parent )
@ -133,6 +133,7 @@ WelcomePage::initLanguages()
m_languages = new LocaleModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
ui->languageWidget->setModel( m_languages );
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
// Find the best initial translation
QLocale defaultLocale = QLocale( QLocale::system().name() );
@ -165,7 +166,7 @@ WelcomePage::initLanguages()
{
QString name = m_languages->locale( matchedLocaleIndex ).name();
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsPathPrefix(), qApp );
ui->languageWidget->setCurrentIndex( matchedLocaleIndex );
}

Loading…
Cancel
Save