2
* EffectSelectDialog.cpp - dialog to choose effect plugin
4
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301 USA.
25
#include "EffectSelectDialog.h"
27
#include "ui_EffectSelectDialog.h"
29
#include "gui_templates.h"
33
EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
35
ui( new Ui::EffectSelectDialog ),
38
m_descriptionWidget( NULL )
42
setWindowIcon( embed::getIconPixmap( "setup_audio" ) );
45
Plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
47
for( Plugin::DescriptorList::ConstIterator it = m_pluginDescriptors.begin();
48
it != m_pluginDescriptors.end(); ++it )
50
if( it->type != Plugin::Effect )
54
if( it->subPluginFeatures )
56
it->subPluginFeatures->listSubPluginKeys(
57
// as iterators are always stated to be not
58
// equal with pointers, we dereference the
59
// iterator and take the address of the item,
60
// so we're on the safe side and the compiler
61
// likely will reduce that to just "it"
67
m_effectKeys << EffectKey( &( *it ), it->name );
72
// and fill our source model
73
QStringList pluginNames;
74
for( EffectKeyList::ConstIterator it = m_effectKeys.begin();
75
it != m_effectKeys.end(); ++it )
77
pluginNames += QString( ( *it ).desc->displayName ) +
78
( ( ( *it ).desc->subPluginFeatures != NULL ) ?
85
for( QStringList::ConstIterator it = pluginNames.begin();
86
it != pluginNames.end(); ++it )
88
m_sourceModel.setItem( row, 0, new QStandardItem( *it ) );
93
m_model.setSourceModel( &m_sourceModel );
94
m_model.setFilterCaseSensitivity( Qt::CaseInsensitive );
96
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
97
&m_model, SLOT( setFilterRegExp( const QString & ) ) );
98
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
99
this, SLOT( updateSelection() ) );
101
ui->pluginList->setModel( &m_model );
103
// setup selection model
104
QItemSelectionModel * selectionModel = new QItemSelectionModel( &m_model );
105
ui->pluginList->setSelectionModel( selectionModel );
106
connect( selectionModel, SIGNAL( currentRowChanged( const QModelIndex &,
107
const QModelIndex & ) ),
108
SLOT( rowChanged( const QModelIndex &, const QModelIndex & ) ) );
109
connect( ui->pluginList, SIGNAL( doubleClicked( const QModelIndex & ) ),
110
SLOT( acceptSelection() ) );
112
// try to accept current selection when pressing "OK"
113
connect( ui->buttonBox, SIGNAL( accepted() ),
114
this, SLOT( acceptSelection() ) );
123
EffectSelectDialog::~EffectSelectDialog()
130
Effect * EffectSelectDialog::instantiateSelectedPlugin( EffectChain * _parent )
132
if( !m_currentSelection.name.isEmpty() && m_currentSelection.desc )
134
return Effect::instantiate( m_currentSelection.desc->name,
135
_parent, &m_currentSelection );
143
void EffectSelectDialog::acceptSelection()
145
if( m_currentSelection.isValid() )
154
void EffectSelectDialog::rowChanged( const QModelIndex & _idx,
155
const QModelIndex & )
157
delete m_descriptionWidget;
158
m_descriptionWidget = NULL;
160
if( m_model.mapToSource( _idx ).row() < 0 )
162
// invalidate current selection
163
m_currentSelection = Plugin::Descriptor::SubPluginFeatures::Key();
167
m_currentSelection = m_effectKeys[m_model.mapToSource( _idx ).row()];
169
if( m_currentSelection.desc && m_currentSelection.desc->subPluginFeatures )
171
m_descriptionWidget = new QWidget;
172
QVBoxLayout * l = new QVBoxLayout( m_descriptionWidget );
176
ui->scrollArea->setWidget( m_descriptionWidget );
178
m_currentSelection.desc->subPluginFeatures->
179
fillDescriptionWidget( m_descriptionWidget, &m_currentSelection );
180
foreach( QWidget * w, m_descriptionWidget->findChildren<QWidget *>() )
182
if( w->parent() == m_descriptionWidget )
187
l->setSizeConstraint( QLayout::SetFixedSize );
188
m_descriptionWidget->show();
195
void EffectSelectDialog::updateSelection()
197
// no valid selection anymore due to changed filter?
198
if( ui->pluginList->selectionModel()->selection().size() <= 0 )
200
// then select our first item
201
ui->pluginList->selectionModel()->select( m_model.index( 0, 0 ),
202
QItemSelectionModel::ClearAndSelect );
203
rowChanged( m_model.index( 0, 0 ), QModelIndex() );
209
#include "moc_EffectSelectDialog.cxx"