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, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
41 #include <QGridLayout>
43 #include <QFileDialog>
44 #include <QFontDialog>
46 #include <QTreeWidgetItem>
47 #include <QSignalMapper>
49 QString formatTooltip(const QString & tooltip)
52 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
53 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
54 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
55 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
56 "-qt-block-indent:0; text-indent:0px;\">" +
62 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
63 module_config_t *p_item,
67 return createControl( p_this, p_item, parent, NULL, i );
70 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
71 module_config_t *p_item,
73 QGridLayout *l, int &line )
75 ConfigControl *p_control = NULL;
76 if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
78 switch( p_item->i_type )
80 case CONFIG_ITEM_MODULE:
81 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
84 case CONFIG_ITEM_MODULE_CAT:
85 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
88 case CONFIG_ITEM_MODULE_LIST:
89 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
92 case CONFIG_ITEM_MODULE_LIST_CAT:
93 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
96 case CONFIG_ITEM_STRING:
98 p_control = new StringConfigControl( p_this, p_item, parent,
101 p_control = new StringListConfigControl( p_this, p_item,
102 parent, false, l, line );
104 case CONFIG_ITEM_PASSWORD:
105 if( !p_item->i_list )
106 p_control = new StringConfigControl( p_this, p_item, parent,
109 p_control = new StringListConfigControl( p_this, p_item,
110 parent, true, l, line );
112 case CONFIG_ITEM_INTEGER:
114 p_control = new IntegerListConfigControl( p_this, p_item,
115 parent, false, l, line );
116 else if( p_item->min.i || p_item->max.i )
117 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
120 p_control = new IntegerConfigControl( p_this, p_item, parent,
123 case CONFIG_ITEM_FILE:
124 p_control = new FileConfigControl( p_this, p_item, parent, l,
127 case CONFIG_ITEM_DIRECTORY:
128 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
131 case CONFIG_ITEM_FONT:
132 p_control = new FontConfigControl( p_this, p_item, parent, l,
135 case CONFIG_ITEM_KEY:
136 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
138 case CONFIG_ITEM_BOOL:
139 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
141 case CONFIG_ITEM_FLOAT:
142 if( p_item->min.f || p_item->max.f )
143 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
146 p_control = new FloatConfigControl( p_this, p_item, parent,
155 void ConfigControl::doApply( intf_thread_t *p_intf )
161 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
163 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
168 VFloatConfigControl *vfcc =
169 qobject_cast<VFloatConfigControl *>(this);
171 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
176 VStringConfigControl *vscc =
177 qobject_cast<VStringConfigControl *>(this);
179 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
184 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
191 /**************************************************************************
192 * String-based controls
193 *************************************************************************/
195 /*********** String **************/
196 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
197 module_config_t *_p_item,
198 QWidget *_parent, QGridLayout *l,
199 int &line, bool pwd ) :
200 VStringConfigControl( _p_this, _p_item, _parent )
202 label = new QLabel( qtr(p_item->psz_text) );
203 text = new QLineEdit( qfu(p_item->value.psz) );
204 if( pwd ) text->setEchoMode( QLineEdit::Password );
209 QHBoxLayout *layout = new QHBoxLayout();
210 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
211 widget->setLayout( layout );
215 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
219 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
220 module_config_t *_p_item,
221 QLabel *_label, QLineEdit *_text, bool pwd ):
222 VStringConfigControl( _p_this, _p_item )
229 void StringConfigControl::finish()
231 text->setText( qfu(p_item->value.psz) );
232 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
234 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
237 /*********** File **************/
238 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
239 module_config_t *_p_item,
240 QWidget *_parent, QGridLayout *l,
241 int &line, bool pwd ) :
242 VStringConfigControl( _p_this, _p_item, _parent )
244 label = new QLabel( qtr(p_item->psz_text) );
245 text = new QLineEdit( qfu(p_item->value.psz) );
246 browse = new QPushButton( qtr( "Browse..." ) );
247 QHBoxLayout *textAndButton = new QHBoxLayout();
248 textAndButton->setMargin( 0 );
249 textAndButton->addWidget( text, 2 );
250 textAndButton->addWidget( browse, 0 );
252 BUTTONACT( browse, updateField() );
258 QHBoxLayout *layout = new QHBoxLayout();
259 layout->addWidget( label, 0 );
260 layout->addLayout( textAndButton, 1 );
261 widget->setLayout( layout );
265 l->addWidget( label, line, 0 );
266 l->addLayout( textAndButton, line, 1 );
271 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
272 module_config_t *_p_item,
273 QLabel *_label, QLineEdit *_text,
274 QPushButton *_button, bool pwd ):
275 VStringConfigControl( _p_this, _p_item )
281 BUTTONACT( browse, updateField() );
286 void FileConfigControl::updateField()
288 QString file = QFileDialog::getOpenFileName( NULL,
289 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
290 if( file.isNull() ) return;
291 text->setText( file );
294 void FileConfigControl::finish()
296 text->setText( qfu(p_item->value.psz) );
297 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
299 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
302 /********* String / Directory **********/
303 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
304 module_config_t *_p_item, QWidget *_p_widget,
305 QGridLayout *_p_layout, int& _int, bool _pwd ) :
306 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
309 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
310 module_config_t *_p_item, QLabel *_p_label,
311 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
312 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
315 void DirectoryConfigControl::updateField()
317 QString dir = QFileDialog::getExistingDirectory( NULL,
318 qtr( "Select Directory" ),
319 text->text().isEmpty() ?
320 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
321 QFileDialog::ShowDirsOnly |
322 QFileDialog::DontResolveSymlinks );
323 if( dir.isNull() ) return;
324 text->setText( dir );
327 /********* String / Font **********/
328 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
329 module_config_t *_p_item, QWidget *_p_widget,
330 QGridLayout *_p_layout, int& _int, bool _pwd ) :
331 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
334 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
335 module_config_t *_p_item, QLabel *_p_label,
336 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
337 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
340 void FontConfigControl::updateField()
343 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
345 text->setText( font.family() );
348 /********* String / choice list **********/
349 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
350 module_config_t *_p_item, QWidget *_parent, bool bycat,
351 QGridLayout *l, int &line) :
352 VStringConfigControl( _p_this, _p_item, _parent )
354 label = new QLabel( qtr(p_item->psz_text) );
355 combo = new QComboBox();
359 QHBoxLayout *layout = new QHBoxLayout();
360 layout->addWidget( label ); layout->addWidget( combo );
361 widget->setLayout( layout );
365 l->addWidget( label, line, 0 );
366 l->addWidget( combo, line, 1, Qt::AlignRight );
369 if( p_item->i_action )
371 QSignalMapper *signalMapper = new QSignalMapper(this);
373 /* Some stringLists like Capture listings have action associated */
374 for( int i = 0; i < p_item->i_action; i++ )
376 QPushButton *button =
377 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
378 CONNECT( button, clicked(), signalMapper, map() );
379 signalMapper->setMapping( button, i );
380 l->addWidget( button, line, 2 + i, Qt::AlignRight );
382 CONNECT( signalMapper, mapped( int ),
383 this, actionRequested( int ) );
387 void StringListConfigControl::actionRequested( int i_action )
389 /* Supplementary check for boundaries */
390 if( i_action < 0 || i_action >= p_item->i_action ) return;
394 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
396 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
398 if( p_item->b_dirty )
402 p_item->b_dirty = VLC_FALSE;
405 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
406 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
407 bool bycat ) : VStringConfigControl( _p_this, _p_item )
414 void StringListConfigControl::finish( bool bycat )
416 combo->setEditable( false );
418 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
420 combo->addItem( qfu(p_item->ppsz_list_text ?
421 p_item->ppsz_list_text[i_index] :
422 p_item->ppsz_list[i_index] ),
423 QVariant( p_item->ppsz_list[i_index] ) );
424 if( p_item->value.psz && !strcmp( p_item->value.psz,
425 p_item->ppsz_list[i_index] ) )
426 combo->setCurrentIndex( combo->count() - 1 );
428 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
430 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
433 QString StringListConfigControl::getValue()
435 return combo->itemData( combo->currentIndex() ).toString();
438 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
439 QComboBox *combo, QWidget *parent )
441 module_config_t *p_config =
442 config_FindConfig( VLC_OBJECT(p_intf), configname );
445 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
447 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
448 QVariant( p_config->pi_list[i_index] ) );
449 if( p_config->value.i == p_config->pi_list[i_index] )
451 combo->setCurrentIndex( i_index );
454 combo->setToolTip( qfu( p_config->psz_longtext ) );
458 /********* Module **********/
459 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
460 module_config_t *_p_item, QWidget *_parent, bool bycat,
461 QGridLayout *l, int &line) :
462 VStringConfigControl( _p_this, _p_item, _parent )
464 label = new QLabel( qtr(p_item->psz_text) );
465 combo = new QComboBox();
469 QHBoxLayout *layout = new QHBoxLayout();
470 layout->addWidget( label ); layout->addWidget( combo );
471 widget->setLayout( layout );
475 l->addWidget( label, line, 0 );
476 l->addWidget( combo, line, 1, Qt::AlignRight );
480 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
481 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
482 bool bycat ) : VStringConfigControl( _p_this, _p_item )
489 void ModuleConfigControl::finish( bool bycat )
494 combo->setEditable( false );
496 /* build a list of available modules */
497 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
498 combo->addItem( qtr("Default") );
499 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
501 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
505 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
507 for (size_t i = 0; i < p_parser->confsize; i++)
509 module_config_t *p_config = p_parser->p_config + i;
510 /* Hack: required subcategory is stored in i_min */
511 if( p_config->i_type == CONFIG_SUBCATEGORY &&
512 p_config->value.i == p_item->min.i )
513 combo->addItem( qtr( module_GetLongName( p_parser )),
514 QVariant( module_GetObjName( p_parser ) ) );
515 if( p_item->value.psz && !strcmp( p_item->value.psz,
516 module_GetObjName( p_parser ) ) )
517 combo->setCurrentIndex( combo->count() - 1 );
520 else if( module_IsCapable( p_parser, p_item->psz_type ) )
522 combo->addItem( qtr(module_GetLongName( p_parser ) ),
523 QVariant( module_GetObjName( p_parser ) ) );
524 if( p_item->value.psz && !strcmp( p_item->value.psz,
525 module_GetObjName( p_parser ) ) )
526 combo->setCurrentIndex( combo->count() - 1 );
529 vlc_list_release( p_list );
530 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
532 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
535 QString ModuleConfigControl::getValue()
537 return combo->itemData( combo->currentIndex() ).toString();
540 /********* Module list **********/
541 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
542 module_config_t *_p_item, QWidget *_parent, bool bycat,
543 QGridLayout *l, int &line) :
544 VStringConfigControl( _p_this, _p_item, _parent )
546 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
547 text = new QLineEdit();
548 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
553 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
554 it != modules.end(); it++ )
556 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
558 layoutGroupBox->addWidget( text, boxline, 0 );
562 QVBoxLayout *layout = new QVBoxLayout();
563 layout->addWidget( groupBox, line, 0 );
564 widget->setLayout( layout );
568 l->addWidget( groupBox, line, 0, 1, -1 );
571 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
574 ModuleListConfigControl::~ModuleListConfigControl()
576 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
577 it != modules.end(); it++ )
585 #define CHECKBOX_LISTS \
587 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
588 checkBoxListItem *cbl = new checkBoxListItem; \
590 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
591 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
592 cbl->checkBox = cb; \
595 while( p_parser->pp_shortcuts[++i] != NULL); \
598 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
599 : module_GetObjName( p_parser ) ); \
600 modules.push_back( cbl ); \
604 void ModuleListConfigControl::finish( bool bycat )
609 /* build a list of available modules */
610 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
611 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
613 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
617 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
619 for (size_t i = 0; i < p_parser->confsize; i++)
621 module_config_t *p_config = p_parser->p_config + i;
622 /* Hack: required subcategory is stored in i_min */
623 if( p_config->i_type == CONFIG_SUBCATEGORY &&
624 p_config->value.i == p_item->min.i )
630 else if( module_IsCapable( p_parser, p_item->psz_type ) )
635 vlc_list_release( p_list );
636 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
638 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
640 #undef CHECKBOX_LISTS
642 QString ModuleListConfigControl::getValue()
647 void ModuleListConfigControl::hide()
649 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
650 it != modules.end(); it++ )
652 (*it)->checkBox->hide();
657 void ModuleListConfigControl::show()
659 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
660 it != modules.end(); it++ )
662 (*it)->checkBox->show();
668 void ModuleListConfigControl::onUpdate( int value )
673 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
674 it != modules.end(); it++ )
676 if( (*it)->checkBox->isChecked() )
680 text->setText( text->text() + (*it)->psz_module );
685 text->setText( text->text() + ":" + (*it)->psz_module );
691 /**************************************************************************
692 * Integer-based controls
693 *************************************************************************/
695 /*********** Integer **************/
696 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
697 module_config_t *_p_item,
698 QWidget *_parent, QGridLayout *l,
700 VIntConfigControl( _p_this, _p_item, _parent )
702 label = new QLabel( qtr(p_item->psz_text) );
703 spin = new QSpinBox; spin->setMinimumWidth( 80 );
704 spin->setAlignment( Qt::AlignRight );
705 spin->setMaximumWidth( 90 );
710 QHBoxLayout *layout = new QHBoxLayout();
711 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
712 widget->setLayout( layout );
716 l->addWidget( label, line, 0 );
717 l->addWidget( spin, line, 1, Qt::AlignRight );
720 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
721 module_config_t *_p_item,
722 QLabel *_label, QSpinBox *_spin ) :
723 VIntConfigControl( _p_this, _p_item )
730 void IntegerConfigControl::finish()
732 spin->setMaximum( 2000000000 );
733 spin->setMinimum( -2000000000 );
734 spin->setValue( p_item->value.i );
735 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
737 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
740 int IntegerConfigControl::getValue()
742 return spin->value();
745 /********* Integer range **********/
746 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
747 module_config_t *_p_item,
748 QWidget *_parent, QGridLayout *l,
750 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
755 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
756 module_config_t *_p_item,
757 QLabel *_label, QSpinBox *_spin ) :
758 IntegerConfigControl( _p_this, _p_item, _label, _spin )
763 void IntegerRangeConfigControl::finish()
765 spin->setMaximum( p_item->max.i );
766 spin->setMinimum( p_item->min.i );
769 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
770 vlc_object_t *_p_this,
771 module_config_t *_p_item,
772 QLabel *_label, QSlider *_slider ):
773 VIntConfigControl( _p_this, _p_item )
777 slider->setMaximum( p_item->max.i );
778 slider->setMinimum( p_item->min.i );
779 slider->setValue( p_item->value.i );
780 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
782 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
785 int IntegerRangeSliderConfigControl::getValue()
787 return slider->value();
791 /********* Integer / choice list **********/
792 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
793 module_config_t *_p_item, QWidget *_parent, bool bycat,
794 QGridLayout *l, int &line) :
795 VIntConfigControl( _p_this, _p_item, _parent )
797 label = new QLabel( qtr(p_item->psz_text) );
798 combo = new QComboBox();
802 QHBoxLayout *layout = new QHBoxLayout();
803 layout->addWidget( label ); layout->addWidget( combo );
804 widget->setLayout( layout );
808 l->addWidget( label, line, 0 );
809 l->addWidget( combo, line, 1, Qt::AlignRight );
812 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
813 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
814 bool bycat ) : VIntConfigControl( _p_this, _p_item )
821 void IntegerListConfigControl::finish( bool bycat )
823 combo->setEditable( false );
825 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
827 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
828 QVariant( p_item->pi_list[i_index] ) );
829 if( p_item->value.i == p_item->pi_list[i_index] )
830 combo->setCurrentIndex( combo->count() - 1 );
832 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
834 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
837 int IntegerListConfigControl::getValue()
839 return combo->itemData( combo->currentIndex() ).toInt();
842 /*********** Boolean **************/
843 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
844 module_config_t *_p_item,
845 QWidget *_parent, QGridLayout *l,
847 VIntConfigControl( _p_this, _p_item, _parent )
849 checkbox = new QCheckBox( qtr(p_item->psz_text) );
854 QHBoxLayout *layout = new QHBoxLayout();
855 layout->addWidget( checkbox, 0 );
856 widget->setLayout( layout );
860 l->addWidget( checkbox, line, 0 );
863 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
864 module_config_t *_p_item,
866 QCheckBox *_checkbox,
868 VIntConfigControl( _p_this, _p_item )
870 checkbox = _checkbox;
874 void BoolConfigControl::finish()
876 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
878 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
881 int BoolConfigControl::getValue()
883 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
886 /**************************************************************************
887 * Float-based controls
888 *************************************************************************/
890 /*********** Float **************/
891 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
892 module_config_t *_p_item,
893 QWidget *_parent, QGridLayout *l,
895 VFloatConfigControl( _p_this, _p_item, _parent )
897 label = new QLabel( qtr(p_item->psz_text) );
898 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
899 spin->setMaximumWidth( 90 );
900 spin->setAlignment( Qt::AlignRight );
905 QHBoxLayout *layout = new QHBoxLayout();
906 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
907 widget->setLayout( layout );
911 l->addWidget( label, line, 0 );
912 l->addWidget( spin, line, 1, Qt::AlignRight );
916 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
917 module_config_t *_p_item,
919 QDoubleSpinBox *_spin ) :
920 VFloatConfigControl( _p_this, _p_item )
927 void FloatConfigControl::finish()
929 spin->setMaximum( 2000000000. );
930 spin->setMinimum( -2000000000. );
931 spin->setSingleStep( 0.1 );
932 spin->setValue( (double)p_item->value.f );
933 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
935 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
938 float FloatConfigControl::getValue()
940 return (float)spin->value();
943 /*********** Float with range **************/
944 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
945 module_config_t *_p_item,
946 QWidget *_parent, QGridLayout *l,
948 FloatConfigControl( _p_this, _p_item, _parent, l, line )
953 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
954 module_config_t *_p_item,
956 QDoubleSpinBox *_spin ) :
957 FloatConfigControl( _p_this, _p_item, _label, _spin )
962 void FloatRangeConfigControl::finish()
964 spin->setMaximum( (double)p_item->max.f );
965 spin->setMinimum( (double)p_item->min.f );
969 /**********************************************************************
970 * Key selector widget
971 **********************************************************************/
972 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
973 module_config_t *_p_item,
974 QWidget *_parent, QGridLayout *l,
976 ConfigControl( _p_this, _p_item, _parent )
979 QWidget *keyContainer = new QWidget;
980 QGridLayout *gLayout = new QGridLayout( keyContainer );
982 label = new QLabel( qtr("Select an action to change the associated hotkey") );
983 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
985 table = new QTreeWidget;
986 table->setColumnCount(2);
987 table->headerItem()->setText( 0, qtr( "Action" ) );
988 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
990 QLineEdit *shortcutValue = new QLineEdit;
991 shortcutValue->setReadOnly(true);
992 QLineEdit *actionSearch = new QLineEdit;
994 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
995 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
998 gLayout->addWidget( label, 0, 0, 1, 4 );
999 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1000 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1001 gLayout->addWidget( table, 2, 0, 1, 4 );
1002 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1003 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1004 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1006 if( !l ) /* This shouldn't happen */
1008 QVBoxLayout *layout = new QVBoxLayout();
1009 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
1010 widget->setLayout( layout );
1014 l->addWidget( keyContainer, 0, 0, 1, 2 );
1018 void KeySelectorControl::finish()
1021 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1023 /* Fill the table */
1024 table->setColumnCount( 2 );
1025 table->setAlternatingRowColors( true );
1027 module_t *p_main = config_FindModule( p_this, "main" );
1030 for (size_t i = 0; i < p_main->confsize; i++)
1032 module_config_t *p_item = p_main->p_config + i;
1034 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1035 strstr( p_item->psz_name , "key-" ) )
1037 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1038 treeItem->setText( 0, qtr( p_item->psz_text ) );
1039 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1040 treeItem->setData( 0, Qt::UserRole,
1041 QVariant::fromValue( (void*)p_item ) );
1043 table->addTopLevelItem( treeItem );
1046 table->resizeColumnToContents( 0 );
1048 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1049 this, selectKey( QTreeWidgetItem * ) );
1052 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1054 module_config_t *p_keyItem = static_cast<module_config_t*>
1055 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1057 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1059 if( d->result() == QDialog::Accepted )
1061 p_keyItem->value.i = d->keyValue;
1064 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1066 QTreeWidgetItem *it = table->topLevelItem(i);
1067 module_config_t *p_item = static_cast<module_config_t*>
1068 (it->data( 0, Qt::UserRole ).value<void*>());
1069 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1070 p_item->value.i = 0;
1071 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1075 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1080 void KeySelectorControl::doApply()
1082 foreach( module_config_t *p_current, values )
1084 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1088 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1089 const char * _keyToChange ) :
1090 QDialog(0), keyValue(0)
1095 keyToChange = _keyToChange;
1096 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1098 QVBoxLayout *l = new QVBoxLayout( this );
1099 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1100 warning = new QLabel();
1101 l->addWidget( selected , Qt::AlignCenter );
1102 l->addWidget( warning, Qt::AlignCenter );
1104 QHBoxLayout *l2 = new QHBoxLayout();
1105 QPushButton *ok = new QPushButton( qtr("OK") );
1106 l2->addWidget( ok );
1107 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1108 l2->addWidget( cancel );
1110 BUTTONACT( ok, accept() );
1111 BUTTONACT( cancel, reject() );
1116 void KeyInputDialog::checkForConflicts( int i_vlckey )
1119 module_config_t *p_current = NULL;
1120 foreach( p_current, values )
1122 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1132 qtr("Warning: the key is already assigned to \"") +
1133 QString( p_current->psz_text ) + "\"" );
1135 else warning->setText( "" );
1138 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1140 if( e->key() == Qt::Key_Tab ) return;
1141 int i_vlck = qtEventToVLCKey( e );
1142 selected->setText( VLCKeyToString( i_vlck ) );
1143 checkForConflicts( i_vlck );
1147 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1149 int i_vlck = qtWheelEventToVLCKey( e );
1150 selected->setText( VLCKeyToString( i_vlck ) );
1151 checkForConflicts( i_vlck );