[vlc-devel] [PATCH 2/6] qt: add positionRole on ChapterListModel
Abel Tesfaye
abeltesfaye45 at gmail.com
Fri May 31 13:00:53 CEST 2019
From: Abel Tesfaye <Abeltesfaye45 at gmail.com>
---
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;
--
2.21.0
More information about the vlc-devel
mailing list