diff --git a/src/playlist/albumview.cpp b/src/playlist/albumview.cpp index de60f9522..1ef44376d 100644 --- a/src/playlist/albumview.cpp +++ b/src/playlist/albumview.cpp @@ -29,10 +29,10 @@ AlbumView::AlbumView( QWidget* parent ) setDragDropOverwriteMode( false ); setUniformItemSizes( true ); setSpacing( 20 ); - setWordWrap( true ); setResizeMode( Adjust ); setViewMode( IconMode ); + setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); // setIconSize( QSize( 64, 64 ) ); setProxyModel( new AlbumProxyModel( this ) ); diff --git a/src/playlist/trackview.cpp b/src/playlist/trackview.cpp index 40a12fd09..8270efccb 100644 --- a/src/playlist/trackview.cpp +++ b/src/playlist/trackview.cpp @@ -1,7 +1,6 @@ #include "trackview.h" #include -#include #include #include #include @@ -22,6 +21,7 @@ TrackView::TrackView( QWidget* parent ) , m_model( 0 ) , m_proxyModel( 0 ) , m_delegate( 0 ) + , m_header( new TrackHeader( this ) ) , m_resizing( false ) { setSortingEnabled( false ); @@ -33,27 +33,24 @@ TrackView::TrackView( QWidget* parent ) setDragDropMode( QAbstractItemView::InternalMove ); setDragDropOverwriteMode( false ); setAllColumnsShowFocus( true ); + setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); setMinimumWidth( 690 ); + setHeader( m_header ); + #ifndef Q_WS_WIN QFont f = font(); f.setPointSize( f.pointSize() - 1 ); setFont( f ); #endif - header()->setMinimumSectionSize( 60 ); - restoreColumnsState(); - connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); - connect( header(), SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int, int, int ) ) ); } TrackView::~TrackView() { qDebug() << Q_FUNC_INFO; - - saveColumnsState(); } @@ -86,51 +83,6 @@ TrackView::setModel( TrackModel* model ) } -void -TrackView::restoreColumnsState() -{ - TomahawkSettings* s = APP->settings(); - QList list = s->playlistColumnSizes(); - - if ( list.count() != 7 ) // FIXME: const - { - m_columnWeights << 0.19 << 0.24 << 0.18 << 0.07 << 0.07 << 0.11 << 0.14; - } - else - { - foreach( const QVariant& v, list ) - m_columnWeights << v.toDouble(); - } - - for ( int i = 0; i < m_columnWeights.count(); i++ ) - m_columnWidths << 0; -} - - -void -TrackView::saveColumnsState() -{ - TomahawkSettings *s = APP->settings(); - QList wlist; -// int i = 0; - - foreach( double w, m_columnWeights ) - { - wlist << QVariant( w ); -// qDebug() << "Storing weight for column" << i++ << w; - } - - s->setPlaylistColumnSizes( wlist ); -} - - -void -TrackView::onSectionResized( int logicalIndex, int oldSize, int newSize ) -{ - return; -} - - void TrackView::onItemActivated( const QModelIndex& index ) { @@ -196,43 +148,8 @@ TrackView::addItemsToQueue() void TrackView::resizeEvent( QResizeEvent* event ) { -// qDebug() << Q_FUNC_INFO; - resizeColumns(); -} - - -void -TrackView::resizeColumns() -{ - double cw = contentsRect().width(); - int i = 0; - int total = 0; - - QList mcw = m_columnWeights; - - if ( verticalScrollBar() && verticalScrollBar()->isVisible() ) - { - cw -= verticalScrollBar()->width() + 1; - } - - m_resizing = true; - foreach( double w, mcw ) - { - int fw = (int)( cw * w ); - if ( fw < header()->minimumSectionSize() ) - fw = header()->minimumSectionSize(); - - if ( i + 1 == header()->count() ) - fw = cw - total; - - total += fw; -// qDebug() << "Resizing column:" << i << fw; - - m_columnWidths[ i ] = fw; - - header()->resizeSection( i++, fw ); - } - m_resizing = false; + qDebug() << Q_FUNC_INFO; + m_header->onResized(); } @@ -451,3 +368,137 @@ TrackView::createDragPixmap( int itemCount ) const return dragPixmap; } + + +TrackHeader::TrackHeader( TrackView* parent ) + : QHeaderView( Qt::Horizontal, parent ) + , m_parent( parent ) + , m_init( false ) +{ + setStretchLastSection( false ); + setResizeMode( QHeaderView::Interactive ); + setMinimumSectionSize( 60 ); + + connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionResized( int, int, int ) ) ); +} + + +TrackHeader::~TrackHeader() +{ + saveColumnsState(); +} + + +static uint negativeWidth = 0; + +void +TrackHeader::onSectionResized( int logicalIndex, int oldSize, int newSize ) +{ + qDebug() << Q_FUNC_INFO; + + if ( !m_init ) + return; + + blockSignals( true ); + + if ( newSize < 0 ) + resizeSection( logicalIndex, 0 ); + + for ( int i = logicalIndex + 1; i < count(); i++ ) + { + int ns = sectionSize( i ) + oldSize - newSize; + + if ( ns < minimumSectionSize() ) + { + resizeSection( logicalIndex, newSize - ( minimumSectionSize() - ns ) ); + ns = minimumSectionSize(); + } + + resizeSection( i, ns ); + break; + } + + blockSignals( false ); + + negativeWidth = 0; + uint w = 0; + + for ( int x = 0; x < m_columnWeights.count(); x++ ) + { + w += sectionSize( x ); + negativeWidth += sectionSize( x ); + } + + for ( int x = 0; x < m_columnWeights.count(); x++ ) + { + m_columnWeights[x] = (double)sectionSize( x ) / double( w ); + } + + negativeWidth -= w; +} + + +void +TrackHeader::onResized() +{ + qDebug() << Q_FUNC_INFO; + + if ( !m_init && count() ) + restoreColumnsState(); + + m_init = false; + blockSignals( true ); + + double width = m_parent->contentsRect().width(); +#ifdef Q_WS_MAC + if ( m_parent->verticalScrollBar() && m_parent->verticalScrollBar()->isVisible() ) + { + width -= m_parent->verticalScrollBar()->width() + 1; + } +#endif + + blockSignals( false ); + + for ( int i = 0; i < m_columnWeights.count(); i++ ) + { + if ( m_columnWeights[i] > 0 ) + resizeSection( i, int( width * m_columnWeights[i] ) ); + } + + m_init = true; +} + + +void +TrackHeader::restoreColumnsState() +{ + TomahawkSettings* s = APP->settings(); + QList list = s->playlistColumnSizes(); + + qDebug() << "COOOOOOUNT:" << count() << list.count(); + if ( list.count() != count() ) // FIXME: const + { + m_columnWeights << 0.19 << 0.24 << 0.18 << 0.07 << 0.07 << 0.11 << 0.14; + } + else + { + foreach( const QVariant& v, list ) + m_columnWeights << v.toDouble(); + } +} + + +void +TrackHeader::saveColumnsState() +{ + TomahawkSettings *s = APP->settings(); + QList wlist; + + foreach( double w, m_columnWeights ) + { + wlist << QVariant( w ); +// qDebug() << "Storing weight for column" << i++ << w; + } + + s->setPlaylistColumnSizes( wlist ); +} diff --git a/src/playlist/trackview.h b/src/playlist/trackview.h index d25b2d522..62596fccb 100644 --- a/src/playlist/trackview.h +++ b/src/playlist/trackview.h @@ -1,6 +1,7 @@ #ifndef TRACKVIEW_H #define TRACKVIEW_H +#include #include #include @@ -9,6 +10,31 @@ class PlaylistInterface; class TrackModel; class TrackProxyModel; +class TrackView; + +class TrackHeader : public QHeaderView +{ +Q_OBJECT + +public: + explicit TrackHeader( TrackView* parent = 0 ); + ~TrackHeader(); + +public slots: + void onResized(); + +private slots: + void onSectionResized( int logicalIndex, int oldSize, int newSize ); + +private: + void restoreColumnsState(); + void saveColumnsState(); + + TrackView* m_parent; + + QList m_columnWeights; + bool m_init; +}; class TrackView : public QTreeView { @@ -50,24 +76,16 @@ protected: private slots: void onItemResized( const QModelIndex& index ); - void resizeColumns(); - void onSectionResized( int logicalIndex, int oldSize, int newSize ); - void onFilterChanged( const QString& filter ); private: - void restoreColumnsState(); - void saveColumnsState(); - QPixmap createDragPixmap( int itemCount ) const; TrackModel* m_model; TrackProxyModel* m_proxyModel; PlaylistInterface* m_modelInterface; PlaylistItemDelegate* m_delegate; - - QList m_columnWeights; - QList m_columnWidths; + TrackHeader* m_header; bool m_resizing; bool m_dragging; diff --git a/src/tomahawksettings.cpp b/src/tomahawksettings.cpp index d2c8441d0..44c1aa029 100644 --- a/src/tomahawksettings.cpp +++ b/src/tomahawksettings.cpp @@ -183,7 +183,7 @@ TomahawkSettings::playlistColumnSizes() const void TomahawkSettings::setPlaylistColumnSizes( const QList& cols ) { - setValue( "ui/playlist/geometry", cols ); + setValue( "ui/playlist/columnSize", cols ); } diff --git a/src/tomahawksettings.h b/src/tomahawksettings.h index fa7ac3b0a..450c2884c 100644 --- a/src/tomahawksettings.h +++ b/src/tomahawksettings.h @@ -24,7 +24,7 @@ public: QByteArray mainWindowState() const; void setMainWindowState( const QByteArray& state ); - + QList playlistColumnSizes() const; void setPlaylistColumnSizes( const QList& cols ); diff --git a/src/utils/tomahawkutils.cpp b/src/utils/tomahawkutils.cpp index b7b6b494c..1ad5cbde8 100644 --- a/src/utils/tomahawkutils.cpp +++ b/src/utils/tomahawkutils.cpp @@ -143,49 +143,49 @@ ageToString( const QDateTime& time ) if ( years ) { if ( years > 1 ) - return QString( "%1 years ago" ).arg( years ); + return QString( "%1 years" ).arg( years ); else - return QString( "%1 year ago" ).arg( years ); + return QString( "%1 year" ).arg( years ); } if ( months ) { if ( months > 1 ) - return QString( "%1 months ago" ).arg( months ); + return QString( "%1 months" ).arg( months ); else - return QString( "%1 month ago" ).arg( months ); + return QString( "%1 month" ).arg( months ); } if ( weeks ) { if ( weeks > 1 ) - return QString( "%1 weeks ago" ).arg( weeks ); + return QString( "%1 weeks" ).arg( weeks ); else - return QString( "%1 week ago" ).arg( weeks ); + return QString( "%1 week" ).arg( weeks ); } if ( days ) { if ( days > 1 ) - return QString( "%1 days ago" ).arg( days ); + return QString( "%1 days" ).arg( days ); else - return QString( "%1 day ago" ).arg( days ); + return QString( "%1 day" ).arg( days ); } if ( hours ) { if ( hours > 1 ) - return QString( "%1 hours ago" ).arg( hours ); + return QString( "%1 hours" ).arg( hours ); else - return QString( "%1 hour ago" ).arg( hours ); + return QString( "%1 hour" ).arg( hours ); } if ( mins ) { if ( mins > 1 ) - return QString( "%1 minutes ago" ).arg( mins ); + return QString( "%1 minutes" ).arg( mins ); else - return QString( "%1 minute ago" ).arg( mins ); + return QString( "%1 minute" ).arg( mins ); } return QString();