1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX)
29 * - Improvements over WX
30 * - Password field implementation (through "pwd" bool param
31 * - Validator for modulelist
32 * - Implement update stuff using a general Updated signal
35 #include "components/preferences_widgets.hpp"
36 #include "util/customwidgets.hpp"
43 #include <QGridLayout>
45 #include <QFileDialog>
46 #include <QFontDialog>
48 #include <QTreeWidgetItem>
50 QString formatTooltip(const QString & tooltip)
53 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
54 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
55 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
56 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
57 "-qt-block-indent:0; text-indent:0px;\">" +
63 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
64 module_config_t *p_item,
68 return createControl( p_this, p_item, parent, NULL, i );
71 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
72 module_config_t *p_item,
74 QGridLayout *l, int &line )
76 ConfigControl *p_control = NULL;
77 if( p_item->psz_current ) return NULL;
79 switch( p_item->i_type )
81 case CONFIG_ITEM_MODULE:
82 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
85 case CONFIG_ITEM_MODULE_CAT:
86 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
89 case CONFIG_ITEM_MODULE_LIST:
90 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
93 case CONFIG_ITEM_MODULE_LIST_CAT:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
97 case CONFIG_ITEM_STRING:
99 p_control = new StringConfigControl( p_this, p_item, parent,
102 p_control = new StringListConfigControl( p_this, p_item,
103 parent, false, l, line );
105 case CONFIG_ITEM_INTEGER:
107 p_control = new IntegerListConfigControl( p_this, p_item,
108 parent, false, l, line );
109 else if( p_item->min.i || p_item->max.i )
110 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
113 p_control = new IntegerConfigControl( p_this, p_item, parent,
116 case CONFIG_ITEM_FILE:
117 p_control = new FileConfigControl( p_this, p_item, parent, l,
120 case CONFIG_ITEM_DIRECTORY:
121 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
124 case CONFIG_ITEM_FONT:
125 p_control = new FontConfigControl( p_this, p_item, parent, l,
128 case CONFIG_ITEM_KEY:
129 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
131 case CONFIG_ITEM_BOOL:
132 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
134 case CONFIG_ITEM_FLOAT:
135 if( p_item->min.f || p_item->max.f )
136 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
139 p_control = new FloatConfigControl( p_this, p_item, parent,
148 void ConfigControl::doApply( intf_thread_t *p_intf )
154 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
156 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
161 VFloatConfigControl *vfcc =
162 qobject_cast<VFloatConfigControl *>(this);
164 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
169 VStringConfigControl *vscc =
170 qobject_cast<VStringConfigControl *>(this);
172 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
177 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
184 /**************************************************************************
185 * String-based controls
186 *************************************************************************/
188 /*********** String **************/
189 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
190 module_config_t *_p_item,
191 QWidget *_parent, QGridLayout *l,
192 int &line, bool pwd ) :
193 VStringConfigControl( _p_this, _p_item, _parent )
195 label = new QLabel( qfu(p_item->psz_text) );
196 text = new QLineEdit( qfu(p_item->value.psz) );
201 QHBoxLayout *layout = new QHBoxLayout();
202 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
203 widget->setLayout( layout );
207 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
211 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
212 module_config_t *_p_item,
213 QLabel *_label, QLineEdit *_text, bool pwd ):
214 VStringConfigControl( _p_this, _p_item )
221 void StringConfigControl::finish()
223 text->setText( qfu(p_item->value.psz) );
224 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
226 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
229 /*********** File **************/
230 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
231 module_config_t *_p_item,
232 QWidget *_parent, QGridLayout *l,
233 int &line, bool pwd ) :
234 VStringConfigControl( _p_this, _p_item, _parent )
236 label = new QLabel( qfu(p_item->psz_text) );
237 text = new QLineEdit( qfu(p_item->value.psz) );
238 browse = new QPushButton( qtr( "Browse..." ) );
239 QHBoxLayout *textAndButton = new QHBoxLayout();
240 textAndButton->setMargin( 0 );
241 textAndButton->addWidget( text, 2 );
242 textAndButton->addWidget( browse, 0 );
244 BUTTONACT( browse, updateField() );
250 QHBoxLayout *layout = new QHBoxLayout();
251 layout->addWidget( label, 0 );
252 layout->addLayout( textAndButton, 1 );
253 widget->setLayout( layout );
257 l->addWidget( label, line, 0 );
258 l->addLayout( textAndButton, line, 1 );
263 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
264 module_config_t *_p_item,
265 QLabel *_label, QLineEdit *_text,
266 QPushButton *_button, bool pwd ):
267 VStringConfigControl( _p_this, _p_item )
273 BUTTONACT( browse, updateField() );
278 void FileConfigControl::updateField()
280 QString file = QFileDialog::getOpenFileName( NULL,
281 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
282 if( file.isNull() ) return;
283 text->setText( file );
286 void FileConfigControl::finish()
288 text->setText( qfu(p_item->value.psz) );
289 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
291 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
294 /********* String / Directory **********/
295 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
296 module_config_t *_p_item, QWidget *_p_widget,
297 QGridLayout *_p_layout, int& _int, bool _pwd ) :
298 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
301 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
302 module_config_t *_p_item, QLabel *_p_label,
303 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
304 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
307 void DirectoryConfigControl::updateField()
309 QString dir = QFileDialog::getExistingDirectory( NULL,
310 qtr( "Select Directory" ),
311 text->text().isEmpty() ?
312 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
313 QFileDialog::ShowDirsOnly |
314 QFileDialog::DontResolveSymlinks );
315 if( dir.isNull() ) return;
316 text->setText( dir );
319 /********* String / Font **********/
320 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
321 module_config_t *_p_item, QWidget *_p_widget,
322 QGridLayout *_p_layout, int& _int, bool _pwd ) :
323 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
326 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
327 module_config_t *_p_item, QLabel *_p_label,
328 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
329 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
332 void FontConfigControl::updateField()
335 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
337 text->setText( font.family() );
340 /********* String / choice list **********/
341 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
342 module_config_t *_p_item, QWidget *_parent, bool bycat,
343 QGridLayout *l, int &line) :
344 VStringConfigControl( _p_this, _p_item, _parent )
346 label = new QLabel( qfu(p_item->psz_text) );
347 combo = new QComboBox();
351 QHBoxLayout *layout = new QHBoxLayout();
352 layout->addWidget( label ); layout->addWidget( combo );
353 widget->setLayout( layout );
357 l->addWidget( label, line, 0 );
358 l->addWidget( combo, line, 1, Qt::AlignRight );
361 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
362 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
363 bool bycat ) : VStringConfigControl( _p_this, _p_item )
370 void StringListConfigControl::finish( bool bycat )
372 combo->setEditable( false );
374 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
376 combo->addItem( qfu(p_item->ppsz_list_text ?
377 p_item->ppsz_list_text[i_index] :
378 p_item->ppsz_list[i_index] ),
379 QVariant( p_item->ppsz_list[i_index] ) );
380 if( p_item->value.psz && !strcmp( p_item->value.psz,
381 p_item->ppsz_list[i_index] ) )
382 combo->setCurrentIndex( combo->count() - 1 );
384 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
386 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
389 QString StringListConfigControl::getValue()
391 return combo->itemData( combo->currentIndex() ).toString();
394 /********* Module **********/
395 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
396 module_config_t *_p_item, QWidget *_parent, bool bycat,
397 QGridLayout *l, int &line) :
398 VStringConfigControl( _p_this, _p_item, _parent )
400 label = new QLabel( qfu(p_item->psz_text) );
401 combo = new QComboBox();
405 QHBoxLayout *layout = new QHBoxLayout();
406 layout->addWidget( label ); layout->addWidget( combo );
407 widget->setLayout( layout );
411 l->addWidget( label, line, 0 );
412 l->addWidget( combo, line, 1, Qt::AlignRight );
415 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
416 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
417 bool bycat ) : VStringConfigControl( _p_this, _p_item )
424 void ModuleConfigControl::finish( bool bycat )
429 combo->setEditable( false );
431 /* build a list of available modules */
432 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
433 combo->addItem( qtr("Default") );
434 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
436 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
440 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
442 for (size_t i = 0; i < p_parser->confsize; i++)
444 module_config_t *p_config = p_parser->p_config + i;
445 /* Hack: required subcategory is stored in i_min */
446 if( p_config->i_type == CONFIG_SUBCATEGORY &&
447 p_config->value.i == p_item->min.i )
448 combo->addItem( qfu(p_parser->psz_longname),
449 QVariant( p_parser->psz_object_name ) );
450 if( p_item->value.psz && !strcmp( p_item->value.psz,
451 p_parser->psz_object_name) )
452 combo->setCurrentIndex( combo->count() - 1 );
455 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
457 combo->addItem( qfu(p_parser->psz_longname),
458 QVariant( p_parser->psz_object_name ) );
459 if( p_item->value.psz && !strcmp( p_item->value.psz,
460 p_parser->psz_object_name) )
461 combo->setCurrentIndex( combo->count() - 1 );
464 vlc_list_release( p_list );
465 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
467 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
470 QString ModuleConfigControl::getValue()
472 return combo->itemData( combo->currentIndex() ).toString();
475 /********* Module list **********/
476 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
477 module_config_t *_p_item, QWidget *_parent, bool bycat,
478 QGridLayout *l, int &line) :
479 VStringConfigControl( _p_this, _p_item, _parent )
481 groupBox = new QGroupBox ( qfu(p_item->psz_text) );
482 text = new QLineEdit();
483 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
488 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
489 it != modules.end(); it++ )
491 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
493 layoutGroupBox->addWidget( text, boxline, 0 );
497 QVBoxLayout *layout = new QVBoxLayout();
498 layout->addWidget( groupBox, line, 0 );
499 widget->setLayout( layout );
503 l->addWidget( groupBox, line, 0, 1, -1 );
506 text->setToolTip( formatTooltip( qfu( p_item->psz_longtext) ) );
509 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
510 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
511 bool bycat ) : VStringConfigControl( _p_this, _p_item )
519 ModuleListConfigControl::~ModuleListConfigControl()
521 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
522 it != modules.end(); it++ )
530 #define CHECKBOX_LISTS \
532 QCheckBox *cb = new QCheckBox( qfu( p_parser->psz_longname ) );\
533 checkBoxListItem *cbl = new checkBoxListItem; \
535 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
536 cb->setToolTip( formatTooltip( qfu(p_parser->psz_longname)) );\
537 cbl->checkBox = cb; \
540 while( p_parser->pp_shortcuts[++i] != NULL); \
543 cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
544 : p_parser->psz_object_name ); \
545 modules.push_back( cbl ); \
549 void ModuleListConfigControl::finish( bool bycat )
554 /* build a list of available modules */
555 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
556 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
558 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
562 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
564 for (size_t i = 0; i < p_parser->confsize; i++)
566 module_config_t *p_config = p_parser->p_config + i;
567 /* Hack: required subcategory is stored in i_min */
568 if( p_config->i_type == CONFIG_SUBCATEGORY &&
569 p_config->value.i == p_item->min.i )
575 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
580 vlc_list_release( p_list );
581 text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
583 groupBox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
585 #undef CHECKBOX_LISTS
587 QString ModuleListConfigControl::getValue()
592 void ModuleListConfigControl::hide()
594 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
595 it != modules.end(); it++ )
597 (*it)->checkBox->hide();
602 void ModuleListConfigControl::show()
604 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
605 it != modules.end(); it++ )
607 (*it)->checkBox->show();
613 void ModuleListConfigControl::onUpdate( int value )
618 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
619 it != modules.end(); it++ )
621 if( (*it)->checkBox->isChecked() )
625 text->setText( text->text() + (*it)->psz_module );
630 text->setText( text->text() + ":" + (*it)->psz_module );
636 /**************************************************************************
637 * Integer-based controls
638 *************************************************************************/
640 /*********** Integer **************/
641 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
642 module_config_t *_p_item,
643 QWidget *_parent, QGridLayout *l,
645 VIntConfigControl( _p_this, _p_item, _parent )
647 label = new QLabel( qfu(p_item->psz_text) );
648 spin = new QSpinBox; spin->setMinimumWidth( 80 );
649 spin->setAlignment( Qt::AlignRight );
650 spin->setMaximumWidth( 90 );
655 QHBoxLayout *layout = new QHBoxLayout();
656 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
657 widget->setLayout( layout );
661 l->addWidget( label, line, 0 );
662 l->addWidget( spin, line, 1, Qt::AlignRight );
665 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
666 module_config_t *_p_item,
667 QLabel *_label, QSpinBox *_spin ) :
668 VIntConfigControl( _p_this, _p_item )
675 void IntegerConfigControl::finish()
677 spin->setMaximum( 2000000000 );
678 spin->setMinimum( -2000000000 );
679 spin->setValue( p_item->value.i );
680 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
682 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
685 int IntegerConfigControl::getValue()
687 return spin->value();
690 /********* Integer range **********/
691 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
692 module_config_t *_p_item,
693 QWidget *_parent, QGridLayout *l,
695 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
700 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
701 module_config_t *_p_item,
702 QLabel *_label, QSpinBox *_spin ) :
703 IntegerConfigControl( _p_this, _p_item, _label, _spin )
708 void IntegerRangeConfigControl::finish()
710 spin->setMaximum( p_item->max.i );
711 spin->setMinimum( p_item->min.i );
714 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
715 vlc_object_t *_p_this,
716 module_config_t *_p_item,
717 QLabel *_label, QSlider *_slider ):
718 VIntConfigControl( _p_this, _p_item )
722 slider->setMaximum( p_item->max.i );
723 slider->setMinimum( p_item->min.i );
724 slider->setValue( p_item->value.i );
725 slider->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
727 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
730 int IntegerRangeSliderConfigControl::getValue()
732 return slider->value();
736 /********* Integer / choice list **********/
737 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
738 module_config_t *_p_item, QWidget *_parent, bool bycat,
739 QGridLayout *l, int &line) :
740 VIntConfigControl( _p_this, _p_item, _parent )
742 label = new QLabel( qfu(p_item->psz_text) );
743 combo = new QComboBox();
747 QHBoxLayout *layout = new QHBoxLayout();
748 layout->addWidget( label ); layout->addWidget( combo );
749 widget->setLayout( layout );
753 l->addWidget( label, line, 0 );
754 l->addWidget( combo, line, 1, Qt::AlignRight );
757 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
758 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
759 bool bycat ) : VIntConfigControl( _p_this, _p_item )
766 void IntegerListConfigControl::finish( bool bycat )
768 combo->setEditable( false );
770 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
772 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
773 QVariant( p_item->pi_list[i_index] ) );
774 if( p_item->value.i == p_item->pi_list[i_index] )
775 combo->setCurrentIndex( combo->count() - 1 );
777 combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
779 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
782 int IntegerListConfigControl::getValue()
784 return combo->itemData( combo->currentIndex() ).toInt();
787 /*********** Boolean **************/
788 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
789 module_config_t *_p_item,
790 QWidget *_parent, QGridLayout *l,
792 VIntConfigControl( _p_this, _p_item, _parent )
794 checkbox = new QCheckBox( qfu(p_item->psz_text) );
799 QHBoxLayout *layout = new QHBoxLayout();
800 layout->addWidget( checkbox, 0 );
801 widget->setLayout( layout );
805 l->addWidget( checkbox, line, 0 );
808 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
809 module_config_t *_p_item,
811 QCheckBox *_checkbox,
813 VIntConfigControl( _p_this, _p_item )
815 checkbox = _checkbox;
819 void BoolConfigControl::finish()
821 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
823 checkbox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
826 int BoolConfigControl::getValue()
828 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
831 /**************************************************************************
832 * Float-based controls
833 *************************************************************************/
835 /*********** Float **************/
836 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
837 module_config_t *_p_item,
838 QWidget *_parent, QGridLayout *l,
840 VFloatConfigControl( _p_this, _p_item, _parent )
842 label = new QLabel( qfu(p_item->psz_text) );
843 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
844 spin->setMaximumWidth( 90 );
845 spin->setAlignment( Qt::AlignRight );
850 QHBoxLayout *layout = new QHBoxLayout();
851 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
852 widget->setLayout( layout );
856 l->addWidget( label, line, 0 );
857 l->addWidget( spin, line, 1, Qt::AlignRight );
861 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
862 module_config_t *_p_item,
864 QDoubleSpinBox *_spin ) :
865 VFloatConfigControl( _p_this, _p_item )
872 void FloatConfigControl::finish()
874 spin->setMaximum( 2000000000. );
875 spin->setMinimum( -2000000000. );
876 spin->setSingleStep( 0.1 );
877 spin->setValue( (double)p_item->value.f );
878 spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
880 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
883 float FloatConfigControl::getValue()
885 return (float)spin->value();
888 /*********** Float with range **************/
889 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
890 module_config_t *_p_item,
891 QWidget *_parent, QGridLayout *l,
893 FloatConfigControl( _p_this, _p_item, _parent, l, line )
898 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
899 module_config_t *_p_item,
901 QDoubleSpinBox *_spin ) :
902 FloatConfigControl( _p_this, _p_item, _label, _spin )
907 void FloatRangeConfigControl::finish()
909 spin->setMaximum( (double)p_item->max.f );
910 spin->setMinimum( (double)p_item->min.f );
914 /**********************************************************************
915 * Key selector widget
916 **********************************************************************/
917 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
918 module_config_t *_p_item,
919 QWidget *_parent, QGridLayout *l,
921 ConfigControl( _p_this, _p_item, _parent )
924 label = new QLabel( qtr("Select an action to change the associated hotkey") );
925 table = new QTreeWidget( 0 );
930 QVBoxLayout *layout = new QVBoxLayout();
931 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
932 widget->setLayout( layout );
936 l->addWidget( label, line, 0, 1, 2 );
937 l->addWidget( table, line+1, 0, 1,2 );
941 void KeySelectorControl::finish()
944 label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
947 table->setColumnCount( 2 );
948 table->setAlternatingRowColors( true );
950 module_t *p_main = config_FindModule( p_this, "main" );
953 for (size_t i = 0; i < p_main->confsize; i++)
955 module_config_t *p_item = p_main->p_config + i;
957 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
958 strstr( p_item->psz_name , "key-" ) )
960 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
961 treeItem->setText( 0, qfu( p_item->psz_text ) );
962 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
963 treeItem->setData( 0, Qt::UserRole,
964 QVariant::fromValue( (void*)p_item ) );
966 table->addTopLevelItem( treeItem );
969 table->resizeColumnToContents( 0 );
971 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
972 this, selectKey( QTreeWidgetItem * ) );
975 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
977 module_config_t *p_keyItem = static_cast<module_config_t*>
978 (keyItem->data( 0, Qt::UserRole ).value<void*>());
980 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
982 if( d->result() == QDialog::Accepted )
984 p_keyItem->value.i = d->keyValue;
987 for( int i = 0; i < table->topLevelItemCount() ; i++ )
989 QTreeWidgetItem *it = table->topLevelItem(i);
990 module_config_t *p_item = static_cast<module_config_t*>
991 (it->data( 0, Qt::UserRole ).value<void*>());
992 it->setText( 1, VLCKeyToString( p_item->value.i ) );
996 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1001 void KeySelectorControl::doApply()
1003 foreach( module_config_t *p_current, values )
1005 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1009 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1010 const char * _keyToChange ) :
1011 QDialog(0), keyValue(0)
1016 keyToChange = _keyToChange;
1017 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1019 QVBoxLayout *l = new QVBoxLayout( this );
1020 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
1021 warning = new QLabel();
1022 l->addWidget( selected , Qt::AlignCenter );
1023 l->addWidget( warning, Qt::AlignCenter );
1025 QHBoxLayout *l2 = new QHBoxLayout();
1026 QPushButton *ok = new QPushButton( qtr("OK") );
1027 l2->addWidget( ok );
1028 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1029 l2->addWidget( cancel );
1031 BUTTONACT( ok, accept() );
1032 BUTTONACT( cancel, reject() );
1037 void KeyInputDialog::checkForConflicts( int i_vlckey )
1040 module_config_t *p_current = NULL;
1041 foreach( p_current, values )
1043 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1046 p_current->value.i = 0;
1054 qtr("Warning: the key is already assigned to \"") +
1055 QString( p_current->psz_text ) + "\"" );
1057 else warning->setText( "" );
1060 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1062 if( e->key() == Qt::Key_Tab ) return;
1063 int i_vlck = qtEventToVLCKey( e );
1064 selected->setText( VLCKeyToString( i_vlck ) );
1065 checkForConflicts( i_vlck );
1069 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1071 int i_vlck = qtWheelEventToVLCKey( e );
1072 selected->setText( VLCKeyToString( i_vlck ) );
1073 checkForConflicts( i_vlck );