Commit 5e6dc330 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Support translation for the category name (preferences).

parent a2e6019e
......@@ -419,10 +419,10 @@ void MainWindow::initializeDockWidgets( void )
void MainWindow::createGlobalPreferences()
{
m_globalPreferences = new Settings( SettingsManager::Vlmc, this );
m_globalPreferences->addCategory( "general", SettingsManager::Vlmc,
m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Vlmc,
QIcon( ":/images/images/vlmc.png" ),
tr ( "VLMC settings" ) );
m_globalPreferences->addCategory( "keyboard", SettingsManager::Vlmc,
m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "keyboard" ), SettingsManager::Vlmc,
QIcon( ":/images/keyboard" ),
tr( "Keyboard Settings" ) );
}
......@@ -430,13 +430,13 @@ void MainWindow::createGlobalPreferences()
void MainWindow::createProjectPreferences()
{
m_projectPreferences = new Settings( SettingsManager::Project, this );
m_projectPreferences->addCategory( "general", SettingsManager::Project,
m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Project,
QIcon( ":/images/images/vlmc.png" ),
tr ( "Project settings" ) );
m_projectPreferences->addCategory( "video", SettingsManager::Project,
m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "video" ), SettingsManager::Project,
QIcon( ":/images/images/video.png" ),
tr ( "Video settings" ) );
m_projectPreferences->addCategory( "audio", SettingsManager::Project,
m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "audio" ), SettingsManager::Project,
QIcon( ":/images/images/audio.png" ),
tr ( "Audio settings" ) );
}
......
......@@ -41,14 +41,14 @@
#include <QHashIterator>
#include <QEvent>
PreferenceWidget::PreferenceWidget( const QString &category, SettingsManager::Type type,
PreferenceWidget::PreferenceWidget( const char *category, SettingsManager::Type type,
QWidget *parent ) :
QScrollArea( parent ),
m_category( category )
{
QWidget *container = new QWidget( this );
SettingsManager::SettingHash settings =
SettingsManager::getInstance()->group( category, type );
SettingsManager::getInstance()->group( QString( category ), type );
QFormLayout *layout = new QFormLayout( container );
layout->setFieldGrowthPolicy( QFormLayout::AllNonFixedFieldsGrow );
......@@ -66,7 +66,6 @@ PreferenceWidget::PreferenceWidget( const QString &category, SettingsManager::Ty
setWidget( container );
setWidgetResizable( true );
setFrameStyle( QFrame::NoFrame );
m_category[0] = m_category[0].toUpper();
}
ISettingsCategoryWidget*
......@@ -96,7 +95,7 @@ PreferenceWidget::save()
w->save();
}
const QString&
const char*
PreferenceWidget::category() const
{
return m_category;
......
......@@ -40,12 +40,12 @@ class PreferenceWidget : public QScrollArea
Q_OBJECT
public:
typedef QList<ISettingsCategoryWidget*> SettingsList;
PreferenceWidget( const QString& category, SettingsManager::Type type,
PreferenceWidget( const char* category, SettingsManager::Type type,
QWidget* parent = 0 );
virtual ~PreferenceWidget() {}
virtual void save();
const QString &category() const;
const char *category() const;
protected:
void changeEvent( QEvent *e );
......@@ -54,7 +54,7 @@ class PreferenceWidget : public QScrollArea
void retranslateUi();
private:
QString m_category;
const char *m_category;
SettingsList m_settings;
QHash<SettingValue*, QLabel*> m_labels;
};
......
......@@ -60,16 +60,19 @@ Settings::Settings( SettingsManager::Type type, QWidget* parent, Qt::WindowFlags
this, SLOT( switchWidget( int ) ) );
}
void Settings::addCategory( const QString& name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label )
void Settings::addCategory( const char* name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label )
{
PreferenceWidget *pWidget = new PreferenceWidget( name, type, this );
m_stackedLayout->addWidget( pWidget );
// Create a button linked to the widget using its index
m_panel->addButton( label, icon, m_stackedLayout->count() - 1 );
switchWidget( 0 );
}
void
......@@ -132,11 +135,34 @@ void Settings::buttonClicked( QAbstractButton* button )
void Settings::switchWidget( int index )
{
PreferenceWidget* pWidget =
qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( index ) );
Q_ASSERT( pWidget != NULL );
m_title->setText( pWidget->category() );
m_stackedLayout->setCurrentIndex( index );
// Reload the translated title
retranslateUi();
}
void Settings::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
retranslateUi();
break;
default:
break;
}
}
void Settings::retranslateUi()
{
PreferenceWidget* pWidget =
qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( m_stackedLayout->currentIndex() ) );
Q_ASSERT( pWidget != NULL );
// Translate the category name using the current locale
QString text = tr( pWidget->category() );
if ( text.length() >= 1 )
text[0] = text[0].toUpper();
m_title->setText( text );
}
......@@ -47,12 +47,16 @@ class Settings : public QDialog
public:
Settings( SettingsManager::Type type, QWidget* parent = 0, Qt::WindowFlags f = 0 );
void addCategory( const QString& name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label );
void addCategory( const char* name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label );
protected:
void changeEvent( QEvent *e );
private:
void buildLayout();
void retranslateUi();
private:
QDialogButtonBox* m_buttons;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment