~ubuntu-branches/ubuntu/oneiric/lmms/oneiric

« back to all changes in this revision

Viewing changes to src/gui/EffectSelectDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-12 13:32:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101112133232-vdld83iyji8srqti
Tags: 0.4.7-2ubuntu1
* Re-sync with Debian (LP: #606533):
  - Replace build-dep on libwine-dev with libwine-dev-unstable to build
    against the newer Wine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * EffectSelectDialog.cpp - dialog to choose effect plugin
 
3
 *
 
4
 * Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 *
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
#include "EffectSelectDialog.h"
 
26
 
 
27
#include "ui_EffectSelectDialog.h"
 
28
 
 
29
#include "gui_templates.h"
 
30
#include "embed.h"
 
31
 
 
32
 
 
33
EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
 
34
        QDialog( _parent ),
 
35
        ui( new Ui::EffectSelectDialog ),
 
36
        m_sourceModel(),
 
37
        m_model(),
 
38
        m_descriptionWidget( NULL )
 
39
{
 
40
        ui->setupUi( this );
 
41
 
 
42
        setWindowIcon( embed::getIconPixmap( "setup_audio" ) );
 
43
 
 
44
        // query effects
 
45
        Plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
 
46
 
 
47
        for( Plugin::DescriptorList::ConstIterator it = m_pluginDescriptors.begin();
 
48
                                                                                it != m_pluginDescriptors.end(); ++it )
 
49
        {
 
50
                if( it->type != Plugin::Effect )
 
51
                {
 
52
                        continue;
 
53
                }
 
54
                if( it->subPluginFeatures )
 
55
                {
 
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"
 
62
                                                        &( *it ),
 
63
                                                        m_effectKeys );
 
64
                }
 
65
                else
 
66
                {
 
67
                        m_effectKeys << EffectKey( &( *it ), it->name );
 
68
 
 
69
                }
 
70
        }
 
71
 
 
72
        // and fill our source model
 
73
        QStringList pluginNames;
 
74
        for( EffectKeyList::ConstIterator it = m_effectKeys.begin();
 
75
                                                                                it != m_effectKeys.end(); ++it )
 
76
        {
 
77
                pluginNames += QString( ( *it ).desc->displayName ) +
 
78
                        ( ( ( *it ).desc->subPluginFeatures != NULL ) ?
 
79
                                                        ": " + ( *it ).name
 
80
                                                :
 
81
                                                        "" );
 
82
        }
 
83
 
 
84
        int row = 0;
 
85
        for( QStringList::ConstIterator it = pluginNames.begin();
 
86
                                                                it != pluginNames.end(); ++it )
 
87
        {
 
88
                m_sourceModel.setItem( row, 0, new QStandardItem( *it ) );
 
89
                ++row;
 
90
        }
 
91
 
 
92
        // setup filtering
 
93
        m_model.setSourceModel( &m_sourceModel );
 
94
        m_model.setFilterCaseSensitivity( Qt::CaseInsensitive );
 
95
 
 
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() ) );
 
100
 
 
101
        ui->pluginList->setModel( &m_model );
 
102
 
 
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() ) );
 
111
 
 
112
        // try to accept current selection when pressing "OK"
 
113
        connect( ui->buttonBox, SIGNAL( accepted() ),
 
114
                                this, SLOT( acceptSelection() ) );
 
115
        
 
116
        updateSelection();
 
117
        show();
 
118
}
 
119
 
 
120
 
 
121
 
 
122
 
 
123
EffectSelectDialog::~EffectSelectDialog()
 
124
{
 
125
}
 
126
 
 
127
 
 
128
 
 
129
 
 
130
Effect * EffectSelectDialog::instantiateSelectedPlugin( EffectChain * _parent )
 
131
{
 
132
        if( !m_currentSelection.name.isEmpty() && m_currentSelection.desc )
 
133
        {
 
134
                return Effect::instantiate( m_currentSelection.desc->name,
 
135
                                                                                _parent, &m_currentSelection );
 
136
        }
 
137
        return NULL;
 
138
}
 
139
 
 
140
 
 
141
 
 
142
 
 
143
void EffectSelectDialog::acceptSelection()
 
144
{
 
145
        if( m_currentSelection.isValid() )
 
146
        {
 
147
                accept();
 
148
        }
 
149
}
 
150
 
 
151
 
 
152
 
 
153
 
 
154
void EffectSelectDialog::rowChanged( const QModelIndex & _idx,
 
155
                                                                                const QModelIndex & )
 
156
{
 
157
        delete m_descriptionWidget;
 
158
        m_descriptionWidget = NULL;
 
159
 
 
160
        if( m_model.mapToSource( _idx ).row() < 0 )
 
161
        {
 
162
                // invalidate current selection
 
163
                m_currentSelection = Plugin::Descriptor::SubPluginFeatures::Key();
 
164
        }
 
165
        else
 
166
        {
 
167
                m_currentSelection = m_effectKeys[m_model.mapToSource( _idx ).row()];
 
168
        }
 
169
        if( m_currentSelection.desc && m_currentSelection.desc->subPluginFeatures )
 
170
        {
 
171
                m_descriptionWidget = new QWidget;
 
172
                QVBoxLayout * l = new QVBoxLayout( m_descriptionWidget );
 
173
                l->setMargin( 4 );
 
174
                l->setSpacing( 0 );
 
175
 
 
176
                ui->scrollArea->setWidget( m_descriptionWidget );
 
177
 
 
178
                m_currentSelection.desc->subPluginFeatures->
 
179
                        fillDescriptionWidget( m_descriptionWidget, &m_currentSelection );
 
180
                foreach( QWidget * w, m_descriptionWidget->findChildren<QWidget *>() )
 
181
                {
 
182
                        if( w->parent() == m_descriptionWidget )
 
183
                        {
 
184
                                l->addWidget( w );
 
185
                        }
 
186
                }
 
187
                l->setSizeConstraint( QLayout::SetFixedSize );
 
188
                m_descriptionWidget->show();
 
189
        }
 
190
}
 
191
 
 
192
 
 
193
 
 
194
 
 
195
void EffectSelectDialog::updateSelection()
 
196
{
 
197
        // no valid selection anymore due to changed filter?
 
198
        if( ui->pluginList->selectionModel()->selection().size() <= 0 )
 
199
        {
 
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() );
 
204
        }
 
205
}
 
206
 
 
207
 
 
208
 
 
209
#include "moc_EffectSelectDialog.cxx"
 
210