-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlyricsmodel.h
More file actions
55 lines (44 loc) · 1.3 KB
/
lyricsmodel.h
File metadata and controls
55 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Backend and model for the lyrics view
#ifndef LYRICSVIEW_H
#define LYRICSVIEW_H
#include "lrc.h"
#include <QAbstractListModel>
#include <QObject>
#include <QQmlEngine>
#include <QQmlListProperty>
class LyricsModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QUrl lyricSource READ lyricSource WRITE setLyricSource NOTIFY lyricSourceChanged)
public:
enum LyricsViewRoles {
SentenceRole = Qt::UserRole + 1,
TimestampRole
};
LyricsModel(QObject* parent = nullptr);
// Allows QML get the lyric line by index
Q_INVOKABLE LyricLine getLyricLine(int index)
{
if (index >= 0 && index < lrc_content.lyricLines.count()) {
return lrc_content.lyricLines[index];
} else {
return LyricLine();
}
}
QUrl lyricSource()
{
return m_lyricSource;
}
void setLyricSource(QUrl lyricSource);
virtual int rowCount(const QModelIndex& parent) const override;
virtual QVariant data(const QModelIndex& index, int role) const override;
public slots:
void loadLyricsFile(QUrl lyricSource);
signals:
void lyricSourceChanged(QUrl lyricSource);
protected:
virtual QHash<int, QByteArray> roleNames() const override;
private:
QUrl m_lyricSource;
LrcContent lrc_content;
};
#endif // LYRICSVIEW_H