53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#ifndef READINGMODEL_H
|
|
#define READINGMODEL_H
|
|
|
|
#include <QAbstractListModel>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
class FormatReader;
|
|
|
|
class ReadingModel : public QAbstractListModel {
|
|
Q_OBJECT
|
|
Q_PROPERTY(QString chapterTitle READ chapterTitle NOTIFY chapterChanged)
|
|
Q_PROPERTY(int currentChapter READ currentChapter NOTIFY chapterChanged)
|
|
Q_PROPERTY(int totalChapters READ totalChapters NOTIFY totalChaptersChanged)
|
|
Q_PROPERTY(double progress READ progress NOTIFY chapterChanged)
|
|
|
|
public:
|
|
enum Roles {
|
|
ContentRole = Qt::UserRole + 1
|
|
};
|
|
|
|
explicit ReadingModel(QObject *parent = nullptr);
|
|
|
|
// QAbstractListModel overrides
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
QString chapterTitle() const;
|
|
int currentChapter() const;
|
|
int totalChapters() const;
|
|
double progress() const;
|
|
void setReader(FormatReader *reader);
|
|
|
|
Q_INVOKABLE void nextChapter();
|
|
Q_INVOKABLE void previousChapter();
|
|
Q_INVOKABLE void goToChapter(int index);
|
|
|
|
signals:
|
|
void chapterChanged();
|
|
void totalChaptersChanged();
|
|
private:
|
|
void loadChapterData(int index);
|
|
|
|
FormatReader *m_reader = nullptr;
|
|
int m_currentChapter = 0;
|
|
int m_totalChapters = 0;
|
|
QString m_chapterTitle;
|
|
QStringList m_chunks;
|
|
};
|
|
|
|
#endif // READINGMODEL_H
|