From a8de6bc53396f50aa3f7f0af05e6bd91824f6a33 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 25 Aug 2017 21:10:06 +0000 Subject: improved scrolling api git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7389 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Ui/qsui/listwidget.cpp | 27 +++++++++++++++------------ src/plugins/Ui/qsui/listwidget.h | 7 +++++-- src/plugins/Ui/skinned/listwidget.cpp | 25 ++++++++++++++----------- src/plugins/Ui/skinned/listwidget.h | 9 +++++---- src/qmmpui/playlistmodel.cpp | 12 +++++++++--- src/qmmpui/playlistmodel.h | 11 +++++------ 6 files changed, 53 insertions(+), 38 deletions(-) diff --git a/src/plugins/Ui/qsui/listwidget.cpp b/src/plugins/Ui/qsui/listwidget.cpp index b86bbf731..bd00ffa49 100644 --- a/src/plugins/Ui/qsui/listwidget.cpp +++ b/src/plugins/Ui/qsui/listwidget.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2016 by Ilya Kotov * + * Copyright (C) 2006-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -74,7 +74,7 @@ ListWidget::ListWidget(PlayListModel *model, QWidget *parent) connect(m_scrollBar, SIGNAL(valueChanged (int)), SLOT(scroll(int))); connect(m_hslider, SIGNAL(valueChanged(int)), m_header, SLOT(scroll(int))); connect(m_hslider, SIGNAL(valueChanged(int)), this, SLOT(update())); - connect(m_model, SIGNAL(currentVisibleRequest()), SLOT(scrollToCurrent())); + connect(m_model, SIGNAL(scrollToRequest(int)), SLOT(scrollTo(int))); connect(m_model, SIGNAL(listChanged(int)), SLOT(updateList(int))); connect(m_model, SIGNAL(sortingByColumnFinished(int,bool)), m_header, SLOT(showSortIndicator(int,bool))); SET_ACTION(ActionManager::PL_SHOW_HEADER, this, SLOT(readSettings())); @@ -174,7 +174,7 @@ void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous) m_first = 0; updateList(PlayListModel::STRUCTURE | PlayListModel::CURRENT); } - connect (m_model, SIGNAL(currentVisibleRequest()), SLOT(scrollToCurrent())); + connect (m_model, SIGNAL(scrollToRequest(int)), SLOT(scrollTo(int))); connect (m_model, SIGNAL(listChanged(int)), SLOT(updateList(int))); connect (m_model, SIGNAL(sortingByColumnFinished(int,bool)), m_header, SLOT(showSortIndicator(int,bool))); } @@ -360,7 +360,7 @@ void ListWidget::updateList(int flags) flags |= PlayListModel::STRUCTURE; if(flags & PlayListModel::CURRENT) - recenterCurrent(); + recenterTo(m_model->currentIndex()); QList items; @@ -500,9 +500,13 @@ void ListWidget::updateRepeatIndicator() updateList(PlayListModel::CURRENT | PlayListModel::STRUCTURE); } -void ListWidget::scrollToCurrent() +void ListWidget::scrollTo(int index) { - updateList(PlayListModel::CURRENT | PlayListModel::STRUCTURE); + if (m_row_count) + { + recenterTo(index); + updateList(PlayListModel::STRUCTURE); + } } void ListWidget::scroll(int sc) @@ -705,14 +709,13 @@ void ListWidget::contextMenuEvent(QContextMenuEvent * event) menu()->exec(event->globalPos()); } -void ListWidget::recenterCurrent() +void ListWidget::recenterTo(int index) { if (m_row_count) { - if (m_first + m_row_count < m_model->currentIndex() + 1) - m_first = qMin(m_model->count() - m_row_count, - m_model->currentIndex() - m_row_count/2); - else if (m_first > m_model->currentIndex()) - m_first = qMax (m_model->currentIndex() - m_row_count/2, 0); + if (m_first + m_row_count < index + 1) + m_first = qMin(m_model->count() - m_row_count, index - m_row_count/2); + else if (m_first > index) + m_first = qMax (index - m_row_count/2, 0); } } diff --git a/src/plugins/Ui/qsui/listwidget.h b/src/plugins/Ui/qsui/listwidget.h index bfbc038e9..6fad7139d 100644 --- a/src/plugins/Ui/qsui/listwidget.h +++ b/src/plugins/Ui/qsui/listwidget.h @@ -71,7 +71,7 @@ public slots: void readSettings(); void updateList(int flags); void scroll(int); //0-99 - void recenterCurrent(); + signals: void selectionChanged(); @@ -98,13 +98,16 @@ private slots: void updateSkin(); void autoscroll(); void updateRepeatIndicator(); - void scrollToCurrent(); + void scrollTo(int index); private: + enum ScrollDirection { NONE = 0,TOP,DOWN }; + + void recenterTo(int index); /*! * Returns string with queue number or(and) repeate flag for the item number \b i. */ diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp index 948a70699..a1a46de95 100644 --- a/src/plugins/Ui/skinned/listwidget.cpp +++ b/src/plugins/Ui/skinned/listwidget.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2016 by Ilya Kotov * + * Copyright (C) 2006-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -306,7 +306,7 @@ void ListWidget::updateList(int flags) flags |= PlayListModel::STRUCTURE; if(flags & PlayListModel::CURRENT) - recenterCurrent(); + recenterTo(m_model->currentIndex()); QList items; @@ -428,9 +428,13 @@ void ListWidget::updateRepeatIndicator() updateList(PlayListModel::CURRENT | PlayListModel::STRUCTURE); } -void ListWidget::scrollToCurrent() +void ListWidget::scrollTo(int index) { - updateList(PlayListModel::CURRENT | PlayListModel::STRUCTURE); + if (m_row_count) + { + recenterTo(index); + updateList(PlayListModel::STRUCTURE); + } } void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous) @@ -454,7 +458,7 @@ void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous) m_first = 0; updateList(PlayListModel::STRUCTURE | PlayListModel::CURRENT); } - connect (m_model, SIGNAL(currentVisibleRequest()), SLOT(scrollToCurrent())); + connect (m_model, SIGNAL(scrollToRequest(int)), SLOT(scrollTo(int))); connect (m_model, SIGNAL(listChanged(int)), SLOT(updateList(int))); connect (m_model, SIGNAL(sortingByColumnFinished(int,bool)), m_header, SLOT(showSortIndicator(int,bool))); } @@ -640,14 +644,13 @@ void ListWidget::contextMenuEvent(QContextMenuEvent * event) menu()->exec(event->globalPos()); } -void ListWidget::recenterCurrent() +void ListWidget::recenterTo(int index) { if (m_row_count) { - if (m_first + m_row_count < m_model->currentIndex() + 1) - m_first = qMin(m_model->count() - m_row_count, - m_model->currentIndex() - m_row_count/2); - else if (m_first > m_model->currentIndex()) - m_first = qMax (m_model->currentIndex() - m_row_count/2, 0); + if (m_first + m_row_count < index + 1) + m_first = qMin(m_model->count() - m_row_count, index - m_row_count/2); + else if (m_first > index) + m_first = qMax (index - m_row_count/2, 0); } } diff --git a/src/plugins/Ui/skinned/listwidget.h b/src/plugins/Ui/skinned/listwidget.h index a28e53ea7..42157dbb8 100644 --- a/src/plugins/Ui/skinned/listwidget.h +++ b/src/plugins/Ui/skinned/listwidget.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2016 by Ilya Kotov * + * Copyright (C) 2006-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -69,8 +69,7 @@ public: public slots: void readSettings(); void updateList(int flags); - void scroll(int); //0-99 - void recenterCurrent(); + void scroll(int); void setModel(PlayListModel *selected, PlayListModel *previous = 0); signals: @@ -97,13 +96,15 @@ private slots: void updateSkin(); void autoscroll(); void updateRepeatIndicator(); - void scrollToCurrent(); + void scrollTo(int index); private: enum ScrollDirection { NONE = 0,TOP,DOWN }; + + void recenterTo(int index); /*! * Returns string with queue number or(and) repeate flag for the item number \b i. */ diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp index 4033aaa20..4710d1066 100644 --- a/src/qmmpui/playlistmodel.cpp +++ b/src/qmmpui/playlistmodel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright(C) 2006-2016 by Ilya Kotov * + * Copyright(C) 2006-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -928,8 +928,14 @@ void PlayListModel::onTaskFinished() void PlayListModel::doCurrentVisibleRequest() { - if(!m_container->isEmpty()) - emit currentVisibleRequest(); + if(!m_container->isEmpty() && m_current >= 0) + emit scrollToRequest(currentIndex()); +} + +void PlayListModel::scrollTo(int index) +{ + if(index >= 0 && index < m_container->count()) + emit scrollToRequest(index); } void PlayListModel::loadPlaylist(const QString &f_name) diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index 1ad03d613..fe5da58f6 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2016 by Ilya Kotov * + * Copyright (C) 2006-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -65,7 +65,7 @@ struct SimpleSelection */ inline void dump()const { - qWarning("top: %d\tbotom: %d", m_top, m_bottom); + qDebug("top: %d\tbotom: %d", m_top, m_bottom); } /*! * Returns number of selected items. @@ -365,10 +365,8 @@ signals: * Emitted when playlist loader thread has finished. */ void loaderFinished(); - /*! - * Emitted to ensure that the current track is visible. - */ - void currentVisibleRequest(); + + void scrollToRequest(int index); /*! * Emitted when sorting by column is finished. * @param column Column index. @@ -476,6 +474,7 @@ public slots: * Ensures that the current track is visible. */ void doCurrentVisibleRequest(); + void scrollTo(int index); /*! * Randomly changes items order. */ -- cgit v1.2.3-13-gbd6f