X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fpreferences_widgets.cpp;h=2b2163d2f16f605047af3aea8c98a81e9db92a89;hb=814c0649f8a4c4e7f8084bdd1f2843a5f14382d6;hp=1adcb1c81f6b002b52f685d80e1272467bf146bd;hpb=97253c8fcabd784cefa4a76d6f1ed0dfa2ed285b;p=vlc diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp index 1adcb1c81f..2b2163d2f1 100644 --- a/modules/gui/qt4/components/preferences_widgets.cpp +++ b/modules/gui/qt4/components/preferences_widgets.cpp @@ -199,6 +199,29 @@ void ConfigControl::doApply( intf_thread_t *p_intf ) } } +/******************************************************* + * Simple widgets + *******************************************************/ +InterfacePreviewWidget::InterfacePreviewWidget + ( QWidget *parent ) : QLabel( parent, 0 ) +{ + setGeometry( 0, 0, 128, 100 ); + setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); +} + +void InterfacePreviewWidget::setPreview( int comboid ) +{ + /* Need to move resources references as soon as qt4.cpp + local defines has been moved somewhere else + */ + char * pixmaps[] = { ":/prefsmenu/sample_classic", + ":/prefsmenu/sample_complete", + ":/prefsmenu/sample_minimal" }; + setPixmap( QPixmap( pixmaps[ comboid ] ) ); +} + + + /************************************************************************** * String-based controls *************************************************************************/ @@ -1138,14 +1161,15 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this, 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;*/ + actionSearch = new SearchLineEdit( keyContainer ); table = new QTreeWidget; - table->setColumnCount(2); + table->setColumnCount(3); table->headerItem()->setText( 0, qtr( "Action" ) ); - table->headerItem()->setText( 1, qtr( "Shortcut" ) ); + table->headerItem()->setText( 1, qtr( "Hotkey" ) ); + table->headerItem()->setText( 2, qtr( "Global" ) ); + table->setAlternatingRowColors( true ); shortcutValue = new KeyShortcutEdit; shortcutValue->setReadOnly(true); @@ -1156,19 +1180,20 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this, 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( 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 ); + l->addWidget( keyContainer, line, 0, 1, -1 ); CONNECT( clearButton, clicked(), shortcutValue, clear() ); CONNECT( clearButton, clicked(), this, setTheKey() ); BUTTONACT( setButton, setTheKey() ); + CONNECT( actionSearch, textChanged( const QString& ), + this, filter( const QString& ) ); } void KeySelectorControl::finish() @@ -1177,8 +1202,6 @@ void KeySelectorControl::finish() 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_get_main(); @@ -1197,6 +1220,7 @@ void KeySelectorControl::finish() /* 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-" ) + && !strstr( p_item->psz_name , "global-key" ) && !EMPTY_STR( p_item->psz_text ) ) { /* @@ -1213,6 +1237,23 @@ void KeySelectorControl::finish() treeItem->setText( 1, VLCKeyToString( p_item->value.i ) ); treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) ); table->addTopLevelItem( treeItem ); + continue; + } + + if( p_item->i_type & CONFIG_ITEM && p_item->psz_name + && strstr( p_item->psz_name , "global-key" ) + && !EMPTY_STR( p_item->psz_text ) ) + { + QList list = + table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly ); + if( list.count() >= 1 ) + { + list[0]->setText( 2, VLCKeyToString( p_item->value.i ) ); + list[0]->setData( 2, Qt::UserRole, + QVariant( p_item->value.i ) ); + } + if( list.count() >= 2 ) + msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text ); } } module_config_free (p_config); @@ -1221,22 +1262,34 @@ void KeySelectorControl::finish() table->resizeColumnToContents( 0 ); CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ), - this, selectKey( QTreeWidgetItem * ) ); - CONNECT( table, itemSelectionChanged (), + this, selectKey( QTreeWidgetItem *, int ) ); + CONNECT( table, itemSelectionChanged(), this, select1Key() ); CONNECT( shortcutValue, pressed(), this, selectKey() ); } +void KeySelectorControl::filter( const QString &qs_search ) +{ + QList resultList = + table->findItems( qs_search, Qt::MatchContains, 0 ); + for( int i = 0; i < table->topLevelItemCount(); i++ ) + { + table->topLevelItem( i )->setHidden( + !resultList.contains( table->topLevelItem( i ) ) ); + } +} + /* 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() ); + shortcutValue->setGlobal( false ); } -void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) +void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column ) { /* This happens when triggered by ClickEater */ if( keyItem == NULL ) keyItem = table->currentItem(); @@ -1245,8 +1298,13 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) and the shortcutValue is clicked */ if( !keyItem ) return; + /* If clicked on the first column, assuming user wants the normal hotkey */ + if( column == 0 ) column = 1; + + bool b_global = ( column == 2 ); + /* Launch a small dialog to ask for a new key */ - KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget ); + KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global ); d->exec(); if( d->result() == QDialog::Accepted ) @@ -1254,6 +1312,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) int newValue = d->keyValue; shortcutValue->setText( VLCKeyToString( newValue ) ); shortcutValue->setValue( newValue ); + shortcutValue->setGlobal( b_global ); if( d->conflicts ) { @@ -1261,11 +1320,11 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) for( int i = 0; i < table->topLevelItemCount() ; i++ ) { it = table->topLevelItem(i); - if( ( keyItem != it ) - && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) ) + if( ( keyItem != it ) && + ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) ) { - it->setData( 1, Qt::UserRole, QVariant( -1 ) ); - it->setText( 1, qtr( "Unset" ) ); + it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) ); + it->setText( b_global ? 2 : 1, qtr( "Unset" ) ); } } /* We already made an OK once. */ @@ -1277,8 +1336,11 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) void KeySelectorControl::setTheKey() { - table->currentItem()->setText( 1, shortcutValue->text() ); - table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() ); + if( !table->currentItem() ) return; + table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1, + shortcutValue->text() ); + table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1, + Qt::UserRole, shortcutValue->getValue() ); } void KeySelectorControl::doApply() @@ -1291,24 +1353,38 @@ void KeySelectorControl::doApply() config_PutInt( p_this, qtu( it->data( 0, Qt::UserRole ).toString() ), it->data( 1, Qt::UserRole ).toInt() ); + if( it->data( 2, Qt::UserRole ).toInt() >= 0 ) + config_PutInt( p_this, + qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ), + it->data( 2, Qt::UserRole ).toInt() ); + } } +/** + * Class KeyInputDialog + **/ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, - QString keyToChange, - QWidget *_parent ) : - QDialog( _parent ), keyValue(0) + const QString& keyToChange, + QWidget *_parent, + bool _b_global ) : + QDialog( _parent ), keyValue(0), b_global( _b_global ) { setModal( true ); conflicts = false; table = _table; - setWindowTitle( qtr( "Hotkey for " ) + keyToChange ); + setWindowTitle( b_global ? qtr( "Global" ): "" + + qtr( "Hotkey for " ) + keyToChange ); vLayout = new QVBoxLayout( this ); selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange ); vLayout->addWidget( selected , Qt::AlignCenter ); + warning = new QLabel; + warning->hide(); + vLayout->insertWidget( 1, warning ); + buttonBox = new QDialogButtonBox; QPushButton *ok = new QPushButton( qtr("OK") ); QPushButton *cancel = new QPushButton( qtr("Cancel") ); @@ -1326,14 +1402,16 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, void KeyInputDialog::checkForConflicts( int i_vlckey ) { QList conflictList = - table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 ); + table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, + b_global ? 2 : 1 ); - if( conflictList.size() ) + if( conflictList.size() && + conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 ) + /* Avoid 0 or -1 that are the "Unset" states */ { - QLabel *warning = new QLabel( - qtr("Warning: the key is already assigned to \"") + - conflictList[0]->text( 0 ) + "\"" ); - vLayout->insertWidget( 1, warning ); + warning->setText( qtr("Warning: the key is already assigned to \"") + + conflictList[0]->text( 0 ) + "\"" ); + warning->show(); buttonBox->show(); conflicts = true;