@@ -49,6 +49,7 @@ public:
|
||||
protected slots:
|
||||
void acceptSelection();
|
||||
void rowChanged( const QModelIndex &, const QModelIndex & );
|
||||
void sortAgain();
|
||||
void updateSelection();
|
||||
|
||||
|
||||
|
||||
55
include/RowTableView.h
Normal file
55
include/RowTableView.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* RowTableView.h - table with rows that act like single cells
|
||||
*
|
||||
* Copyright (c) 2016 Javier Serrano Polo <javier@jasp.net>
|
||||
*
|
||||
* 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
|
||||
@@ -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
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -87,4 +99,10 @@
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>RowTableView</class>
|
||||
<header>RowTableView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
</ui>
|
||||
|
||||
139
src/gui/RowTableView.cpp
Normal file
139
src/gui/RowTableView.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* RowTableView.cpp - table with rows that act like single cells
|
||||
*
|
||||
* Copyright (c) 2016 Javier Serrano Polo <javier@jasp.net>
|
||||
*
|
||||
* 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user