mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
* Check auto-resizing GridView when items are being added or removed.
This commit is contained in:
@@ -82,8 +82,10 @@ GridView::GridView( QWidget* parent )
|
|||||||
|
|
||||||
connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
|
connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
|
||||||
connect( this, SIGNAL( customContextMenuRequested( QPoint ) ), SLOT( onCustomContextMenu( QPoint ) ) );
|
connect( this, SIGNAL( customContextMenuRequested( QPoint ) ), SLOT( onCustomContextMenu( QPoint ) ) );
|
||||||
|
|
||||||
connect( proxyModel(), SIGNAL( modelReset() ), SLOT( layoutItems() ) );
|
connect( proxyModel(), SIGNAL( modelReset() ), SLOT( layoutItems() ) );
|
||||||
// connect( m_contextMenu, SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) );
|
connect( proxyModel(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
||||||
|
connect( proxyModel(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -197,6 +199,29 @@ GridView::resizeEvent( QResizeEvent* event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GridView::verifySize()
|
||||||
|
{
|
||||||
|
if ( !autoResize() || !m_model )
|
||||||
|
return;
|
||||||
|
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
// int scrollbar = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() + 16 : 0;
|
||||||
|
int scrollbar = 0; verticalScrollBar()->rect().width();
|
||||||
|
#else
|
||||||
|
int scrollbar = verticalScrollBar()->rect().width();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const int rectWidth = contentsRect().width() - scrollbar - 3;
|
||||||
|
const int itemWidth = 160;
|
||||||
|
const int itemsPerRow = qMax( 1, qFloor( rectWidth / itemWidth ) );
|
||||||
|
|
||||||
|
const int rows = ceil( (double)m_proxyModel->rowCount( QModelIndex() ) / (double)itemsPerRow );
|
||||||
|
const int newHeight = rows * m_model->itemSize().height();
|
||||||
|
setFixedHeight( newHeight );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GridView::layoutItems()
|
GridView::layoutItems()
|
||||||
{
|
{
|
||||||
@@ -208,26 +233,17 @@ GridView::layoutItems()
|
|||||||
#else
|
#else
|
||||||
int scrollbar = verticalScrollBar()->rect().width();
|
int scrollbar = verticalScrollBar()->rect().width();
|
||||||
#endif
|
#endif
|
||||||
int rectWidth = contentsRect().width() - scrollbar - 3;
|
|
||||||
int itemWidth = 160;
|
|
||||||
// QSize itemSize = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize();
|
|
||||||
|
|
||||||
int itemsPerRow = qMax( 1, qFloor( rectWidth / itemWidth ) );
|
const int rectWidth = contentsRect().width() - scrollbar - 3;
|
||||||
// int rightSpacing = rectWidth - ( itemsPerRow * ( itemSize.width() + 16 ) );
|
const int itemWidth = 160;
|
||||||
// int newSpacing = 16 + floor( rightSpacing / ( itemsPerRow + 1 ) );
|
const int itemsPerRow = qMax( 1, qFloor( rectWidth / itemWidth ) );
|
||||||
|
|
||||||
int remSpace = rectWidth - ( itemsPerRow * itemWidth );
|
const int remSpace = rectWidth - ( itemsPerRow * itemWidth );
|
||||||
int extraSpace = remSpace / itemsPerRow;
|
const int extraSpace = remSpace / itemsPerRow;
|
||||||
int newItemWidth = itemWidth + extraSpace;
|
const int newItemWidth = itemWidth + extraSpace;
|
||||||
|
|
||||||
m_model->setItemSize( QSize( newItemWidth, newItemWidth ) );
|
m_model->setItemSize( QSize( newItemWidth, newItemWidth ) );
|
||||||
|
verifySize();
|
||||||
if ( autoResize() )
|
|
||||||
{
|
|
||||||
int rows = ceil( (double)m_proxyModel->rowCount( QModelIndex() ) / (double)itemsPerRow );
|
|
||||||
int newHeight = rows * newItemWidth;
|
|
||||||
setFixedHeight( newHeight );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !m_inited )
|
if ( !m_inited )
|
||||||
{
|
{
|
||||||
|
@@ -94,6 +94,7 @@ private slots:
|
|||||||
void onCustomContextMenu( const QPoint& pos );
|
void onCustomContextMenu( const QPoint& pos );
|
||||||
|
|
||||||
void layoutItems();
|
void layoutItems();
|
||||||
|
void verifySize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlayableModel* m_model;
|
PlayableModel* m_model;
|
||||||
|
Reference in New Issue
Block a user