+
+/*********** Boolean **************/
+BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QWidget *_parent, QGridLayout *l,
+ int &line ) :
+ VIntConfigControl( _p_this, _p_item, _parent )
+{
+ checkbox = new QCheckBox( qtr(p_item->psz_text) );
+ finish();
+
+ if( !l )
+ {
+ QHBoxLayout *layout = new QHBoxLayout();
+ layout->addWidget( checkbox, 0 );
+ widget->setLayout( layout );
+ }
+ else
+ {
+ l->addWidget( checkbox, line, 0 );
+ }
+}
+BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QLabel *_label,
+ QCheckBox *_checkbox,
+ bool bycat ) :
+ VIntConfigControl( _p_this, _p_item )
+{
+ checkbox = _checkbox;
+ finish();
+}
+
+void BoolConfigControl::finish()
+{
+ checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
+ : Qt::Unchecked );
+ checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
+}
+
+int BoolConfigControl::getValue()
+{
+ return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
+}
+
+/**************************************************************************
+ * Float-based controls
+ *************************************************************************/
+
+/*********** Float **************/
+FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QWidget *_parent, QGridLayout *l,
+ int &line ) :
+ VFloatConfigControl( _p_this, _p_item, _parent )
+{
+ label = new QLabel( qtr(p_item->psz_text) );
+ spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
+ spin->setMaximumWidth( 90 );
+ spin->setAlignment( Qt::AlignRight );
+ finish();
+
+ if( !l )
+ {
+ QHBoxLayout *layout = new QHBoxLayout();
+ layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
+ widget->setLayout( layout );
+ }
+ else
+ {
+ l->addWidget( label, line, 0 );
+ l->addWidget( spin, line, 1, Qt::AlignRight );
+ }
+}
+
+FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QLabel *_label,
+ QDoubleSpinBox *_spin ) :
+ VFloatConfigControl( _p_this, _p_item )
+{
+ spin = _spin;
+ label = _label;
+ finish();
+}
+
+void FloatConfigControl::finish()
+{
+ spin->setMaximum( 2000000000. );
+ spin->setMinimum( -2000000000. );
+ spin->setSingleStep( 0.1 );
+ spin->setValue( (double)p_item->value.f );
+ spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
+ if( label )
+ label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
+}
+
+float FloatConfigControl::getValue()
+{
+ return (float)spin->value();
+}
+
+/*********** Float with range **************/
+FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QWidget *_parent, QGridLayout *l,
+ int &line ) :
+ FloatConfigControl( _p_this, _p_item, _parent, l, line )
+{
+ finish();
+}
+
+FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QLabel *_label,
+ QDoubleSpinBox *_spin ) :
+ FloatConfigControl( _p_this, _p_item, _label, _spin )
+{
+ finish();
+}
+
+void FloatRangeConfigControl::finish()
+{
+ spin->setMaximum( (double)p_item->max.f );
+ spin->setMinimum( (double)p_item->min.f );
+}
+
+
+/**********************************************************************
+ * Key selector widget
+ **********************************************************************/
+KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QWidget *_parent, QGridLayout *l,
+ int &line ) :
+ ConfigControl( _p_this, _p_item, _parent )
+
+{
+ QWidget *keyContainer = new QWidget;
+ QGridLayout *gLayout = new QGridLayout( keyContainer );
+
+ label = new QLabel( qtr("Select an action to change the associated hotkey") );
+ QLabel *searchLabel = new QLabel( qtr( "Search" ) );
+
+ table = new QTreeWidget;
+ table->setColumnCount(2);
+ table->headerItem()->setText( 0, qtr( "Action" ) );
+ table->headerItem()->setText( 1, qtr( "Shortcut" ) );
+
+ QLineEdit *shortcutValue = new QLineEdit;
+ shortcutValue->setReadOnly(true);
+ QLineEdit *actionSearch = new QLineEdit;
+
+ QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
+ QPushButton *setButton = new QPushButton( qtr( "Set" ) );
+ finish();
+
+ gLayout->addWidget( label, 0, 0, 1, 4 );
+ gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
+ gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
+ gLayout->addWidget( table, 2, 0, 1, 4 );
+ gLayout->addWidget( clearButton, 3, 0, 1, 1 );
+ gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
+ gLayout->addWidget( setButton, 3, 3, 1, 1 );
+
+ if( !l ) /* This shouldn't happen */
+ {
+ QVBoxLayout *layout = new QVBoxLayout();
+ layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
+ widget->setLayout( layout );
+ }
+ else
+ {
+ l->addWidget( keyContainer, 0, 0, 1, 2 );
+ }
+}
+
+void KeySelectorControl::finish()
+{
+ if( label )
+ label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
+
+ /* Fill the table */
+ table->setColumnCount( 2 );
+ table->setAlternatingRowColors( true );
+
+ module_t *p_main = config_FindModule( p_this, "main" );
+ assert( p_main );
+
+ for (size_t i = 0; i < p_main->confsize; i++)
+ {
+ module_config_t *p_item = p_main->p_config + i;
+
+ if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
+ strstr( p_item->psz_name , "key-" ) )
+ {
+ QTreeWidgetItem *treeItem = new QTreeWidgetItem();
+ treeItem->setText( 0, qtr( p_item->psz_text ) );
+ treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
+ treeItem->setData( 0, Qt::UserRole,
+ QVariant::fromValue( (void*)p_item ) );
+ values += p_item;
+ table->addTopLevelItem( treeItem );
+ }
+ }
+ table->resizeColumnToContents( 0 );
+
+ CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
+ this, selectKey( QTreeWidgetItem * ) );
+}
+
+void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
+{
+ module_config_t *p_keyItem = static_cast<module_config_t*>
+ (keyItem->data( 0, Qt::UserRole ).value<void*>());
+
+ KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
+ d->exec();
+ if( d->result() == QDialog::Accepted )
+ {
+ p_keyItem->value.i = d->keyValue;
+ if( d->conflicts )
+ {
+ for( int i = 0; i < table->topLevelItemCount() ; i++ )
+ {
+ QTreeWidgetItem *it = table->topLevelItem(i);
+ module_config_t *p_item = static_cast<module_config_t*>
+ (it->data( 0, Qt::UserRole ).value<void*>());
+ if( p_keyItem != p_item && p_item->value.i == d->keyValue )
+ p_item->value.i = 0;
+ it->setText( 1, VLCKeyToString( p_item->value.i ) );
+ }
+ }
+ else
+ keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
+ }
+ delete d;
+}
+
+void KeySelectorControl::doApply()
+{
+ foreach( module_config_t *p_current, values )
+ {
+ config_PutInt( p_this, p_current->psz_name, p_current->value.i );
+ }
+}
+
+KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
+ const char * _keyToChange ) :
+ QDialog(0), keyValue(0)
+{
+ setModal( true );
+ values = _values;
+ conflicts = false;
+ keyToChange = _keyToChange;
+ setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
+
+ QVBoxLayout *l = new QVBoxLayout( this );
+ selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
+ warning = new QLabel();
+ l->addWidget( selected , Qt::AlignCenter );
+ l->addWidget( warning, Qt::AlignCenter );
+
+ QHBoxLayout *l2 = new QHBoxLayout();
+ QPushButton *ok = new QPushButton( qtr("OK") );
+ l2->addWidget( ok );
+ QPushButton *cancel = new QPushButton( qtr("Cancel") );
+ l2->addWidget( cancel );
+
+ BUTTONACT( ok, accept() );
+ BUTTONACT( cancel, reject() );
+
+ l->addLayout( l2 );
+}
+
+void KeyInputDialog::checkForConflicts( int i_vlckey )
+{
+ conflicts = false;
+ module_config_t *p_current = NULL;
+ foreach( p_current, values )
+ {
+ if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
+ keyToChange ) )
+ {
+ conflicts = true;
+ break;
+ }
+ }
+ if( conflicts )
+ {
+ warning->setText(
+ qtr("Warning: the key is already assigned to \"") +
+ QString( p_current->psz_text ) + "\"" );
+ }
+ else warning->setText( "" );
+}
+
+void KeyInputDialog::keyPressEvent( QKeyEvent *e )
+{
+ if( e->key() == Qt::Key_Tab ) return;
+ int i_vlck = qtEventToVLCKey( e );
+ selected->setText( VLCKeyToString( i_vlck ) );
+ checkForConflicts( i_vlck );
+ keyValue = i_vlck;
+}
+
+void KeyInputDialog::wheelEvent( QWheelEvent *e )
+{
+ int i_vlck = qtWheelEventToVLCKey( e );
+ selected->setText( VLCKeyToString( i_vlck ) );
+ checkForConflicts( i_vlck );
+ keyValue = i_vlck;
+}