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"
42 #include <QDoubleSpinBox>
45 #include <QGridLayout>
46 #include <QPushButton>
48 #include <QFileDialog>
49 #include <QFontDialog>
55 QString formatTooltip(const QString & tooltip)
58 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
59 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
60 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
61 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
62 "-qt-block-indent:0; text-indent:0px;\">" +
68 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
69 module_config_t *p_item,
73 return createControl( p_this, p_item, parent, NULL, i );
76 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
77 module_config_t *p_item,
79 QGridLayout *l, int &line )
81 ConfigControl *p_control = NULL;
82 if( p_item->psz_current ) return NULL;
84 switch( p_item->i_type )
86 case CONFIG_ITEM_MODULE:
87 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
90 case CONFIG_ITEM_MODULE_CAT:
91 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
94 case CONFIG_ITEM_MODULE_LIST:
95 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
98 case CONFIG_ITEM_MODULE_LIST_CAT:
99 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
102 case CONFIG_ITEM_STRING:
103 if( !p_item->i_list )
104 p_control = new StringConfigControl( p_this, p_item, parent,
107 p_control = new StringListConfigControl( p_this, p_item,
108 parent, false, l, line );
110 case CONFIG_ITEM_INTEGER:
112 p_control = new IntegerListConfigControl( p_this, p_item,
113 parent, false, l, line );
114 else if( p_item->min.i || p_item->max.i )
115 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
118 p_control = new IntegerConfigControl( p_this, p_item, parent,
121 case CONFIG_ITEM_FILE:
122 p_control = new FileConfigControl( p_this, p_item, parent, l,
125 case CONFIG_ITEM_DIRECTORY:
126 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
129 case CONFIG_ITEM_FONT:
130 p_control = new FontConfigControl( p_this, p_item, parent, l,
133 case CONFIG_ITEM_KEY:
134 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
136 case CONFIG_ITEM_BOOL:
137 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
139 case CONFIG_ITEM_FLOAT:
140 if( p_item->min.f || p_item->max.f )
141 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
144 p_control = new FloatConfigControl( p_this, p_item, parent,
153 void ConfigControl::doApply( intf_thread_t *p_intf )
159 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
161 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
166 VFloatConfigControl *vfcc =
167 qobject_cast<VFloatConfigControl *>(this);
169 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
174 VStringConfigControl *vscc =
175 qobject_cast<VStringConfigControl *>(this);
177 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
182 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
189 /**************************************************************************
190 * String-based controls
191 *************************************************************************/
193 /*********** String **************/
194 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
195 module_config_t *_p_item,
196 QWidget *_parent, QGridLayout *l,
197 int &line, bool pwd ) :
198 VStringConfigControl( _p_this, _p_item, _parent )
200 label = new QLabel( qfu(p_item->psz_text) );
201 text = new QLineEdit( qfu(p_item->value.psz) );
206 QHBoxLayout *layout = new QHBoxLayout();
207 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
208 widget->setLayout( layout );
212 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
216 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
217 module_config_t *_p_item,
218 QLabel *_label, QLineEdit *_text, bool pwd ):
219 VStringConfigControl( _p_this, _p_item )
226 void StringConfigControl::finish()
228 text->setText( qfu(p_item->value.psz) );
229 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
231 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
234 /*********** File **************/
235 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
236 module_config_t *_p_item,
237 QWidget *_parent, QGridLayout *l,
238 int &line, bool pwd ) :
239 VStringConfigControl( _p_this, _p_item, _parent )
241 label = new QLabel( qfu(p_item->psz_text) );
242 text = new QLineEdit( qfu(p_item->value.psz) );
243 browse = new QPushButton( qtr( "Browse..." ) );
244 QHBoxLayout *textAndButton = new QHBoxLayout();
245 textAndButton->setMargin( 0 );
246 textAndButton->addWidget( text, 2 );
247 textAndButton->addWidget( browse, 0 );
249 BUTTONACT( browse, updateField() );
255 QHBoxLayout *layout = new QHBoxLayout();
256 layout->addWidget( label, 0 );
257 layout->addLayout( textAndButton, 1 );
258 widget->setLayout( layout );
262 l->addWidget( label, line, 0 );
263 l->addLayout( textAndButton, line, 1 );
268 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
269 module_config_t *_p_item,
270 QLabel *_label, QLineEdit *_text,
271 QPushButton *_button, bool pwd ):
272 VStringConfigControl( _p_this, _p_item )
278 BUTTONACT( browse, updateField() );
283 void FileConfigControl::updateField()
285 QString file = QFileDialog::getOpenFileName( NULL,
286 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
287 if( file.isNull() ) return;
288 text->setText( file );
291 void FileConfigControl::finish()
293 text->setText( qfu(p_item->value.psz) );
294 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
296 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
299 /********* String / Directory **********/
300 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
301 module_config_t *_p_item, QWidget *_p_widget,
302 QGridLayout *_p_layout, int& _int, bool _pwd ) :
303 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
306 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
307 module_config_t *_p_item, QLabel *_p_label,
308 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
309 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
312 void DirectoryConfigControl::updateField()
314 QString dir = QFileDialog::getExistingDirectory( NULL,
315 qtr( "Select Directory" ),
316 text->text().isEmpty() ?
317 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
318 QFileDialog::ShowDirsOnly |
319 QFileDialog::DontResolveSymlinks );
320 if( dir.isNull() ) return;
321 text->setText( dir );
324 /********* String / Font **********/
325 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
326 module_config_t *_p_item, QWidget *_p_widget,
327 QGridLayout *_p_layout, int& _int, bool _pwd ) :
328 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
331 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
332 module_config_t *_p_item, QLabel *_p_label,
333 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
334 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
337 void FontConfigControl::updateField()
340 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
342 text->setText( font.family() );
345 /********* String / choice list **********/
346 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
347 module_config_t *_p_item, QWidget *_parent, bool bycat,
348 QGridLayout *l, int &line) :
349 VStringConfigControl( _p_this, _p_item, _parent )
351 label = new QLabel( qfu(p_item->psz_text) );
352 combo = new QComboBox();
356 QHBoxLayout *layout = new QHBoxLayout();
357 layout->addWidget( label ); layout->addWidget( combo );
358 widget->setLayout( layout );
362 l->addWidget( label, line, 0 );
363 l->addWidget( combo, line, 1, Qt::AlignRight );
366 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
367 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
368 bool bycat ) : VStringConfigControl( _p_this, _p_item )
375 void StringListConfigControl::finish( bool bycat )
377 combo->setEditable( false );
379 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
381 combo->addItem( qfu(p_item->ppsz_list_text ?
382 p_item->ppsz_list_text[i_index] :
383 p_item->ppsz_list[i_index] ),
384 QVariant( p_item->ppsz_list[i_index] ) );
385 if( p_item->value.psz && !strcmp( p_item->value.psz,
386 p_item->ppsz_list[i_index] ) )
387 combo->setCurrentIndex( combo->count() - 1 );
389 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
391 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
394 QString StringListConfigControl::getValue()
396 return combo->itemData( combo->currentIndex() ).toString();
399 /********* Module **********/
400 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
401 module_config_t *_p_item, QWidget *_parent, bool bycat,
402 QGridLayout *l, int &line) :
403 VStringConfigControl( _p_this, _p_item, _parent )
405 label = new QLabel( qfu(p_item->psz_text) );
406 combo = new QComboBox();
410 QHBoxLayout *layout = new QHBoxLayout();
411 layout->addWidget( label ); layout->addWidget( combo );
412 widget->setLayout( layout );
416 l->addWidget( label, line, 0 );
417 l->addWidget( combo, line, 1, Qt::AlignRight );
420 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
421 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
422 bool bycat ) : VStringConfigControl( _p_this, _p_item )
429 void ModuleConfigControl::finish( bool bycat )
434 combo->setEditable( false );
436 /* build a list of available modules */
437 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
438 combo->addItem( qtr("Default") );
439 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
441 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
445 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
447 for (size_t i = 0; i < p_parser->confsize; i++)
449 module_config_t *p_config = p_parser->p_config + i;
450 /* Hack: required subcategory is stored in i_min */
451 if( p_config->i_type == CONFIG_SUBCATEGORY &&
452 p_config->value.i == p_item->min.i )
453 combo->addItem( qfu(p_parser->psz_longname),
454 QVariant( p_parser->psz_object_name ) );
455 if( p_item->value.psz && !strcmp( p_item->value.psz,
456 p_parser->psz_object_name) )
457 combo->setCurrentIndex( combo->count() - 1 );
460 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
462 combo->addItem( qfu(p_parser->psz_longname),
463 QVariant( p_parser->psz_object_name ) );
464 if( p_item->value.psz && !strcmp( p_item->value.psz,
465 p_parser->psz_object_name) )
466 combo->setCurrentIndex( combo->count() - 1 );
469 vlc_list_release( p_list );
470 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
472 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
475 QString ModuleConfigControl::getValue()
477 return combo->itemData( combo->currentIndex() ).toString();
480 /********* Module list **********/
481 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
482 module_config_t *_p_item, QWidget *_parent, bool bycat,
483 QGridLayout *l, int &line) :
484 VStringConfigControl( _p_this, _p_item, _parent )
486 groupBox = new QGroupBox ( qfu(p_item->psz_text) );
487 text = new QLineEdit();
488 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
493 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
494 it != modules.end(); it++ )
496 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
498 layoutGroupBox->addWidget( text, boxline, 0 );
502 QVBoxLayout *layout = new QVBoxLayout();
503 layout->addWidget( groupBox, line, 0 );
504 widget->setLayout( layout );
508 l->addWidget( groupBox, line, 0, 1, -1 );
511 text->setToolTip( formatTooltip( qfu( p_item->psz_longtext) ) );
514 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
515 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
516 bool bycat ) : VStringConfigControl( _p_this, _p_item )
524 ModuleListConfigControl::~ModuleListConfigControl()
526 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
527 it != modules.end(); it++ )
535 #define CHECKBOX_LISTS \
537 QCheckBox *cb = new QCheckBox( qfu( p_parser->psz_longname ) );\
538 checkBoxListItem *cbl = new checkBoxListItem; \
540 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
541 cb->setToolTip( formatTooltip( qfu(p_parser->psz_longname)) );\
542 cbl->checkBox = cb; \
545 while( p_parser->pp_shortcuts[++i] != NULL); \
548 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
549 : p_parser->psz_object_name ); \
550 modules.push_back( cbl ); \
554 void ModuleListConfigControl::finish( bool bycat )
559 /* build a list of available modules */
560 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
561 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
563 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
567 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
569 for (size_t i = 0; i < p_parser->confsize; i++)
571 module_config_t *p_config = p_parser->p_config + i;
572 /* Hack: required subcategory is stored in i_min */
573 if( p_config->i_type == CONFIG_SUBCATEGORY &&
574 p_config->value.i == p_item->min.i )
580 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
585 vlc_list_release( p_list );
586 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
588 groupBox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
590 #undef CHECKBOX_LISTS
592 QString ModuleListConfigControl::getValue()
597 void ModuleListConfigControl::hide()
599 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
600 it != modules.end(); it++ )
602 (*it)->checkBox->hide();
607 void ModuleListConfigControl::show()
609 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
610 it != modules.end(); it++ )
612 (*it)->checkBox->show();
618 void ModuleListConfigControl::onUpdate( int value )
623 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
624 it != modules.end(); it++ )
626 if( (*it)->checkBox->isChecked() )
630 text->setText( text->text() + (*it)->psz_module );
635 text->setText( text->text() + ":" + (*it)->psz_module );
641 /**************************************************************************
642 * Integer-based controls
643 *************************************************************************/
645 /*********** Integer **************/
646 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
647 module_config_t *_p_item,
648 QWidget *_parent, QGridLayout *l,
650 VIntConfigControl( _p_this, _p_item, _parent )
652 label = new QLabel( qfu(p_item->psz_text) );
653 spin = new QSpinBox; spin->setMinimumWidth( 80 );
654 spin->setAlignment( Qt::AlignRight );
655 spin->setMaximumWidth( 90 );
660 QHBoxLayout *layout = new QHBoxLayout();
661 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
662 widget->setLayout( layout );
666 l->addWidget( label, line, 0 );
667 l->addWidget( spin, line, 1, Qt::AlignRight );
670 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
671 module_config_t *_p_item,
672 QLabel *_label, QSpinBox *_spin ) :
673 VIntConfigControl( _p_this, _p_item )
680 void IntegerConfigControl::finish()
682 spin->setMaximum( 2000000000 );
683 spin->setMinimum( -2000000000 );
684 spin->setValue( p_item->value.i );
685 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
687 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
690 int IntegerConfigControl::getValue()
692 return spin->value();
695 /********* Integer range **********/
696 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
697 module_config_t *_p_item,
698 QWidget *_parent, QGridLayout *l,
700 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
705 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
706 module_config_t *_p_item,
707 QLabel *_label, QSpinBox *_spin ) :
708 IntegerConfigControl( _p_this, _p_item, _label, _spin )
713 void IntegerRangeConfigControl::finish()
715 spin->setMaximum( p_item->max.i );
716 spin->setMinimum( p_item->min.i );
719 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
720 vlc_object_t *_p_this,
721 module_config_t *_p_item,
722 QLabel *_label, QSlider *_slider ):
723 VIntConfigControl( _p_this, _p_item )
727 slider->setMaximum( p_item->max.i );
728 slider->setMinimum( p_item->min.i );
729 slider->setValue( p_item->value.i );
730 slider->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
732 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
735 int IntegerRangeSliderConfigControl::getValue()
737 return slider->value();
741 /********* Integer / choice list **********/
742 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
743 module_config_t *_p_item, QWidget *_parent, bool bycat,
744 QGridLayout *l, int &line) :
745 VIntConfigControl( _p_this, _p_item, _parent )
747 label = new QLabel( qfu(p_item->psz_text) );
748 combo = new QComboBox();
752 QHBoxLayout *layout = new QHBoxLayout();
753 layout->addWidget( label ); layout->addWidget( combo );
754 widget->setLayout( layout );
758 l->addWidget( label, line, 0 );
759 l->addWidget( combo, line, 1, Qt::AlignRight );
762 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
763 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
764 bool bycat ) : VIntConfigControl( _p_this, _p_item )
771 void IntegerListConfigControl::finish( bool bycat )
773 combo->setEditable( false );
775 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
777 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
778 QVariant( p_item->pi_list[i_index] ) );
779 if( p_item->value.i == p_item->pi_list[i_index] )
780 combo->setCurrentIndex( combo->count() - 1 );
782 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
784 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
787 int IntegerListConfigControl::getValue()
789 return combo->itemData( combo->currentIndex() ).toInt();
792 /*********** Boolean **************/
793 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
794 module_config_t *_p_item,
795 QWidget *_parent, QGridLayout *l,
797 VIntConfigControl( _p_this, _p_item, _parent )
799 checkbox = new QCheckBox( qfu(p_item->psz_text) );
804 QHBoxLayout *layout = new QHBoxLayout();
805 layout->addWidget( checkbox, 0 );
806 widget->setLayout( layout );
810 l->addWidget( checkbox, line, 0 );
813 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
814 module_config_t *_p_item,
816 QCheckBox *_checkbox,
818 VIntConfigControl( _p_this, _p_item )
820 checkbox = _checkbox;
824 void BoolConfigControl::finish()
826 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
828 checkbox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
831 int BoolConfigControl::getValue()
833 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
836 /**************************************************************************
837 * Float-based controls
838 *************************************************************************/
840 /*********** Float **************/
841 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
842 module_config_t *_p_item,
843 QWidget *_parent, QGridLayout *l,
845 VFloatConfigControl( _p_this, _p_item, _parent )
847 label = new QLabel( qfu(p_item->psz_text) );
848 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
849 spin->setMaximumWidth( 90 );
850 spin->setAlignment( Qt::AlignRight );
855 QHBoxLayout *layout = new QHBoxLayout();
856 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
857 widget->setLayout( layout );
861 l->addWidget( label, line, 0 );
862 l->addWidget( spin, line, 1, Qt::AlignRight );
866 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
867 module_config_t *_p_item,
869 QDoubleSpinBox *_spin ) :
870 VFloatConfigControl( _p_this, _p_item )
877 void FloatConfigControl::finish()
879 spin->setMaximum( 2000000000. );
880 spin->setMinimum( -2000000000. );
881 spin->setSingleStep( 0.1 );
882 spin->setValue( (double)p_item->value.f );
883 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
885 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
888 float FloatConfigControl::getValue()
890 return (float)spin->value();
893 /*********** Float with range **************/
894 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
895 module_config_t *_p_item,
896 QWidget *_parent, QGridLayout *l,
898 FloatConfigControl( _p_this, _p_item, _parent, l, line )
903 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
904 module_config_t *_p_item,
906 QDoubleSpinBox *_spin ) :
907 FloatConfigControl( _p_this, _p_item, _label, _spin )
912 void FloatRangeConfigControl::finish()
914 spin->setMaximum( (double)p_item->max.f );
915 spin->setMinimum( (double)p_item->min.f );
919 /**********************************************************************
920 * Key selector widget
921 **********************************************************************/
922 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
923 module_config_t *_p_item,
924 QWidget *_parent, QGridLayout *l,
926 ConfigControl( _p_this, _p_item, _parent )
929 label = new QLabel( qtr("Select an action to change the associated hotkey") );
930 table = new QTreeWidget( 0 );
935 QVBoxLayout *layout = new QVBoxLayout();
936 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
937 widget->setLayout( layout );
941 l->addWidget( label, line, 0, 1, 2 );
942 l->addWidget( table, line+1, 0, 1,2 );
946 void KeySelectorControl::finish()
949 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
952 table->setColumnCount( 2 );
953 table->setAlternatingRowColors( true );
955 module_t *p_main = config_FindModule( p_this, "main" );
958 for (size_t i = 0; i < p_main->confsize; i++)
960 module_config_t *p_item = p_main->p_config + i;
962 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
963 strstr( p_item->psz_name , "key-" ) )
965 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
966 treeItem->setText( 0, qfu( p_item->psz_text ) );
967 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
968 treeItem->setData( 0, Qt::UserRole,
969 QVariant::fromValue( (void*)p_item ) );
971 table->addTopLevelItem( treeItem );
974 table->resizeColumnToContents( 0 );
976 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
977 this, selectKey( QTreeWidgetItem * ) );
980 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
982 module_config_t *p_keyItem = static_cast<module_config_t*>
983 (keyItem->data( 0, Qt::UserRole ).value<void*>());
985 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
987 if( d->result() == QDialog::Accepted )
989 p_keyItem->value.i = d->keyValue;
992 for( int i = 0; i < table->topLevelItemCount() ; i++ )
994 QTreeWidgetItem *it = table->topLevelItem(i);
995 module_config_t *p_item = static_cast<module_config_t*>
996 (it->data( 0, Qt::UserRole ).value<void*>());
997 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1001 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1006 void KeySelectorControl::doApply()
1008 foreach( module_config_t *p_current, values )
1010 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1014 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1015 const char * _keyToChange ) :
1016 QDialog(0), keyValue(0)
1021 keyToChange = _keyToChange;
1022 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1024 QVBoxLayout *l = new QVBoxLayout( this );
1025 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1026 warning = new QLabel();
1027 l->addWidget( selected , Qt::AlignCenter );
1028 l->addWidget( warning, Qt::AlignCenter );
1030 QHBoxLayout *l2 = new QHBoxLayout();
1031 QPushButton *ok = new QPushButton( qtr("OK") );
1032 l2->addWidget( ok );
1033 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1034 l2->addWidget( cancel );
1036 BUTTONACT( ok, accept() );
1037 BUTTONACT( cancel, reject() );
1042 void KeyInputDialog::checkForConflicts( int i_vlckey )
1045 module_config_t *p_current = NULL;
1046 foreach( p_current, values )
1048 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1051 p_current->value.i = 0;
1059 qtr("Warning: the key is already assigned to \"") +
1060 QString( p_current->psz_text ) + "\"" );
1062 else warning->setText( "" );
1065 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1067 if( e->key() == Qt::Key_Tab ) return;
1068 int i_vlck = qtEventToVLCKey( e );
1069 selected->setText( VLCKeyToString( i_vlck ) );
1070 checkForConflicts( i_vlck );
1074 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1076 int i_vlck = qtWheelEventToVLCKey( e );
1077 selected->setText( VLCKeyToString( i_vlck ) );
1078 checkForConflicts( i_vlck );