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>
53 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
54 module_config_t *p_item,
58 return createControl( p_this, p_item, parent, NULL, i );
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62 module_config_t *p_item,
64 QGridLayout *l, int &line )
66 ConfigControl *p_control = NULL;
67 if( p_item->psz_current ) return NULL;
69 switch( p_item->i_type )
71 case CONFIG_ITEM_MODULE:
72 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
75 case CONFIG_ITEM_MODULE_CAT:
76 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
79 case CONFIG_ITEM_MODULE_LIST:
80 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
83 case CONFIG_ITEM_MODULE_LIST_CAT:
84 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
87 case CONFIG_ITEM_STRING:
89 p_control = new StringConfigControl( p_this, p_item, parent,
92 p_control = new StringListConfigControl( p_this, p_item,
93 parent, false, l, line );
95 case CONFIG_ITEM_INTEGER:
97 p_control = new IntegerListConfigControl( p_this, p_item,
98 parent, false, l, line );
99 else if( p_item->min.i || p_item->max.i )
100 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
103 p_control = new IntegerConfigControl( p_this, p_item, parent,
106 case CONFIG_ITEM_FILE:
107 p_control = new FileConfigControl( p_this, p_item, parent, l,
110 case CONFIG_ITEM_DIRECTORY:
111 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
114 case CONFIG_ITEM_FONT:
115 p_control = new FontConfigControl( p_this, p_item, parent, l,
118 case CONFIG_ITEM_KEY:
119 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
121 case CONFIG_ITEM_BOOL:
122 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
124 case CONFIG_ITEM_FLOAT:
125 if( p_item->min.f || p_item->max.f )
126 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
129 p_control = new FloatConfigControl( p_this, p_item, parent,
138 void ConfigControl::doApply( intf_thread_t *p_intf )
144 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
146 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
151 VFloatConfigControl *vfcc =
152 qobject_cast<VFloatConfigControl *>(this);
154 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
159 VStringConfigControl *vscc =
160 qobject_cast<VStringConfigControl *>(this);
162 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
167 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
174 /**************************************************************************
175 * String-based controls
176 *************************************************************************/
178 /*********** String **************/
179 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
180 module_config_t *_p_item,
181 QWidget *_parent, QGridLayout *l,
182 int &line, bool pwd ) :
183 VStringConfigControl( _p_this, _p_item, _parent )
185 label = new QLabel( qfu(p_item->psz_text) );
186 text = new QLineEdit( qfu(p_item->value.psz) );
191 QHBoxLayout *layout = new QHBoxLayout();
192 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
193 widget->setLayout( layout );
197 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
201 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
202 module_config_t *_p_item,
203 QLabel *_label, QLineEdit *_text, bool pwd ):
204 VStringConfigControl( _p_this, _p_item )
211 void StringConfigControl::finish()
213 text->setText( qfu(p_item->value.psz) );
214 text->setToolTip( qfu(p_item->psz_longtext) );
216 label->setToolTip( qfu(p_item->psz_longtext) );
219 /*********** File **************/
220 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
221 module_config_t *_p_item,
222 QWidget *_parent, QGridLayout *l,
223 int &line, bool pwd ) :
224 VStringConfigControl( _p_this, _p_item, _parent )
226 label = new QLabel( qfu(p_item->psz_text) );
227 text = new QLineEdit( qfu(p_item->value.psz) );
228 browse = new QPushButton( qtr( "Browse" ) );
230 BUTTONACT( browse, updateField() );
236 QHBoxLayout *layout = new QHBoxLayout();
237 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
238 layout->addWidget( browse, 2 );
239 widget->setLayout( layout );
243 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
244 l->addWidget( browse, line, 2 );
249 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
250 module_config_t *_p_item,
251 QLabel *_label, QLineEdit *_text,
252 QPushButton *_button, bool pwd ):
253 VStringConfigControl( _p_this, _p_item )
259 BUTTONACT( browse, updateField() );
264 void FileConfigControl::updateField()
266 QString file = QFileDialog::getOpenFileName( NULL,
267 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
268 if( file.isNull() ) return;
269 text->setText( file );
272 void FileConfigControl::finish()
274 text->setText( qfu(p_item->value.psz) );
275 text->setToolTip( qfu(p_item->psz_longtext) );
277 label->setToolTip( qfu(p_item->psz_longtext) );
280 /********* String / Directory **********/
281 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
282 module_config_t *_p_item, QWidget *_p_widget,
283 QGridLayout *_p_layout, int& _int, bool _pwd ) :
284 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
287 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
288 module_config_t *_p_item, QLabel *_p_label,
289 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
290 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
293 void DirectoryConfigControl::updateField()
295 QString dir = QFileDialog::getExistingDirectory( NULL,
296 qtr( "Select Directory" ),
297 text->text().isEmpty() ?
298 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
299 QFileDialog::ShowDirsOnly |
300 QFileDialog::DontResolveSymlinks );
301 if( dir.isNull() ) return;
302 text->setText( dir );
305 /********* String / Font **********/
306 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
307 module_config_t *_p_item, QWidget *_p_widget,
308 QGridLayout *_p_layout, int& _int, bool _pwd ) :
309 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
312 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
313 module_config_t *_p_item, QLabel *_p_label,
314 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
315 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
318 void FontConfigControl::updateField()
321 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
323 text->setText( font.family() );
326 /********* String / choice list **********/
327 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
328 module_config_t *_p_item, QWidget *_parent, bool bycat,
329 QGridLayout *l, int &line) :
330 VStringConfigControl( _p_this, _p_item, _parent )
332 label = new QLabel( qfu(p_item->psz_text) );
333 combo = new QComboBox();
337 QHBoxLayout *layout = new QHBoxLayout();
338 layout->addWidget( label ); layout->addWidget( combo );
339 widget->setLayout( layout );
343 l->addWidget( label, line, 0 );
344 l->addWidget( combo, line, 1, Qt::AlignRight );
347 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
349 bool bycat ) : VStringConfigControl( _p_this, _p_item )
356 void StringListConfigControl::finish( bool bycat )
358 combo->setEditable( false );
360 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
362 combo->addItem( qfu(p_item->ppsz_list_text ?
363 p_item->ppsz_list_text[i_index] :
364 p_item->ppsz_list[i_index] ),
365 QVariant( p_item->ppsz_list[i_index] ) );
366 if( p_item->value.psz && !strcmp( p_item->value.psz,
367 p_item->ppsz_list[i_index] ) )
368 combo->setCurrentIndex( combo->count() - 1 );
370 combo->setToolTip( qfu(p_item->psz_longtext) );
372 label->setToolTip( qfu(p_item->psz_longtext) );
375 QString StringListConfigControl::getValue()
377 return combo->itemData( combo->currentIndex() ).toString();
380 /********* Module **********/
381 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
382 module_config_t *_p_item, QWidget *_parent, bool bycat,
383 QGridLayout *l, int &line) :
384 VStringConfigControl( _p_this, _p_item, _parent )
386 label = new QLabel( qfu(p_item->psz_text) );
387 combo = new QComboBox();
391 QHBoxLayout *layout = new QHBoxLayout();
392 layout->addWidget( label ); layout->addWidget( combo );
393 widget->setLayout( layout );
397 l->addWidget( label, line, 0 );
398 l->addWidget( combo, line, 1, Qt::AlignRight );
401 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
402 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
403 bool bycat ) : VStringConfigControl( _p_this, _p_item )
410 void ModuleConfigControl::finish( bool bycat )
415 combo->setEditable( false );
417 /* build a list of available modules */
418 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
419 combo->addItem( qtr("Default") );
420 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
422 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
426 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
428 for (size_t i = 0; i < p_parser->confsize; i++)
430 module_config_t *p_config = p_parser->p_config + i;
431 /* Hack: required subcategory is stored in i_min */
432 if( p_config->i_type == CONFIG_SUBCATEGORY &&
433 p_config->value.i == p_item->min.i )
434 combo->addItem( qfu(p_parser->psz_longname),
435 QVariant( p_parser->psz_object_name ) );
436 if( p_item->value.psz && !strcmp( p_item->value.psz,
437 p_parser->psz_object_name) )
438 combo->setCurrentIndex( combo->count() - 1 );
441 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
443 combo->addItem( qfu(p_parser->psz_longname),
444 QVariant( p_parser->psz_object_name ) );
445 if( p_item->value.psz && !strcmp( p_item->value.psz,
446 p_parser->psz_object_name) )
447 combo->setCurrentIndex( combo->count() - 1 );
450 vlc_list_release( p_list );
451 combo->setToolTip( qfu(p_item->psz_longtext) );
453 label->setToolTip( qfu(p_item->psz_longtext) );
456 QString ModuleConfigControl::getValue()
458 return combo->itemData( combo->currentIndex() ).toString();
461 /********* Module list **********/
462 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
463 module_config_t *_p_item, QWidget *_parent, bool bycat,
464 QGridLayout *l, int &line) :
465 VStringConfigControl( _p_this, _p_item, _parent )
467 label = new QLabel( qfu(p_item->psz_text) );
468 text = new QLineEdit();
474 l = new QGridLayout();
478 for( QVector<QCheckBox*>::iterator it = modules.begin();
479 it != modules.end(); it++ )
481 l->addWidget( *it, line++, 1 );
483 l->addWidget( label, line, 0 );
484 l->addWidget( text, line, 1 );
486 widget->setLayout( l );
489 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
490 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
491 bool bycat ) : VStringConfigControl( _p_this, _p_item )
499 ModuleListConfigControl::~ModuleListConfigControl()
501 for( QVector<QCheckBox*>::iterator it = modules.begin();
502 it != modules.end(); it++ )
510 void ModuleListConfigControl::finish( bool bycat )
515 /* build a list of available modules */
516 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
517 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
519 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
523 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
525 for (size_t i = 0; i < p_parser->confsize; i++)
527 module_config_t *p_config = p_parser->p_config + i;
528 /* Hack: required subcategory is stored in i_min */
529 if( p_config->i_type == CONFIG_SUBCATEGORY &&
530 p_config->value.i == p_item->min.i )
533 new QCheckBox( qfu( p_parser->psz_object_name ) );
534 cb->setToolTip( qfu(p_parser->psz_longname) );
535 modules.push_back( cb );
539 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
542 new QCheckBox( qfu( p_parser->psz_object_name ) );
543 cb->setToolTip( qfu(p_parser->psz_longname) );
544 modules.push_back( cb );
547 vlc_list_release( p_list );
548 text->setToolTip( qfu(p_item->psz_longtext) );
550 label->setToolTip( qfu(p_item->psz_longtext) );
553 QString ModuleListConfigControl::getValue()
558 void ModuleListConfigControl::hide()
560 for( QVector<QCheckBox*>::iterator it = modules.begin();
561 it != modules.end(); it++ )
569 void ModuleListConfigControl::show()
571 for( QVector<QCheckBox*>::iterator it = modules.begin();
572 it != modules.end(); it++ )
581 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
584 for( QVector<QCheckBox*>::iterator it = modules.begin();
585 it != modules.end(); it++ )
590 /**************************************************************************
591 * Integer-based controls
592 *************************************************************************/
594 /*********** Integer **************/
595 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
596 module_config_t *_p_item,
597 QWidget *_parent, QGridLayout *l,
599 VIntConfigControl( _p_this, _p_item, _parent )
601 label = new QLabel( qfu(p_item->psz_text) );
602 spin = new QSpinBox; spin->setMinimumWidth( 80 );
603 spin->setMaximumWidth( 90 );
608 QHBoxLayout *layout = new QHBoxLayout();
609 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
610 widget->setLayout( layout );
614 l->addWidget( label, line, 0 );
615 l->addWidget( spin, line, 1, Qt::AlignRight );
618 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
619 module_config_t *_p_item,
620 QLabel *_label, QSpinBox *_spin ) :
621 VIntConfigControl( _p_this, _p_item )
628 void IntegerConfigControl::finish()
630 spin->setMaximum( 2000000000 );
631 spin->setMinimum( -2000000000 );
632 spin->setValue( p_item->value.i );
633 spin->setToolTip( qfu(p_item->psz_longtext) );
635 label->setToolTip( qfu(p_item->psz_longtext) );
638 int IntegerConfigControl::getValue()
640 return spin->value();
643 /********* Integer range **********/
644 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
645 module_config_t *_p_item,
646 QWidget *_parent, QGridLayout *l,
648 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
653 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
654 module_config_t *_p_item,
655 QLabel *_label, QSpinBox *_spin ) :
656 IntegerConfigControl( _p_this, _p_item, _label, _spin )
661 void IntegerRangeConfigControl::finish()
663 spin->setMaximum( p_item->max.i );
664 spin->setMinimum( p_item->min.i );
667 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
668 vlc_object_t *_p_this,
669 module_config_t *_p_item,
670 QLabel *_label, QSlider *_slider ):
671 VIntConfigControl( _p_this, _p_item )
675 slider->setMaximum( p_item->max.i );
676 slider->setMinimum( p_item->min.i );
677 slider->setValue( p_item->value.i );
678 slider->setToolTip( qfu(p_item->psz_longtext) );
680 label->setToolTip( qfu(p_item->psz_longtext) );
683 int IntegerRangeSliderConfigControl::getValue()
685 return slider->value();
689 /********* Integer / choice list **********/
690 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
691 module_config_t *_p_item, QWidget *_parent, bool bycat,
692 QGridLayout *l, int &line) :
693 VIntConfigControl( _p_this, _p_item, _parent )
695 label = new QLabel( qfu(p_item->psz_text) );
696 combo = new QComboBox();
700 QHBoxLayout *layout = new QHBoxLayout();
701 layout->addWidget( label ); layout->addWidget( combo );
702 widget->setLayout( layout );
706 l->addWidget( label, line, 0 );
707 l->addWidget( combo, line, 1, Qt::AlignRight );
710 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
711 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
712 bool bycat ) : VIntConfigControl( _p_this, _p_item )
719 void IntegerListConfigControl::finish( bool bycat )
721 combo->setEditable( false );
723 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
725 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
726 QVariant( p_item->pi_list[i_index] ) );
727 if( p_item->value.i == p_item->pi_list[i_index] )
728 combo->setCurrentIndex( combo->count() - 1 );
730 combo->setToolTip( qfu(p_item->psz_longtext) );
732 label->setToolTip( qfu(p_item->psz_longtext) );
735 int IntegerListConfigControl::getValue()
737 return combo->itemData( combo->currentIndex() ).toInt();
740 /*********** Boolean **************/
741 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
742 module_config_t *_p_item,
743 QWidget *_parent, QGridLayout *l,
745 VIntConfigControl( _p_this, _p_item, _parent )
747 checkbox = new QCheckBox( qfu(p_item->psz_text) );
752 QHBoxLayout *layout = new QHBoxLayout();
753 layout->addWidget( checkbox, 0 );
754 widget->setLayout( layout );
758 l->addWidget( checkbox, line, 0 );
761 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
762 module_config_t *_p_item,
764 QCheckBox *_checkbox,
766 VIntConfigControl( _p_this, _p_item )
768 checkbox = _checkbox;
772 void BoolConfigControl::finish()
774 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
776 checkbox->setToolTip( qfu(p_item->psz_longtext) );
779 int BoolConfigControl::getValue()
781 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
784 /**************************************************************************
785 * Float-based controls
786 *************************************************************************/
788 /*********** Float **************/
789 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
790 module_config_t *_p_item,
791 QWidget *_parent, QGridLayout *l,
793 VFloatConfigControl( _p_this, _p_item, _parent )
795 label = new QLabel( qfu(p_item->psz_text) );
796 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
797 spin->setMaximumWidth( 90 );
802 QHBoxLayout *layout = new QHBoxLayout();
803 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
804 widget->setLayout( layout );
808 l->addWidget( label, line, 0 );
809 l->addWidget( spin, line, 1, Qt::AlignRight );
813 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
814 module_config_t *_p_item,
816 QDoubleSpinBox *_spin ) :
817 VFloatConfigControl( _p_this, _p_item )
824 void FloatConfigControl::finish()
826 spin->setMaximum( 2000000000. );
827 spin->setMinimum( -2000000000. );
828 spin->setSingleStep( 0.1 );
829 spin->setValue( (double)p_item->value.f );
830 spin->setToolTip( qfu(p_item->psz_longtext) );
832 label->setToolTip( qfu(p_item->psz_longtext) );
835 float FloatConfigControl::getValue()
837 return (float)spin->value();
840 /*********** Float with range **************/
841 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
842 module_config_t *_p_item,
843 QWidget *_parent, QGridLayout *l,
845 FloatConfigControl( _p_this, _p_item, _parent, l, line )
850 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
851 module_config_t *_p_item,
853 QDoubleSpinBox *_spin ) :
854 FloatConfigControl( _p_this, _p_item, _label, _spin )
859 void FloatRangeConfigControl::finish()
861 spin->setMaximum( (double)p_item->max.f );
862 spin->setMinimum( (double)p_item->min.f );
866 /**********************************************************************
867 * Key selector widget
868 **********************************************************************/
869 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
870 module_config_t *_p_item,
871 QWidget *_parent, QGridLayout *l,
873 ConfigControl( _p_this, _p_item, _parent )
876 label = new QLabel( qtr("Select an action to change the associated hotkey") );
877 table = new QTreeWidget( 0 );
882 QVBoxLayout *layout = new QVBoxLayout();
883 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
884 widget->setLayout( layout );
888 l->addWidget( label, line, 0, 1, 2 );
889 l->addWidget( table, line+1, 0, 1,2 );
893 void KeySelectorControl::finish()
896 label->setToolTip( qfu(p_item->psz_longtext) );
899 table->setColumnCount( 2 );
900 table->setAlternatingRowColors( true );
902 module_t *p_main = config_FindModule( p_this, "main" );
905 for (size_t i = 0; i < p_main->confsize; i++)
907 module_config_t *p_item = p_main->p_config + i;
909 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
910 strstr( p_item->psz_name , "key-" ) )
912 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
913 treeItem->setText( 0, qfu( p_item->psz_text ) );
914 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
915 treeItem->setData( 0, Qt::UserRole,
916 QVariant::fromValue( (void*)p_item ) );
918 table->addTopLevelItem( treeItem );
921 table->resizeColumnToContents( 0 );
923 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
924 this, selectKey( QTreeWidgetItem * ) );
927 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
929 module_config_t *p_keyItem = static_cast<module_config_t*>
930 (keyItem->data( 0, Qt::UserRole ).value<void*>());
932 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
934 if( d->result() == QDialog::Accepted )
936 p_keyItem->value.i = d->keyValue;
939 for( int i = 0; i < table->topLevelItemCount() ; i++ )
941 QTreeWidgetItem *it = table->topLevelItem(i);
942 module_config_t *p_item = static_cast<module_config_t*>
943 (it->data( 0, Qt::UserRole ).value<void*>());
944 it->setText( 1, VLCKeyToString( p_item->value.i ) );
948 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
953 void KeySelectorControl::doApply()
955 foreach( module_config_t *p_current, values )
957 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
961 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
962 const char * _keyToChange ) :
963 QDialog(0), keyValue(0)
968 keyToChange = _keyToChange;
969 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
971 QVBoxLayout *l = new QVBoxLayout( this );
972 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
973 warning = new QLabel();
974 l->addWidget( selected , Qt::AlignCenter );
975 l->addWidget( warning, Qt::AlignCenter );
977 QHBoxLayout *l2 = new QHBoxLayout();
978 QPushButton *ok = new QPushButton( qtr("OK") );
980 QPushButton *cancel = new QPushButton( qtr("Cancel") );
981 l2->addWidget( cancel );
983 BUTTONACT( ok, accept() );
984 BUTTONACT( cancel, reject() );
989 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
991 if( e->key() == Qt::Key_Tab ) return;
992 int i_vlck = qtEventToVLCKey( e );
993 selected->setText( VLCKeyToString( i_vlck ) );
995 module_config_t *p_current = NULL;
996 foreach( p_current, values )
998 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
1001 p_current->value.i = 0;
1009 qtr("Warning: the key is already assigned to \"") +
1010 QString( p_current->psz_text ) + "\"" );
1012 else warning->setText( "" );