mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
(trunk qt) "Qt client's Files list should be sortable" -- fixed
This commit is contained in:
parent
969c72b927
commit
cee744fcdd
2 changed files with 62 additions and 11 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <QHeaderView>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStringList>
|
||||
|
||||
#include <libtransmission/transmission.h> // priorities
|
||||
|
@ -505,6 +506,39 @@ FileTreeModel :: clicked( const QModelIndex& index )
|
|||
*****
|
||||
****/
|
||||
|
||||
QSize
|
||||
FileTreeDelegate :: sizeHint( const QStyleOptionViewItem& item, const QModelIndex& index ) const
|
||||
{
|
||||
QSize size;
|
||||
|
||||
switch( index.column( ) )
|
||||
{
|
||||
case COL_NAME: {
|
||||
const QFontMetrics fm( item.font );
|
||||
const QString text = index.model()->data(index).toString();
|
||||
const int iconSize = QApplication::style()->pixelMetric( QStyle::PM_SmallIconSize );
|
||||
size.rwidth() = HIG::PAD_SMALL + iconSize;
|
||||
size.rheight() = std::max( iconSize, fm.height( ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case COL_PROGRESS:
|
||||
case COL_WANTED:
|
||||
size = QSize( 20, 1 );
|
||||
break;
|
||||
|
||||
default: {
|
||||
const QFontMetrics fm( item.font );
|
||||
const QString text = index.model()->data(index).toString();
|
||||
size = fm.size( 0, text );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size.rheight() += 8; // make the spacing a little nicer
|
||||
return size;
|
||||
}
|
||||
|
||||
void
|
||||
FileTreeDelegate :: paint( QPainter * painter,
|
||||
const QStyleOptionViewItem & option,
|
||||
|
@ -512,7 +546,6 @@ FileTreeDelegate :: paint( QPainter * painter,
|
|||
{
|
||||
const int column( index.column( ) );
|
||||
|
||||
|
||||
if( ( column != COL_PROGRESS ) && ( column != COL_WANTED ) && ( column != COL_NAME ) )
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
|
@ -594,21 +627,25 @@ FileTreeDelegate :: paint( QPainter * painter,
|
|||
FileTreeView :: FileTreeView( QWidget * parent ):
|
||||
QTreeView( parent ),
|
||||
myModel( this ),
|
||||
myProxy( new QSortFilterProxyModel( ) ),
|
||||
myDelegate( this )
|
||||
{
|
||||
setSortingEnabled( true );
|
||||
setAlternatingRowColors( true );
|
||||
setSelectionBehavior( QAbstractItemView::SelectRows );
|
||||
setSelectionMode( QAbstractItemView::ExtendedSelection );
|
||||
setModel( &myModel );
|
||||
myProxy->setSourceModel( &myModel );
|
||||
setModel( myProxy );
|
||||
setItemDelegate( &myDelegate );
|
||||
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
sortByColumn( COL_NAME, Qt::AscendingOrder );
|
||||
installEventFilter( this );
|
||||
|
||||
for( int i=0; i<=NUM_COLUMNS; ++i )
|
||||
header()->setResizeMode( i, QHeaderView::Fixed );
|
||||
|
||||
connect( this, SIGNAL(clicked(const QModelIndex&)),
|
||||
&myModel, SLOT(clicked(const QModelIndex&)));
|
||||
connect( this, SIGNAL(clicked(const QModelIndex&)),
|
||||
this, SLOT(onClicked(const QModelIndex&)) );
|
||||
|
||||
connect( &myModel, SIGNAL(priorityChanged(const QSet<int>&, int)),
|
||||
this, SIGNAL(priorityChanged(const QSet<int>&, int)));
|
||||
|
@ -617,6 +654,13 @@ FileTreeView :: FileTreeView( QWidget * parent ):
|
|||
this, SIGNAL(wantedChanged(const QSet<int>&, bool)));
|
||||
}
|
||||
|
||||
void
|
||||
FileTreeView :: onClicked( const QModelIndex& proxyIndex )
|
||||
{
|
||||
const QModelIndex modelIndex = myProxy->mapToSource( proxyIndex );
|
||||
myModel.clicked( modelIndex );
|
||||
}
|
||||
|
||||
bool
|
||||
FileTreeView :: eventFilter( QObject * o, QEvent * event )
|
||||
{
|
||||
|
@ -662,7 +706,7 @@ FileTreeView :: update( const FileList& files, bool torrentChanged )
|
|||
QList<QModelIndex> added;
|
||||
myModel.addFile( file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, torrentChanged );
|
||||
foreach( QModelIndex i, added )
|
||||
expand( i );
|
||||
expand( myProxy->mapFromSource( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,16 @@
|
|||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QObject>
|
||||
#include <QItemDelegate>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QSet>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
#include <QTreeView>
|
||||
#include <QVariant>
|
||||
#include <QItemDelegate>
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
class QStyle;
|
||||
|
||||
#include "torrent.h" // FileList
|
||||
|
||||
|
@ -123,13 +127,12 @@ class FileTreeDelegate: public QItemDelegate
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
FileTreeDelegate( QObject * parent=0 ): QItemDelegate( parent ) { }
|
||||
virtual ~FileTreeDelegate( ) { }
|
||||
|
||||
void paint( QPainter * painter,
|
||||
const QStyleOptionViewItem & option,
|
||||
const QModelIndex & index ) const;
|
||||
public:
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
|
||||
virtual void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
|
||||
};
|
||||
|
||||
class FileTreeView: public QTreeView
|
||||
|
@ -152,7 +155,11 @@ class FileTreeView: public QTreeView
|
|||
|
||||
private:
|
||||
FileTreeModel myModel;
|
||||
QSortFilterProxyModel * myProxy;
|
||||
FileTreeDelegate myDelegate;
|
||||
|
||||
public slots:
|
||||
void onClicked ( const QModelIndex & index );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue