Commit 667cab00 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

EffectStack: Allow items to be reordered.

parent 7020e58e
......@@ -60,3 +60,23 @@ EffectInstanceListModel::data( const QModelIndex &index, int role ) const
return QVariant();
}
}
void
EffectInstanceListModel::moveUp( const QModelIndex &index )
{
if ( index.row() == 0 || index.row() >= m_list->size() )
return ;
emit layoutAboutToBeChanged();
m_list->swap( index.row(), index.row() - 1 );
emit layoutChanged();
}
void
EffectInstanceListModel::moveDown( const QModelIndex &index )
{
if ( index.row() >= m_list->size() - 1 )
return ;
emit layoutAboutToBeChanged();
m_list->swap( index.row(), index.row() + 1 );
emit layoutChanged();
}
......@@ -33,6 +33,8 @@ class EffectInstanceListModel : public QAbstractListModel
EffectInstanceListModel( EffectsEngine::EffectList *list );
virtual qint32 rowCount( const QModelIndex &parent ) const;
virtual QVariant data( const QModelIndex &index, int role ) const;
void moveUp( const QModelIndex &index );
void moveDown( const QModelIndex &index );
private:
EffectsEngine::EffectList *m_list;
......
......@@ -36,6 +36,8 @@ EffectStack::EffectStack( EffectsEngine::EffectList *list, QWidget *parent ):
m_ui->list->setModel( m_model );
connect( m_ui->list, SIGNAL( clicked( QModelIndex ) ),
this, SLOT( selectedChanged( QModelIndex ) ) );
connect( m_ui->upButton, SIGNAL( clicked() ), this, SLOT( moveUp() ) );
connect( m_ui->downButton, SIGNAL( clicked() ), this, SLOT( moveDown() ) );
}
EffectStack::~EffectStack()
......@@ -49,3 +51,15 @@ EffectStack::selectedChanged( const QModelIndex &index )
{
m_ui->instanceWidget->setEffectInstance( m_model->data( index, Qt::EditRole ).value<EffectsEngine::EffectHelper*>()->effect );
}
void
EffectStack::moveUp()
{
m_model->moveUp( m_ui->list->currentIndex() );
}
void
EffectStack::moveDown()
{
m_model->moveDown( m_ui->list->currentIndex() );
}
......@@ -46,6 +46,8 @@ class EffectStack : public QDialog
private slots:
void selectedChanged( const QModelIndex &index );
void moveUp();
void moveDown();
private:
Ui::EffectStack *m_ui;
......
......@@ -17,7 +17,59 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListView" name="list"/>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="upButton">
<property name="toolTip">
<string>Move the effect up in the stack</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../resources.qrc">
<normaloff>:/images/up</normaloff>:/images/up</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="downButton">
<property name="toolTip">
<string>Move the effect down in the stack</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.qrc">
<normaloff>:/images/down</normaloff>:/images/down</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QListView" name="list">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="EffectInstanceWidget" name="instanceWidget" native="true"/>
......@@ -44,7 +96,9 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../../../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttons</sender>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment