EffectSelectDialog: rewritten using Designer

All of the GUI code of EffectSelectDialog has been replaced by an
according UI file. Also merged EffectListWidget class into
EffectSelectDialog to further simplify logic.
This commit is contained in:
Tobias Doerffel
2009-08-26 00:45:50 +02:00
parent d7365e4cf3
commit cb85bfc906
3 changed files with 189 additions and 212 deletions

View File

@@ -33,9 +33,7 @@
#include "Effect.h"
class QLineEdit;
class QListView;
class QScrollArea;
namespace Ui { class EffectSelectDialog; }
class EffectSelectDialog : public QDialog
@@ -48,54 +46,25 @@ public:
Effect * instantiateSelectedPlugin( EffectChain * _parent );
public slots:
void setSelection( const EffectKey & _selection );
void selectPlugin();
private:
EffectKey m_currentSelection;
} ;
class EffectListWidget : public QWidget
{
Q_OBJECT
public:
EffectListWidget( QWidget * _parent );
virtual ~EffectListWidget();
inline EffectKey getSelected()
{
return( m_currentSelection );
}
signals:
void highlighted( const EffectKey & _key );
void doubleClicked( const EffectKey & _key );
protected slots:
void acceptSelection();
void rowChanged( const QModelIndex &, const QModelIndex & );
void onDoubleClicked( const QModelIndex & );
void updateSelection();
private:
Ui::EffectSelectDialog * ui;
QVector<Plugin::Descriptor> m_pluginDescriptors;
EffectKeyList m_effectKeys;
EffectKey m_currentSelection;
QLineEdit * m_filterEdit;
QListView * m_pluginList;
QStandardItemModel m_sourceModel;
QSortFilterProxyModel m_model;
QScrollArea * m_scrollArea;
QWidget * m_descriptionWidget;
} ;
#endif

View File

@@ -22,129 +22,30 @@
*
*/
#include <QtGui/QGroupBox>
#include <QtGui/QLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QListView>
#include <QtGui/QPushButton>
#include <QtGui/QScrollArea>
#include "EffectSelectDialog.h"
#include "ui_EffectSelectDialog.h"
#include "gui_templates.h"
#include "embed.h"
EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
QDialog( _parent )
{
setWindowIcon( embed::getIconPixmap( "setup_audio" ) );
setWindowTitle( tr( "Effects Selector" ) );
setModal( true );
QVBoxLayout * vlayout = new QVBoxLayout( this );
vlayout->setSpacing( 10 );
vlayout->setMargin( 10 );
EffectListWidget * elist = new EffectListWidget( this );
elist->setMinimumSize( 540, 400 );
connect( elist, SIGNAL( doubleClicked( const effectKey & ) ),
this, SLOT( selectPlugin() ) );
connect( elist, SIGNAL( highlighted( const effectKey & ) ),
this, SLOT( setSelection( const effectKey & ) ) );
m_currentSelection = elist->getSelected();
QWidget * buttons = new QWidget( this );
QHBoxLayout * btn_layout = new QHBoxLayout( buttons );
btn_layout->setSpacing( 0 );
btn_layout->setMargin( 0 );
QPushButton * select_btn = new QPushButton(
embed::getIconPixmap( "add" ),
tr( "Add" ), buttons );
connect( select_btn, SIGNAL( clicked() ),
this, SLOT( selectPlugin() ) );
QPushButton * cancel_btn = new QPushButton(
embed::getIconPixmap( "cancel" ),
tr( "Cancel" ), buttons );
connect( cancel_btn, SIGNAL( clicked() ),
this, SLOT( reject() ) );
btn_layout->addStretch();
btn_layout->addSpacing( 10 );
btn_layout->addWidget( select_btn );
btn_layout->addSpacing( 10 );
btn_layout->addWidget( cancel_btn );
btn_layout->addSpacing( 10 );
vlayout->addWidget( elist );
vlayout->addSpacing( 10 );
vlayout->addWidget( buttons );
vlayout->addSpacing( 10 );
//vlayout->addStretch();
show();
}
EffectSelectDialog::~EffectSelectDialog()
{
}
Effect * EffectSelectDialog::instantiateSelectedPlugin( EffectChain * _parent )
{
if( !m_currentSelection.name.isEmpty() && m_currentSelection.desc )
{
return Effect::instantiate( m_currentSelection.desc->name,
_parent,
&m_currentSelection );
}
return( NULL );
}
void EffectSelectDialog::setSelection( const EffectKey & _selection )
{
m_currentSelection = _selection;
}
void EffectSelectDialog::selectPlugin()
{
if( m_currentSelection.isValid() )
{
accept();
}
}
EffectListWidget::EffectListWidget( QWidget * _parent ) :
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
Plugin::getDescriptorsOfAvailPlugins( m_pluginDescriptors );
for( QVector<Plugin::Descriptor>::iterator it =
m_pluginDescriptors.begin();
it != m_pluginDescriptors.end(); ++it )
for( QVector<Plugin::Descriptor>::Iterator it = m_pluginDescriptors.begin();
it != m_pluginDescriptors.end(); ++it )
{
if( it->type != Plugin::Effect )
{
@@ -168,82 +69,90 @@ EffectListWidget::EffectListWidget( QWidget * _parent ) :
}
}
QStringList plugin_names;
// and fill our source model
QStringList pluginNames;
for( EffectKeyList::ConstIterator it = m_effectKeys.begin();
it != m_effectKeys.end(); ++it )
it != m_effectKeys.end(); ++it )
{
plugin_names += QString( ( *it ).desc->displayName ) +
pluginNames += QString( ( *it ).desc->displayName ) +
( ( ( *it ).desc->sub_plugin_features != NULL ) ?
": " + ( *it ).name
:
"" );
}
int row = 0;
for( QStringList::iterator it = plugin_names.begin();
it != plugin_names.end(); ++it )
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 );
m_filterEdit = new QLineEdit( this );
connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ),
&m_model, SLOT( setFilterRegExp( const QString & ) ) );
connect( m_filterEdit, SIGNAL( textChanged( const QString & ) ),
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
&m_model, SLOT( setFilterRegExp( const QString & ) ) );
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( updateSelection() ) );
m_pluginList = new QListView( this );
m_pluginList->setModel( &m_model );
QItemSelectionModel * sm = new QItemSelectionModel( &m_model );
m_pluginList->setSelectionModel( sm );
m_pluginList->setSelectionBehavior( QAbstractItemView::SelectRows );
m_pluginList->setSelectionMode( QAbstractItemView::SingleSelection );
m_pluginList->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
connect( sm, SIGNAL( currentRowChanged( const QModelIndex &,
const QModelIndex & ) ),
SLOT( rowChanged( const QModelIndex &,
const QModelIndex & ) ) );
connect( m_pluginList, SIGNAL( doubleClicked( const QModelIndex & ) ),
SLOT( onDoubleClicked( const QModelIndex & ) ) );
ui->pluginList->setModel( &m_model );
QGroupBox * groupbox = new QGroupBox( tr( "Description" ), this );
groupbox->setFixedHeight( 200 );
QVBoxLayout * gbl = new QVBoxLayout( groupbox );
gbl->setMargin( 0 );
gbl->setSpacing( 10 );
m_scrollArea = new QScrollArea( groupbox );
m_scrollArea->setFrameStyle( 0 );
gbl->addWidget( m_scrollArea );
QVBoxLayout * vboxl = new QVBoxLayout( this );
vboxl->setMargin( 0 );
vboxl->setSpacing( 10 );
vboxl->addWidget( m_filterEdit );
vboxl->addWidget( m_pluginList );
vboxl->addWidget( groupbox );
// 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();
}
EffectListWidget::~EffectListWidget()
EffectSelectDialog::~EffectSelectDialog()
{
}
void EffectListWidget::rowChanged( const QModelIndex & _idx, const QModelIndex & )
Effect * EffectSelectDialog::instantiateSelectedPlugin( EffectChain * _parent )
{
if( !m_currentSelection.name.isEmpty() && m_currentSelection.desc )
{
return Effect::instantiate( m_currentSelection.desc->name,
_parent, &m_currentSelection );
}
return NULL;
}
void EffectSelectDialog::acceptSelection()
{
if( m_currentSelection.isValid() )
{
accept();
}
}
void EffectSelectDialog::rowChanged( const QModelIndex & _idx,
const QModelIndex & )
{
delete m_descriptionWidget;
m_descriptionWidget = NULL;
@@ -251,13 +160,11 @@ void EffectListWidget::rowChanged( const QModelIndex & _idx, const QModelIndex &
if( m_model.mapToSource( _idx ).row() < 0 )
{
// invalidate current selection
m_currentSelection =
Plugin::Descriptor::SubPluginFeatures::Key();
m_currentSelection = Plugin::Descriptor::SubPluginFeatures::Key();
}
else
{
m_currentSelection =
m_effectKeys[m_model.mapToSource( _idx ).row()];
m_currentSelection = m_effectKeys[m_model.mapToSource( _idx ).row()];
}
if( m_currentSelection.desc &&
m_currentSelection.desc->sub_plugin_features )
@@ -267,13 +174,11 @@ void EffectListWidget::rowChanged( const QModelIndex & _idx, const QModelIndex &
l->setMargin( 4 );
l->setSpacing( 0 );
m_scrollArea->setWidget( m_descriptionWidget );
ui->scrollArea->setWidget( m_descriptionWidget );
m_currentSelection.desc->sub_plugin_features->
fillDescriptionWidget( m_descriptionWidget,
&m_currentSelection );
foreach( QWidget * w,
m_descriptionWidget->findChildren<QWidget *>() )
fillDescriptionWidget( m_descriptionWidget, &m_currentSelection );
foreach( QWidget * w, m_descriptionWidget->findChildren<QWidget *>() )
{
if( w->parent() == m_descriptionWidget )
{
@@ -283,32 +188,24 @@ void EffectListWidget::rowChanged( const QModelIndex & _idx, const QModelIndex &
l->setSizeConstraint( QLayout::SetFixedSize );
m_descriptionWidget->show();
}
emit highlighted( m_currentSelection );
}
void EffectListWidget::onDoubleClicked( const QModelIndex & )
{
emit doubleClicked( m_currentSelection );
}
void EffectListWidget::updateSelection()
void EffectSelectDialog::updateSelection()
{
// no valid selection anymore due to changed filter?
if( m_pluginList->selectionModel()->selection().size() <= 0 )
if( ui->pluginList->selectionModel()->selection().size() <= 0 )
{
// then select our first item
m_pluginList->selectionModel()->select( m_model.index( 0, 0 ),
QItemSelectionModel::ClearAndSelect );
ui->pluginList->selectionModel()->select( m_model.index( 0, 0 ),
QItemSelectionModel::ClearAndSelect );
rowChanged( m_model.index( 0, 0 ), QModelIndex() );
}
}
#include "moc_EffectSelectDialog.cxx"

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EffectSelectDialog</class>
<widget class="QDialog" name="EffectSelectDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>585</width>
<height>547</height>
</rect>
</property>
<property name="windowTitle">
<string>Add effect</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>10</number>
</property>
<item>
<widget class="QLineEdit" name="filterEdit"/>
</item>
<item>
<widget class="QListView" name="pluginList">
<property name="minimumSize">
<size>
<width>500</width>
<height>250</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>210</height>
</size>
</property>
<property name="title">
<string>Plugin description</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>497</width>
<height>109</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EffectSelectDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>