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 * - Password field implementation (through "pwd" bool param
31 * - Validator for modulelist
32 * - Implement update stuff using a general Updated signal
35 #include "components/preferences_widgets.hpp"
36 #include "util/customwidgets.hpp"
43 #include <QGridLayout>
45 #include <QFileDialog>
46 #include <QFontDialog>
48 #include <QTreeWidgetItem>
50 QString formatTooltip(const QString & tooltip)
53 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
54 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
55 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
56 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
57 "-qt-block-indent:0; text-indent:0px;\">" +
63 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
64 module_config_t *p_item,
68 return createControl( p_this, p_item, parent, NULL, i );
71 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
72 module_config_t *p_item,
74 QGridLayout *l, int &line )
76 ConfigControl *p_control = NULL;
77 if( p_item->psz_current ) return NULL;
79 switch( p_item->i_type )
81 case CONFIG_ITEM_MODULE:
82 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
85 case CONFIG_ITEM_MODULE_CAT:
86 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
89 case CONFIG_ITEM_MODULE_LIST:
90 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
93 case CONFIG_ITEM_MODULE_LIST_CAT:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
97 case CONFIG_ITEM_STRING:
99 p_control = new StringConfigControl( p_this, p_item, parent,
102 p_control = new StringListConfigControl( p_this, p_item,
103 parent, false, l, line );
105 case CONFIG_ITEM_PASSWORD:
106 if( !p_item->i_list )
107 p_control = new StringConfigControl( p_this, p_item, parent,
110 p_control = new StringListConfigControl( p_this, p_item,
111 parent, true, l, line );
113 case CONFIG_ITEM_INTEGER:
115 p_control = new IntegerListConfigControl( p_this, p_item,
116 parent, false, l, line );
117 else if( p_item->min.i || p_item->max.i )
118 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
121 p_control = new IntegerConfigControl( p_this, p_item, parent,
124 case CONFIG_ITEM_FILE:
125 p_control = new FileConfigControl( p_this, p_item, parent, l,
128 case CONFIG_ITEM_DIRECTORY:
129 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
132 case CONFIG_ITEM_FONT:
133 p_control = new FontConfigControl( p_this, p_item, parent, l,
136 case CONFIG_ITEM_KEY:
137 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
139 case CONFIG_ITEM_BOOL:
140 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
142 case CONFIG_ITEM_FLOAT:
143 if( p_item->min.f || p_item->max.f )
144 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
147 p_control = new FloatConfigControl( p_this, p_item, parent,
156 void ConfigControl::doApply( intf_thread_t *p_intf )
162 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
164 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
169 VFloatConfigControl *vfcc =
170 qobject_cast<VFloatConfigControl *>(this);
172 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
177 VStringConfigControl *vscc =
178 qobject_cast<VStringConfigControl *>(this);
180 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
185 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
192 /**************************************************************************
193 * String-based controls
194 *************************************************************************/
196 /*********** String **************/
197 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
198 module_config_t *_p_item,
199 QWidget *_parent, QGridLayout *l,
200 int &line, bool pwd ) :
201 VStringConfigControl( _p_this, _p_item, _parent )
203 label = new QLabel( qtr(p_item->psz_text) );
204 text = new QLineEdit( qfu(p_item->value.psz) );
205 if( pwd ) text->setEchoMode( QLineEdit::Password );
210 QHBoxLayout *layout = new QHBoxLayout();
211 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
212 widget->setLayout( layout );
216 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
220 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
221 module_config_t *_p_item,
222 QLabel *_label, QLineEdit *_text, bool pwd ):
223 VStringConfigControl( _p_this, _p_item )
230 void StringConfigControl::finish()
232 text->setText( qfu(p_item->value.psz) );
233 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
235 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
238 /*********** File **************/
239 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
240 module_config_t *_p_item,
241 QWidget *_parent, QGridLayout *l,
242 int &line, bool pwd ) :
243 VStringConfigControl( _p_this, _p_item, _parent )
245 label = new QLabel( qtr(p_item->psz_text) );
246 text = new QLineEdit( qfu(p_item->value.psz) );
247 browse = new QPushButton( qtr( "Browse..." ) );
248 QHBoxLayout *textAndButton = new QHBoxLayout();
249 textAndButton->setMargin( 0 );
250 textAndButton->addWidget( text, 2 );
251 textAndButton->addWidget( browse, 0 );
253 BUTTONACT( browse, updateField() );
259 QHBoxLayout *layout = new QHBoxLayout();
260 layout->addWidget( label, 0 );
261 layout->addLayout( textAndButton, 1 );
262 widget->setLayout( layout );
266 l->addWidget( label, line, 0 );
267 l->addLayout( textAndButton, line, 1 );
272 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
273 module_config_t *_p_item,
274 QLabel *_label, QLineEdit *_text,
275 QPushButton *_button, bool pwd ):
276 VStringConfigControl( _p_this, _p_item )
282 BUTTONACT( browse, updateField() );
287 void FileConfigControl::updateField()
289 QString file = QFileDialog::getOpenFileName( NULL,
290 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
291 if( file.isNull() ) return;
292 text->setText( file );
295 void FileConfigControl::finish()
297 text->setText( qfu(p_item->value.psz) );
298 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
300 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
303 /********* String / Directory **********/
304 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
305 module_config_t *_p_item, QWidget *_p_widget,
306 QGridLayout *_p_layout, int& _int, bool _pwd ) :
307 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
310 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
311 module_config_t *_p_item, QLabel *_p_label,
312 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
313 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
316 void DirectoryConfigControl::updateField()
318 QString dir = QFileDialog::getExistingDirectory( NULL,
319 qtr( "Select Directory" ),
320 text->text().isEmpty() ?
321 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
322 QFileDialog::ShowDirsOnly |
323 QFileDialog::DontResolveSymlinks );
324 if( dir.isNull() ) return;
325 text->setText( dir );
328 /********* String / Font **********/
329 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
330 module_config_t *_p_item, QWidget *_p_widget,
331 QGridLayout *_p_layout, int& _int, bool _pwd ) :
332 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
335 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
336 module_config_t *_p_item, QLabel *_p_label,
337 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
338 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
341 void FontConfigControl::updateField()
344 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
346 text->setText( font.family() );
349 /********* String / choice list **********/
350 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
351 module_config_t *_p_item, QWidget *_parent, bool bycat,
352 QGridLayout *l, int &line) :
353 VStringConfigControl( _p_this, _p_item, _parent )
355 label = new QLabel( qtr(p_item->psz_text) );
356 combo = new QComboBox();
360 QHBoxLayout *layout = new QHBoxLayout();
361 layout->addWidget( label ); layout->addWidget( combo );
362 widget->setLayout( layout );
366 l->addWidget( label, line, 0 );
367 l->addWidget( combo, line, 1, Qt::AlignRight );
370 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
371 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
372 bool bycat ) : VStringConfigControl( _p_this, _p_item )
379 void StringListConfigControl::finish( bool bycat )
381 combo->setEditable( false );
383 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
385 combo->addItem( qfu(p_item->ppsz_list_text ?
386 p_item->ppsz_list_text[i_index] :
387 p_item->ppsz_list[i_index] ),
388 QVariant( p_item->ppsz_list[i_index] ) );
389 if( p_item->value.psz && !strcmp( p_item->value.psz,
390 p_item->ppsz_list[i_index] ) )
391 combo->setCurrentIndex( combo->count() - 1 );
393 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
395 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
398 QString StringListConfigControl::getValue()
400 return combo->itemData( combo->currentIndex() ).toString();
403 /********* Module **********/
404 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
405 module_config_t *_p_item, QWidget *_parent, bool bycat,
406 QGridLayout *l, int &line) :
407 VStringConfigControl( _p_this, _p_item, _parent )
409 label = new QLabel( qtr(p_item->psz_text) );
410 combo = new QComboBox();
414 QHBoxLayout *layout = new QHBoxLayout();
415 layout->addWidget( label ); layout->addWidget( combo );
416 widget->setLayout( layout );
420 l->addWidget( label, line, 0 );
421 l->addWidget( combo, line, 1, Qt::AlignRight );
424 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
425 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
426 bool bycat ) : VStringConfigControl( _p_this, _p_item )
433 void ModuleConfigControl::finish( bool bycat )
438 combo->setEditable( false );
440 /* build a list of available modules */
441 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
442 combo->addItem( qtr("Default") );
443 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
445 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
449 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
451 for (size_t i = 0; i < p_parser->confsize; i++)
453 module_config_t *p_config = p_parser->p_config + i;
454 /* Hack: required subcategory is stored in i_min */
455 if( p_config->i_type == CONFIG_SUBCATEGORY &&
456 p_config->value.i == p_item->min.i )
457 combo->addItem( qtr( module_GetLongName( p_parser )),
458 QVariant( module_GetObjName( p_parser ) ) );
459 if( p_item->value.psz && !strcmp( p_item->value.psz,
460 module_GetObjName( p_parser ) ) )
461 combo->setCurrentIndex( combo->count() - 1 );
464 else if( module_IsCapable( p_parser, p_item->psz_type ) )
466 combo->addItem( qtr(module_GetLongName( p_parser ) ),
467 QVariant( module_GetObjName( p_parser ) ) );
468 if( p_item->value.psz && !strcmp( p_item->value.psz,
469 module_GetObjName( p_parser ) ) )
470 combo->setCurrentIndex( combo->count() - 1 );
473 vlc_list_release( p_list );
474 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
476 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
479 QString ModuleConfigControl::getValue()
481 return combo->itemData( combo->currentIndex() ).toString();
484 /********* Module list **********/
485 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
486 module_config_t *_p_item, QWidget *_parent, bool bycat,
487 QGridLayout *l, int &line) :
488 VStringConfigControl( _p_this, _p_item, _parent )
490 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
491 text = new QLineEdit();
492 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
497 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
498 it != modules.end(); it++ )
500 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
502 layoutGroupBox->addWidget( text, boxline, 0 );
506 QVBoxLayout *layout = new QVBoxLayout();
507 layout->addWidget( groupBox, line, 0 );
508 widget->setLayout( layout );
512 l->addWidget( groupBox, line, 0, 1, -1 );
515 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
518 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
519 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
520 bool bycat ) : VStringConfigControl( _p_this, _p_item )
528 ModuleListConfigControl::~ModuleListConfigControl()
530 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
531 it != modules.end(); it++ )
539 #define CHECKBOX_LISTS \
541 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
542 checkBoxListItem *cbl = new checkBoxListItem; \
544 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
545 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
546 cbl->checkBox = cb; \
549 while( p_parser->pp_shortcuts[++i] != NULL); \
552 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
553 : module_GetObjName( p_parser ) ); \
554 modules.push_back( cbl ); \
558 void ModuleListConfigControl::finish( bool bycat )
563 /* build a list of available modules */
564 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
565 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
567 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
571 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
573 for (size_t i = 0; i < p_parser->confsize; i++)
575 module_config_t *p_config = p_parser->p_config + i;
576 /* Hack: required subcategory is stored in i_min */
577 if( p_config->i_type == CONFIG_SUBCATEGORY &&
578 p_config->value.i == p_item->min.i )
584 else if( module_IsCapable( p_parser, p_item->psz_type ) )
589 vlc_list_release( p_list );
590 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
592 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
594 #undef CHECKBOX_LISTS
596 QString ModuleListConfigControl::getValue()
601 void ModuleListConfigControl::hide()
603 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
604 it != modules.end(); it++ )
606 (*it)->checkBox->hide();
611 void ModuleListConfigControl::show()
613 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
614 it != modules.end(); it++ )
616 (*it)->checkBox->show();
622 void ModuleListConfigControl::onUpdate( int value )
627 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
628 it != modules.end(); it++ )
630 if( (*it)->checkBox->isChecked() )
634 text->setText( text->text() + (*it)->psz_module );
639 text->setText( text->text() + ":" + (*it)->psz_module );
645 /**************************************************************************
646 * Integer-based controls
647 *************************************************************************/
649 /*********** Integer **************/
650 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
651 module_config_t *_p_item,
652 QWidget *_parent, QGridLayout *l,
654 VIntConfigControl( _p_this, _p_item, _parent )
656 label = new QLabel( qtr(p_item->psz_text) );
657 spin = new QSpinBox; spin->setMinimumWidth( 80 );
658 spin->setAlignment( Qt::AlignRight );
659 spin->setMaximumWidth( 90 );
664 QHBoxLayout *layout = new QHBoxLayout();
665 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
666 widget->setLayout( layout );
670 l->addWidget( label, line, 0 );
671 l->addWidget( spin, line, 1, Qt::AlignRight );
674 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
675 module_config_t *_p_item,
676 QLabel *_label, QSpinBox *_spin ) :
677 VIntConfigControl( _p_this, _p_item )
684 void IntegerConfigControl::finish()
686 spin->setMaximum( 2000000000 );
687 spin->setMinimum( -2000000000 );
688 spin->setValue( p_item->value.i );
689 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
691 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
694 int IntegerConfigControl::getValue()
696 return spin->value();
699 /********* Integer range **********/
700 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
701 module_config_t *_p_item,
702 QWidget *_parent, QGridLayout *l,
704 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
709 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
710 module_config_t *_p_item,
711 QLabel *_label, QSpinBox *_spin ) :
712 IntegerConfigControl( _p_this, _p_item, _label, _spin )
717 void IntegerRangeConfigControl::finish()
719 spin->setMaximum( p_item->max.i );
720 spin->setMinimum( p_item->min.i );
723 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
724 vlc_object_t *_p_this,
725 module_config_t *_p_item,
726 QLabel *_label, QSlider *_slider ):
727 VIntConfigControl( _p_this, _p_item )
731 slider->setMaximum( p_item->max.i );
732 slider->setMinimum( p_item->min.i );
733 slider->setValue( p_item->value.i );
734 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
736 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
739 int IntegerRangeSliderConfigControl::getValue()
741 return slider->value();
745 /********* Integer / choice list **********/
746 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
747 module_config_t *_p_item, QWidget *_parent, bool bycat,
748 QGridLayout *l, int &line) :
749 VIntConfigControl( _p_this, _p_item, _parent )
751 label = new QLabel( qtr(p_item->psz_text) );
752 combo = new QComboBox();
756 QHBoxLayout *layout = new QHBoxLayout();
757 layout->addWidget( label ); layout->addWidget( combo );
758 widget->setLayout( layout );
762 l->addWidget( label, line, 0 );
763 l->addWidget( combo, line, 1, Qt::AlignRight );
766 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
767 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
768 bool bycat ) : VIntConfigControl( _p_this, _p_item )
775 void IntegerListConfigControl::finish( bool bycat )
777 combo->setEditable( false );
779 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
781 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
782 QVariant( p_item->pi_list[i_index] ) );
783 if( p_item->value.i == p_item->pi_list[i_index] )
784 combo->setCurrentIndex( combo->count() - 1 );
786 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
788 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
791 int IntegerListConfigControl::getValue()
793 return combo->itemData( combo->currentIndex() ).toInt();
796 /*********** Boolean **************/
797 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
798 module_config_t *_p_item,
799 QWidget *_parent, QGridLayout *l,
801 VIntConfigControl( _p_this, _p_item, _parent )
803 checkbox = new QCheckBox( qtr(p_item->psz_text) );
808 QHBoxLayout *layout = new QHBoxLayout();
809 layout->addWidget( checkbox, 0 );
810 widget->setLayout( layout );
814 l->addWidget( checkbox, line, 0 );
817 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
818 module_config_t *_p_item,
820 QCheckBox *_checkbox,
822 VIntConfigControl( _p_this, _p_item )
824 checkbox = _checkbox;
828 void BoolConfigControl::finish()
830 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
832 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
835 int BoolConfigControl::getValue()
837 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
840 /**************************************************************************
841 * Float-based controls
842 *************************************************************************/
844 /*********** Float **************/
845 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
846 module_config_t *_p_item,
847 QWidget *_parent, QGridLayout *l,
849 VFloatConfigControl( _p_this, _p_item, _parent )
851 label = new QLabel( qtr(p_item->psz_text) );
852 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
853 spin->setMaximumWidth( 90 );
854 spin->setAlignment( Qt::AlignRight );
859 QHBoxLayout *layout = new QHBoxLayout();
860 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
861 widget->setLayout( layout );
865 l->addWidget( label, line, 0 );
866 l->addWidget( spin, line, 1, Qt::AlignRight );
870 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
871 module_config_t *_p_item,
873 QDoubleSpinBox *_spin ) :
874 VFloatConfigControl( _p_this, _p_item )
881 void FloatConfigControl::finish()
883 spin->setMaximum( 2000000000. );
884 spin->setMinimum( -2000000000. );
885 spin->setSingleStep( 0.1 );
886 spin->setValue( (double)p_item->value.f );
887 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
889 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
892 float FloatConfigControl::getValue()
894 return (float)spin->value();
897 /*********** Float with range **************/
898 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
899 module_config_t *_p_item,
900 QWidget *_parent, QGridLayout *l,
902 FloatConfigControl( _p_this, _p_item, _parent, l, line )
907 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
908 module_config_t *_p_item,
910 QDoubleSpinBox *_spin ) :
911 FloatConfigControl( _p_this, _p_item, _label, _spin )
916 void FloatRangeConfigControl::finish()
918 spin->setMaximum( (double)p_item->max.f );
919 spin->setMinimum( (double)p_item->min.f );
923 /**********************************************************************
924 * Key selector widget
925 **********************************************************************/
926 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
927 module_config_t *_p_item,
928 QWidget *_parent, QGridLayout *l,
930 ConfigControl( _p_this, _p_item, _parent )
933 label = new QLabel( qtr("Select an action to change the associated hotkey") );
934 table = new QTreeWidget( 0 );
939 QVBoxLayout *layout = new QVBoxLayout();
940 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
941 widget->setLayout( layout );
945 l->addWidget( label, line, 0, 1, 2 );
946 l->addWidget( table, line+1, 0, 1,2 );
950 void KeySelectorControl::finish()
953 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
956 table->setColumnCount( 2 );
957 table->setAlternatingRowColors( true );
959 module_t *p_main = config_FindModule( p_this, "main" );
962 for (size_t i = 0; i < p_main->confsize; i++)
964 module_config_t *p_item = p_main->p_config + i;
966 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
967 strstr( p_item->psz_name , "key-" ) )
969 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
970 treeItem->setText( 0, qtr( p_item->psz_text ) );
971 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
972 treeItem->setData( 0, Qt::UserRole,
973 QVariant::fromValue( (void*)p_item ) );
975 table->addTopLevelItem( treeItem );
978 table->resizeColumnToContents( 0 );
980 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
981 this, selectKey( QTreeWidgetItem * ) );
984 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
986 module_config_t *p_keyItem = static_cast<module_config_t*>
987 (keyItem->data( 0, Qt::UserRole ).value<void*>());
989 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
991 if( d->result() == QDialog::Accepted )
993 p_keyItem->value.i = d->keyValue;
996 for( int i = 0; i < table->topLevelItemCount() ; i++ )
998 QTreeWidgetItem *it = table->topLevelItem(i);
999 module_config_t *p_item = static_cast<module_config_t*>
1000 (it->data( 0, Qt::UserRole ).value<void*>());
1001 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1002 p_item->value.i = 0;
1003 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1007 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1012 void KeySelectorControl::doApply()
1014 foreach( module_config_t *p_current, values )
1016 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1020 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1021 const char * _keyToChange ) :
1022 QDialog(0), keyValue(0)
1027 keyToChange = _keyToChange;
1028 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1030 QVBoxLayout *l = new QVBoxLayout( this );
1031 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1032 warning = new QLabel();
1033 l->addWidget( selected , Qt::AlignCenter );
1034 l->addWidget( warning, Qt::AlignCenter );
1036 QHBoxLayout *l2 = new QHBoxLayout();
1037 QPushButton *ok = new QPushButton( qtr("OK") );
1038 l2->addWidget( ok );
1039 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1040 l2->addWidget( cancel );
1042 BUTTONACT( ok, accept() );
1043 BUTTONACT( cancel, reject() );
1048 void KeyInputDialog::checkForConflicts( int i_vlckey )
1051 module_config_t *p_current = NULL;
1052 foreach( p_current, values )
1054 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1064 qtr("Warning: the key is already assigned to \"") +
1065 QString( p_current->psz_text ) + "\"" );
1067 else warning->setText( "" );
1070 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1072 if( e->key() == Qt::Key_Tab ) return;
1073 int i_vlck = qtEventToVLCKey( e );
1074 selected->setText( VLCKeyToString( i_vlck ) );
1075 checkForConflicts( i_vlck );
1079 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1081 int i_vlck = qtWheelEventToVLCKey( e );
1082 selected->setText( VLCKeyToString( i_vlck ) );
1083 checkForConflicts( i_vlck );