Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort effects in dialog #2836

Merged
merged 1 commit into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/EffectSelectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class EffectSelectDialog : public QDialog
protected slots:
void acceptSelection();
void rowChanged( const QModelIndex &, const QModelIndex & );
void sortAgain();
void updateSelection();


Expand Down
55 changes: 55 additions & 0 deletions include/RowTableView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* RowTableView.h - table with rows that act like single cells
*
* Copyright (c) 2016 Javier Serrano Polo <[email protected]>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef ROW_TABLE_VIEW_H
#define ROW_TABLE_VIEW_H

#include <QTableView>


class RowDelegate;


class RowTableView : public QTableView
{
Q_OBJECT
public:
RowTableView( QWidget * parent = 0 );
virtual ~RowTableView();

virtual void setModel( QAbstractItemModel * model );


protected:
virtual void keyPressEvent( QKeyEvent * event );


private:
RowDelegate * m_rowDelegate;

} ;



#endif
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SET(LMMS_SRCS
gui/PeakControllerDialog.cpp
gui/PianoView.cpp
gui/PluginBrowser.cpp
gui/RowTableView.cpp
gui/SetupDialog.cpp
gui/StringPairDrag.cpp
gui/SubWindow.cpp
Expand Down
54 changes: 41 additions & 13 deletions src/gui/EffectSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,26 @@ EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
m_effectKeys += subPluginEffectKeys;

// and fill our source model
QStringList pluginNames;
for( EffectKeyList::ConstIterator it = m_effectKeys.begin(); it != m_effectKeys.end(); ++it )
m_sourceModel.setHorizontalHeaderItem( 0, new QStandardItem( "Name" ) );
m_sourceModel.setHorizontalHeaderItem( 1, new QStandardItem( "Type" ) );
int row = 0;
for( EffectKeyList::ConstIterator it = m_effectKeys.begin();
it != m_effectKeys.end(); ++it )
{
QString name;
QString type;
if( ( *it ).desc->subPluginFeatures )
{
pluginNames += QString( "%1: %2" ).arg( ( *it ).desc->displayName, ( *it ).name );
name = ( *it ).name;
type = ( *it ).desc->displayName;
}
else
{
pluginNames += ( *it ).desc->displayName;
name = ( *it ).desc->displayName;
type = "LMMS";
}
}

int row = 0;
for( QStringList::ConstIterator it = pluginNames.begin();
it != pluginNames.end(); ++it )
{
m_sourceModel.setItem( row, 0, new QStandardItem( *it ) );
m_sourceModel.setItem( row, 0, new QStandardItem( name ) );
m_sourceModel.setItem( row, 1, new QStandardItem( type ) );
++row;
}

Expand All @@ -100,6 +102,8 @@ EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
&m_model, SLOT( setFilterFixedString( const QString & ) ) );
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( updateSelection() ) );
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
SLOT( sortAgain() ) );

ui->pluginList->setModel( &m_model );

Expand All @@ -115,7 +119,22 @@ EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) :
// try to accept current selection when pressing "OK"
connect( ui->buttonBox, SIGNAL( accepted() ),
this, SLOT( acceptSelection() ) );


#if QT_VERSION >= 0x050000
#define setResizeMode setSectionResizeMode
#endif
ui->pluginList->verticalHeader()->setResizeMode(
QHeaderView::ResizeToContents );
ui->pluginList->verticalHeader()->hide();
ui->pluginList->horizontalHeader()->setResizeMode( 0,
QHeaderView::Stretch );
ui->pluginList->horizontalHeader()->setResizeMode( 1,
QHeaderView::ResizeToContents );
ui->pluginList->sortByColumn( 0, Qt::AscendingOrder );
#if QT_VERSION >= 0x050000
#undef setResizeMode
#endif

updateSelection();
show();
}
Expand Down Expand Up @@ -235,14 +254,23 @@ void EffectSelectDialog::rowChanged( const QModelIndex & _idx,



void EffectSelectDialog::sortAgain()
{
ui->pluginList->setSortingEnabled( ui->pluginList->isSortingEnabled() );
}




void EffectSelectDialog::updateSelection()
{
// no valid selection anymore due to changed filter?
if( ui->pluginList->selectionModel()->selection().size() <= 0 )
{
// then select our first item
ui->pluginList->selectionModel()->select( m_model.index( 0, 0 ),
QItemSelectionModel::ClearAndSelect );
QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Rows );
rowChanged( m_model.index( 0, 0 ), QModelIndex() );
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/gui/Forms/EffectSelectDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,31 @@
<widget class="QLineEdit" name="filterEdit"/>
</item>
<item>
<widget class="QListView" name="pluginList">
<widget class="RowTableView" name="pluginList">
<property name="minimumSize">
<size>
<width>500</width>
<height>250</height>
</size>
</property>
<property name="editTriggers">
<enum>QAbstractItemView::NoEditTriggers</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -87,4 +99,10 @@
</hints>
</connection>
</connections>
<customwidgets>
<customwidget>
<class>RowTableView</class>
<header>RowTableView.h</header>
</customwidget>
</customwidgets>
</ui>
139 changes: 139 additions & 0 deletions src/gui/RowTableView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* RowTableView.cpp - table with rows that act like single cells
*
* Copyright (c) 2016 Javier Serrano Polo <[email protected]>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#include "RowTableView.h"

#include <QKeyEvent>
#include <QPainter>
#include <QStyledItemDelegate>


class RowDelegate : public QStyledItemDelegate
{
public:
RowDelegate( QAbstractItemView * table, QObject * parent = 0 ) :
QStyledItemDelegate( parent ),
m_table( table )
{
}
virtual void paint( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const;


protected:
virtual void initStyleOption( QStyleOptionViewItem * option,
const QModelIndex & index ) const;


private:
QAbstractItemView * m_table;

} ;




void RowDelegate::initStyleOption( QStyleOptionViewItem * option,
const QModelIndex & index ) const
{
QStyledItemDelegate::initStyleOption( option, index );
option->state &= ~QStyle::State_HasFocus;
}




void RowDelegate::paint( QPainter * painter,
const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QStyledItemDelegate::paint( painter, option, index );
if ( index.row() == m_table->currentIndex().row() )
{
const QRect rect( option.rect );
painter->drawLine( rect.topLeft(), rect.topRight() );
painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
if ( index.column() == 0 )
{
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
}
if ( index.column() == index.model()->columnCount() - 1 )
{
painter->drawLine( rect.topRight(),
rect.bottomRight() );
}
}
}




RowTableView::RowTableView( QWidget * parent ) :
QTableView( parent )
{
m_rowDelegate = new RowDelegate( this, this );
}




RowTableView::~RowTableView()
{
delete m_rowDelegate;
}




void RowTableView::setModel( QAbstractItemModel * model )
{
QTableView::setModel( model );
for ( int i = 0; i < model->rowCount(); i++ )
{
setItemDelegateForRow( i, m_rowDelegate );
}

}




void RowTableView::keyPressEvent( QKeyEvent * event )
{
switch( event->key() )
{
case Qt::Key_Tab:
case Qt::Key_Backtab:
for( int i = 0; i < model()->columnCount() - 1; i++ )
{
QTableView::keyPressEvent( event );
}
default:
QTableView::keyPressEvent( event );
}
}