diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-10-26 18:48:56 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-10-26 18:48:56 +0000 |
| commit | 52d3353ebd2b19319dcceb176bdd78e99ff79067 (patch) | |
| tree | 9360b5a7d754dc1c4eec5e35c7b4106da564b2f1 /src/plugins/Ui/skinned | |
| parent | 86c836dd2fb6a35470c1df3fece51607fd6f28d5 (diff) | |
| download | qmmp-52d3353ebd2b19319dcceb176bdd78e99ff79067.tar.gz qmmp-52d3353ebd2b19319dcceb176bdd78e99ff79067.tar.bz2 qmmp-52d3353ebd2b19319dcceb176bdd78e99ff79067.zip | |
do not lose first visible item after adding more tracks
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8399 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Ui/skinned')
| -rw-r--r-- | src/plugins/Ui/skinned/listwidget.cpp | 45 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/listwidget.h | 9 |
2 files changed, 50 insertions, 4 deletions
diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp index b82ab6e14..2a469e12d 100644 --- a/src/plugins/Ui/skinned/listwidget.cpp +++ b/src/plugins/Ui/skinned/listwidget.cpp @@ -64,6 +64,8 @@ ListWidget::ListWidget(QWidget *parent) m_pressed_index = INVALID_INDEX; m_first = 0; m_row_count = 0; + m_count = 0; + m_firstItem = 0; m_select_on_release = false; setAcceptDrops(true); @@ -321,9 +323,19 @@ void ListWidget::updateList(int flags) m_first = qMax(0, m_model->count() - m_row_count); emit positionChanged(m_first, m_first); } + else if((m_count > 0) && (m_count != m_model->count()) && + m_firstItem && m_model->item(m_first) != m_firstItem) + { + restoreFirstVisible(); + emit positionChanged(m_first, m_model->count() - m_row_count); + } else + { emit positionChanged(m_first, m_model->count() - m_row_count); + } + m_firstItem = m_model->isEmpty() ? 0 : m_model->item(m_first); + m_count = m_model->count(); items = m_model->mid(m_first, m_row_count); while(m_rows.count() < qMin(m_row_count, items.count())) @@ -446,6 +458,8 @@ void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous) } qApp->processEvents(); m_model = selected; + m_count = m_model->count(); + m_firstItem = 0; if(m_model->property("first_visible").isValid()) { @@ -564,6 +578,37 @@ bool ListWidget::updateRowCount() return false; } +void ListWidget::restoreFirstVisible() +{ + if(m_first >= m_model->count() || m_firstItem == m_model->item(m_first)) + return; + + int delta = m_model->count() - m_count; + + if(delta > 0) + { + for(int i = m_first + 1; i <= qMin(m_model->count() - 1, m_first + delta); ++i) + { + if(m_model->item(i) == m_firstItem) + { + m_first = i; + break; + } + } + } + else + { + for(int i = m_first - 1; i >= qMax(0, m_first + delta); --i) + { + if(m_model->item(i) == m_firstItem) + { + m_first = i; + break; + } + } + } +} + void ListWidget::mouseMoveEvent(QMouseEvent *e) { if(e->buttons() == Qt::LeftButton) diff --git a/src/plugins/Ui/skinned/listwidget.h b/src/plugins/Ui/skinned/listwidget.h index 9e019d630..abaa5fec8 100644 --- a/src/plugins/Ui/skinned/listwidget.h +++ b/src/plugins/Ui/skinned/listwidget.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2017 by Ilya Kotov * + * Copyright (C) 2006-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -109,18 +109,19 @@ private: * Returns string with queue number or(and) repeate flag for the item number \b i. */ const QString getExtraString(int i); - bool updateRowCount(); + void restoreFirstVisible(); bool m_update; int m_pressed_index; QMenu *m_menu; PlayListModel *m_model; - int m_row_count, m_first; + int m_row_count, m_first, m_count; //visible rows, first visible index, total item count + PlayListItem *m_firstItem; //first visible item Skin *m_skin; int m_anchor_index; /*! - * Scroll direction that is preforming in current moment. + * Scroll direction that is performing in current moment. */ ScrollDirection m_scroll_direction; int m_prev_y; |
