diff --git a/include/EffectSelectDialog.h b/include/EffectSelectDialog.h index 995f14fb1..e034002d7 100644 --- a/include/EffectSelectDialog.h +++ b/include/EffectSelectDialog.h @@ -49,6 +49,7 @@ public: protected slots: void acceptSelection(); void rowChanged( const QModelIndex &, const QModelIndex & ); + void sortAgain(); void updateSelection(); diff --git a/include/RowTableView.h b/include/RowTableView.h new file mode 100644 index 000000000..b4e8d61e5 --- /dev/null +++ b/include/RowTableView.h @@ -0,0 +1,55 @@ +/* + * RowTableView.h - table with rows that act like single cells + * + * Copyright (c) 2016 Javier Serrano Polo + * + * 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 + + +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 diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 16df0b77b..3b1d3197b 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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 diff --git a/src/gui/EffectSelectDialog.cpp b/src/gui/EffectSelectDialog.cpp index bd45ceae9..e7d5afe84 100644 --- a/src/gui/EffectSelectDialog.cpp +++ b/src/gui/EffectSelectDialog.cpp @@ -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; } @@ -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 ); @@ -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(); } @@ -235,6 +254,14 @@ 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? @@ -242,7 +269,8 @@ void EffectSelectDialog::updateSelection() { // 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() ); } } diff --git a/src/gui/Forms/EffectSelectDialog.ui b/src/gui/Forms/EffectSelectDialog.ui index a19233ac8..a9c6de019 100644 --- a/src/gui/Forms/EffectSelectDialog.ui +++ b/src/gui/Forms/EffectSelectDialog.ui @@ -24,19 +24,31 @@ - + 500 250 + + QAbstractItemView::NoEditTriggers + Qt::ScrollBarAlwaysOff QAbstractItemView::SelectRows + + QAbstractItemView::SingleSelection + + + false + + + true + @@ -87,4 +99,10 @@ + + + RowTableView +
RowTableView.h
+
+
diff --git a/src/gui/RowTableView.cpp b/src/gui/RowTableView.cpp new file mode 100644 index 000000000..cbd1bd849 --- /dev/null +++ b/src/gui/RowTableView.cpp @@ -0,0 +1,139 @@ +/* + * RowTableView.cpp - table with rows that act like single cells + * + * Copyright (c) 2016 Javier Serrano Polo + * + * 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 +#include +#include + + +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 ); + } +} + + + +