diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2008-06-14 02:14:31 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2008-06-14 02:14:31 -0400 |
commit | 9e975a77d1ab078e1d599a04d3893053570b4840 (patch) | |
tree | 3b0fd9530b49c08b311d5f6edf3f908933b825a3 | |
parent | Added absolute paths to packager. (diff) | |
download | zmusicplayer-9e975a77d1ab078e1d599a04d3893053570b4840.tar.xz zmusicplayer-9e975a77d1ab078e1d599a04d3893053570b4840.zip |
Scroll to currently playing song on filter change.
-rw-r--r-- | AutoSizingList.cpp | 25 |
1 files 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<CollectionFilter*>(model()); + if(filter && filter->rowCount() == 0) + return; setUpdatesEnabled(false); header()->setStretchLastSection(false); - QAbstractItemModel *abstractModel = model(); - CollectionModel *model = 0; - CollectionFilter *filter = qobject_cast<CollectionFilter*>(abstractModel); + CollectionModel *collectionModel = 0; if(filter) - model = qobject_cast<CollectionModel*>(filter->sourceModel()); - if(model) - model->setFakeBoldState(true); + collectionModel = qobject_cast<CollectionModel*>(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<CollectionFilter*>(model()); + if(filter) { + QModelIndex index = filter->currentItem(); + if(index.isValid()) + scrollTo(filter->mapFromSource(index), QAbstractItemView::PositionAtCenter); + } setUpdatesEnabled(true); } void AutoSizingList::resizeEvent(QResizeEvent *event) |