1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-04 16:12:24 +02:00

* Safe approach to prevent resizing of album items.

This commit is contained in:
Christian Muehlhaeuser 2011-12-05 10:15:07 +01:00
parent 3520a7d0d8
commit 09087e2a8e

View File

@ -208,7 +208,7 @@ AlbumView::onScrollTimeout()
void
AlbumView::paintEvent( QPaintEvent* event )
{
if ( m_inited )
if ( !autoFitItems() || m_inited || !m_proxyModel->rowCount() )
QListView::paintEvent( event );
}
@ -216,28 +216,30 @@ AlbumView::paintEvent( QPaintEvent* event )
void
AlbumView::resizeEvent( QResizeEvent* event )
{
QListView::resizeEvent( event );
m_inited = true;
if ( !autoFitItems() )
return;
if ( autoFitItems() )
{
#ifdef Q_WS_X11
int scrollbar = !verticalScrollBar()->isVisible() ? verticalScrollBar()->rect().width() : 0;
int scrollbar = !verticalScrollBar()->isVisible() ? verticalScrollBar()->rect().width() : 0;
#else
int scrollbar = verticalScrollBar()->rect().width();
int scrollbar = verticalScrollBar()->rect().width();
#endif
int rectWidth = contentsRect().width() - scrollbar - 16 - 3;
QSize itemSize = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize();
int rectWidth = contentsRect().width() - scrollbar - 16 - 3;
QSize itemSize = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize();
int itemsPerRow = qFloor( rectWidth / ( itemSize.width() + 16 ) );
int rightSpacing = rectWidth - ( itemsPerRow * ( itemSize.width() + 16 ) );
int newSpacing = 16 + floor( rightSpacing / ( itemsPerRow + 1 ) );
int itemsPerRow = qFloor( rectWidth / ( itemSize.width() + 16 ) );
int rightSpacing = rectWidth - ( itemsPerRow * ( itemSize.width() + 16 ) );
int newSpacing = 16 + floor( rightSpacing / ( itemsPerRow + 1 ) );
if ( itemsPerRow < 1 )
setSpacing( 16 );
else
setSpacing( newSpacing );
if ( itemsPerRow < 1 )
setSpacing( 16 );
else
setSpacing( newSpacing );
if ( !m_inited && m_proxyModel->rowCount() )
m_inited = true;
}
QListView::resizeEvent( event );
}