Commit f94438db authored by Clement CHAVANCE's avatar Clement CHAVANCE

Settings are now functionnals

parent 712d34b9
#include "SettingsManager.h"
#include "ProjectSettingsDefault.h"
void ProjectSettingsDefault::load( void )
void ProjectSettingsDefault::load( const QString& part )
{
SettingsManager::getInstance()->addNewSettingsPart( "default" );
ProjectSettingsDefault::loadAudioDefaults();
ProjectSettingsDefault::loadVideoDefaults();
ProjectSettingsDefault::loadProjectDefaults();
SettingsManager::getInstance()->addNewSettingsPart( part );
ProjectSettingsDefault::loadAudioDefaults( part );
ProjectSettingsDefault::loadVideoDefaults( part );
ProjectSettingsDefault::loadProjectDefaults( part );
return ;
}
void ProjectSettingsDefault::loadAudioDefaults( void )
void ProjectSettingsDefault::loadAudioDefaults( const QString& part )
{
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultSampleRate = 0;
//SettingsManager::getInstance()->setValue( "AudioSampleRate", defaultSampleRate );
setMan->setValue( part, "AudioSampleRate", defaultSampleRate );
return ;
}
void ProjectSettingsDefault::loadVideoDefaults( void )
void ProjectSettingsDefault::loadVideoDefaults( const QString& part )
{
SettingsManager* settingsMan = SettingsManager::getInstance();
QVariant defaultProjectFPS = 25;
QVariant defaultProjectHeight = 800;
QVariant defaultProjectWidth = 600;
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VideoProjectFPS",
defaultProjectFPS );
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VideoProjectHeight",
defaultProjectHeight );
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VideoProjectWidth",
defaultProjectWidth );
return ;
}
void ProjectSettingsDefault::loadProjectDefaults( void )
void ProjectSettingsDefault::loadProjectDefaults( const QString& part )
{
SettingsManager* settingsMan = SettingsManager::getInstance();
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultName = "project";
QVariant defaultPath = "./";
//settingsMan->setValue( "ProjectName", defaultName );
//settingsMan->setValue( "ProjectDirectory", defaultPath );
setMan->setValue( part, "ProjectName", defaultName );
setMan->setValue( part, "ProjectDirectory", defaultPath );
return ;
}
......
......@@ -4,12 +4,12 @@
class ProjectSettingsDefault
{
public:
static void load( void );
static void load( const QString& part );
private:
static void loadAudioDefaults( void );
static void loadVideoDefaults( void );
static void loadProjectDefaults( void );
static void loadAudioDefaults( const QString& part );
static void loadVideoDefaults( const QString& part );
static void loadProjectDefaults( const QString& part );
private:
ProjectSettingsDefault();
......
......@@ -61,9 +61,12 @@ void SettingsManager::setValues( const QString& part, QHash<QString, QVariant>
void SettingsManager::setValue( const QString& part , const QString& key, QVariant& value )
{
//qDebug() << "Setting value " << key << "for" << part;
m_globalLock.lockForRead();
if ( !m_data.contains( part ) )
{
addNewSettingsPart( part );
}
m_globalLock.unlock();
QWriteLocker lock( &m_globalLock );
SettingsPart* tmp = m_data[part];
......@@ -73,11 +76,13 @@ void SettingsManager::setValue( const QString& part , const QString& key, QVari
const QVariant& SettingsManager::getValue( const QString& part, const QString& key ) const
{
//qDebug() << "getValue" << part << " key :" << key;
if ( !m_data.contains( part ) )
return getValue( "default", key );
QReadLocker readLock( &m_globalLock );
QReadLocker rdLock( &m_data[part]->m_lock );
QVariant& value = m_data[part]->m_data[key];
qDebug() << "value" << value;
return value;
}
......@@ -103,12 +108,6 @@ void SettingsManager::saveSettings( const QString& part, QDomDocument& xmlfile,
settingsNode.appendChild( elem );
}
//DEBUG
{
QTextStream stream( stdout );
stream << settingsNode;
}
root.appendChild( settingsNode );
}
......@@ -154,7 +153,7 @@ void SettingsManager::addNewSettingsPart( const QString& name )
void SettingsManager::loadDefaultsSettings()
{
VLMCSettingsDefault::load();
ProjectSettingsDefault::load();
VLMCSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "default" );
}
......@@ -38,6 +38,7 @@ struct SettingsPart
SettingsPart() {}
QHash<QString, QVariant> m_data;
mutable QReadWriteLock m_lock;
bool m_rdOnly;
private:
SettingsPart( const SettingsPart& );
......
......@@ -3,34 +3,34 @@
#include "VLMCSettingsDefault.h"
#include "SettingsManager.h"
void VLMCSettingsDefault::load( void )
void VLMCSettingsDefault::load( const QString& part )
{
SettingsManager::getInstance()->addNewSettingsPart( "default" );
VLMCSettingsDefault::loadVLMCDefaults();
VLMCSettingsDefault::loadlanguageDefaults();
SettingsManager::getInstance()->addNewSettingsPart( part );
VLMCSettingsDefault::loadVLMCDefaults( part );
VLMCSettingsDefault::loadlanguageDefaults( part );
return ;
}
void VLMCSettingsDefault::loadVLMCDefaults( void )
void VLMCSettingsDefault::loadVLMCDefaults( const QString& part )
{
SettingsManager* settingsMan = SettingsManager::getInstance();
QVariant defaultOutputPFS = "25";
QVariant defaultPreviewFPS = "25";
QVariant defaultTrackNb = "64";
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VLMCOutPutFPS", defaultOutputPFS );
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VLMCPreviewFPS",
defaultPreviewFPS );
settingsMan->setValue( "default",
settingsMan->setValue( part,
"VLMCTracksNb",
defaultTrackNb );
return ;
}
void VLMCSettingsDefault::loadlanguageDefaults( void )
void VLMCSettingsDefault::loadlanguageDefaults( const QString& part )
{
}
......@@ -4,11 +4,11 @@
class VLMCSettingsDefault
{
public:
static void load( void );
static void load( const QString& part );
private:
static void loadVLMCDefaults( void );
static void loadlanguageDefaults( void );
static void loadVLMCDefaults( const QString& part );
static void loadlanguageDefaults( const QString& part );
private:
VLMCSettingsDefault();
~VLMCSettingsDefault();
......
......@@ -36,7 +36,7 @@ AudioProjectPreferences::~AudioProjectPreferences() { }
void AudioProjectPreferences::load()
{
SettingsManager* setMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "defaults" : m_settName;
const QString& part = m_defaults ? "default" : m_settName;
int sampleRate = setMan->getValue( part, "AudioSampleRate" ).toInt();
m_ui.SampleRate->setValue( sampleRate );
......
......@@ -50,6 +50,8 @@
#include "ProjectManager.h"
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
#include "VLMCPreferences.h"
MainWindow::MainWindow( QWidget *parent ) :
......@@ -59,6 +61,9 @@ MainWindow::MainWindow( QWidget *parent ) :
DockWidgetManager::instance( this )->setMainWindow( this );
initializeDockWidgets();
createStatusBar();
loadDefaults();
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
createGlobalPreferences();
createProjectPreferences();
......@@ -286,7 +291,7 @@ void MainWindow::initializeDockWidgets( void )
void MainWindow::createGlobalPreferences()
{
m_globalPreferences = new Settings( this );
m_globalPreferences = new Settings( false, "VLMC", this );
m_globalPreferences->addWidget("VLMC",
new VLMCPreferences( m_globalPreferences ),
"../images/vlmc.png",
......@@ -296,7 +301,7 @@ void MainWindow::createGlobalPreferences()
void MainWindow::createProjectPreferences()
{
m_projectPreferences = new Settings( );
m_projectPreferences = new Settings( false, "project", this );
m_projectPreferences->addWidget("Project",
new ProjectPreferences,
"../images/vlmc.png",
......@@ -312,6 +317,14 @@ void MainWindow::createProjectPreferences()
m_projectPreferences->build();
}
void MainWindow::loadDefaults()
{
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
ProjectSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "project" );
}
//Private slots definition
void MainWindow::on_actionQuit_triggered()
......@@ -321,7 +334,7 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionPreferences_triggered()
{
m_globalPreferences->show();
m_projectPreferences->show();
}
void MainWindow::on_actionAbout_triggered()
......@@ -407,5 +420,5 @@ void MainWindow::toolButtonClicked( int id )
void MainWindow::on_actionProject_Preferences_triggered()
{
m_projectPreferences->show();
m_projectPreferences->show( "project" );
}
......@@ -64,6 +64,7 @@ private:
void createStatusBar();
void createGlobalPreferences();
void createProjectPreferences();
void loadDefaults();
Ui::MainWindow m_ui;
MetaDataManager* m_metaDataManager;
......@@ -73,6 +74,7 @@ private:
PreviewWidget* m_projectPreview;
WorkflowFileRenderer* m_renderer;
Settings* m_globalPreferences;
Settings* m_DefaultProjectPreferences;
Settings* m_projectPreferences;
private slots:
......
......@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QtDebug>
#include <QWidget>
#include "PreferenceWidget.h"
......@@ -41,3 +42,12 @@ void PreferenceWidget::setName( const QString& name )
{
m_settName = name;
}
void PreferenceWidget::loadThemAll( const QString& part,
bool defaults)
{
qDebug() << "part :" << part << "defaults" << defaults;
m_defaults = defaults;
m_settName = part;
load();
}
......@@ -32,6 +32,7 @@
class PreferenceWidget : public QWidget
{
Q_OBJECT
public:
PreferenceWidget( QWidget* parent = 0 );
virtual ~PreferenceWidget() {}
......@@ -45,6 +46,10 @@ class PreferenceWidget : public QWidget
protected:
bool m_defaults;
QString m_settName;
protected slots:
void loadThemAll( const QString& part = "default",
bool defaults = false );
};
#endif
......@@ -41,7 +41,7 @@ ProjectPreferences::~ProjectPreferences() { }
void ProjectPreferences::load()
{
SettingsManager* settMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "defaults" : m_settName;
const QString& part = m_defaults ? "default" : m_settName;
QString Name = settMan->getValue( part, "ProjectName" ).toString();
QString Dir = settMan->getValue( part, "ProjectDirectory" ).toString();
......@@ -51,6 +51,7 @@ void ProjectPreferences::load()
void ProjectPreferences::save()
{
qDebug() << "save proj" << m_settName;
SettingsManager* settMan = SettingsManager::getInstance();
QVariant name( m_ui.ProjectNameLineEdit->text() );
QVariant dir( m_ui.ProjectDirectoryLineEdit->text() );
......
......@@ -49,6 +49,7 @@ Settings::Settings( bool loadDefaults,
m_panel = new Panel( this );
m_stackedWidgets = new QStackedWidget( this );
SettingsManager::getInstance()->addNewSettingsPart( m_name );
connect();
}
Settings::~Settings()
......@@ -63,9 +64,13 @@ void Settings::addWidget( const QString& name,
const QString& icon,
const QString& label )
{
qDebug() << "calling SettingsManager::addWidget()";
qDebug() << "Adding Widget" << m_name << " default" << m_defaults;
m_stackedWidgets->addWidget( pWidget );
QObject::connect( this,
SIGNAL( loadSettings( const QString&, bool ) ) ,
pWidget,
SLOT( loadThemAll( const QString&, bool ) ) );
int idx = m_stackedWidgets->indexOf( pWidget );
m_widgets.insert( idx, name );
m_pWidgets.push_back( pWidget );
......@@ -84,6 +89,20 @@ void Settings::build()
//TODO : change the size of the widgets to make it look cleaner
hLayout->addWidget( m_panel );
hLayout->insertLayout( 1, buildRightHLayout() );
load();
}
void Settings::show( const QString& part )
{
if ( part == "default" )
m_defaults = true;
else
{
m_name = part;
m_defaults = false;
}
load();
QWidget::show();
}
void Settings::connect( void )
......@@ -149,7 +168,6 @@ void Settings::buttonClicked( QAbstractButton* button )
break;
case QDialogButtonBox::Cancel :
hide = true;
load();
break;
case QDialogButtonBox::Apply :
save = true;
......@@ -159,7 +177,6 @@ void Settings::buttonClicked( QAbstractButton* button )
}
if ( save == true )
{
qDebug() << "Saving Preferences";
//Save Settings
PreferenceWidget* widg;
......@@ -183,7 +200,5 @@ void Settings::switchWidget( int widget )
void Settings::load()
{
PreferenceWidget* pwidg;
foreach( pwidg, m_pWidgets )
pwidg->load( );
emit loadSettings( m_name, m_defaults );
}
......@@ -53,6 +53,7 @@ class Settings : public QDialog
const QString& icon,
const QString& label );
void build();
void show( const QString& part = "default" );
private:
void connect( void );
......@@ -80,6 +81,7 @@ class Settings : public QDialog
signals:
void widgetSwitched( int widget );
void loadSettings( const QString& part, bool defaults );
};
#endif /* !SIMPLEPREFERENCES_H */
......@@ -36,7 +36,7 @@ VLMCPreferences::~VLMCPreferences() { }
void VLMCPreferences::load()
{
SettingsManager* settMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "defaults" : m_settName;
const QString& part = m_defaults ? "default" : m_settName;
QString outputFPS = settMan->getValue( part, "VLMCOutPutFPS" ).toString();
QString previewFPS = settMan->getValue( part, "VLMCPreviewFPS" ).toString();
......
......@@ -36,7 +36,7 @@ VideoProjectPreferences::~VideoProjectPreferences() { }
void VideoProjectPreferences::load()
{
SettingsManager* setMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "defaults" : m_settName;
const QString& part = m_defaults ? "default" : m_settName;
int projectFps = setMan->getValue( part, "VideoProjectFPS" ).toInt();
int projectHeight = setMan->getValue( part, "VideoProjectHeight" ).toInt();
int projectWidth = setMan->getValue( part, "VideoProjectWidth" ).toInt();
......
......@@ -125,7 +125,8 @@ HEADERS += src/GUI/MainWindow.h \
src/Project/ProjectManager.h \
src/Configuration/SettingsManager.h \
src/Configuration/VLMCSettingsDefault.h \
src/Configuration/ProjectSettingsDefault.h
src/Configuration/ProjectSettingsDefault.h \
src/GUI/PreferenceWidget.h
FORMS += src/GUI/ui/MainWindow.ui \
src/GUI/ui/PreviewWidget.ui \
src/GUI/ui/LanguagePreferences.ui \
......
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