an unsuccessful attemnt to calculate current/total pages
This commit is contained in:
1 parent
353c82f6d6
commit
1a4726b95a
6 files changed
+288
-3
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
class FormatReader;
|
||||
|
||||
@@ -13,6 +14,8 @@ class ReadingModel : public QAbstractListModel {
|
||||
Q_PROPERTY(int currentChapter READ currentChapter NOTIFY chapterChanged)
|
||||
Q_PROPERTY(int totalChapters READ totalChapters NOTIFY totalChaptersChanged)
|
||||
Q_PROPERTY(double progress READ progress NOTIFY chapterChanged)
|
||||
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
|
||||
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
@@ -30,8 +33,15 @@ public:
|
||||
int currentChapter() const;
|
||||
int totalChapters() const;
|
||||
double progress() const;
|
||||
int currentPage() const;
|
||||
int totalPages() const;
|
||||
void setReader(FormatReader *reader);
|
||||
|
||||
// Called from QML on resize
|
||||
Q_INVOKABLE void setViewportSize(qreal width, qreal height);
|
||||
// Called from QML on every scroll (real-time)
|
||||
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal offsetInChunk);
|
||||
|
||||
Q_INVOKABLE void nextChapter();
|
||||
Q_INVOKABLE void previousChapter();
|
||||
Q_INVOKABLE void goToChapter(int index);
|
||||
@@ -39,14 +49,30 @@ public:
|
||||
signals:
|
||||
void chapterChanged();
|
||||
void totalChaptersChanged();
|
||||
void currentPageChanged();
|
||||
void totalPagesChanged();
|
||||
|
||||
private:
|
||||
void loadChapterData(int index);
|
||||
void computeChunkHeights();
|
||||
void recalculateTotalPages();
|
||||
void recalculateCurrentPage();
|
||||
|
||||
FormatReader *m_reader = nullptr;
|
||||
int m_currentChapter = 0;
|
||||
int m_totalChapters = 0;
|
||||
QString m_chapterTitle;
|
||||
int m_currentPage = 0;
|
||||
int m_totalPages = 0;
|
||||
qreal m_viewportWidth = 0;
|
||||
qreal m_viewportHeight = 0;
|
||||
qreal m_absoluteScrollY = 0;
|
||||
|
||||
QStringList m_chunks;
|
||||
QVector<qreal> m_chunkHeights; // rendered height of each chunk
|
||||
QVector<qreal> m_chunkOffsets; // prefix sums: offset[i] = sum of heights[0..i-1]
|
||||
qreal m_totalContentHeight = 0;
|
||||
|
||||
QString m_chapterTitle;
|
||||
};
|
||||
|
||||
#endif // READINGMODEL_H
|
||||
Reference in new issue
Block a user