X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fpreferences_widgets.cpp;h=396da64011dfcc9bdf35b2a9f54df96f1e134da9;hb=60e75ffe8f3643379916d86625203426854df5e5;hp=96dcb92c91af7a451ddd31d550960bc3fb57e185;hpb=f5d10727954d8b176a25a54e12e30832b599b509;p=vlc diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp index 96dcb92c91..396da64011 100644 --- a/modules/gui/qt4/components/preferences_widgets.cpp +++ b/modules/gui/qt4/components/preferences_widgets.cpp @@ -136,12 +136,10 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, p_control = new DirectoryConfigControl( p_this, p_item, parent, l, line ); break; -#if 0 case CONFIG_ITEM_FONT: p_control = new FontConfigControl( p_this, p_item, parent, l, - line, false ); + line); break; -#endif case CONFIG_ITEM_KEY: p_control = new KeySelectorControl( p_this, p_item, parent, l, line ); break; @@ -199,6 +197,29 @@ void ConfigControl::doApply( intf_thread_t *p_intf ) } } +/******************************************************* + * Simple widgets + *******************************************************/ +InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent ) +{ + 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 + */ + const char * pixmaps[] = { ":/prefsmenu/sample_classic", + ":/prefsmenu/sample_complete", + ":/prefsmenu/sample_minimal", + ":/prefsmenu/sample_skins" }; + setPixmap( QPixmap( pixmaps[ comboid ] ) ); +} + + + /************************************************************************** * String-based controls *************************************************************************/ @@ -306,7 +327,7 @@ FileConfigControl::FileConfigControl( vlc_object_t *_p_this, void FileConfigControl::updateField() { QString file = QFileDialog::getOpenFileName( NULL, - qtr( "Select File" ), qfu( config_GetHomeDir() ) ); + qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) ); if( file.isNull() ) return; text->setText( toNativeSeparators( file ) ); } @@ -340,37 +361,45 @@ void DirectoryConfigControl::updateField() QString dir = QFileDialog::getExistingDirectory( NULL, qtr( "Select Directory" ), text->text().isEmpty() ? - qfu( config_GetHomeDir() ) : text->text(), + QVLCUserDir( VLC_HOME_DIR ) : text->text(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); if( dir.isNull() ) return; text->setText( toNativeSepNoSlash( dir ) ); } -#if 0 -#include - /********* String / Font **********/ FontConfigControl::FontConfigControl( vlc_object_t *_p_this, - module_config_t *_p_item, QWidget *_p_widget, - QGridLayout *_p_layout, int& _int, bool _pwd ) : - FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd) -{} + module_config_t *_p_item, QWidget *_parent, + QGridLayout *_p_layout, int& line) : + VStringConfigControl( _p_this, _p_item, _parent ) +{ + label = new QLabel( qtr(p_item->psz_text) ); + font = new QFontComboBox( _parent ); + font->setCurrentFont( QFont( qfu( p_item->value.psz) ) ); + if( !_p_layout ) + { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget( label, 0 ); + layout->addWidget( font, 1 ); + widget->setLayout( layout ); + } + else + { + _p_layout->addWidget( label, line, 0 ); + _p_layout->addWidget( font, line, 1, 1, -1 ); + } +} FontConfigControl::FontConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_p_label, - QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ): - FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd) -{} - -void FontConfigControl::updateField() + QFontComboBox *_p_font): + VStringConfigControl( _p_this, _p_item) { - bool ok; - QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL ); - if( !ok ) return; - text->setText( font.family() ); + label = _p_label; + font = _p_font; + font->setCurrentFont( QFont( qfu( p_item->value.psz) ) ); } -#endif /********* String / choice list **********/ StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this, @@ -1014,7 +1043,7 @@ BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this, BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_label, - QCheckBox *_checkbox, + QAbstractButton *_checkbox, bool bycat ) : VIntConfigControl( _p_this, _p_item ) { @@ -1025,14 +1054,13 @@ BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this, void BoolConfigControl::finish() { - checkbox->setCheckState( p_item->value.i == true ? Qt::Checked - : Qt::Unchecked ); + checkbox->setChecked( p_item->value.i == true ); checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) ); } int BoolConfigControl::getValue() { - return checkbox->checkState() == Qt::Checked ? true : false; + return checkbox->isChecked(); } /************************************************************************** @@ -1138,9 +1166,8 @@ 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(3); @@ -1158,9 +1185,8 @@ 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 ); @@ -1171,6 +1197,8 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this, 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() @@ -1223,12 +1251,14 @@ void KeySelectorControl::finish() { QList list = table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly ); - if( list.count() > 1 ) + 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); @@ -1237,23 +1267,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(); - if( !keyItem ) return; 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(); @@ -1262,8 +1303,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 ) @@ -1271,6 +1317,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) int newValue = d->keyValue; shortcutValue->setText( VLCKeyToString( newValue ) ); shortcutValue->setValue( newValue ); + shortcutValue->setGlobal( b_global ); if( d->conflicts ) { @@ -1278,11 +1325,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. */ @@ -1295,8 +1342,10 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) void KeySelectorControl::setTheKey() { if( !table->currentItem() ) return; - table->currentItem()->setText( 1, shortcutValue->text() ); - table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() ); + table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1, + shortcutValue->text() ); + table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1, + Qt::UserRole, shortcutValue->getValue() ); } void KeySelectorControl::doApply() @@ -1309,24 +1358,39 @@ 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, const QString& keyToChange, - QWidget *_parent ) : - QDialog( _parent ), keyValue(0) + 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 ); + setWindowRole( "vlc-key-input" ); 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") ); @@ -1344,14 +1408,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;