[vlc-commits] qt: add positionRole on ChapterListModel
Abel Tesfaye
git at videolan.org
Thu Jun 13 13:11:17 CEST 2019
vlc | branch: master | Abel Tesfaye <Abeltesfaye45 at gmail.com> | Fri May 31 14:00:53 2019 +0300| [f9243e9a2be0c6a91acd48b2b05bca637e78f8e4] | committer: Thomas Guillem
qt: add positionRole on ChapterListModel
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f9243e9a2be0c6a91acd48b2b05bca637e78f8e4
---
modules/gui/qt/util/input_models.cpp | 26 +++++++++++++++++++++++++-
modules/gui/qt/util/input_models.hpp | 6 +++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/modules/gui/qt/util/input_models.cpp b/modules/gui/qt/util/input_models.cpp
index e381fbb917..918f93193d 100644
--- a/modules/gui/qt/util/input_models.cpp
+++ b/modules/gui/qt/util/input_models.cpp
@@ -287,6 +287,8 @@ QVariant ChapterListModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue<bool>(row == m_current);
else if (role == ChapterListRoles::TimeRole )
return QVariant::fromValue<vlc_tick_t>(chapter.time);
+ else if (role == ChapterListRoles::PositionRole && (m_title->length != 0) )
+ return QVariant::fromValue<float>(chapter.time /(float) m_title->length);
return QVariant{};
}
@@ -313,7 +315,8 @@ QHash<int, QByteArray> ChapterListModel::roleNames() const
return QHash<int, QByteArray>{
{Qt::DisplayRole, "display"},
{Qt::CheckStateRole, "checked"},
- {ChapterListRoles::TimeRole, "time"}
+ {ChapterListRoles::TimeRole, "time"},
+ {ChapterListRoles::PositionRole, "position"}
};
}
@@ -341,6 +344,27 @@ void ChapterListModel::resetTitle(const vlc_player_title *newTitle)
endResetModel();
}
+QString ChapterListModel::getNameAtPosition(float pos) const
+{
+ if(m_title == nullptr)
+ return qtr("nothing found");
+
+ vlc_tick_t posTime = pos * m_title->length;
+ int prevChapterIndex = 0;
+
+ for(unsigned int i=0;i<m_title->chapter_count;i++){
+
+ vlc_tick_t currentChapterTime = m_title->chapters[i].time;
+
+ if(currentChapterTime > posTime)
+ return qfu(m_title->chapters[prevChapterIndex].name);
+
+ else if(i == (m_title->chapter_count - 1))
+ return qfu(m_title->chapters[i].name);
+
+ prevChapterIndex = i;
+ }
+}
//***************************
// ProgramListModel
diff --git a/modules/gui/qt/util/input_models.hpp b/modules/gui/qt/util/input_models.hpp
index aab6dfe0f3..3744291cff 100644
--- a/modules/gui/qt/util/input_models.hpp
+++ b/modules/gui/qt/util/input_models.hpp
@@ -140,7 +140,8 @@ class ChapterListModel : public QAbstractListModel
public:
//user role
enum ChapterListRoles {
- TimeRole = Qt::UserRole + 1
+ TimeRole = Qt::UserRole + 1 ,
+ PositionRole
};
public:
ChapterListModel(vlc_player_t* player, QObject* parent = nullptr);
@@ -159,6 +160,9 @@ public:
void resetTitle(const vlc_player_title* newTitle);
+public slots:
+ QString getNameAtPosition(float pos) const;
+
private:
vlc_player_t* m_player = nullptr;
const vlc_player_title* m_title = nullptr;
More information about the vlc-commits
mailing list