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<QCheckBox*>::iterator it = modules.begin();
494 it != modules.end(); it++ )
496 layoutGroupBox->addWidget( *it, 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 );
512 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
513 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
514 bool bycat ) : VStringConfigControl( _p_this, _p_item )
522 ModuleListConfigControl::~ModuleListConfigControl()
524 for( QVector<QCheckBox*>::iterator it = modules.begin();
525 it != modules.end(); it++ )
533 void ModuleListConfigControl::finish( bool bycat )
538 /* build a list of available modules */
539 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
540 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
542 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
546 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
548 for (size_t i = 0; i < p_parser->confsize; i++)
550 module_config_t *p_config = p_parser->p_config + i;
551 /* Hack: required subcategory is stored in i_min */
552 if( p_config->i_type == CONFIG_SUBCATEGORY &&
553 p_config->value.i == p_item->min.i )
556 new QCheckBox( qfu( p_parser->psz_object_name ) );
557 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );
559 formatTooltip( qfu(p_parser->psz_longname)) );
560 modules.push_back( cb );
564 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
567 new QCheckBox( qfu( p_parser->psz_object_name ) );
568 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );
569 cb->setToolTip( formatTooltip(qfu(p_parser->psz_longname)) );
570 modules.push_back( cb );
573 vlc_list_release( p_list );
574 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
576 groupBox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
579 QString ModuleListConfigControl::getValue()
584 void ModuleListConfigControl::hide()
586 for( QVector<QCheckBox*>::iterator it = modules.begin();
587 it != modules.end(); it++ )
594 void ModuleListConfigControl::show()
596 for( QVector<QCheckBox*>::iterator it = modules.begin();
597 it != modules.end(); it++ )
605 void ModuleListConfigControl::onUpdate( int value )
610 for( QVector<QCheckBox*>::iterator it = modules.begin();
611 it != modules.end(); it++ )
613 if( (*it)->isChecked() )
617 text->setText( text->text() + (*it)->text() );
622 text->setText( text->text() + ":" + (*it)->text() );
628 /**************************************************************************
629 * Integer-based controls
630 *************************************************************************/
632 /*********** Integer **************/
633 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
634 module_config_t *_p_item,
635 QWidget *_parent, QGridLayout *l,
637 VIntConfigControl( _p_this, _p_item, _parent )
639 label = new QLabel( qfu(p_item->psz_text) );
640 spin = new QSpinBox; spin->setMinimumWidth( 80 );
641 spin->setAlignment( Qt::AlignRight );
642 spin->setMaximumWidth( 90 );
647 QHBoxLayout *layout = new QHBoxLayout();
648 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
649 widget->setLayout( layout );
653 l->addWidget( label, line, 0 );
654 l->addWidget( spin, line, 1, Qt::AlignRight );
657 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
658 module_config_t *_p_item,
659 QLabel *_label, QSpinBox *_spin ) :
660 VIntConfigControl( _p_this, _p_item )
667 void IntegerConfigControl::finish()
669 spin->setMaximum( 2000000000 );
670 spin->setMinimum( -2000000000 );
671 spin->setValue( p_item->value.i );
672 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
674 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
677 int IntegerConfigControl::getValue()
679 return spin->value();
682 /********* Integer range **********/
683 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
684 module_config_t *_p_item,
685 QWidget *_parent, QGridLayout *l,
687 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
692 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
693 module_config_t *_p_item,
694 QLabel *_label, QSpinBox *_spin ) :
695 IntegerConfigControl( _p_this, _p_item, _label, _spin )
700 void IntegerRangeConfigControl::finish()
702 spin->setMaximum( p_item->max.i );
703 spin->setMinimum( p_item->min.i );
706 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
707 vlc_object_t *_p_this,
708 module_config_t *_p_item,
709 QLabel *_label, QSlider *_slider ):
710 VIntConfigControl( _p_this, _p_item )
714 slider->setMaximum( p_item->max.i );
715 slider->setMinimum( p_item->min.i );
716 slider->setValue( p_item->value.i );
717 slider->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
719 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
722 int IntegerRangeSliderConfigControl::getValue()
724 return slider->value();
728 /********* Integer / choice list **********/
729 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
730 module_config_t *_p_item, QWidget *_parent, bool bycat,
731 QGridLayout *l, int &line) :
732 VIntConfigControl( _p_this, _p_item, _parent )
734 label = new QLabel( qfu(p_item->psz_text) );
735 combo = new QComboBox();
739 QHBoxLayout *layout = new QHBoxLayout();
740 layout->addWidget( label ); layout->addWidget( combo );
741 widget->setLayout( layout );
745 l->addWidget( label, line, 0 );
746 l->addWidget( combo, line, 1, Qt::AlignRight );
749 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
750 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
751 bool bycat ) : VIntConfigControl( _p_this, _p_item )
758 void IntegerListConfigControl::finish( bool bycat )
760 combo->setEditable( false );
762 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
764 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
765 QVariant( p_item->pi_list[i_index] ) );
766 if( p_item->value.i == p_item->pi_list[i_index] )
767 combo->setCurrentIndex( combo->count() - 1 );
769 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
771 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
774 int IntegerListConfigControl::getValue()
776 return combo->itemData( combo->currentIndex() ).toInt();
779 /*********** Boolean **************/
780 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
781 module_config_t *_p_item,
782 QWidget *_parent, QGridLayout *l,
784 VIntConfigControl( _p_this, _p_item, _parent )
786 checkbox = new QCheckBox( qfu(p_item->psz_text) );
791 QHBoxLayout *layout = new QHBoxLayout();
792 layout->addWidget( checkbox, 0 );
793 widget->setLayout( layout );
797 l->addWidget( checkbox, line, 0 );
800 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
801 module_config_t *_p_item,
803 QCheckBox *_checkbox,
805 VIntConfigControl( _p_this, _p_item )
807 checkbox = _checkbox;
811 void BoolConfigControl::finish()
813 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
815 checkbox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
818 int BoolConfigControl::getValue()
820 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
823 /**************************************************************************
824 * Float-based controls
825 *************************************************************************/
827 /*********** Float **************/
828 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
829 module_config_t *_p_item,
830 QWidget *_parent, QGridLayout *l,
832 VFloatConfigControl( _p_this, _p_item, _parent )
834 label = new QLabel( qfu(p_item->psz_text) );
835 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
836 spin->setMaximumWidth( 90 );
837 spin->setAlignment( Qt::AlignRight );
842 QHBoxLayout *layout = new QHBoxLayout();
843 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
844 widget->setLayout( layout );
848 l->addWidget( label, line, 0 );
849 l->addWidget( spin, line, 1, Qt::AlignRight );
853 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
854 module_config_t *_p_item,
856 QDoubleSpinBox *_spin ) :
857 VFloatConfigControl( _p_this, _p_item )
864 void FloatConfigControl::finish()
866 spin->setMaximum( 2000000000. );
867 spin->setMinimum( -2000000000. );
868 spin->setSingleStep( 0.1 );
869 spin->setValue( (double)p_item->value.f );
870 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
872 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
875 float FloatConfigControl::getValue()
877 return (float)spin->value();
880 /*********** Float with range **************/
881 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
882 module_config_t *_p_item,
883 QWidget *_parent, QGridLayout *l,
885 FloatConfigControl( _p_this, _p_item, _parent, l, line )
890 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
891 module_config_t *_p_item,
893 QDoubleSpinBox *_spin ) :
894 FloatConfigControl( _p_this, _p_item, _label, _spin )
899 void FloatRangeConfigControl::finish()
901 spin->setMaximum( (double)p_item->max.f );
902 spin->setMinimum( (double)p_item->min.f );
906 /**********************************************************************
907 * Key selector widget
908 **********************************************************************/
909 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
910 module_config_t *_p_item,
911 QWidget *_parent, QGridLayout *l,
913 ConfigControl( _p_this, _p_item, _parent )
916 label = new QLabel( qtr("Select an action to change the associated hotkey") );
917 table = new QTreeWidget( 0 );
922 QVBoxLayout *layout = new QVBoxLayout();
923 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
924 widget->setLayout( layout );
928 l->addWidget( label, line, 0, 1, 2 );
929 l->addWidget( table, line+1, 0, 1,2 );
933 void KeySelectorControl::finish()
936 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
939 table->setColumnCount( 2 );
940 table->setAlternatingRowColors( true );
942 module_t *p_main = config_FindModule( p_this, "main" );
945 for (size_t i = 0; i < p_main->confsize; i++)
947 module_config_t *p_item = p_main->p_config + i;
949 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
950 strstr( p_item->psz_name , "key-" ) )
952 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
953 treeItem->setText( 0, qfu( p_item->psz_text ) );
954 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
955 treeItem->setData( 0, Qt::UserRole,
956 QVariant::fromValue( (void*)p_item ) );
958 table->addTopLevelItem( treeItem );
961 table->resizeColumnToContents( 0 );
963 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
964 this, selectKey( QTreeWidgetItem * ) );
967 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
969 module_config_t *p_keyItem = static_cast<module_config_t*>
970 (keyItem->data( 0, Qt::UserRole ).value<void*>());
972 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
974 if( d->result() == QDialog::Accepted )
976 p_keyItem->value.i = d->keyValue;
979 for( int i = 0; i < table->topLevelItemCount() ; i++ )
981 QTreeWidgetItem *it = table->topLevelItem(i);
982 module_config_t *p_item = static_cast<module_config_t*>
983 (it->data( 0, Qt::UserRole ).value<void*>());
984 it->setText( 1, VLCKeyToString( p_item->value.i ) );
988 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
993 void KeySelectorControl::doApply()
995 foreach( module_config_t *p_current, values )
997 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1001 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1002 const char * _keyToChange ) :
1003 QDialog(0), keyValue(0)
1008 keyToChange = _keyToChange;
1009 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1011 QVBoxLayout *l = new QVBoxLayout( this );
1012 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1013 warning = new QLabel();
1014 l->addWidget( selected , Qt::AlignCenter );
1015 l->addWidget( warning, Qt::AlignCenter );
1017 QHBoxLayout *l2 = new QHBoxLayout();
1018 QPushButton *ok = new QPushButton( qtr("OK") );
1019 l2->addWidget( ok );
1020 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1021 l2->addWidget( cancel );
1023 BUTTONACT( ok, accept() );
1024 BUTTONACT( cancel, reject() );
1029 void KeyInputDialog::checkForConflicts( int i_vlckey )
1032 module_config_t *p_current = NULL;
1033 foreach( p_current, values )
1035 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1038 p_current->value.i = 0;
1046 qtr("Warning: the key is already assigned to \"") +
1047 QString( p_current->psz_text ) + "\"" );
1049 else warning->setText( "" );
1052 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1054 if( e->key() == Qt::Key_Tab ) return;
1055 int i_vlck = qtEventToVLCKey( e );
1056 selected->setText( VLCKeyToString( i_vlck ) );
1057 checkForConflicts( i_vlck );
1061 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1063 int i_vlck = qtWheelEventToVLCKey( e );
1064 selected->setText( VLCKeyToString( i_vlck ) );
1065 checkForConflicts( i_vlck );