📄 preferences_widgets.cpp
字号:
QSignalMapper *signalMapper = new QSignalMapper(this); /* Some stringLists like Capture listings have action associated */ for( int i = 0; i < p_item->i_action; i++ ) { QPushButton *button = new QPushButton( qfu( p_item->ppsz_action_text[i] )); CONNECT( button, clicked(), signalMapper, map() ); signalMapper->setMapping( button, i ); l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i, Qt::AlignRight ); } CONNECT( signalMapper, mapped( int ), this, actionRequested( int ) ); }}IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_label, QComboBox *_combo, bool bycat ) : VIntConfigControl( _p_this, _p_item ){ combo = _combo; label = _label; module_config_t *p_module_config = config_FindConfig( p_this, getName() ); finish( p_module_config, bycat );}void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat ){ combo->setEditable( false ); if(!p_module_config) return; for( int i_index = 0; i_index < p_module_config->i_list; i_index++ ) { combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ), QVariant( p_module_config->pi_list[i_index] ) ); if( p_module_config->value.i == p_module_config->pi_list[i_index] ) combo->setCurrentIndex( combo->count() - 1 ); } combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) ); if( label ) label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );}void IntegerListConfigControl::actionRequested( int i_action ){ /* Supplementary check for boundaries */ if( i_action < 0 || i_action >= p_item->i_action ) return; module_config_t *p_module_config = config_FindConfig( p_this, getName() ); if(!p_module_config) return; vlc_value_t val; val.i_int = combo->itemData( combo->currentIndex() ).toInt(); p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 ); if( p_module_config->b_dirty ) { combo->clear(); finish( p_module_config, true ); p_module_config->b_dirty = false; }}int IntegerListConfigControl::getValue(){ return combo->itemData( combo->currentIndex() ).toInt();}/*********** 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 == true ? Qt::Checked : Qt::Unchecked ); checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );}int BoolConfigControl::getValue(){ return checkbox->checkState() == Qt::Checked ? true : 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( MINWIDTH_BOX ); spin->setMaximumWidth( MINWIDTH_BOX ); spin->setAlignment( Qt::AlignRight ); finish(); if( !l ) { QHBoxLayout *layout = new QHBoxLayout(); layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN ); widget->setLayout( layout ); } else { l->addWidget( label, line, 0 ); l->addWidget( spin, line, LAST_COLUMN, 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") ); /* Deactivated for now QLabel *searchLabel = new QLabel( qtr( "Search" ) ); QLineEdit *actionSearch = new QLineEdit;*/ table = new QTreeWidget; table->setColumnCount(2); table->headerItem()->setText( 0, qtr( "Action" ) ); table->headerItem()->setText( 1, qtr( "Shortcut" ) ); shortcutValue = new KeyShortcutEdit; shortcutValue->setReadOnly(true); QPushButton *clearButton = new QPushButton( qtr( "Clear" ) ); QPushButton *setButton = new QPushButton( qtr( "Set" ) ); setButton->setDefault( true ); finish(); gLayout->addWidget( label, 0, 0, 1, 4 ); /* deactivated for now 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 ); l->addWidget( keyContainer, line, 0, 1, 2 ); CONNECT( clearButton, clicked(), shortcutValue, clear() ); CONNECT( clearButton, clicked(), this, setTheKey() ); BUTTONACT( setButton, setTheKey() );}void KeySelectorControl::finish(){ if( label ) label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) ); /* Fill the table */ table->setColumnCount( 2 ); table->setAlternatingRowColors( true ); /* Get the main Module */ module_t *p_main = module_Find( p_this, "main" ); assert( p_main ); /* Access to the module_config_t */ unsigned confsize; module_config_t *p_config; p_config = module_GetConfig (p_main, &confsize); for (size_t i = 0; i < confsize; i++) { module_config_t *p_item = p_config + i; /* If we are a key option not empty */ if( p_item->i_type & CONFIG_ITEM && p_item->psz_name && strstr( p_item->psz_name , "key-" ) && !EMPTY_STR( p_item->psz_text ) ) { /* Each tree item has: - QString text in column 0 - QString name in data of column 0 - KeyValue in String in column 1 - KeyValue in int in column 1 */ QTreeWidgetItem *treeItem = new QTreeWidgetItem(); treeItem->setText( 0, qtr( p_item->psz_text ) ); treeItem->setData( 0, Qt::UserRole, QVariant( qfu( p_item->psz_name ) ) ); treeItem->setText( 1, VLCKeyToString( p_item->value.i ) ); treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) ); table->addTopLevelItem( treeItem ); } } module_PutConfig (p_config); module_Put (p_main); table->resizeColumnToContents( 0 ); CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ), this, selectKey( QTreeWidgetItem * ) ); CONNECT( table, itemSelectionChanged (), this, select1Key() ); CONNECT( shortcutValue, pressed(), this, selectKey() );}/* Show the key selected from the table in the keySelector */void KeySelectorControl::select1Key(){ QTreeWidgetItem *keyItem = table->currentItem(); shortcutValue->setText( keyItem->text( 1 ) ); shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );}void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ){ /* This happens when triggered by ClickEater */ if( keyItem == NULL ) keyItem = table->currentItem(); /* This can happen when nothing is selected on the treeView and the shortcutValue is clicked */ if( !keyItem ) return; /* Launch a small dialog to ask for a new key */ KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget ); d->exec(); if( d->result() == QDialog::Accepted ) { int newValue = d->keyValue; shortcutValue->setText( VLCKeyToString( newValue ) ); shortcutValue->setValue( newValue ); if( d->conflicts ) { QTreeWidgetItem *it; for( int i = 0; i < table->topLevelItemCount() ; i++ ) { it = table->topLevelItem(i); if( ( keyItem != it ) && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) ) { it->setData( 1, Qt::UserRole, QVariant( -1 ) ); it->setText( 1, qtr( "Unset" ) ); } } /* We already made an OK once. */ setTheKey(); } } delete d;}void KeySelectorControl::setTheKey(){ table->currentItem()->setText( 1, shortcutValue->text() ); table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );}void KeySelectorControl::doApply(){ QTreeWidgetItem *it; for( int i = 0; i < table->topLevelItemCount() ; i++ ) { it = table->topLevelItem(i); if( it->data( 1, Qt::UserRole ).toInt() >= 0 ) config_PutInt( p_this, qtu( it->data( 0, Qt::UserRole ).toString() ), it->data( 1, Qt::UserRole ).toInt() ); }}KeyInputDialog::KeyInputDialog( QTreeWidget *_table, QString keyToChange, QWidget *_parent ) : QDialog( _parent ), keyValue(0){ setModal( true ); conflicts = false; table = _table; setWindowTitle( qtr( "Hotkey for " ) + keyToChange ); vLayout = new QVBoxLayout( this ); selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange ); vLayout->addWidget( selected , Qt::AlignCenter ); buttonBox = new QDialogButtonBox; QPushButton *ok = new QPushButton( qtr("OK") ); QPushButton *cancel = new QPushButton( qtr("Cancel") ); buttonBox->addButton( ok, QDialogButtonBox::AcceptRole ); buttonBox->addButton( cancel, QDialogButtonBox::RejectRole ); ok->setDefault( true ); vLayout->addWidget( buttonBox ); buttonBox->hide(); CONNECT( buttonBox, accepted(), this, accept() ); CONNECT( buttonBox, rejected(), this, reject() );}void KeyInputDialog::checkForConflicts( int i_vlckey ){ QList<QTreeWidgetItem *> conflictList = table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 ); if( conflictList.size() ) { QLabel *warning = new QLabel( qtr("Warning: the key is already assigned to \"") + conflictList[0]->text( 0 ) + "\"" ); vLayout->insertWidget( 1, warning ); buttonBox->show(); conflicts = true; } else accept();}void KeyInputDialog::keyPressEvent( QKeyEvent *e ){ if( e->key() == Qt::Key_Tab || e->key() == Qt::Key_Shift || e->key() == Qt::Key_Control || e->key() == Qt::Key_Meta || e->key() == Qt::Key_Alt || e->key() == Qt::Key_AltGr ) return; int i_vlck = qtEventToVLCKey( e ); selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) ); checkForConflicts( i_vlck ); keyValue = i_vlck;}void KeyInputDialog::wheelEvent( QWheelEvent *e ){ int i_vlck = qtWheelEventToVLCKey( e ); selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) ); checkForConflicts( i_vlck ); keyValue = i_vlck;}void KeyShortcutEdit::mousePressEvent( QMouseEvent *){ emit pressed();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -