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

Support for realtime retranslation of the preferences.

parent 9c516757
......@@ -172,26 +172,69 @@ void
MainWindow::initVlmcPreferences()
{
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/defaultmode", "n", "Select mode", "Select the selection tool in the timeline" );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/cutmode", "x", "Cut mode", "Select the cut/razor tool in the timeline" );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/mediapreview", "Ctrl+Return", "Media preview", "Preview the selected media, or pause the current preview" );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderpreview", "Space", "Render preview", "Preview the project, or pause the current preview" );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/defaultmode", "n",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Select mode" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the selection tool in the timeline" ) );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/cutmode", "x",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Cut mode" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the cut/razor tool in the timeline" ) );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/mediapreview", "Ctrl+Return",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Media preview" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Preview the selected media, or pause the current preview" ) );
VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderpreview", "Space",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Render preview" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Preview the project, or pause the current preview" ) );
//A bit nasty, but we better use what Qt's providing as default shortcut
CREATE_MENU_SHORTCUT( "keyboard/undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(), "Undo", "Undo the last action", actionUndo );
CREATE_MENU_SHORTCUT( "keyboard/redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(), "Redo", "Redo the last action", actionRedo );
CREATE_MENU_SHORTCUT( "keyboard/help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(), "Help", "Toggle the help page", actionHelp );
CREATE_MENU_SHORTCUT( "keyboard/quit", "Ctrl+Q", "Quit", "Quit VLMC", actionQuit );
CREATE_MENU_SHORTCUT( "keyboard/preferences", "Alt+P", "Preferences", "Open VLMC preferences", actionPreferences );
CREATE_MENU_SHORTCUT( "keyboard/fullscreen", "F", "Fullscreen", "Switch to fullscreen mode", actionFullscreen );
CREATE_MENU_SHORTCUT( "keyboard/newproject", QKeySequence( QKeySequence::New ).toString().toLocal8Bit(), "New project", "Open the new project wizzard", actionNew_Project );
CREATE_MENU_SHORTCUT( "keyboard/openproject", QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(), "Open a project", "Open an existing project", actionLoad_Project );
CREATE_MENU_SHORTCUT( "keyboard/save", QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(), "Save", "Save the current project", actionSave );
CREATE_MENU_SHORTCUT( "keyboard/saveas", "Ctrl+Shift+S", "Save as", "Save the current project to a new file", actionSave_As );
CREATE_MENU_SHORTCUT( "keyboard/closeproject", QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(), "Close the project", "Close the current project", actionClose_Project );
CREATE_MENU_SHORTCUT( "keyboard/importmedia", "Ctrl+I", "Import media", "Open the import window", actionImport );
CREATE_MENU_SHORTCUT( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file", actionRender );
VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "default", "Langage", "The VLMC's UI language" );
CREATE_MENU_SHORTCUT( "keyboard/undo",
QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo the last action" ), actionUndo );
CREATE_MENU_SHORTCUT( "keyboard/redo",
QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo the last action" ), actionRedo );
CREATE_MENU_SHORTCUT( "keyboard/help",
QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Help" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Toggle the help page" ), actionHelp );
CREATE_MENU_SHORTCUT( "keyboard/quit", "Ctrl+Q",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit VLMC" ), actionQuit );
CREATE_MENU_SHORTCUT( "keyboard/preferences", "Alt+P",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Preferences" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Open VLMC preferences" ), actionPreferences );
CREATE_MENU_SHORTCUT( "keyboard/fullscreen", "F",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Fullscreen" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Switch to fullscreen mode" ), actionFullscreen );
CREATE_MENU_SHORTCUT( "keyboard/newproject",
QKeySequence( QKeySequence::New ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "New project" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the new project wizzard" ), actionNew_Project );
CREATE_MENU_SHORTCUT( "keyboard/openproject",
QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Open a project" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Open an existing project" ), actionLoad_Project );
CREATE_MENU_SHORTCUT( "keyboard/save",
QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Save" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Save the current project" ), actionSave );
CREATE_MENU_SHORTCUT( "keyboard/saveas", "Ctrl+Shift+S",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Save as" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Save the current project to a new file" ), actionSave_As );
CREATE_MENU_SHORTCUT( "keyboard/closeproject",
QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Close the project" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Close the current project" ), actionClose_Project );
CREATE_MENU_SHORTCUT( "keyboard/importmedia", "Ctrl+I",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Import media" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the import window" ), actionImport );
CREATE_MENU_SHORTCUT( "keyboard/renderproject", "Ctrl+R",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Render the project" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Render the project to a file" ), actionRender );
VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "default",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Langage" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "The VLMC's UI language" ) );
SettingsManager::getInstance()->watchValue( "general/VLMCLang",
LanguageHelper::getInstance(),
SLOT( languageChanged( const QVariant& ) ),
......
......@@ -38,15 +38,19 @@ GUIProjectManager::GUIProjectManager()
//Automatic save part :
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( autoSaveRequired() ) );
VLMC_CREATE_PREFERENCE_BOOL( "general/AutomaticBackup", false, "Automatic save",
"When this option is activated,"
"VLMC will automatically save your project at a specified interval" );
VLMC_CREATE_PREFERENCE_BOOL( "general/AutomaticBackup", false,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "When this option is activated,"
"VLMC will automatically save your project "
"at a specified interval" ) );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
VLMC_CREATE_PREFERENCE_INT( "general/AutomaticBackupInterval", 5, "Automatic save interval",
"This is the interval that VLMC will wait between two automatic save" );
VLMC_CREATE_PREFERENCE_INT( "general/AutomaticBackupInterval", 5,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "This is the interval that VLMC will wait "
"between two automatic save" ) );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
SettingsManager::Vlmc,
......
......@@ -37,6 +37,9 @@
#include <QtDebug>
#include <QWidget>
#include <QLabel>
#include <QHash>
#include <QHashIterator>
#include <QEvent>
PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::Type type,
QWidget *parent ) :
......@@ -48,15 +51,18 @@ PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::T
SettingsManager::getInstance()->group( categorie, type );
QFormLayout *layout = new QFormLayout( container );
layout->setFieldGrowthPolicy( QFormLayout::AllNonFixedFieldsGrow );
foreach ( SettingValue* s, settings.values() )
{
ISettingsCategorieWidget *widget = widgetFactory( s );
QLabel *label = new QLabel( s->name(), this );
label->setToolTip( s->description() );
QLabel *label = new QLabel( tr( s->name() ), this );
label->setToolTip( tr( s->description() ) );
m_labels.insert( s, label );
widget->widget()->setToolTip( s->description() );
layout->addRow( label, widget->widget() );
m_settings.push_back( widget );
}
setWidget( container );
setWidgetResizable( true );
setFrameStyle( QFrame::NoFrame );
......@@ -95,3 +101,29 @@ PreferenceWidget::categorie() const
{
return m_categorie;
}
void
PreferenceWidget::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
retranslateUi();
break;
default:
break;
}
}
void
PreferenceWidget::retranslateUi()
{
QHashIterator<SettingValue*, QLabel*> i( m_labels );
while ( i.hasNext() )
{
i.next();
i.value()->setText( tr( i.key()->name() ) );
i.value()->setToolTip( tr( i.key()->description() ) );
}
}
......@@ -27,10 +27,13 @@
#include <QScrollArea>
#include <QString>
#include <QHash>
#include "SettingsManager.h"
class ISettingsCategorieWidget;
class SettingValue;
class QLabel;
class QEvent;
class PreferenceWidget : public QScrollArea
{
......@@ -43,12 +46,17 @@ class PreferenceWidget : public QScrollArea
virtual void save();
const QString &categorie() const;
protected:
void changeEvent( QEvent *e );
private:
ISettingsCategorieWidget *widgetFactory( SettingValue* s );
void retranslateUi();
private:
QString m_categorie;
SettingsList m_settings;
QString m_categorie;
SettingsList m_settings;
QHash<SettingValue*, QLabel*> m_labels;
};
#endif
......@@ -44,13 +44,25 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
QSettings s;
m_recentsProjects = s.value( "RecentsProjects" ).toStringList();
VLMC_CREATE_PROJECT_DOUBLE( "video/VLMCOutputFPS", 29.97, "Output video FPS", "Frame Per Second used when previewing and rendering the project" );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectWidth", 480, "Video width", "Width resolution of the output video" );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 300, "Video height", "Height resolution of the output video" );
VLMC_CREATE_PROJECT_INT( "audio/AudioSampleRate", 0, "Audio samplerate", "Output project audio samplerate" );
VLMC_CREATE_PROJECT_STRING( "general/VLMCWorkspace", QDir::homePath(), "Workspace location", "The place where all project's videos will be stored" );
VLMC_CREATE_PROJECT_STRING( "general/ProjectName", unNamedProject, "Project name", "The project name" );
VLMC_CREATE_PROJECT_DOUBLE( "video/VLMCOutputFPS", 29.97,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Output video FPS" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Frame Per Second used when previewing and rendering the project" ) );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectWidth", 480,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video width" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Width resolution of the output video" ) );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 300,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video height" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Height resolution of the output video" ) );
VLMC_CREATE_PROJECT_INT( "audio/AudioSampleRate", 0,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Audio samplerate" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Output project audio samplerate" ) );
VLMC_CREATE_PROJECT_STRING( "general/VLMCWorkspace", QDir::homePath(),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Workspace location" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "The place where all project's videos will be stored" ) );
VLMC_CREATE_PROJECT_STRING( "general/ProjectName", unNamedProject,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Project name" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "The project name" ) );
connect( Library::getInstance(), SIGNAL( projectLoaded() ), this, SLOT( loadTimeline() ) );
}
......
......@@ -24,7 +24,7 @@
#include <QtDebug>
SettingValue::SettingValue( SettingValue::Type type, const QVariant& defaultValue,
const QString &name, const QString& desc ) :
const char* name, const char* desc ) :
m_val( defaultValue ),
m_defaultVal( defaultValue ),
m_name( name ),
......@@ -49,7 +49,7 @@ SettingValue::get() const
return m_val;
}
const QString&
const char*
SettingValue::description() const
{
return m_desc;
......@@ -61,7 +61,7 @@ SettingValue::restoreDefault()
set( m_defaultVal );
}
const QString&
const char*
SettingValue::name() const
{
return m_name;
......
......@@ -52,8 +52,8 @@ class SettingValue : public QObject
* \param defaultValue The setting default value.
* \param desc The setting description
*/
SettingValue( Type type, const QVariant& defaultValue, const QString& name,
const QString& desc );
SettingValue( Type type, const QVariant& defaultValue, const char* name,
const char* desc );
/**
* \brief setter for the m_val member
......@@ -69,13 +69,13 @@ class SettingValue : public QObject
/**
* \return The setting's description
*/
const QString &description() const;
const char *description() const;
/**
* \brief Set the setting to its default value.
*/
void restoreDefault();
const QString &name() const;
const char *name() const;
Type type() const;
private:
......@@ -84,8 +84,8 @@ class SettingValue : public QObject
*/
QVariant m_val;
QVariant m_defaultVal;
QString m_name;
QString m_desc;
const char* m_name;
const char* m_desc;
Type m_type;
signals:
/**
......
......@@ -255,8 +255,8 @@ SettingsManager::commit( SettingsManager::Type type )
void
SettingsManager::createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue, const QString &name,
const QString &desc, SettingsManager::Type varType /*= Vlmc*/ )
const QVariant &defaultValue, const char *name,
const char *desc, SettingsManager::Type varType /*= Vlmc*/ )
{
QWriteLocker wlock( &m_rwLock );
......
......@@ -52,8 +52,8 @@ class QDomElement;
#define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, QObject::tr( name ), \
QObject::tr(desc), SettingsManager::Project );
SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
desc, SettingsManager::Project );
#define VLMC_CREATE_PROJECT_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc )
......@@ -65,8 +65,8 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, QObject::tr(
VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, QObject::tr( name ), \
QObject::tr(desc), SettingsManager::Vlmc );
SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
desc, SettingsManager::Vlmc );
#define VLMC_CREATE_PREFERENCE_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc )
......@@ -106,7 +106,7 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
void createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue,
const QString &name, const QString &desc,
const char *name, const char *desc,
Type varType = Vlmc );
bool watchValue( const QString &key,
QObject* receiver,
......
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