1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX)
29 * - Improvements over WX
30 * - Validator for modulelist
33 #include "components/preferences_widgets.hpp"
34 #include "util/customwidgets.hpp"
40 #include <QGridLayout>
42 #include <QFileDialog>
43 #include <QFontDialog>
45 #include <QTreeWidgetItem>
46 #include <QSignalMapper>
47 QString formatTooltip(const QString & tooltip)
50 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
51 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
52 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
53 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
54 "-qt-block-indent:0; text-indent:0px;\">" +
60 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
61 module_config_t *p_item,
65 return createControl( p_this, p_item, parent, NULL, i );
68 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
69 module_config_t *p_item,
71 QGridLayout *l, int &line )
73 ConfigControl *p_control = NULL;
74 if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
76 switch( p_item->i_type )
78 case CONFIG_ITEM_MODULE:
79 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
82 case CONFIG_ITEM_MODULE_CAT:
83 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
86 case CONFIG_ITEM_MODULE_LIST:
87 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
90 case CONFIG_ITEM_MODULE_LIST_CAT:
91 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
94 case CONFIG_ITEM_STRING:
96 p_control = new StringConfigControl( p_this, p_item, parent,
99 p_control = new StringListConfigControl( p_this, p_item,
100 parent, false, l, line );
102 case CONFIG_ITEM_PASSWORD:
103 if( !p_item->i_list )
104 p_control = new StringConfigControl( p_this, p_item, parent,
107 p_control = new StringListConfigControl( p_this, p_item,
108 parent, true, l, line );
110 case CONFIG_ITEM_INTEGER:
112 p_control = new IntegerListConfigControl( p_this, p_item,
113 parent, false, l, line );
114 else if( p_item->min.i || p_item->max.i )
115 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
118 p_control = new IntegerConfigControl( p_this, p_item, parent,
121 case CONFIG_ITEM_FILE:
122 p_control = new FileConfigControl( p_this, p_item, parent, l,
125 case CONFIG_ITEM_DIRECTORY:
126 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
129 case CONFIG_ITEM_FONT:
130 p_control = new FontConfigControl( p_this, p_item, parent, l,
133 case CONFIG_ITEM_KEY:
134 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
136 case CONFIG_ITEM_BOOL:
137 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
139 case CONFIG_ITEM_FLOAT:
140 if( p_item->min.f || p_item->max.f )
141 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
144 p_control = new FloatConfigControl( p_this, p_item, parent,
153 void ConfigControl::doApply( intf_thread_t *p_intf )
159 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
161 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
166 VFloatConfigControl *vfcc =
167 qobject_cast<VFloatConfigControl *>(this);
169 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
174 VStringConfigControl *vscc =
175 qobject_cast<VStringConfigControl *>(this);
177 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
182 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
189 /**************************************************************************
190 * String-based controls
191 *************************************************************************/
193 /*********** String **************/
194 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
195 module_config_t *_p_item,
196 QWidget *_parent, QGridLayout *l,
197 int &line, bool pwd ) :
198 VStringConfigControl( _p_this, _p_item, _parent )
200 label = new QLabel( qtr(p_item->psz_text) );
201 text = new QLineEdit( qfu(p_item->value.psz) );
202 if( pwd ) text->setEchoMode( QLineEdit::Password );
207 QHBoxLayout *layout = new QHBoxLayout();
208 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
209 widget->setLayout( layout );
213 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
217 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
218 module_config_t *_p_item,
219 QLabel *_label, QLineEdit *_text, bool pwd ):
220 VStringConfigControl( _p_this, _p_item )
227 void StringConfigControl::finish()
229 text->setText( qfu(p_item->value.psz) );
230 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
232 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
235 /*********** File **************/
236 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
237 module_config_t *_p_item,
238 QWidget *_parent, QGridLayout *l,
239 int &line, bool pwd ) :
240 VStringConfigControl( _p_this, _p_item, _parent )
242 label = new QLabel( qtr(p_item->psz_text) );
243 text = new QLineEdit( qfu(p_item->value.psz) );
244 browse = new QPushButton( qtr( "Browse..." ) );
245 QHBoxLayout *textAndButton = new QHBoxLayout();
246 textAndButton->setMargin( 0 );
247 textAndButton->addWidget( text, 2 );
248 textAndButton->addWidget( browse, 0 );
250 BUTTONACT( browse, updateField() );
256 QHBoxLayout *layout = new QHBoxLayout();
257 layout->addWidget( label, 0 );
258 layout->addLayout( textAndButton, 1 );
259 widget->setLayout( layout );
263 l->addWidget( label, line, 0 );
264 l->addLayout( textAndButton, line, 1 );
269 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
270 module_config_t *_p_item,
271 QLabel *_label, QLineEdit *_text,
272 QPushButton *_button, bool pwd ):
273 VStringConfigControl( _p_this, _p_item )
279 BUTTONACT( browse, updateField() );
284 void FileConfigControl::updateField()
286 QString file = QFileDialog::getOpenFileName( NULL,
287 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
288 if( file.isNull() ) return;
289 text->setText( file );
292 void FileConfigControl::finish()
294 text->setText( qfu(p_item->value.psz) );
295 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
297 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
300 /********* String / Directory **********/
301 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
302 module_config_t *_p_item, QWidget *_p_widget,
303 QGridLayout *_p_layout, int& _int, bool _pwd ) :
304 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
307 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
308 module_config_t *_p_item, QLabel *_p_label,
309 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
310 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
313 void DirectoryConfigControl::updateField()
315 QString dir = QFileDialog::getExistingDirectory( NULL,
316 qtr( "Select Directory" ),
317 text->text().isEmpty() ?
318 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
319 QFileDialog::ShowDirsOnly |
320 QFileDialog::DontResolveSymlinks );
321 if( dir.isNull() ) return;
322 text->setText( dir );
325 /********* String / Font **********/
326 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
327 module_config_t *_p_item, QWidget *_p_widget,
328 QGridLayout *_p_layout, int& _int, bool _pwd ) :
329 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
332 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
333 module_config_t *_p_item, QLabel *_p_label,
334 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
335 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
338 void FontConfigControl::updateField()
341 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
343 text->setText( font.family() );
346 /********* String / choice list **********/
347 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QWidget *_parent, bool bycat,
349 QGridLayout *l, int &line) :
350 VStringConfigControl( _p_this, _p_item, _parent )
352 label = new QLabel( qtr(p_item->psz_text) );
353 combo = new QComboBox();
357 QHBoxLayout *layout = new QHBoxLayout();
358 layout->addWidget( label ); layout->addWidget( combo );
359 widget->setLayout( layout );
363 l->addWidget( label, line, 0 );
364 l->addWidget( combo, line, 1, Qt::AlignRight );
367 if( p_item->i_action )
369 QSignalMapper *signalMapper = new QSignalMapper(this);
371 /* Some stringLists like Capture listings have action associated */
372 for( int i = 0; i < p_item->i_action; i++ )
374 QPushButton *button =
375 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
376 CONNECT( button, clicked(), signalMapper, map() );
377 signalMapper->setMapping( button, i );
378 l->addWidget( button, line, 2 + i, Qt::AlignRight );
380 CONNECT( signalMapper, mapped( int ),
381 this, actionRequested( int ) );
385 void StringListConfigControl::actionRequested( int i_action )
387 /* Supplementary check for boundaries */
388 if( i_action < 0 || i_action >= p_item->i_action ) return;
391 val.psz_string = qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
393 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
395 if( p_item->b_dirty )
399 p_item->b_dirty = VLC_FALSE;
403 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
404 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
405 bool bycat ) : VStringConfigControl( _p_this, _p_item )
412 void StringListConfigControl::finish( bool bycat )
414 combo->setEditable( false );
416 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
418 combo->addItem( qfu(p_item->ppsz_list_text ?
419 p_item->ppsz_list_text[i_index] :
420 p_item->ppsz_list[i_index] ),
421 QVariant( p_item->ppsz_list[i_index] ) );
422 if( p_item->value.psz && !strcmp( p_item->value.psz,
423 p_item->ppsz_list[i_index] ) )
424 combo->setCurrentIndex( combo->count() - 1 );
426 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
428 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
431 QString StringListConfigControl::getValue()
433 return combo->itemData( combo->currentIndex() ).toString();
436 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
437 QComboBox *combo, QWidget *parent )
439 module_config_t *p_config =
440 config_FindConfig( VLC_OBJECT(p_intf), configname );
443 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
445 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
446 QVariant( p_config->pi_list[i_index] ) );
447 if( p_config->value.i == p_config->pi_list[i_index] )
449 combo->setCurrentIndex( i_index );
452 combo->setToolTip( qfu( p_config->psz_longtext ) );
456 /********* Module **********/
457 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
458 module_config_t *_p_item, QWidget *_parent, bool bycat,
459 QGridLayout *l, int &line) :
460 VStringConfigControl( _p_this, _p_item, _parent )
462 label = new QLabel( qtr(p_item->psz_text) );
463 combo = new QComboBox();
467 QHBoxLayout *layout = new QHBoxLayout();
468 layout->addWidget( label ); layout->addWidget( combo );
469 widget->setLayout( layout );
473 l->addWidget( label, line, 0 );
474 l->addWidget( combo, line, 1, Qt::AlignRight );
478 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
479 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
480 bool bycat ) : VStringConfigControl( _p_this, _p_item )
487 void ModuleConfigControl::finish( bool bycat )
492 combo->setEditable( false );
494 /* build a list of available modules */
495 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
496 combo->addItem( qtr("Default") );
497 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
499 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
503 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
505 for (size_t i = 0; i < p_parser->confsize; i++)
507 module_config_t *p_config = p_parser->p_config + i;
508 /* Hack: required subcategory is stored in i_min */
509 if( p_config->i_type == CONFIG_SUBCATEGORY &&
510 p_config->value.i == p_item->min.i )
511 combo->addItem( qtr( module_GetLongName( p_parser )),
512 QVariant( module_GetObjName( p_parser ) ) );
513 if( p_item->value.psz && !strcmp( p_item->value.psz,
514 module_GetObjName( p_parser ) ) )
515 combo->setCurrentIndex( combo->count() - 1 );
518 else if( module_IsCapable( p_parser, p_item->psz_type ) )
520 combo->addItem( qtr(module_GetLongName( p_parser ) ),
521 QVariant( module_GetObjName( p_parser ) ) );
522 if( p_item->value.psz && !strcmp( p_item->value.psz,
523 module_GetObjName( p_parser ) ) )
524 combo->setCurrentIndex( combo->count() - 1 );
527 vlc_list_release( p_list );
528 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
530 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
533 QString ModuleConfigControl::getValue()
535 return combo->itemData( combo->currentIndex() ).toString();
538 /********* Module list **********/
539 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
540 module_config_t *_p_item, QWidget *_parent, bool bycat,
541 QGridLayout *l, int &line) :
542 VStringConfigControl( _p_this, _p_item, _parent )
544 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
545 text = new QLineEdit();
546 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
551 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
552 it != modules.end(); it++ )
554 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
556 layoutGroupBox->addWidget( text, boxline, 0 );
560 QVBoxLayout *layout = new QVBoxLayout();
561 layout->addWidget( groupBox, line, 0 );
562 widget->setLayout( layout );
566 l->addWidget( groupBox, line, 0, 1, -1 );
569 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
572 ModuleListConfigControl::~ModuleListConfigControl()
574 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
575 it != modules.end(); it++ )
583 #define CHECKBOX_LISTS \
585 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
586 checkBoxListItem *cbl = new checkBoxListItem; \
588 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
589 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
590 cbl->checkBox = cb; \
593 while( p_parser->pp_shortcuts[++i] != NULL); \
596 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
597 : module_GetObjName( p_parser ) ); \
598 modules.push_back( cbl ); \
602 void ModuleListConfigControl::finish( bool bycat )
607 /* build a list of available modules */
608 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
609 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
611 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
615 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
617 for (size_t i = 0; i < p_parser->confsize; i++)
619 module_config_t *p_config = p_parser->p_config + i;
620 /* Hack: required subcategory is stored in i_min */
621 if( p_config->i_type == CONFIG_SUBCATEGORY &&
622 p_config->value.i == p_item->min.i )
628 else if( module_IsCapable( p_parser, p_item->psz_type ) )
633 vlc_list_release( p_list );
634 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
636 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
638 #undef CHECKBOX_LISTS
640 QString ModuleListConfigControl::getValue()
645 void ModuleListConfigControl::hide()
647 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
648 it != modules.end(); it++ )
650 (*it)->checkBox->hide();
655 void ModuleListConfigControl::show()
657 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
658 it != modules.end(); it++ )
660 (*it)->checkBox->show();
666 void ModuleListConfigControl::onUpdate( int value )
671 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
672 it != modules.end(); it++ )
674 if( (*it)->checkBox->isChecked() )
678 text->setText( text->text() + (*it)->psz_module );
683 text->setText( text->text() + ":" + (*it)->psz_module );
689 /**************************************************************************
690 * Integer-based controls
691 *************************************************************************/
693 /*********** Integer **************/
694 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
695 module_config_t *_p_item,
696 QWidget *_parent, QGridLayout *l,
698 VIntConfigControl( _p_this, _p_item, _parent )
700 label = new QLabel( qtr(p_item->psz_text) );
701 spin = new QSpinBox; spin->setMinimumWidth( 80 );
702 spin->setAlignment( Qt::AlignRight );
703 spin->setMaximumWidth( 90 );
708 QHBoxLayout *layout = new QHBoxLayout();
709 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
710 widget->setLayout( layout );
714 l->addWidget( label, line, 0 );
715 l->addWidget( spin, line, 1, Qt::AlignRight );
718 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
719 module_config_t *_p_item,
720 QLabel *_label, QSpinBox *_spin ) :
721 VIntConfigControl( _p_this, _p_item )
728 void IntegerConfigControl::finish()
730 spin->setMaximum( 2000000000 );
731 spin->setMinimum( -2000000000 );
732 spin->setValue( p_item->value.i );
733 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
735 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
738 int IntegerConfigControl::getValue()
740 return spin->value();
743 /********* Integer range **********/
744 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
745 module_config_t *_p_item,
746 QWidget *_parent, QGridLayout *l,
748 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
753 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
754 module_config_t *_p_item,
755 QLabel *_label, QSpinBox *_spin ) :
756 IntegerConfigControl( _p_this, _p_item, _label, _spin )
761 void IntegerRangeConfigControl::finish()
763 spin->setMaximum( p_item->max.i );
764 spin->setMinimum( p_item->min.i );
767 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
768 vlc_object_t *_p_this,
769 module_config_t *_p_item,
770 QLabel *_label, QSlider *_slider ):
771 VIntConfigControl( _p_this, _p_item )
775 slider->setMaximum( p_item->max.i );
776 slider->setMinimum( p_item->min.i );
777 slider->setValue( p_item->value.i );
778 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
780 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
783 int IntegerRangeSliderConfigControl::getValue()
785 return slider->value();
789 /********* Integer / choice list **********/
790 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
791 module_config_t *_p_item, QWidget *_parent, bool bycat,
792 QGridLayout *l, int &line) :
793 VIntConfigControl( _p_this, _p_item, _parent )
795 label = new QLabel( qtr(p_item->psz_text) );
796 combo = new QComboBox();
800 QHBoxLayout *layout = new QHBoxLayout();
801 layout->addWidget( label ); layout->addWidget( combo );
802 widget->setLayout( layout );
806 l->addWidget( label, line, 0 );
807 l->addWidget( combo, line, 1, Qt::AlignRight );
810 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
811 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
812 bool bycat ) : VIntConfigControl( _p_this, _p_item )
819 void IntegerListConfigControl::finish( bool bycat )
821 combo->setEditable( false );
823 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
825 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
826 QVariant( p_item->pi_list[i_index] ) );
827 if( p_item->value.i == p_item->pi_list[i_index] )
828 combo->setCurrentIndex( combo->count() - 1 );
830 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
832 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
835 int IntegerListConfigControl::getValue()
837 return combo->itemData( combo->currentIndex() ).toInt();
840 /*********** Boolean **************/
841 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
842 module_config_t *_p_item,
843 QWidget *_parent, QGridLayout *l,
845 VIntConfigControl( _p_this, _p_item, _parent )
847 checkbox = new QCheckBox( qtr(p_item->psz_text) );
852 QHBoxLayout *layout = new QHBoxLayout();
853 layout->addWidget( checkbox, 0 );
854 widget->setLayout( layout );
858 l->addWidget( checkbox, line, 0 );
861 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
862 module_config_t *_p_item,
864 QCheckBox *_checkbox,
866 VIntConfigControl( _p_this, _p_item )
868 checkbox = _checkbox;
872 void BoolConfigControl::finish()
874 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
876 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
879 int BoolConfigControl::getValue()
881 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
884 /**************************************************************************
885 * Float-based controls
886 *************************************************************************/
888 /*********** Float **************/
889 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
890 module_config_t *_p_item,
891 QWidget *_parent, QGridLayout *l,
893 VFloatConfigControl( _p_this, _p_item, _parent )
895 label = new QLabel( qtr(p_item->psz_text) );
896 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
897 spin->setMaximumWidth( 90 );
898 spin->setAlignment( Qt::AlignRight );
903 QHBoxLayout *layout = new QHBoxLayout();
904 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
905 widget->setLayout( layout );
909 l->addWidget( label, line, 0 );
910 l->addWidget( spin, line, 1, Qt::AlignRight );
914 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
915 module_config_t *_p_item,
917 QDoubleSpinBox *_spin ) :
918 VFloatConfigControl( _p_this, _p_item )
925 void FloatConfigControl::finish()
927 spin->setMaximum( 2000000000. );
928 spin->setMinimum( -2000000000. );
929 spin->setSingleStep( 0.1 );
930 spin->setValue( (double)p_item->value.f );
931 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
933 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
936 float FloatConfigControl::getValue()
938 return (float)spin->value();
941 /*********** Float with range **************/
942 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
943 module_config_t *_p_item,
944 QWidget *_parent, QGridLayout *l,
946 FloatConfigControl( _p_this, _p_item, _parent, l, line )
951 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
952 module_config_t *_p_item,
954 QDoubleSpinBox *_spin ) :
955 FloatConfigControl( _p_this, _p_item, _label, _spin )
960 void FloatRangeConfigControl::finish()
962 spin->setMaximum( (double)p_item->max.f );
963 spin->setMinimum( (double)p_item->min.f );
967 /**********************************************************************
968 * Key selector widget
969 **********************************************************************/
970 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
971 module_config_t *_p_item,
972 QWidget *_parent, QGridLayout *l,
974 ConfigControl( _p_this, _p_item, _parent )
977 label = new QLabel( qtr("Select an action to change the associated hotkey") );
978 table = new QTreeWidget( 0 );
983 QVBoxLayout *layout = new QVBoxLayout();
984 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
985 widget->setLayout( layout );
989 l->addWidget( label, line, 0, 1, 2 );
990 l->addWidget( table, line+1, 0, 1,2 );
994 void KeySelectorControl::finish()
997 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1000 table->setColumnCount( 2 );
1001 table->setAlternatingRowColors( true );
1003 module_t *p_main = config_FindModule( p_this, "main" );
1006 for (size_t i = 0; i < p_main->confsize; i++)
1008 module_config_t *p_item = p_main->p_config + i;
1010 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1011 strstr( p_item->psz_name , "key-" ) )
1013 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1014 treeItem->setText( 0, qtr( p_item->psz_text ) );
1015 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1016 treeItem->setData( 0, Qt::UserRole,
1017 QVariant::fromValue( (void*)p_item ) );
1019 table->addTopLevelItem( treeItem );
1022 table->resizeColumnToContents( 0 );
1024 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1025 this, selectKey( QTreeWidgetItem * ) );
1028 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1030 module_config_t *p_keyItem = static_cast<module_config_t*>
1031 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1033 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1035 if( d->result() == QDialog::Accepted )
1037 p_keyItem->value.i = d->keyValue;
1040 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1042 QTreeWidgetItem *it = table->topLevelItem(i);
1043 module_config_t *p_item = static_cast<module_config_t*>
1044 (it->data( 0, Qt::UserRole ).value<void*>());
1045 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1046 p_item->value.i = 0;
1047 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1051 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1056 void KeySelectorControl::doApply()
1058 foreach( module_config_t *p_current, values )
1060 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1064 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1065 const char * _keyToChange ) :
1066 QDialog(0), keyValue(0)
1071 keyToChange = _keyToChange;
1072 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1074 QVBoxLayout *l = new QVBoxLayout( this );
1075 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1076 warning = new QLabel();
1077 l->addWidget( selected , Qt::AlignCenter );
1078 l->addWidget( warning, Qt::AlignCenter );
1080 QHBoxLayout *l2 = new QHBoxLayout();
1081 QPushButton *ok = new QPushButton( qtr("OK") );
1082 l2->addWidget( ok );
1083 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1084 l2->addWidget( cancel );
1086 BUTTONACT( ok, accept() );
1087 BUTTONACT( cancel, reject() );
1092 void KeyInputDialog::checkForConflicts( int i_vlckey )
1095 module_config_t *p_current = NULL;
1096 foreach( p_current, values )
1098 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1108 qtr("Warning: the key is already assigned to \"") +
1109 QString( p_current->psz_text ) + "\"" );
1111 else warning->setText( "" );
1114 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1116 if( e->key() == Qt::Key_Tab ) return;
1117 int i_vlck = qtEventToVLCKey( e );
1118 selected->setText( VLCKeyToString( i_vlck ) );
1119 checkForConflicts( i_vlck );
1123 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1125 int i_vlck = qtWheelEventToVLCKey( e );
1126 selected->setText( VLCKeyToString( i_vlck ) );
1127 checkForConflicts( i_vlck );