EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) : QDialog( _parent ), ui( new Ui::EffectSelectDialog ), m_sourceModel(), m_model(), m_descriptionWidget( NULL ) { ui->setupUi( this ); setWindowIcon( embed::getIconPixmap( "setup_audio" ) ); // query effects EffectKeyList subPluginEffectKeys; for (const Plugin::Descriptor* desc: pluginFactory->descriptors(Plugin::Effect)) { if( desc->subPluginFeatures ) { desc->subPluginFeatures->listSubPluginKeys( // as iterators are always stated to be not // equal with pointers, we dereference the // iterator and take the address of the item, // so we're on the safe side and the compiler // likely will reduce that to just "it" desc, subPluginEffectKeys ); } else { m_effectKeys << EffectKey( desc, desc->name ); } } m_effectKeys += subPluginEffectKeys; // and fill our source model m_sourceModel.setHorizontalHeaderItem( 0, new QStandardItem( "Name" ) ); m_sourceModel.setHorizontalHeaderItem( 1, new QStandardItem( "Type" ) ); int row = 0; for( EffectKeyList::ConstIterator it = m_effectKeys.begin(); it != m_effectKeys.end(); ++it ) { QString name; QString type; if( ( *it ).desc->subPluginFeatures ) { name = ( *it ).name; type = ( *it ).desc->displayName; } else { name = ( *it ).desc->displayName; type = "LMMS"; } m_sourceModel.setItem( row, 0, new QStandardItem( name ) ); m_sourceModel.setItem( row, 1, new QStandardItem( type ) ); ++row; } // setup filtering m_model.setSourceModel( &m_sourceModel ); m_model.setFilterCaseSensitivity( Qt::CaseInsensitive ); connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ), &m_model, SLOT( setFilterFixedString( const QString & ) ) ); connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( updateSelection() ) ); connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ), SLOT( sortAgain() ) ); ui->pluginList->setModel( &m_model ); // setup selection model QItemSelectionModel * selectionModel = new QItemSelectionModel( &m_model ); ui->pluginList->setSelectionModel( selectionModel ); connect( selectionModel, SIGNAL( currentRowChanged( const QModelIndex &, const QModelIndex & ) ), SLOT( rowChanged( const QModelIndex &, const QModelIndex & ) ) ); connect( ui->pluginList, SIGNAL( doubleClicked( const QModelIndex & ) ), SLOT( acceptSelection() ) ); // try to accept current selection when pressing "OK" connect( ui->buttonBox, SIGNAL( accepted() ), this, SLOT( acceptSelection() ) ); #if QT_VERSION >= 0x050000 #define setResizeMode setSectionResizeMode #endif ui->pluginList->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ); ui->pluginList->verticalHeader()->hide(); ui->pluginList->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch ); ui->pluginList->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents ); ui->pluginList->sortByColumn( 0, Qt::AscendingOrder ); #if QT_VERSION >= 0x050000 #undef setResizeMode #endif updateSelection(); show(); }
EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) : QDialog( _parent ), ui( new Ui::EffectSelectDialog ), m_sourceModel(), m_model(), m_descriptionWidget( NULL ) { ui->setupUi( this ); setWindowIcon( embed::getIconPixmap( "setup_audio" ) ); // query effects EffectKeyList subPluginEffectKeys; for (const Plugin::Descriptor* desc: pluginFactory->descriptors(Plugin::Effect)) { if( desc->subPluginFeatures ) { desc->subPluginFeatures->listSubPluginKeys( // as iterators are always stated to be not // equal with pointers, we dereference the // iterator and take the address of the item, // so we're on the safe side and the compiler // likely will reduce that to just "it" desc, subPluginEffectKeys ); } else { m_effectKeys << EffectKey( desc, desc->name ); } } m_effectKeys += subPluginEffectKeys; // and fill our source model QStringList pluginNames; for( EffectKeyList::ConstIterator it = m_effectKeys.begin(); it != m_effectKeys.end(); ++it ) { if( ( *it ).desc->subPluginFeatures ) { pluginNames += QString( "%1: %2" ).arg( ( *it ).desc->displayName, ( *it ).name ); } else { pluginNames += ( *it ).desc->displayName; } } int row = 0; for( QStringList::ConstIterator it = pluginNames.begin(); it != pluginNames.end(); ++it ) { m_sourceModel.setItem( row, 0, new QStandardItem( *it ) ); ++row; } // setup filtering m_model.setSourceModel( &m_sourceModel ); m_model.setFilterCaseSensitivity( Qt::CaseInsensitive ); connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ), &m_model, SLOT( setFilterFixedString( const QString & ) ) ); connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( updateSelection() ) ); ui->pluginList->setModel( &m_model ); // setup selection model QItemSelectionModel * selectionModel = new QItemSelectionModel( &m_model ); ui->pluginList->setSelectionModel( selectionModel ); connect( selectionModel, SIGNAL( currentRowChanged( const QModelIndex &, const QModelIndex & ) ), SLOT( rowChanged( const QModelIndex &, const QModelIndex & ) ) ); connect( ui->pluginList, SIGNAL( doubleClicked( const QModelIndex & ) ), SLOT( acceptSelection() ) ); // try to accept current selection when pressing "OK" connect( ui->buttonBox, SIGNAL( accepted() ), this, SLOT( acceptSelection() ) ); updateSelection(); show(); }