00001 #include "SmartListView.h" 00002 00003 SmartListView::SmartListView( QWidget *parent = 0, const char* name = 0 ) 00004 : QListView( parent, name ), stretchColumn( -1 ), allColumnsWide( false ) { 00005 } 00006 00007 SmartListView::~SmartListView() { 00008 } 00009 00010 void SmartListView::setStretchColumn( int col ) { 00011 stretchColumn = col; 00012 } 00013 00014 int SmartListView::getStretchColumn() const { 00015 return( stretchColumn ); 00016 } 00017 00018 void SmartListView::setAllColumnsWide( bool isOn ) { 00019 allColumnsWide = isOn; 00020 } 00021 00022 bool SmartListView::areAllColumnsWide() const { 00023 return( allColumnsWide ); 00024 } 00025 00026 void SmartListView::updateColumnsWidth() { 00027 //cerr << "update w=" << width() << " vp.w=" << viewport()->width(); 00028 //cerr << " vw=" << visibleWidth(); 00029 //cerr << " cw=" << contentsWidth(); 00030 //cerr << endl; 00031 //resizeContents( width() + 20, height() ); 00032 viewport()->adjustSize(); 00033 if( stretchColumn != -1 ) { 00034 int otherColumnsWidth = 0; 00035 for( int i = 0; i < columns(); i++ ) { 00036 if( i != stretchColumn ) 00037 otherColumnsWidth += columnWidth( i ); 00038 } 00039 setColumnWidth( stretchColumn, viewport()->width() - otherColumnsWidth ); 00040 } 00041 if( allColumnsWide ) { 00042 int columnWidth = viewport()->width() / columns(); 00043 for( int i = 0; i < columns(); i++ ) 00044 setColumnWidth( i, columnWidth ); 00045 } 00046 } 00047 00048 void SmartListView::resizeEvent( QResizeEvent* event ) { 00049 QListView::resizeEvent( event ); 00050 updateColumnsWidth(); 00051 }