From 9e975a77d1ab078e1d599a04d3893053570b4840 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 14 Jun 2008 02:14:31 -0400 Subject: Scroll to currently playing song on filter change. --- AutoSizingList.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/AutoSizingList.cpp b/AutoSizingList.cpp index c20794d..cb99151 100644 --- a/AutoSizingList.cpp +++ b/AutoSizingList.cpp @@ -27,22 +27,23 @@ AutoSizingList::AutoSizingList(QWidget *parent) } void AutoSizingList::rowChange() { + CollectionFilter *filter = qobject_cast(model()); + if(filter && filter->rowCount() == 0) + return; setUpdatesEnabled(false); header()->setStretchLastSection(false); - QAbstractItemModel *abstractModel = model(); - CollectionModel *model = 0; - CollectionFilter *filter = qobject_cast(abstractModel); + CollectionModel *collectionModel = 0; if(filter) - model = qobject_cast(filter->sourceModel()); - if(model) - model->setFakeBoldState(true); + collectionModel = qobject_cast(filter->sourceModel()); + if(collectionModel) + collectionModel->setFakeBoldState(true); double suggestedWidth0 = qMin(sizeHintForColumn(0), 70); setColumnWidth(0, suggestedWidth0); double suggestedWidth1 = sizeHintForColumn(1); double suggestedWidth2 = sizeHintForColumn(2); double suggestedWidth3 = sizeHintForColumn(3); - if(model) - model->setFakeBoldState(false); + if(collectionModel) + collectionModel->setFakeBoldState(false); header()->setStretchLastSection(true); double suggestedWidthTotal = suggestedWidth0 + suggestedWidth1 + suggestedWidth2 + suggestedWidth3; @@ -80,12 +81,18 @@ void AutoSizingList::rowChange() void AutoSizingList::fixColumnSizes() { setUpdatesEnabled(false); - if(m_suggestedRatio1 + m_suggestedRatio2 + m_suggestedRatio3) { + if(m_suggestedRatio1 + m_suggestedRatio2 + m_suggestedRatio3 != 0) { int width = viewport()->width() - 40; //HACK: Why not 0? setColumnWidth(1, m_suggestedRatio1 * width); setColumnWidth(2, m_suggestedRatio2 * width); setColumnWidth(3, m_suggestedRatio3 * width); } + CollectionFilter *filter = qobject_cast(model()); + if(filter) { + QModelIndex index = filter->currentItem(); + if(index.isValid()) + scrollTo(filter->mapFromSource(index), QAbstractItemView::PositionAtCenter); + } setUpdatesEnabled(true); } void AutoSizingList::resizeEvent(QResizeEvent *event) -- cgit v1.2.3-59-g8ed1b