Changeset 11063
- Timestamp:
- Jul 28, 2010, 6:53:25 PM (12 years ago)
- Location:
- trunk/qt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/file-tree.cc
r10933 r11063 18 18 #include <QPainter> 19 19 #include <QResizeEvent> 20 #include <QSortFilterProxyModel> 20 21 #include <QStringList> 21 22 … … 506 507 ****/ 507 508 509 QSize 510 FileTreeDelegate :: sizeHint( const QStyleOptionViewItem& item, const QModelIndex& index ) const 511 { 512 QSize size; 513 514 switch( index.column( ) ) 515 { 516 case COL_NAME: { 517 const QFontMetrics fm( item.font ); 518 const QString text = index.model()->data(index).toString(); 519 const int iconSize = QApplication::style()->pixelMetric( QStyle::PM_SmallIconSize ); 520 size.rwidth() = HIG::PAD_SMALL + iconSize; 521 size.rheight() = std::max( iconSize, fm.height( ) ); 522 break; 523 } 524 525 case COL_PROGRESS: 526 case COL_WANTED: 527 size = QSize( 20, 1 ); 528 break; 529 530 default: { 531 const QFontMetrics fm( item.font ); 532 const QString text = index.model()->data(index).toString(); 533 size = fm.size( 0, text ); 534 break; 535 } 536 } 537 538 size.rheight() += 8; // make the spacing a little nicer 539 return size; 540 } 541 508 542 void 509 543 FileTreeDelegate :: paint( QPainter * painter, … … 512 546 { 513 547 const int column( index.column( ) ); 514 515 548 516 549 if( ( column != COL_PROGRESS ) && ( column != COL_WANTED ) && ( column != COL_NAME ) ) … … 595 628 QTreeView( parent ), 596 629 myModel( this ), 630 myProxy( new QSortFilterProxyModel( ) ), 597 631 myDelegate( this ) 598 632 { 633 setSortingEnabled( true ); 599 634 setAlternatingRowColors( true ); 600 635 setSelectionBehavior( QAbstractItemView::SelectRows ); 601 636 setSelectionMode( QAbstractItemView::ExtendedSelection ); 602 setModel( &myModel ); 637 myProxy->setSourceModel( &myModel ); 638 setModel( myProxy ); 603 639 setItemDelegate( &myDelegate ); 604 640 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); 641 sortByColumn( COL_NAME, Qt::AscendingOrder ); 605 642 installEventFilter( this ); 606 643 … … 608 645 header()->setResizeMode( i, QHeaderView::Fixed ); 609 646 610 connect( this, 611 &myModel, SLOT(clicked(const QModelIndex&)));647 connect( this, SIGNAL(clicked(const QModelIndex&)), 648 this, SLOT(onClicked(const QModelIndex&)) ); 612 649 613 650 connect( &myModel, SIGNAL(priorityChanged(const QSet<int>&, int)), … … 616 653 connect( &myModel, SIGNAL(wantedChanged(const QSet<int>&, bool)), 617 654 this, SIGNAL(wantedChanged(const QSet<int>&, bool))); 655 } 656 657 void 658 FileTreeView :: onClicked( const QModelIndex& proxyIndex ) 659 { 660 const QModelIndex modelIndex = myProxy->mapToSource( proxyIndex ); 661 myModel.clicked( modelIndex ); 618 662 } 619 663 … … 663 707 myModel.addFile( file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, torrentChanged ); 664 708 foreach( QModelIndex i, added ) 665 expand( i);709 expand( myProxy->mapFromSource( i ) ); 666 710 } 667 711 } -
trunk/qt/file-tree.h
r10627 r11063 16 16 #include <QAbstractItemModel> 17 17 #include <QObject> 18 #include <QItemDelegate> 18 19 #include <QList> 20 #include <QSet> 21 #include <QSize> 19 22 #include <QString> 20 #include <QSet>21 23 #include <QTreeView> 22 24 #include <QVariant> 23 #include <QItemDelegate> 25 26 class QSortFilterProxyModel; 27 class QStyle; 24 28 25 29 #include "torrent.h" // FileList … … 124 128 125 129 public: 126 127 130 FileTreeDelegate( QObject * parent=0 ): QItemDelegate( parent ) { } 128 131 virtual ~FileTreeDelegate( ) { } 129 132 130 void paint( QPainter * painter,131 const QStyleOptionViewItem & option,132 const QModelIndex & index) const;133 public: 134 virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const; 135 virtual void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; 133 136 }; 134 137 … … 153 156 private: 154 157 FileTreeModel myModel; 158 QSortFilterProxyModel * myProxy; 155 159 FileTreeDelegate myDelegate; 160 161 public slots: 162 void onClicked ( const QModelIndex & index ); 156 163 }; 157 164
Note: See TracChangeset
for help on using the changeset viewer.