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
31 * - Implement update stuff using a general Updated signal
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>
48 QString formatTooltip(const QString & tooltip)
51 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
52 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
53 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
54 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
55 "-qt-block-indent:0; text-indent:0px;\">" +
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62 module_config_t *p_item,
66 return createControl( p_this, p_item, parent, NULL, i );
69 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
70 module_config_t *p_item,
72 QGridLayout *l, int &line )
74 ConfigControl *p_control = NULL;
75 if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
77 switch( p_item->i_type )
79 case CONFIG_ITEM_MODULE:
80 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
83 case CONFIG_ITEM_MODULE_CAT:
84 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
87 case CONFIG_ITEM_MODULE_LIST:
88 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
91 case CONFIG_ITEM_MODULE_LIST_CAT:
92 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
95 case CONFIG_ITEM_STRING:
97 p_control = new StringConfigControl( p_this, p_item, parent,
100 p_control = new StringListConfigControl( p_this, p_item,
101 parent, false, l, line );
103 case CONFIG_ITEM_PASSWORD:
104 if( !p_item->i_list )
105 p_control = new StringConfigControl( p_this, p_item, parent,
108 p_control = new StringListConfigControl( p_this, p_item,
109 parent, true, l, line );
111 case CONFIG_ITEM_INTEGER:
113 p_control = new IntegerListConfigControl( p_this, p_item,
114 parent, false, l, line );
115 else if( p_item->min.i || p_item->max.i )
116 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
119 p_control = new IntegerConfigControl( p_this, p_item, parent,
122 case CONFIG_ITEM_FILE:
123 p_control = new FileConfigControl( p_this, p_item, parent, l,
126 case CONFIG_ITEM_DIRECTORY:
127 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
130 case CONFIG_ITEM_FONT:
131 p_control = new FontConfigControl( p_this, p_item, parent, l,
134 case CONFIG_ITEM_KEY:
135 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
137 case CONFIG_ITEM_BOOL:
138 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
140 case CONFIG_ITEM_FLOAT:
141 if( p_item->min.f || p_item->max.f )
142 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
145 p_control = new FloatConfigControl( p_this, p_item, parent,
154 void ConfigControl::doApply( intf_thread_t *p_intf )
160 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
162 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
167 VFloatConfigControl *vfcc =
168 qobject_cast<VFloatConfigControl *>(this);
170 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
175 VStringConfigControl *vscc =
176 qobject_cast<VStringConfigControl *>(this);
178 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
183 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
190 /**************************************************************************
191 * String-based controls
192 *************************************************************************/
194 /*********** String **************/
195 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
196 module_config_t *_p_item,
197 QWidget *_parent, QGridLayout *l,
198 int &line, bool pwd ) :
199 VStringConfigControl( _p_this, _p_item, _parent )
201 label = new QLabel( qtr(p_item->psz_text) );
202 text = new QLineEdit( qfu(p_item->value.psz) );
203 if( pwd ) text->setEchoMode( QLineEdit::Password );
208 QHBoxLayout *layout = new QHBoxLayout();
209 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
210 widget->setLayout( layout );
214 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
218 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
219 module_config_t *_p_item,
220 QLabel *_label, QLineEdit *_text, bool pwd ):
221 VStringConfigControl( _p_this, _p_item )
228 void StringConfigControl::finish()
230 text->setText( qfu(p_item->value.psz) );
231 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
233 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
236 /*********** File **************/
237 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
238 module_config_t *_p_item,
239 QWidget *_parent, QGridLayout *l,
240 int &line, bool pwd ) :
241 VStringConfigControl( _p_this, _p_item, _parent )
243 label = new QLabel( qtr(p_item->psz_text) );
244 text = new QLineEdit( qfu(p_item->value.psz) );
245 browse = new QPushButton( qtr( "Browse..." ) );
246 QHBoxLayout *textAndButton = new QHBoxLayout();
247 textAndButton->setMargin( 0 );
248 textAndButton->addWidget( text, 2 );
249 textAndButton->addWidget( browse, 0 );
251 BUTTONACT( browse, updateField() );
257 QHBoxLayout *layout = new QHBoxLayout();
258 layout->addWidget( label, 0 );
259 layout->addLayout( textAndButton, 1 );
260 widget->setLayout( layout );
264 l->addWidget( label, line, 0 );
265 l->addLayout( textAndButton, line, 1 );
270 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
271 module_config_t *_p_item,
272 QLabel *_label, QLineEdit *_text,
273 QPushButton *_button, bool pwd ):
274 VStringConfigControl( _p_this, _p_item )
280 BUTTONACT( browse, updateField() );
285 void FileConfigControl::updateField()
287 QString file = QFileDialog::getOpenFileName( NULL,
288 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
289 if( file.isNull() ) return;
290 text->setText( file );
293 void FileConfigControl::finish()
295 text->setText( qfu(p_item->value.psz) );
296 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
298 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
301 /********* String / Directory **********/
302 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
303 module_config_t *_p_item, QWidget *_p_widget,
304 QGridLayout *_p_layout, int& _int, bool _pwd ) :
305 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
308 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
309 module_config_t *_p_item, QLabel *_p_label,
310 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
311 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
314 void DirectoryConfigControl::updateField()
316 QString dir = QFileDialog::getExistingDirectory( NULL,
317 qtr( "Select Directory" ),
318 text->text().isEmpty() ?
319 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
320 QFileDialog::ShowDirsOnly |
321 QFileDialog::DontResolveSymlinks );
322 if( dir.isNull() ) return;
323 text->setText( dir );
326 /********* String / Font **********/
327 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
328 module_config_t *_p_item, QWidget *_p_widget,
329 QGridLayout *_p_layout, int& _int, bool _pwd ) :
330 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
333 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
334 module_config_t *_p_item, QLabel *_p_label,
335 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
336 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
339 void FontConfigControl::updateField()
342 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
344 text->setText( font.family() );
347 /********* String / choice list **********/
348 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
349 module_config_t *_p_item, QWidget *_parent, bool bycat,
350 QGridLayout *l, int &line) :
351 VStringConfigControl( _p_this, _p_item, _parent )
353 label = new QLabel( qtr(p_item->psz_text) );
354 combo = new QComboBox();
358 QHBoxLayout *layout = new QHBoxLayout();
359 layout->addWidget( label ); layout->addWidget( combo );
360 widget->setLayout( layout );
364 l->addWidget( label, line, 0 );
365 l->addWidget( combo, line, 1, Qt::AlignRight );
368 if( p_item->i_action )
370 QSignalMapper *signalMapper = new QSignalMapper(this);
372 /* Some stringLists like Capture listings have action associated */
373 for( int i = 0; i < p_item->i_action; i++ )
375 QPushButton *button =
376 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
377 CONNECT( button, clicked(), signalMapper, map() );
378 signalMapper->setMapping( button, i );
379 l->addWidget( button, line, 2 + i, Qt::AlignRight );
381 CONNECT( signalMapper, mapped( int ),
382 this, actionRequested( int ) );
386 void StringListConfigControl::actionRequested( int i_action )
388 /* Supplementary check for boundaries */
389 if( i_action < 0 || i_action >= p_item->i_action ) return;
392 val.psz_string = qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
394 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
396 if( p_item->b_dirty )
400 p_item->b_dirty = VLC_FALSE;
404 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
405 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
406 bool bycat ) : VStringConfigControl( _p_this, _p_item )
413 void StringListConfigControl::finish( bool bycat )
415 combo->setEditable( false );
417 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
419 combo->addItem( qfu(p_item->ppsz_list_text ?
420 p_item->ppsz_list_text[i_index] :
421 p_item->ppsz_list[i_index] ),
422 QVariant( p_item->ppsz_list[i_index] ) );
423 if( p_item->value.psz && !strcmp( p_item->value.psz,
424 p_item->ppsz_list[i_index] ) )
425 combo->setCurrentIndex( combo->count() - 1 );
427 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
429 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
432 QString StringListConfigControl::getValue()
434 return combo->itemData( combo->currentIndex() ).toString();
437 /********* Module **********/
438 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
439 module_config_t *_p_item, QWidget *_parent, bool bycat,
440 QGridLayout *l, int &line) :
441 VStringConfigControl( _p_this, _p_item, _parent )
443 label = new QLabel( qtr(p_item->psz_text) );
444 combo = new QComboBox();
448 QHBoxLayout *layout = new QHBoxLayout();
449 layout->addWidget( label ); layout->addWidget( combo );
450 widget->setLayout( layout );
454 l->addWidget( label, line, 0 );
455 l->addWidget( combo, line, 1, Qt::AlignRight );
459 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
460 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
461 bool bycat ) : VStringConfigControl( _p_this, _p_item )
468 void ModuleConfigControl::finish( bool bycat )
473 combo->setEditable( false );
475 /* build a list of available modules */
476 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
477 combo->addItem( qtr("Default") );
478 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
480 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
484 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
486 for (size_t i = 0; i < p_parser->confsize; i++)
488 module_config_t *p_config = p_parser->p_config + i;
489 /* Hack: required subcategory is stored in i_min */
490 if( p_config->i_type == CONFIG_SUBCATEGORY &&
491 p_config->value.i == p_item->min.i )
492 combo->addItem( qtr( module_GetLongName( p_parser )),
493 QVariant( module_GetObjName( p_parser ) ) );
494 if( p_item->value.psz && !strcmp( p_item->value.psz,
495 module_GetObjName( p_parser ) ) )
496 combo->setCurrentIndex( combo->count() - 1 );
499 else if( module_IsCapable( p_parser, p_item->psz_type ) )
501 combo->addItem( qtr(module_GetLongName( p_parser ) ),
502 QVariant( module_GetObjName( p_parser ) ) );
503 if( p_item->value.psz && !strcmp( p_item->value.psz,
504 module_GetObjName( p_parser ) ) )
505 combo->setCurrentIndex( combo->count() - 1 );
508 vlc_list_release( p_list );
509 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
511 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
514 QString ModuleConfigControl::getValue()
516 return combo->itemData( combo->currentIndex() ).toString();
519 /********* Module list **********/
520 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
521 module_config_t *_p_item, QWidget *_parent, bool bycat,
522 QGridLayout *l, int &line) :
523 VStringConfigControl( _p_this, _p_item, _parent )
525 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
526 text = new QLineEdit();
527 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
532 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
533 it != modules.end(); it++ )
535 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
537 layoutGroupBox->addWidget( text, boxline, 0 );
541 QVBoxLayout *layout = new QVBoxLayout();
542 layout->addWidget( groupBox, line, 0 );
543 widget->setLayout( layout );
547 l->addWidget( groupBox, line, 0, 1, -1 );
550 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
553 ModuleListConfigControl::~ModuleListConfigControl()
555 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
556 it != modules.end(); it++ )
564 #define CHECKBOX_LISTS \
566 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
567 checkBoxListItem *cbl = new checkBoxListItem; \
569 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
570 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
571 cbl->checkBox = cb; \
574 while( p_parser->pp_shortcuts[++i] != NULL); \
577 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
578 : module_GetObjName( p_parser ) ); \
579 modules.push_back( cbl ); \
583 void ModuleListConfigControl::finish( bool bycat )
588 /* build a list of available modules */
589 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
590 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
592 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
596 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
598 for (size_t i = 0; i < p_parser->confsize; i++)
600 module_config_t *p_config = p_parser->p_config + i;
601 /* Hack: required subcategory is stored in i_min */
602 if( p_config->i_type == CONFIG_SUBCATEGORY &&
603 p_config->value.i == p_item->min.i )
609 else if( module_IsCapable( p_parser, p_item->psz_type ) )
614 vlc_list_release( p_list );
615 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
617 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
619 #undef CHECKBOX_LISTS
621 QString ModuleListConfigControl::getValue()
626 void ModuleListConfigControl::hide()
628 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
629 it != modules.end(); it++ )
631 (*it)->checkBox->hide();
636 void ModuleListConfigControl::show()
638 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
639 it != modules.end(); it++ )
641 (*it)->checkBox->show();
647 void ModuleListConfigControl::onUpdate( int value )
652 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
653 it != modules.end(); it++ )
655 if( (*it)->checkBox->isChecked() )
659 text->setText( text->text() + (*it)->psz_module );
664 text->setText( text->text() + ":" + (*it)->psz_module );
671 /**************************************************************************
672 * Integer-based controls
673 *************************************************************************/
675 /*********** Integer **************/
676 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
677 module_config_t *_p_item,
678 QWidget *_parent, QGridLayout *l,
680 VIntConfigControl( _p_this, _p_item, _parent )
682 label = new QLabel( qtr(p_item->psz_text) );
683 spin = new QSpinBox; spin->setMinimumWidth( 80 );
684 spin->setAlignment( Qt::AlignRight );
685 spin->setMaximumWidth( 90 );
690 QHBoxLayout *layout = new QHBoxLayout();
691 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
692 widget->setLayout( layout );
696 l->addWidget( label, line, 0 );
697 l->addWidget( spin, line, 1, Qt::AlignRight );
700 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
701 module_config_t *_p_item,
702 QLabel *_label, QSpinBox *_spin ) :
703 VIntConfigControl( _p_this, _p_item )
710 void IntegerConfigControl::finish()
712 spin->setMaximum( 2000000000 );
713 spin->setMinimum( -2000000000 );
714 spin->setValue( p_item->value.i );
715 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
717 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
720 int IntegerConfigControl::getValue()
722 return spin->value();
725 /********* Integer range **********/
726 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
727 module_config_t *_p_item,
728 QWidget *_parent, QGridLayout *l,
730 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
735 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
736 module_config_t *_p_item,
737 QLabel *_label, QSpinBox *_spin ) :
738 IntegerConfigControl( _p_this, _p_item, _label, _spin )
743 void IntegerRangeConfigControl::finish()
745 spin->setMaximum( p_item->max.i );
746 spin->setMinimum( p_item->min.i );
749 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
750 vlc_object_t *_p_this,
751 module_config_t *_p_item,
752 QLabel *_label, QSlider *_slider ):
753 VIntConfigControl( _p_this, _p_item )
757 slider->setMaximum( p_item->max.i );
758 slider->setMinimum( p_item->min.i );
759 slider->setValue( p_item->value.i );
760 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
762 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
765 int IntegerRangeSliderConfigControl::getValue()
767 return slider->value();
771 /********* Integer / choice list **********/
772 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
773 module_config_t *_p_item, QWidget *_parent, bool bycat,
774 QGridLayout *l, int &line) :
775 VIntConfigControl( _p_this, _p_item, _parent )
777 label = new QLabel( qtr(p_item->psz_text) );
778 combo = new QComboBox();
782 QHBoxLayout *layout = new QHBoxLayout();
783 layout->addWidget( label ); layout->addWidget( combo );
784 widget->setLayout( layout );
788 l->addWidget( label, line, 0 );
789 l->addWidget( combo, line, 1, Qt::AlignRight );
792 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
793 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
794 bool bycat ) : VIntConfigControl( _p_this, _p_item )
801 void IntegerListConfigControl::finish( bool bycat )
803 combo->setEditable( false );
805 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
807 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
808 QVariant( p_item->pi_list[i_index] ) );
809 if( p_item->value.i == p_item->pi_list[i_index] )
810 combo->setCurrentIndex( combo->count() - 1 );
812 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
814 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
817 int IntegerListConfigControl::getValue()
819 return combo->itemData( combo->currentIndex() ).toInt();
822 /*********** Boolean **************/
823 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
824 module_config_t *_p_item,
825 QWidget *_parent, QGridLayout *l,
827 VIntConfigControl( _p_this, _p_item, _parent )
829 checkbox = new QCheckBox( qtr(p_item->psz_text) );
834 QHBoxLayout *layout = new QHBoxLayout();
835 layout->addWidget( checkbox, 0 );
836 widget->setLayout( layout );
840 l->addWidget( checkbox, line, 0 );
843 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
844 module_config_t *_p_item,
846 QCheckBox *_checkbox,
848 VIntConfigControl( _p_this, _p_item )
850 checkbox = _checkbox;
854 void BoolConfigControl::finish()
856 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
858 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
861 int BoolConfigControl::getValue()
863 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
866 /**************************************************************************
867 * Float-based controls
868 *************************************************************************/
870 /*********** Float **************/
871 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
872 module_config_t *_p_item,
873 QWidget *_parent, QGridLayout *l,
875 VFloatConfigControl( _p_this, _p_item, _parent )
877 label = new QLabel( qtr(p_item->psz_text) );
878 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
879 spin->setMaximumWidth( 90 );
880 spin->setAlignment( Qt::AlignRight );
885 QHBoxLayout *layout = new QHBoxLayout();
886 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
887 widget->setLayout( layout );
891 l->addWidget( label, line, 0 );
892 l->addWidget( spin, line, 1, Qt::AlignRight );
896 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
897 module_config_t *_p_item,
899 QDoubleSpinBox *_spin ) :
900 VFloatConfigControl( _p_this, _p_item )
907 void FloatConfigControl::finish()
909 spin->setMaximum( 2000000000. );
910 spin->setMinimum( -2000000000. );
911 spin->setSingleStep( 0.1 );
912 spin->setValue( (double)p_item->value.f );
913 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
915 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
918 float FloatConfigControl::getValue()
920 return (float)spin->value();
923 /*********** Float with range **************/
924 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
925 module_config_t *_p_item,
926 QWidget *_parent, QGridLayout *l,
928 FloatConfigControl( _p_this, _p_item, _parent, l, line )
933 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
934 module_config_t *_p_item,
936 QDoubleSpinBox *_spin ) :
937 FloatConfigControl( _p_this, _p_item, _label, _spin )
942 void FloatRangeConfigControl::finish()
944 spin->setMaximum( (double)p_item->max.f );
945 spin->setMinimum( (double)p_item->min.f );
949 /**********************************************************************
950 * Key selector widget
951 **********************************************************************/
952 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
953 module_config_t *_p_item,
954 QWidget *_parent, QGridLayout *l,
956 ConfigControl( _p_this, _p_item, _parent )
959 label = new QLabel( qtr("Select an action to change the associated hotkey") );
960 table = new QTreeWidget( 0 );
965 QVBoxLayout *layout = new QVBoxLayout();
966 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
967 widget->setLayout( layout );
971 l->addWidget( label, line, 0, 1, 2 );
972 l->addWidget( table, line+1, 0, 1,2 );
976 void KeySelectorControl::finish()
979 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
982 table->setColumnCount( 2 );
983 table->setAlternatingRowColors( true );
985 module_t *p_main = config_FindModule( p_this, "main" );
988 for (size_t i = 0; i < p_main->confsize; i++)
990 module_config_t *p_item = p_main->p_config + i;
992 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
993 strstr( p_item->psz_name , "key-" ) )
995 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
996 treeItem->setText( 0, qtr( p_item->psz_text ) );
997 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
998 treeItem->setData( 0, Qt::UserRole,
999 QVariant::fromValue( (void*)p_item ) );
1001 table->addTopLevelItem( treeItem );
1004 table->resizeColumnToContents( 0 );
1006 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1007 this, selectKey( QTreeWidgetItem * ) );
1010 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1012 module_config_t *p_keyItem = static_cast<module_config_t*>
1013 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1015 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1017 if( d->result() == QDialog::Accepted )
1019 p_keyItem->value.i = d->keyValue;
1022 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1024 QTreeWidgetItem *it = table->topLevelItem(i);
1025 module_config_t *p_item = static_cast<module_config_t*>
1026 (it->data( 0, Qt::UserRole ).value<void*>());
1027 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1028 p_item->value.i = 0;
1029 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1033 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1038 void KeySelectorControl::doApply()
1040 foreach( module_config_t *p_current, values )
1042 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1046 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1047 const char * _keyToChange ) :
1048 QDialog(0), keyValue(0)
1053 keyToChange = _keyToChange;
1054 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1056 QVBoxLayout *l = new QVBoxLayout( this );
1057 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1058 warning = new QLabel();
1059 l->addWidget( selected , Qt::AlignCenter );
1060 l->addWidget( warning, Qt::AlignCenter );
1062 QHBoxLayout *l2 = new QHBoxLayout();
1063 QPushButton *ok = new QPushButton( qtr("OK") );
1064 l2->addWidget( ok );
1065 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1066 l2->addWidget( cancel );
1068 BUTTONACT( ok, accept() );
1069 BUTTONACT( cancel, reject() );
1074 void KeyInputDialog::checkForConflicts( int i_vlckey )
1077 module_config_t *p_current = NULL;
1078 foreach( p_current, values )
1080 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1090 qtr("Warning: the key is already assigned to \"") +
1091 QString( p_current->psz_text ) + "\"" );
1093 else warning->setText( "" );
1096 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1098 if( e->key() == Qt::Key_Tab ) return;
1099 int i_vlck = qtEventToVLCKey( e );
1100 selected->setText( VLCKeyToString( i_vlck ) );
1101 checkForConflicts( i_vlck );
1105 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1107 int i_vlck = qtWheelEventToVLCKey( e );
1108 selected->setText( VLCKeyToString( i_vlck ) );
1109 checkForConflicts( i_vlck );