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) );
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 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
370 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
371 bool bycat ) : VStringConfigControl( _p_this, _p_item )
378 void StringListConfigControl::finish( bool bycat )
380 combo->setEditable( false );
382 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
384 combo->addItem( qfu(p_item->ppsz_list_text ?
385 p_item->ppsz_list_text[i_index] :
386 p_item->ppsz_list[i_index] ),
387 QVariant( p_item->ppsz_list[i_index] ) );
388 if( p_item->value.psz && !strcmp( p_item->value.psz,
389 p_item->ppsz_list[i_index] ) )
390 combo->setCurrentIndex( combo->count() - 1 );
392 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
394 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
397 QString StringListConfigControl::getValue()
399 return combo->itemData( combo->currentIndex() ).toString();
402 /********* Module **********/
403 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
404 module_config_t *_p_item, QWidget *_parent, bool bycat,
405 QGridLayout *l, int &line) :
406 VStringConfigControl( _p_this, _p_item, _parent )
408 label = new QLabel( qtr(p_item->psz_text) );
409 combo = new QComboBox();
413 QHBoxLayout *layout = new QHBoxLayout();
414 layout->addWidget( label ); layout->addWidget( combo );
415 widget->setLayout( layout );
419 l->addWidget( label, line, 0 );
420 l->addWidget( combo, line, 1, Qt::AlignRight );
423 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
424 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
425 bool bycat ) : VStringConfigControl( _p_this, _p_item )
432 void ModuleConfigControl::finish( bool bycat )
437 combo->setEditable( false );
439 /* build a list of available modules */
440 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
441 combo->addItem( qtr("Default") );
442 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
444 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
448 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
450 for (size_t i = 0; i < p_parser->confsize; i++)
452 module_config_t *p_config = p_parser->p_config + i;
453 /* Hack: required subcategory is stored in i_min */
454 if( p_config->i_type == CONFIG_SUBCATEGORY &&
455 p_config->value.i == p_item->min.i )
456 combo->addItem( qtr( module_GetLongName( p_parser )),
457 QVariant( module_GetObjName( p_parser ) ) );
458 if( p_item->value.psz && !strcmp( p_item->value.psz,
459 module_GetObjName( p_parser ) ) )
460 combo->setCurrentIndex( combo->count() - 1 );
463 else if( module_IsCapable( p_parser, p_item->psz_type ) )
465 combo->addItem( qtr(module_GetLongName( p_parser ) ),
466 QVariant( module_GetObjName( p_parser ) ) );
467 if( p_item->value.psz && !strcmp( p_item->value.psz,
468 module_GetObjName( p_parser ) ) )
469 combo->setCurrentIndex( combo->count() - 1 );
472 vlc_list_release( p_list );
473 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
475 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
478 QString ModuleConfigControl::getValue()
480 return combo->itemData( combo->currentIndex() ).toString();
483 /********* Module list **********/
484 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
485 module_config_t *_p_item, QWidget *_parent, bool bycat,
486 QGridLayout *l, int &line) :
487 VStringConfigControl( _p_this, _p_item, _parent )
489 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
490 text = new QLineEdit();
491 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
496 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
497 it != modules.end(); it++ )
499 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
501 layoutGroupBox->addWidget( text, boxline, 0 );
505 QVBoxLayout *layout = new QVBoxLayout();
506 layout->addWidget( groupBox, line, 0 );
507 widget->setLayout( layout );
511 l->addWidget( groupBox, line, 0, 1, -1 );
514 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
517 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
518 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
519 bool bycat ) : VStringConfigControl( _p_this, _p_item )
527 ModuleListConfigControl::~ModuleListConfigControl()
529 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
530 it != modules.end(); it++ )
538 #define CHECKBOX_LISTS \
540 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
541 checkBoxListItem *cbl = new checkBoxListItem; \
543 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
544 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
545 cbl->checkBox = cb; \
548 while( p_parser->pp_shortcuts[++i] != NULL); \
551 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
552 : module_GetObjName( p_parser ) ); \
553 modules.push_back( cbl ); \
557 void ModuleListConfigControl::finish( bool bycat )
562 /* build a list of available modules */
563 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
564 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
566 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
570 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
572 for (size_t i = 0; i < p_parser->confsize; i++)
574 module_config_t *p_config = p_parser->p_config + i;
575 /* Hack: required subcategory is stored in i_min */
576 if( p_config->i_type == CONFIG_SUBCATEGORY &&
577 p_config->value.i == p_item->min.i )
583 else if( module_IsCapable( p_parser, p_item->psz_type ) )
588 vlc_list_release( p_list );
589 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
591 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
593 #undef CHECKBOX_LISTS
595 QString ModuleListConfigControl::getValue()
600 void ModuleListConfigControl::hide()
602 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
603 it != modules.end(); it++ )
605 (*it)->checkBox->hide();
610 void ModuleListConfigControl::show()
612 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
613 it != modules.end(); it++ )
615 (*it)->checkBox->show();
621 void ModuleListConfigControl::onUpdate( int value )
626 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
627 it != modules.end(); it++ )
629 if( (*it)->checkBox->isChecked() )
633 text->setText( text->text() + (*it)->psz_module );
638 text->setText( text->text() + ":" + (*it)->psz_module );
644 /**************************************************************************
645 * Integer-based controls
646 *************************************************************************/
648 /*********** Integer **************/
649 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
650 module_config_t *_p_item,
651 QWidget *_parent, QGridLayout *l,
653 VIntConfigControl( _p_this, _p_item, _parent )
655 label = new QLabel( qtr(p_item->psz_text) );
656 spin = new QSpinBox; spin->setMinimumWidth( 80 );
657 spin->setAlignment( Qt::AlignRight );
658 spin->setMaximumWidth( 90 );
663 QHBoxLayout *layout = new QHBoxLayout();
664 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
665 widget->setLayout( layout );
669 l->addWidget( label, line, 0 );
670 l->addWidget( spin, line, 1, Qt::AlignRight );
673 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
674 module_config_t *_p_item,
675 QLabel *_label, QSpinBox *_spin ) :
676 VIntConfigControl( _p_this, _p_item )
683 void IntegerConfigControl::finish()
685 spin->setMaximum( 2000000000 );
686 spin->setMinimum( -2000000000 );
687 spin->setValue( p_item->value.i );
688 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
690 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
693 int IntegerConfigControl::getValue()
695 return spin->value();
698 /********* Integer range **********/
699 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
700 module_config_t *_p_item,
701 QWidget *_parent, QGridLayout *l,
703 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
708 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
709 module_config_t *_p_item,
710 QLabel *_label, QSpinBox *_spin ) :
711 IntegerConfigControl( _p_this, _p_item, _label, _spin )
716 void IntegerRangeConfigControl::finish()
718 spin->setMaximum( p_item->max.i );
719 spin->setMinimum( p_item->min.i );
722 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
723 vlc_object_t *_p_this,
724 module_config_t *_p_item,
725 QLabel *_label, QSlider *_slider ):
726 VIntConfigControl( _p_this, _p_item )
730 slider->setMaximum( p_item->max.i );
731 slider->setMinimum( p_item->min.i );
732 slider->setValue( p_item->value.i );
733 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
735 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
738 int IntegerRangeSliderConfigControl::getValue()
740 return slider->value();
744 /********* Integer / choice list **********/
745 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
746 module_config_t *_p_item, QWidget *_parent, bool bycat,
747 QGridLayout *l, int &line) :
748 VIntConfigControl( _p_this, _p_item, _parent )
750 label = new QLabel( qtr(p_item->psz_text) );
751 combo = new QComboBox();
755 QHBoxLayout *layout = new QHBoxLayout();
756 layout->addWidget( label ); layout->addWidget( combo );
757 widget->setLayout( layout );
761 l->addWidget( label, line, 0 );
762 l->addWidget( combo, line, 1, Qt::AlignRight );
765 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
766 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
767 bool bycat ) : VIntConfigControl( _p_this, _p_item )
774 void IntegerListConfigControl::finish( bool bycat )
776 combo->setEditable( false );
778 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
780 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
781 QVariant( p_item->pi_list[i_index] ) );
782 if( p_item->value.i == p_item->pi_list[i_index] )
783 combo->setCurrentIndex( combo->count() - 1 );
785 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
787 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
790 int IntegerListConfigControl::getValue()
792 return combo->itemData( combo->currentIndex() ).toInt();
795 /*********** Boolean **************/
796 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
797 module_config_t *_p_item,
798 QWidget *_parent, QGridLayout *l,
800 VIntConfigControl( _p_this, _p_item, _parent )
802 checkbox = new QCheckBox( qtr(p_item->psz_text) );
807 QHBoxLayout *layout = new QHBoxLayout();
808 layout->addWidget( checkbox, 0 );
809 widget->setLayout( layout );
813 l->addWidget( checkbox, line, 0 );
816 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
817 module_config_t *_p_item,
819 QCheckBox *_checkbox,
821 VIntConfigControl( _p_this, _p_item )
823 checkbox = _checkbox;
827 void BoolConfigControl::finish()
829 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
831 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
834 int BoolConfigControl::getValue()
836 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
839 /**************************************************************************
840 * Float-based controls
841 *************************************************************************/
843 /*********** Float **************/
844 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
845 module_config_t *_p_item,
846 QWidget *_parent, QGridLayout *l,
848 VFloatConfigControl( _p_this, _p_item, _parent )
850 label = new QLabel( qtr(p_item->psz_text) );
851 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
852 spin->setMaximumWidth( 90 );
853 spin->setAlignment( Qt::AlignRight );
858 QHBoxLayout *layout = new QHBoxLayout();
859 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
860 widget->setLayout( layout );
864 l->addWidget( label, line, 0 );
865 l->addWidget( spin, line, 1, Qt::AlignRight );
869 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
870 module_config_t *_p_item,
872 QDoubleSpinBox *_spin ) :
873 VFloatConfigControl( _p_this, _p_item )
880 void FloatConfigControl::finish()
882 spin->setMaximum( 2000000000. );
883 spin->setMinimum( -2000000000. );
884 spin->setSingleStep( 0.1 );
885 spin->setValue( (double)p_item->value.f );
886 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
888 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
891 float FloatConfigControl::getValue()
893 return (float)spin->value();
896 /*********** Float with range **************/
897 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
898 module_config_t *_p_item,
899 QWidget *_parent, QGridLayout *l,
901 FloatConfigControl( _p_this, _p_item, _parent, l, line )
906 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
907 module_config_t *_p_item,
909 QDoubleSpinBox *_spin ) :
910 FloatConfigControl( _p_this, _p_item, _label, _spin )
915 void FloatRangeConfigControl::finish()
917 spin->setMaximum( (double)p_item->max.f );
918 spin->setMinimum( (double)p_item->min.f );
922 /**********************************************************************
923 * Key selector widget
924 **********************************************************************/
925 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
926 module_config_t *_p_item,
927 QWidget *_parent, QGridLayout *l,
929 ConfigControl( _p_this, _p_item, _parent )
932 label = new QLabel( qtr("Select an action to change the associated hotkey") );
933 table = new QTreeWidget( 0 );
938 QVBoxLayout *layout = new QVBoxLayout();
939 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
940 widget->setLayout( layout );
944 l->addWidget( label, line, 0, 1, 2 );
945 l->addWidget( table, line+1, 0, 1,2 );
949 void KeySelectorControl::finish()
952 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
955 table->setColumnCount( 2 );
956 table->setAlternatingRowColors( true );
958 module_t *p_main = config_FindModule( p_this, "main" );
961 for (size_t i = 0; i < p_main->confsize; i++)
963 module_config_t *p_item = p_main->p_config + i;
965 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
966 strstr( p_item->psz_name , "key-" ) )
968 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
969 treeItem->setText( 0, qtr( p_item->psz_text ) );
970 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
971 treeItem->setData( 0, Qt::UserRole,
972 QVariant::fromValue( (void*)p_item ) );
974 table->addTopLevelItem( treeItem );
977 table->resizeColumnToContents( 0 );
979 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
980 this, selectKey( QTreeWidgetItem * ) );
983 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
985 module_config_t *p_keyItem = static_cast<module_config_t*>
986 (keyItem->data( 0, Qt::UserRole ).value<void*>());
988 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
990 if( d->result() == QDialog::Accepted )
992 p_keyItem->value.i = d->keyValue;
995 for( int i = 0; i < table->topLevelItemCount() ; i++ )
997 QTreeWidgetItem *it = table->topLevelItem(i);
998 module_config_t *p_item = static_cast<module_config_t*>
999 (it->data( 0, Qt::UserRole ).value<void*>());
1000 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1004 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1009 void KeySelectorControl::doApply()
1011 foreach( module_config_t *p_current, values )
1013 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1017 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1018 const char * _keyToChange ) :
1019 QDialog(0), keyValue(0)
1024 keyToChange = _keyToChange;
1025 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1027 QVBoxLayout *l = new QVBoxLayout( this );
1028 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1029 warning = new QLabel();
1030 l->addWidget( selected , Qt::AlignCenter );
1031 l->addWidget( warning, Qt::AlignCenter );
1033 QHBoxLayout *l2 = new QHBoxLayout();
1034 QPushButton *ok = new QPushButton( qtr("OK") );
1035 l2->addWidget( ok );
1036 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1037 l2->addWidget( cancel );
1039 BUTTONACT( ok, accept() );
1040 BUTTONACT( cancel, reject() );
1045 void KeyInputDialog::checkForConflicts( int i_vlckey )
1048 module_config_t *p_current = NULL;
1049 foreach( p_current, values )
1051 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1054 p_current->value.i = 0;
1062 qtr("Warning: the key is already assigned to \"") +
1063 QString( p_current->psz_text ) + "\"" );
1065 else warning->setText( "" );
1068 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1070 if( e->key() == Qt::Key_Tab ) return;
1071 int i_vlck = qtEventToVLCKey( e );
1072 selected->setText( VLCKeyToString( i_vlck ) );
1073 checkForConflicts( i_vlck );
1077 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1079 int i_vlck = qtWheelEventToVLCKey( e );
1080 selected->setText( VLCKeyToString( i_vlck ) );
1081 checkForConflicts( i_vlck );