~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to src/core/effect_select_dialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Tobias Doerffel
  • Date: 2007-09-17 15:00:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070917150024-mo0zk4ks81jawqii
Tags: 0.3.0-1ubuntu1
* Resynchronized with Debian (LP: #139759, LP: #90806, LP: #102639,
  LP: #113447, LP: #121172, LP: #124890)
* reverted changes from 0.2.1-1.1ubuntu1 as upstream merged/included them

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SINGLE_SOURCE_COMPILE
 
2
 
 
3
/*
 
4
 * effect_select_dialog.cpp - dialog to choose effect plugin
 
5
 *
 
6
 * Copyright (c) 2006-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
7
 * 
 
8
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU General Public
 
12
 * License as published by the Free Software Foundation; either
 
13
 * version 2 of the License, or (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
 * General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public
 
21
 * License along with this program (see COPYING); if not, write to the
 
22
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
23
 * Boston, MA 02110-1301 USA.
 
24
 *
 
25
 */
 
26
 
 
27
 
 
28
#include "qt3support.h"
 
29
 
 
30
#ifdef QT4
 
31
 
 
32
#include <QtGui/QGroupBox>
 
33
#include <QtGui/QLayout>
 
34
#include <QtGui/QPushButton>
 
35
#include <QtGui/QScrollArea>
 
36
 
 
37
#else
 
38
 
 
39
#include <qgroupbox.h>
 
40
#include <qlayout.h>
 
41
#include <qpushbutton.h>
 
42
#include <qvbox.h>
 
43
 
 
44
#endif
 
45
 
 
46
#include "effect_select_dialog.h"
 
47
 
 
48
#include "gui_templates.h"
 
49
#include "embed.h"
 
50
 
 
51
 
 
52
effectSelectDialog::effectSelectDialog( QWidget * _parent ) :
 
53
        QDialog( _parent )
 
54
{
 
55
        setWindowIcon( embed::getIconPixmap( "setup_audio" ) );
 
56
        setWindowTitle( tr( "Effects Selector" ) );
 
57
        setModal( TRUE );
 
58
 
 
59
        QVBoxLayout * vlayout = new QVBoxLayout( this );
 
60
        vlayout->setSpacing( 10 );
 
61
        vlayout->setMargin( 10 );
 
62
 
 
63
        effectList * elist = new effectList( this );
 
64
        elist->setMinimumSize( 500, 400 );
 
65
        connect( elist, SIGNAL( doubleClicked( const effectKey & ) ),
 
66
                                this, SLOT( selectPlugin() ) );
 
67
        connect( elist, SIGNAL( highlighted( const effectKey & ) ),
 
68
                        this, SLOT( setSelection( const effectKey & ) ) );
 
69
        m_currentSelection = elist->getSelected();
 
70
 
 
71
        QWidget * buttons = new QWidget( this );
 
72
        QHBoxLayout * btn_layout = new QHBoxLayout( buttons );
 
73
        btn_layout->setSpacing( 0 );
 
74
        btn_layout->setMargin( 0 );
 
75
 
 
76
        
 
77
        QPushButton * select_btn = new QPushButton( 
 
78
                                        embed::getIconPixmap( "add" ),
 
79
                                        tr( "Add" ), buttons );
 
80
        connect( select_btn, SIGNAL( clicked() ), 
 
81
                                this, SLOT( selectPlugin() ) );
 
82
        
 
83
/*      QPushButton * ports_btn = new QPushButton( 
 
84
                                        embed::getIconPixmap("ports" ), 
 
85
                                        tr( "Ports" ), buttons );
 
86
        connect( ports_btn, SIGNAL( clicked() ),
 
87
                                this, SLOT( showPorts() ) );
 
88
*/      
 
89
        QPushButton * cancel_btn = new QPushButton( 
 
90
                                        embed::getIconPixmap( "cancel" ),
 
91
                                        tr( "Cancel" ), buttons );
 
92
        connect( cancel_btn, SIGNAL( clicked() ),
 
93
                                this, SLOT( reject() ) );
 
94
        
 
95
        btn_layout->addStretch();
 
96
        btn_layout->addSpacing( 10 );
 
97
        btn_layout->addWidget( select_btn );
 
98
/*      btn_layout->addSpacing( 10 );
 
99
        btn_layout->addWidget( ports_btn );*/
 
100
        btn_layout->addSpacing( 10 );
 
101
        btn_layout->addWidget( cancel_btn );
 
102
        btn_layout->addSpacing( 10 );
 
103
 
 
104
        vlayout->addWidget( elist );
 
105
        vlayout->addSpacing( 10 );
 
106
        vlayout->addWidget( buttons );
 
107
        vlayout->addSpacing( 10 );
 
108
        //vlayout->addStretch();
 
109
 
 
110
        show();
 
111
}
 
112
 
 
113
 
 
114
 
 
115
 
 
116
effectSelectDialog::~effectSelectDialog()
 
117
{
 
118
}
 
119
 
 
120
 
 
121
 
 
122
 
 
123
effect * effectSelectDialog::instantiateSelectedPlugin( void )
 
124
{
 
125
        if( !m_currentSelection.name.isEmpty() && m_currentSelection.desc )
 
126
        {
 
127
                return( effect::instantiate( m_currentSelection.desc->name,
 
128
                                                        &m_currentSelection ) );
 
129
        }
 
130
        return( NULL );
 
131
}
 
132
 
 
133
 
 
134
 
 
135
 
 
136
void effectSelectDialog::showPorts( void )
 
137
{
 
138
/*      ladspaPortDialog ports( m_currentSelection );
 
139
        ports.exec();*/
 
140
}
 
141
 
 
142
 
 
143
 
 
144
 
 
145
void effectSelectDialog::setSelection( const effectKey & _selection )
 
146
{
 
147
        m_currentSelection = _selection;
 
148
}
 
149
 
 
150
 
 
151
 
 
152
 
 
153
void effectSelectDialog::selectPlugin( void )
 
154
{
 
155
        accept();
 
156
}
 
157
 
 
158
 
 
159
 
 
160
 
 
161
 
 
162
 
 
163
 
 
164
effectList::effectList( QWidget * _parent ) :
 
165
        QWidget( _parent )
 
166
{
 
167
        plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
 
168
 
 
169
        for( vvector<plugin::descriptor>::iterator it =
 
170
                                                m_pluginDescriptors.begin();
 
171
                                        it != m_pluginDescriptors.end(); ++it )
 
172
        {
 
173
                if( it->type != plugin::Effect )
 
174
                {
 
175
                        continue;
 
176
                }
 
177
                if( it->sub_plugin_features )
 
178
                {
 
179
                        it->sub_plugin_features->listSubPluginKeys(
 
180
                                // as iterators are always stated to be not
 
181
                                // equal with pointers, we dereference the
 
182
                                // iterator and take the address of the item,
 
183
                                // so we're on the safe side and the compiler
 
184
                                // likely will reduce that to just "it"
 
185
                                                        &( *it ),
 
186
                                                        m_effectKeys );
 
187
                }
 
188
                else
 
189
                {
 
190
                        m_effectKeys << effectKey( &( *it ), it->name );
 
191
 
 
192
                }
 
193
        }
 
194
 
 
195
        QStringList plugin_names;
 
196
        for( effectKeyList::const_iterator it = m_effectKeys.begin();
 
197
                                                it != m_effectKeys.end(); ++it )
 
198
        {
 
199
                plugin_names += QString( ( *it ).desc->public_name ) +
 
200
                        ( ( ( *it ).desc->sub_plugin_features != NULL ) ?
 
201
                                                        ": " + ( *it ).name
 
202
                                                :
 
203
                                                        "" );
 
204
        }
 
205
 
 
206
        m_pluginList = new Q3ListBox( this );
 
207
        m_pluginList->insertStringList( plugin_names );
 
208
        connect( m_pluginList, SIGNAL( highlighted( int ) ),
 
209
                                SLOT( onHighlighted( int ) ) ); 
 
210
        connect( m_pluginList, SIGNAL( doubleClicked( QListBoxItem * ) ),
 
211
                                SLOT( onDoubleClicked( QListBoxItem * ) ) );
 
212
 
 
213
#ifndef QT3
 
214
        QGroupBox * groupbox = new QGroupBox( tr( "Description" ), this );
 
215
#else
 
216
        QGroupBox * groupbox = new QGroupBox( 1, Qt::Vertical,
 
217
                                                tr( "Description" ), this );
 
218
#endif
 
219
        groupbox->setFixedHeight( 200 );
 
220
#ifdef QT3
 
221
        groupbox->setInsideMargin( 2 );
 
222
#endif
 
223
 
 
224
        QScrollArea * scrollArea = new QScrollArea( groupbox );
 
225
        scrollArea->setFrameStyle( 0 );
 
226
#ifdef QT3
 
227
        scrollArea->setMargin( 10 );
 
228
#endif
 
229
#ifndef QT3
 
230
        m_descriptionWidget = new QWidget;
 
231
        QVBoxLayout * l = new QVBoxLayout( m_descriptionWidget );
 
232
        l->setMargin( 0 );
 
233
        l->setSpacing( 0 );
 
234
 
 
235
        scrollArea->setWidget( m_descriptionWidget );
 
236
        m_descriptionWidget->show();
 
237
        m_descriptionWidget->setFixedSize( 200, 200 );
 
238
#else
 
239
        m_descriptionWidget = new QVBox( scrollArea->viewport() );
 
240
        scrollArea->addChild( m_descriptionWidget );
 
241
#endif
 
242
 
 
243
        QVBoxLayout * vboxl = new QVBoxLayout( this );
 
244
        vboxl->setMargin( 0 );
 
245
        vboxl->setSpacing( 10 );
 
246
        vboxl->addWidget( m_pluginList );
 
247
        vboxl->addWidget( groupbox );
 
248
 
 
249
        if( m_pluginList->numRows() > 0 )
 
250
        {
 
251
                m_pluginList->setSelected( 0, true );
 
252
                onHighlighted( 0 );
 
253
        }
 
254
}
 
255
 
 
256
 
 
257
 
 
258
 
 
259
effectList::~effectList()
 
260
{
 
261
}
 
262
 
 
263
 
 
264
 
 
265
 
 
266
void effectList::onHighlighted( int _pluginIndex )
 
267
{
 
268
#ifndef QT3
 
269
        QLayoutItem * i;
 
270
        while( ( i = m_descriptionWidget->layout() ) != 0 )
 
271
        {
 
272
                delete i;
 
273
        }
 
274
#else
 
275
        QLayoutIterator it = m_descriptionWidget->layout()->iterator();
 
276
        while( it.current() )
 
277
        {
 
278
                it.deleteCurrent();
 
279
        }
 
280
#endif
 
281
        m_descriptionWidget->hide();
 
282
 
 
283
        m_currentSelection = m_effectKeys[_pluginIndex];
 
284
        if( m_currentSelection.desc &&
 
285
                                m_currentSelection.desc->sub_plugin_features )
 
286
        {
 
287
                m_currentSelection.desc->sub_plugin_features->
 
288
                        fillDescriptionWidget( m_descriptionWidget,
 
289
                                                        &m_currentSelection );
 
290
                m_descriptionWidget->show();
 
291
        }
 
292
        emit( highlighted( m_currentSelection ) );
 
293
}
 
294
 
 
295
 
 
296
 
 
297
 
 
298
void effectList::onDoubleClicked( QListBoxItem * _item )
 
299
{
 
300
        emit( doubleClicked( m_currentSelection ) );
 
301
}
 
302
 
 
303
 
 
304
 
 
305
 
 
306
void effectList::onAddButtonReleased()
 
307
{
 
308
        emit( addPlugin( m_currentSelection ) );
 
309
}
 
310
 
 
311
 
 
312
 
 
313
 
 
314
void effectList::resizeEvent( QResizeEvent * )
 
315
{
 
316
        m_descriptionWidget->setFixedWidth( width() - 40 );
 
317
}
 
318
 
 
319
 
 
320
 
 
321
 
 
322
#include "effect_select_dialog.moc"
 
323
 
 
324
#endif