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, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
41 #include <QGridLayout>
43 #include <QFileDialog>
44 #include <QFontDialog>
46 #include <QTreeWidgetItem>
47 #include <QSignalMapper>
48 #include <QDialogButtonBox>
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 || p_item->b_unsaveable ) return NULL;
79 switch( p_item->i_type )
81 case CONFIG_ITEM_MODULE:
82 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
85 case CONFIG_ITEM_MODULE_CAT:
86 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
89 case CONFIG_ITEM_MODULE_LIST:
90 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
93 case CONFIG_ITEM_MODULE_LIST_CAT:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
97 case CONFIG_ITEM_STRING:
99 p_control = new StringConfigControl( p_this, p_item, parent,
102 p_control = new StringListConfigControl( p_this, p_item,
103 parent, false, l, line );
105 case CONFIG_ITEM_PASSWORD:
106 if( !p_item->i_list )
107 p_control = new StringConfigControl( p_this, p_item, parent,
110 p_control = new StringListConfigControl( p_this, p_item,
111 parent, true, l, line );
113 case CONFIG_ITEM_INTEGER:
115 p_control = new IntegerListConfigControl( p_this, p_item,
116 parent, false, l, line );
117 else if( p_item->min.i || p_item->max.i )
118 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
121 p_control = new IntegerConfigControl( p_this, p_item, parent,
124 case CONFIG_ITEM_FILE:
125 p_control = new FileConfigControl( p_this, p_item, parent, l,
128 case CONFIG_ITEM_DIRECTORY:
129 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
132 case CONFIG_ITEM_FONT:
133 p_control = new FontConfigControl( p_this, p_item, parent, l,
136 case CONFIG_ITEM_KEY:
137 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
139 case CONFIG_ITEM_BOOL:
140 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
142 case CONFIG_ITEM_FLOAT:
143 if( p_item->min.f || p_item->max.f )
144 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
147 p_control = new FloatConfigControl( p_this, p_item, parent,
156 void ConfigControl::doApply( intf_thread_t *p_intf )
162 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
164 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
169 VFloatConfigControl *vfcc =
170 qobject_cast<VFloatConfigControl *>(this);
172 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
177 VStringConfigControl *vscc =
178 qobject_cast<VStringConfigControl *>(this);
180 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
185 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
192 /**************************************************************************
193 * String-based controls
194 *************************************************************************/
196 /*********** String **************/
197 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
198 module_config_t *_p_item,
199 QWidget *_parent, QGridLayout *l,
200 int &line, bool pwd ) :
201 VStringConfigControl( _p_this, _p_item, _parent )
203 label = new QLabel( qtr(p_item->psz_text) );
204 text = new QLineEdit( qfu(p_item->value.psz) );
205 if( pwd ) text->setEchoMode( QLineEdit::Password );
210 QHBoxLayout *layout = new QHBoxLayout();
211 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
212 widget->setLayout( layout );
216 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
220 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
221 module_config_t *_p_item,
222 QLabel *_label, QLineEdit *_text, bool pwd ):
223 VStringConfigControl( _p_this, _p_item )
230 void StringConfigControl::finish()
232 text->setText( qfu(p_item->value.psz) );
233 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
235 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
238 /*********** File **************/
239 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
240 module_config_t *_p_item,
241 QWidget *_parent, QGridLayout *l,
242 int &line, bool pwd ) :
243 VStringConfigControl( _p_this, _p_item, _parent )
245 label = new QLabel( qtr(p_item->psz_text) );
246 text = new QLineEdit( qfu(p_item->value.psz) );
247 browse = new QPushButton( qtr( "Browse..." ) );
248 QHBoxLayout *textAndButton = new QHBoxLayout();
249 textAndButton->setMargin( 0 );
250 textAndButton->addWidget( text, 2 );
251 textAndButton->addWidget( browse, 0 );
253 BUTTONACT( browse, updateField() );
259 QHBoxLayout *layout = new QHBoxLayout();
260 layout->addWidget( label, 0 );
261 layout->addLayout( textAndButton, 1 );
262 widget->setLayout( layout );
266 l->addWidget( label, line, 0 );
267 l->addLayout( textAndButton, line, 1 );
272 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
273 module_config_t *_p_item,
274 QLabel *_label, QLineEdit *_text,
275 QPushButton *_button, bool pwd ):
276 VStringConfigControl( _p_this, _p_item )
282 BUTTONACT( browse, updateField() );
287 void FileConfigControl::updateField()
289 QString file = QFileDialog::getOpenFileName( NULL,
290 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
291 if( file.isNull() ) return;
292 text->setText( file );
295 void FileConfigControl::finish()
297 text->setText( qfu(p_item->value.psz) );
298 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
300 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
303 /********* String / Directory **********/
304 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
305 module_config_t *_p_item, QWidget *_p_widget,
306 QGridLayout *_p_layout, int& _int, bool _pwd ) :
307 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
310 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
311 module_config_t *_p_item, QLabel *_p_label,
312 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
313 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
316 void DirectoryConfigControl::updateField()
318 QString dir = QFileDialog::getExistingDirectory( NULL,
319 qtr( "Select Directory" ),
320 text->text().isEmpty() ?
321 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
322 QFileDialog::ShowDirsOnly |
323 QFileDialog::DontResolveSymlinks );
324 if( dir.isNull() ) return;
325 text->setText( dir );
328 /********* String / Font **********/
329 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
330 module_config_t *_p_item, QWidget *_p_widget,
331 QGridLayout *_p_layout, int& _int, bool _pwd ) :
332 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
335 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
336 module_config_t *_p_item, QLabel *_p_label,
337 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
338 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
341 void FontConfigControl::updateField()
344 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
346 text->setText( font.family() );
349 /********* String / choice list **********/
350 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
351 module_config_t *_p_item, QWidget *_parent, bool bycat,
352 QGridLayout *l, int &line) :
353 VStringConfigControl( _p_this, _p_item, _parent )
355 label = new QLabel( qtr(p_item->psz_text) );
356 combo = new QComboBox();
357 combo->setMinimumWidth( 80 );
361 QHBoxLayout *layout = new QHBoxLayout();
362 layout->addWidget( label ); layout->addWidget( combo );
363 widget->setLayout( layout );
367 l->addWidget( label, line, 0 );
368 l->addWidget( combo, line, 1, Qt::AlignRight );
371 if( p_item->i_action )
373 QSignalMapper *signalMapper = new QSignalMapper(this);
375 /* Some stringLists like Capture listings have action associated */
376 for( int i = 0; i < p_item->i_action; i++ )
378 QPushButton *button =
379 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
380 CONNECT( button, clicked(), signalMapper, map() );
381 signalMapper->setMapping( button, i );
382 l->addWidget( button, line, 2 + i, Qt::AlignRight );
384 CONNECT( signalMapper, mapped( int ),
385 this, actionRequested( int ) );
389 void StringListConfigControl::actionRequested( int i_action )
391 /* Supplementary check for boundaries */
392 if( i_action < 0 || i_action >= p_item->i_action ) return;
396 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
398 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
400 if( p_item->b_dirty )
404 p_item->b_dirty = VLC_FALSE;
407 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
408 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
409 bool bycat ) : VStringConfigControl( _p_this, _p_item )
416 void StringListConfigControl::finish( bool bycat )
418 combo->setEditable( false );
420 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
422 combo->addItem( qfu(p_item->ppsz_list_text ?
423 p_item->ppsz_list_text[i_index] :
424 p_item->ppsz_list[i_index] ),
425 QVariant( p_item->ppsz_list[i_index] ) );
426 if( p_item->value.psz && !strcmp( p_item->value.psz,
427 p_item->ppsz_list[i_index] ) )
428 combo->setCurrentIndex( combo->count() - 1 );
430 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
432 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
435 QString StringListConfigControl::getValue()
437 return combo->itemData( combo->currentIndex() ).toString();
440 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
441 QComboBox *combo, QWidget *parent )
443 module_config_t *p_config =
444 config_FindConfig( VLC_OBJECT(p_intf), configname );
447 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
449 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
450 QVariant( p_config->pi_list[i_index] ) );
451 if( p_config->value.i == p_config->pi_list[i_index] )
453 combo->setCurrentIndex( i_index );
456 combo->setToolTip( qfu( p_config->psz_longtext ) );
460 /********* Module **********/
461 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
462 module_config_t *_p_item, QWidget *_parent, bool bycat,
463 QGridLayout *l, int &line) :
464 VStringConfigControl( _p_this, _p_item, _parent )
466 label = new QLabel( qtr(p_item->psz_text) );
467 combo = new QComboBox();
468 combo->setMinimumWidth( 80 );
472 QHBoxLayout *layout = new QHBoxLayout();
473 layout->addWidget( label ); layout->addWidget( combo );
474 widget->setLayout( layout );
478 l->addWidget( label, line, 0 );
479 l->addWidget( combo, line, 1, Qt::AlignRight );
483 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
484 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
485 bool bycat ) : VStringConfigControl( _p_this, _p_item )
492 void ModuleConfigControl::finish( bool bycat )
497 combo->setEditable( false );
499 /* build a list of available modules */
500 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
501 combo->addItem( qtr("Default") );
502 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
504 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
508 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
510 for (size_t i = 0; i < p_parser->confsize; i++)
512 module_config_t *p_config = p_parser->p_config + i;
513 /* Hack: required subcategory is stored in i_min */
514 if( p_config->i_type == CONFIG_SUBCATEGORY &&
515 p_config->value.i == p_item->min.i )
516 combo->addItem( qtr( module_GetLongName( p_parser )),
517 QVariant( module_GetObjName( p_parser ) ) );
518 if( p_item->value.psz && !strcmp( p_item->value.psz,
519 module_GetObjName( p_parser ) ) )
520 combo->setCurrentIndex( combo->count() - 1 );
523 else if( module_IsCapable( p_parser, p_item->psz_type ) )
525 combo->addItem( qtr(module_GetLongName( p_parser ) ),
526 QVariant( module_GetObjName( p_parser ) ) );
527 if( p_item->value.psz && !strcmp( p_item->value.psz,
528 module_GetObjName( p_parser ) ) )
529 combo->setCurrentIndex( combo->count() - 1 );
532 vlc_list_release( p_list );
533 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
535 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
538 QString ModuleConfigControl::getValue()
540 return combo->itemData( combo->currentIndex() ).toString();
543 /********* Module list **********/
544 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
545 module_config_t *_p_item, QWidget *_parent, bool bycat,
546 QGridLayout *l, int &line) :
547 VStringConfigControl( _p_this, _p_item, _parent )
549 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
550 text = new QLineEdit();
551 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
556 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
557 it != modules.end(); it++ )
559 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
561 layoutGroupBox->addWidget( text, boxline, 0 );
565 QVBoxLayout *layout = new QVBoxLayout();
566 layout->addWidget( groupBox, line, 0 );
567 widget->setLayout( layout );
571 l->addWidget( groupBox, line, 0, 1, -1 );
574 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
577 ModuleListConfigControl::~ModuleListConfigControl()
579 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
580 it != modules.end(); it++ )
588 #define CHECKBOX_LISTS \
590 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
591 checkBoxListItem *cbl = new checkBoxListItem; \
593 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
594 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
595 cbl->checkBox = cb; \
598 while( p_parser->pp_shortcuts[++i] != NULL); \
601 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
602 : module_GetObjName( p_parser ) ); \
603 modules.push_back( cbl ); \
607 void ModuleListConfigControl::finish( bool bycat )
612 /* build a list of available modules */
613 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
614 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
616 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
620 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
622 for (size_t i = 0; i < p_parser->confsize; i++)
624 module_config_t *p_config = p_parser->p_config + i;
625 /* Hack: required subcategory is stored in i_min */
626 if( p_config->i_type == CONFIG_SUBCATEGORY &&
627 p_config->value.i == p_item->min.i )
633 else if( module_IsCapable( p_parser, p_item->psz_type ) )
638 vlc_list_release( p_list );
639 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
641 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
643 #undef CHECKBOX_LISTS
645 QString ModuleListConfigControl::getValue()
650 void ModuleListConfigControl::hide()
652 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
653 it != modules.end(); it++ )
655 (*it)->checkBox->hide();
660 void ModuleListConfigControl::show()
662 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
663 it != modules.end(); it++ )
665 (*it)->checkBox->show();
671 void ModuleListConfigControl::onUpdate( int value )
676 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
677 it != modules.end(); it++ )
679 if( (*it)->checkBox->isChecked() )
683 text->setText( text->text() + (*it)->psz_module );
688 text->setText( text->text() + ":" + (*it)->psz_module );
694 /**************************************************************************
695 * Integer-based controls
696 *************************************************************************/
698 /*********** Integer **************/
699 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
700 module_config_t *_p_item,
701 QWidget *_parent, QGridLayout *l,
703 VIntConfigControl( _p_this, _p_item, _parent )
705 label = new QLabel( qtr(p_item->psz_text) );
706 spin = new QSpinBox; spin->setMinimumWidth( 80 );
707 spin->setAlignment( Qt::AlignRight );
708 spin->setMaximumWidth( 90 );
713 QHBoxLayout *layout = new QHBoxLayout();
714 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
715 widget->setLayout( layout );
719 l->addWidget( label, line, 0 );
720 l->addWidget( spin, line, 1, Qt::AlignRight );
723 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
724 module_config_t *_p_item,
725 QLabel *_label, QSpinBox *_spin ) :
726 VIntConfigControl( _p_this, _p_item )
733 void IntegerConfigControl::finish()
735 spin->setMaximum( 2000000000 );
736 spin->setMinimum( -2000000000 );
737 spin->setValue( p_item->value.i );
738 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
740 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
743 int IntegerConfigControl::getValue()
745 return spin->value();
748 /********* Integer range **********/
749 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
750 module_config_t *_p_item,
751 QWidget *_parent, QGridLayout *l,
753 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
758 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
759 module_config_t *_p_item,
760 QLabel *_label, QSpinBox *_spin ) :
761 IntegerConfigControl( _p_this, _p_item, _label, _spin )
766 void IntegerRangeConfigControl::finish()
768 spin->setMaximum( p_item->max.i );
769 spin->setMinimum( p_item->min.i );
772 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
773 vlc_object_t *_p_this,
774 module_config_t *_p_item,
775 QLabel *_label, QSlider *_slider ):
776 VIntConfigControl( _p_this, _p_item )
780 slider->setMaximum( p_item->max.i );
781 slider->setMinimum( p_item->min.i );
782 slider->setValue( p_item->value.i );
783 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
785 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
788 int IntegerRangeSliderConfigControl::getValue()
790 return slider->value();
794 /********* Integer / choice list **********/
795 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
796 module_config_t *_p_item, QWidget *_parent, bool bycat,
797 QGridLayout *l, int &line) :
798 VIntConfigControl( _p_this, _p_item, _parent )
800 label = new QLabel( qtr(p_item->psz_text) );
801 combo = new QComboBox();
802 combo->setMinimumWidth( 80 );
806 QHBoxLayout *layout = new QHBoxLayout();
807 layout->addWidget( label ); layout->addWidget( combo );
808 widget->setLayout( layout );
812 l->addWidget( label, line, 0 );
813 l->addWidget( combo, line, 1, Qt::AlignRight );
816 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
817 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
818 bool bycat ) : VIntConfigControl( _p_this, _p_item )
825 void IntegerListConfigControl::finish( bool bycat )
827 combo->setEditable( false );
829 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
831 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
832 QVariant( p_item->pi_list[i_index] ) );
833 if( p_item->value.i == p_item->pi_list[i_index] )
834 combo->setCurrentIndex( combo->count() - 1 );
836 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
838 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
841 int IntegerListConfigControl::getValue()
843 return combo->itemData( combo->currentIndex() ).toInt();
846 /*********** Boolean **************/
847 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
848 module_config_t *_p_item,
849 QWidget *_parent, QGridLayout *l,
851 VIntConfigControl( _p_this, _p_item, _parent )
853 checkbox = new QCheckBox( qtr(p_item->psz_text) );
858 QHBoxLayout *layout = new QHBoxLayout();
859 layout->addWidget( checkbox, 0 );
860 widget->setLayout( layout );
864 l->addWidget( checkbox, line, 0 );
867 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
868 module_config_t *_p_item,
870 QCheckBox *_checkbox,
872 VIntConfigControl( _p_this, _p_item )
874 checkbox = _checkbox;
878 void BoolConfigControl::finish()
880 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
882 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
885 int BoolConfigControl::getValue()
887 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
890 /**************************************************************************
891 * Float-based controls
892 *************************************************************************/
894 /*********** Float **************/
895 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
896 module_config_t *_p_item,
897 QWidget *_parent, QGridLayout *l,
899 VFloatConfigControl( _p_this, _p_item, _parent )
901 label = new QLabel( qtr(p_item->psz_text) );
902 spin = new QDoubleSpinBox;
903 spin->setMinimumWidth( 80 );
904 spin->setMaximumWidth( 90 );
905 spin->setAlignment( Qt::AlignRight );
910 QHBoxLayout *layout = new QHBoxLayout();
911 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
912 widget->setLayout( layout );
916 l->addWidget( label, line, 0 );
917 l->addWidget( spin, line, 1, Qt::AlignRight );
921 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
922 module_config_t *_p_item,
924 QDoubleSpinBox *_spin ) :
925 VFloatConfigControl( _p_this, _p_item )
932 void FloatConfigControl::finish()
934 spin->setMaximum( 2000000000. );
935 spin->setMinimum( -2000000000. );
936 spin->setSingleStep( 0.1 );
937 spin->setValue( (double)p_item->value.f );
938 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
940 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
943 float FloatConfigControl::getValue()
945 return (float)spin->value();
948 /*********** Float with range **************/
949 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
950 module_config_t *_p_item,
951 QWidget *_parent, QGridLayout *l,
953 FloatConfigControl( _p_this, _p_item, _parent, l, line )
958 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
959 module_config_t *_p_item,
961 QDoubleSpinBox *_spin ) :
962 FloatConfigControl( _p_this, _p_item, _label, _spin )
967 void FloatRangeConfigControl::finish()
969 spin->setMaximum( (double)p_item->max.f );
970 spin->setMinimum( (double)p_item->min.f );
974 /**********************************************************************
975 * Key selector widget
976 **********************************************************************/
977 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
978 module_config_t *_p_item,
979 QWidget *_parent, QGridLayout *l,
981 ConfigControl( _p_this, _p_item, _parent )
984 QWidget *keyContainer = new QWidget;
985 QGridLayout *gLayout = new QGridLayout( keyContainer );
988 qtr( "Select an action to change the associated hotkey") );
990 /* Deactivated for now
991 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
992 QLineEdit *actionSearch = new QLineEdit;*/
994 table = new QTreeWidget;
995 table->setColumnCount(2);
996 table->headerItem()->setText( 0, qtr( "Action" ) );
997 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
999 shortcutValue = new KeyShortcutEdit;
1000 shortcutValue->setReadOnly(true);
1002 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1003 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1006 gLayout->addWidget( label, 0, 0, 1, 4 );
1007 /* deactivated for now
1008 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1009 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1010 gLayout->addWidget( table, 2, 0, 1, 4 );
1011 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1012 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1013 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1015 l->addWidget( keyContainer, line, 0, 1, 2 );
1017 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1018 BUTTONACT( setButton, setTheKey() );
1021 void KeySelectorControl::finish()
1024 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1026 /* Fill the table */
1027 table->setColumnCount( 2 );
1028 table->setAlternatingRowColors( true );
1030 module_t *p_main = config_FindModule( p_this, "main" );
1033 for (size_t i = 0; i < p_main->confsize; i++)
1035 module_config_t *p_item = p_main->p_config + i;
1037 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1038 strstr( p_item->psz_name , "key-" ) && !EMPTY_STR( p_item->psz_text ) )
1040 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1041 treeItem->setText( 0, qtr( p_item->psz_text ) );
1042 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1043 treeItem->setData( 0, Qt::UserRole,
1044 QVariant::fromValue( (void*)p_item ) );
1046 table->addTopLevelItem( treeItem );
1049 table->resizeColumnToContents( 0 );
1051 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1052 this, select1Key( QTreeWidgetItem * ) );
1053 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1054 this, selectKey( QTreeWidgetItem * ) );
1055 CONNECT( shortcutValue, pressed(), this, selectKey() );
1058 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1060 shortcutValue->setText( keyItem->text( 1 ) );
1063 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1065 /* This happens when triggered by ClickEater */
1066 if( keyItem == NULL ) keyItem = table->currentItem();
1068 /* This can happen when nothing is selected on the treeView
1069 and the shortcutValue is clicked */
1070 if( !keyItem ) return;
1072 module_config_t *p_keyItem = static_cast<module_config_t*>
1073 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1075 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text, widget );
1077 if( d->result() == QDialog::Accepted )
1079 p_keyItem->value.i = d->keyValue;
1082 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1084 QTreeWidgetItem *it = table->topLevelItem(i);
1085 module_config_t *p_item = static_cast<module_config_t*>
1086 (it->data( 0, Qt::UserRole ).value<void*>());
1087 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1088 p_item->value.i = 0;
1089 shortcutValue->setText( VLCKeyToString( p_item->value.i ) );
1093 shortcutValue->setText( VLCKeyToString( p_keyItem->value.i ) );
1098 void KeySelectorControl::setTheKey()
1100 table->currentItem()->setText( 1, shortcutValue->text() );
1103 void KeySelectorControl::doApply()
1105 foreach( module_config_t *p_current, values )
1107 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1111 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1112 const char * _keyToChange,
1113 QWidget *_parent ) :
1114 QDialog( _parent ), keyValue(0)
1119 keyToChange = _keyToChange;
1121 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1123 vLayout = new QVBoxLayout( this );
1124 selected = new QLabel( qtr("Press the new keys for ") + qfu( keyToChange ) );
1125 vLayout->addWidget( selected , Qt::AlignCenter );
1127 buttonBox = new QDialogButtonBox;
1128 QPushButton *ok = new QPushButton( qtr("OK") );
1129 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1130 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1131 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1133 vLayout->addWidget( buttonBox );
1136 CONNECT( buttonBox, accepted(), this, accept() );
1137 CONNECT( buttonBox, rejected(), this, reject() );
1140 void KeyInputDialog::checkForConflicts( int i_vlckey )
1143 module_config_t *p_current = NULL;
1144 /* Search for conflicts */
1145 foreach( p_current, values )
1147 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1157 QLabel *warning = new QLabel(
1158 qtr("Warning: the key is already assigned to \"") +
1159 qfu( p_current->psz_text ) + "\"" );
1160 warning->setWordWrap( true );
1161 vLayout->insertWidget( 1, warning );
1167 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1169 if( e->key() == Qt::Key_Tab ) return;
1170 int i_vlck = qtEventToVLCKey( e );
1171 selected->setText( VLCKeyToString( i_vlck ) );
1172 checkForConflicts( i_vlck );
1176 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1178 int i_vlck = qtWheelEventToVLCKey( e );
1179 selected->setText( VLCKeyToString( i_vlck ) );
1180 checkForConflicts( i_vlck );
1184 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)