Commit 4717c1ac authored by Clément Stenac's avatar Clément Stenac

Preferences

* Enable Save/Cancel. Please test heavily with already implemented stuff. There is a layout bug with simple prefs because they don't implement save yet. Also, we still have some parenting issues to fix
* Remove "advanced" stuff
parent f9e66b98
......@@ -274,43 +274,62 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) :
PrefsTree::~PrefsTree() {}
void PrefsTree::ApplyAll()
void PrefsTree::applyAll()
{
DoAll( false );
doAll( false );
}
void PrefsTree::CleanAll()
void PrefsTree::cleanAll()
{
DoAll( true );
doAll( true );
}
/// \todo When cleaning, we should remove the panel ?
void PrefsTree::DoAll( bool doclean )
void PrefsTree::doAll( bool doclean )
{
for( int i_cat_index = 0 ; i_cat_index < topLevelItemCount();
i_cat_index++ )
{
QTreeWidgetItem *cat_item = topLevelItem( i_cat_index );
for( int i_sc_index = 0; i_sc_index <= cat_item->childCount();
for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
i_sc_index++ )
{
QTreeWidgetItem *sc_item = cat_item->child( i_sc_index );
for( int i_module = 0 ; i_module <= sc_item->childCount();
for( int i_module = 0 ; i_module < sc_item->childCount();
i_module++ )
{
PrefsItemData *data = sc_item->child( i_sc_index )->
data( 0, Qt::UserRole ).
PrefsItemData *data = sc_item->child( i_module )->
data( 0, Qt::UserRole).value<PrefsItemData *>();
if( data->panel && doclean )
{
delete data->panel;
data->panel = NULL;
}
else if( data->panel )
data->panel->apply();
}
PrefsItemData *data = sc_item->data( 0, Qt::UserRole).
value<PrefsItemData *>();
if( data->panel && doclean )
data->panel->Clean();
{
delete data->panel;
data->panel = NULL;
}
else if( data->panel )
data->panel->Apply();
data->panel->apply();
}
PrefsItemData *data = cat_item->data( 0, Qt::UserRole).
value<PrefsItemData *>();
if( data->panel && doclean )
{
delete data->panel;
data->panel = NULL;
}
else if( data->panel )
data->panel->apply();
}
}
/*********************************************************************
* The Panel
*********************************************************************/
......@@ -478,45 +497,53 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
scroller->setWidget( scrolled_area );
scroller->setWidgetResizable( true );
global_layout->addWidget( scroller );
setLayout( global_layout );
#if 0
some_hidden_text = new QLabel( qfu( I_HIDDEN_ADV ) );
some_hidden_text->setWordWrap( true );
setLayout( global_layout );
setAdvanced( currently_advanced, true );
#endif
}
void PrefsPanel::Apply()
void PrefsPanel::apply()
{
/* todo */
QList<ConfigControl *>::Iterator i;
for( i = controls.begin() ; i != controls.end() ; i++ )
{
ConfigControl *c = qobject_cast<ConfigControl *>(*i);
fprintf( stderr, "Get a control %s\n", c->getName() );
switch( c->getType() )
{
case 1:
{
VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
if( !vicc )
fprintf( stderr, "Put %s = %i\n", vicc->getName(),vicc->getValue() );
config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
break;
}
case 2:
{
VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
if( !vfcc)
fprintf( stderr, "Put %s = %f\n", vfcc->getName(),vfcc->getValue() );
config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
break;
}
case 3:
{
VStringConfigControl *vscc =
qobject_cast<VStringConfigControl *>(*i);
assert( vscc );
config_PutPsz( p_intf, vscc->getName().toAscii().data(),
fprintf( stderr, "Put %s = %s\n", vscc->getName(),vscc->getValue().toAscii().data() );
config_PutPsz( p_intf, vscc->getName(),
vscc->getValue().toAscii().data() );
continue;
}
config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
vfcc->getValue() );
continue;
}
config_PutInt( p_intf, vicc->getName().toAscii().data(),
vicc->getValue() );
}
}
void PrefsPanel::Clean()
void PrefsPanel::clean()
{}
#if 0
void PrefsPanel::setAdvanced( bool adv, bool force )
{
bool some_hidden = false;
......@@ -548,3 +575,4 @@ void PrefsPanel::setAdvanced( bool adv, bool force )
some_hidden_text->show();
}
}
#endif
......@@ -64,11 +64,11 @@ public:
PrefsTree( intf_thread_t *, QWidget * );
virtual ~PrefsTree();
void ApplyAll();
void CleanAll();
void applyAll();
void cleanAll();
private:
void DoAll( bool );
void doAll( bool );
intf_thread_t *p_intf;
};
......@@ -81,17 +81,21 @@ public:
PrefsPanel( intf_thread_t *, QWidget *, PrefsItemData *, bool );
PrefsPanel( QWidget *);
virtual ~PrefsPanel() {};
void Apply();
void Clean();
void apply();
void clean();
private:
intf_thread_t *p_intf;
QList<ConfigControl *> controls;
QLabel *some_hidden_text;
QVBoxLayout *global_layout;
#if 0
QLabel *some_hidden_text;
bool advanced;
#endif
public slots:
#if 0
void setAdvanced( bool, bool );
void setAdvanced( bool a ) { return setAdvanced( a, false ); }
#endif
};
#endif
......@@ -50,7 +50,8 @@ public:
widget = NULL;
}
virtual ~ConfigControl() {};
QString getName() { return qfu( p_item->psz_name ); }
virtual int getType() = 0;
char * getName() { return p_item->psz_name; }
QWidget *getWidget() { assert( widget ); return widget; }
bool isAdvanced() { return p_item->b_advanced; }
virtual void hide() { getWidget()->hide(); };
......@@ -83,6 +84,7 @@ public:
ConfigControl(a,b) {};
virtual ~VIntConfigControl() {};
virtual int getValue() = 0;
virtual int getType() { return 1; }
};
class IntegerConfigControl : public VIntConfigControl
......@@ -161,6 +163,7 @@ public:
ConfigControl(a,b) {};
virtual ~VFloatConfigControl() {};
virtual float getValue() = 0;
virtual int getType() { return 2; }
};
class FloatConfigControl : public VFloatConfigControl
......@@ -218,6 +221,7 @@ public:
ConfigControl(a,b) {};
virtual ~VStringConfigControl() {};
virtual QString getValue() = 0;
virtual int getType() { return 3; }
};
class StringConfigControl : public VStringConfigControl
......
......@@ -86,18 +86,18 @@ SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
setCurrentRow( SPrefsInterface );
}
void SPrefsCatList::ApplyAll()
void SPrefsCatList::applyAll()
{
DoAll( false );
doAll( false );
}
void SPrefsCatList::CleanAll()
void SPrefsCatList::cleanAll()
{
DoAll( true );
doAll( true );
}
/// \todo When cleaning, we should remove the panel ?
void SPrefsCatList::DoAll( bool doclean )
void SPrefsCatList::doAll( bool doclean )
{
/* Todo */
}
......@@ -202,15 +202,15 @@ void SPrefsPanel::Apply()
VStringConfigControl *vscc =
qobject_cast<VStringConfigControl *>(*i);
assert( vscc );
config_PutPsz( p_intf, vscc->getName().toAscii().data(),
config_PutPsz( p_intf, vscc->getName(),
vscc->getValue().toAscii().data() );
continue;
}
config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
config_PutFloat( p_intf, vfcc->getName(),
vfcc->getValue() );
continue;
}
config_PutInt( p_intf, vicc->getName().toAscii().data(),
config_PutInt( p_intf, vicc->getName(),
vicc->getValue() );
}
}
......
......@@ -48,11 +48,11 @@ public:
SPrefsCatList( intf_thread_t *, QWidget *);
virtual ~SPrefsCatList() {};
void ApplyAll();
void CleanAll();
void applyAll();
void cleanAll();
private:
void DoAll( bool );
void doAll( bool );
intf_thread_t *p_intf;
};
......
......@@ -57,9 +57,9 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
all = new QRadioButton( "All", types ); tl->addWidget( all );
types->setLayout(tl);
small->setChecked( true );
#if 0
adv_chk = new QCheckBox("Advanced options");
#endif
advanced_tree = NULL;
simple_tree = NULL;
simple_panel = NULL;
......@@ -67,29 +67,42 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
main_layout->addWidget( types, 0,0,1,1 );
main_layout->addWidget( tree_panel, 1,0,1,1 );
#if 0
main_layout->addWidget( adv_chk , 2,0,1,1 );
main_layout->addWidget( main_panel, 0, 1, 3, 1 );
#endif
main_layout->addWidget( main_panel, 0, 1, 2, 1 );
main_layout->setColumnMinimumWidth( 0, 200 );
main_layout->setColumnStretch( 0, 1 );
main_layout->setColumnStretch( 1,3 );
setSmall();
#if 0
connect( adv_chk, SIGNAL( toggled(bool) ),
this, SLOT( setAdvanced( bool ) ) );
#endif
QPushButton *save, *cancel;
QHBoxLayout *buttonsLayout =
QVLCFrame::doButtons( this, NULL, &save, _("Save"),
&cancel, _("Cancel"),
NULL, NULL );
connect( save, SIGNAL( clicked() ), this, SLOT( save() ) );
connect( cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
main_layout->addLayout( buttonsLayout, 2,0, 1 ,3 );
setLayout( main_layout );
connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
}
#if 0
void PrefsDialog::setAdvanced( bool advanced )
{
if( advanced_panel )
advanced_panel->setAdvanced( advanced );
}
#endif
void PrefsDialog::setAll()
{
if( simple_tree )
......@@ -117,7 +130,9 @@ void PrefsDialog::setAll()
advanced_panel = new PrefsPanel( main_panel );
main_panel_l->addWidget( advanced_panel );
advanced_panel->show();
#if 0
adv_chk->show();
#endif
}
void PrefsDialog::setSmall()
......@@ -146,7 +161,9 @@ void PrefsDialog::setSmall()
simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
main_panel_l->addWidget( simple_panel );
simple_panel->show();
#if 0
adv_chk->hide();
#endif
}
PrefsDialog::~PrefsDialog()
......@@ -179,11 +196,40 @@ void PrefsDialog::changePanel( QTreeWidgetItem *item )
}
if( !data->panel )
{
data->panel = new PrefsPanel( p_intf, main_panel , data,
data->panel = new PrefsPanel( p_intf, main_panel , data, true );
#if 0
adv_chk->isChecked() );
#endif
}
advanced_panel = data->panel;
main_panel_l->addWidget( advanced_panel );
advanced_panel->show();
#if 0
setAdvanced( adv_chk->isChecked() );
#endif
}
void PrefsDialog::save()
{
if( small->isChecked() && simple_tree )
simple_tree->applyAll();
else if( all->isChecked() && advanced_tree )
advanced_tree->applyAll();
config_SaveConfigFile( p_intf, NULL );
hide();
}
void PrefsDialog::cancel()
{
if( small->isChecked() && simple_tree )
{
simple_tree->cleanAll();
simple_panel = NULL;
}
else if( all->isChecked() && advanced_tree )
{
advanced_tree->cleanAll();
advanced_panel = NULL;
}
hide();
}
......@@ -67,7 +67,9 @@ private:
QGroupBox *types;
QRadioButton *small,*all;
#if 0
QCheckBox *adv_chk;
#endif
QGridLayout *main_layout;
......@@ -77,7 +79,11 @@ private slots:
void changeSimplePanel( QListWidgetItem *);
void setAll();
void setSmall();
void save();
void cancel();
#if 0
void setAdvanced( bool );
#endif
};
#endif
......@@ -59,7 +59,7 @@ public:
}
#endif
}
static void doButtons( QWidget *w, QBoxLayout *l,
static QHBoxLayout* doButtons( QWidget *w, QBoxLayout *l,
QPushButton **defaul, char *psz_default,
QPushButton **alt, char *psz_alt,
QPushButton **other, char *psz_other )
......@@ -73,6 +73,7 @@ public:
if( psz_default )
{
fprintf( stderr, "Creating default button %s\n", psz_default );
*defaul = new QPushButton(0);
buttons_layout->addWidget( *defaul );
(*defaul)->setText( qfu( psz_default ) );
......@@ -89,8 +90,10 @@ public:
buttons_layout->addWidget( *other );
(*other)->setText( qfu( psz_other ) );
}
if( l )
l->addLayout( buttons_layout );
#endif
return buttons_layout;
};
QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
......
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