81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
#ifndef READINGMODEL_H
|
|
#define READINGMODEL_H
|
|
|
|
#include <QObject>
|
|
#include <QSize>
|
|
#include <QString>
|
|
#include <QVariantList>
|
|
#include <QVector>
|
|
#include "backend/FormatReader.h"
|
|
#include "reading/MangaPagination.h"
|
|
#include "state/BookPositionStore.h"
|
|
|
|
class ReadingModel : public QObject {
|
|
Q_OBJECT
|
|
Q_PROPERTY(double progress READ progress NOTIFY currentPageChanged)
|
|
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
|
|
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
|
|
Q_PROPERTY(int totalPagePairs READ totalPagePairs NOTIFY totalPagePairsChanged)
|
|
Q_PROPERTY(bool pageShift READ pageShift NOTIFY pageShiftChanged)
|
|
Q_PROPERTY(bool mangaRTL READ mangaRTL NOTIFY mangaRTLChanged)
|
|
|
|
public:
|
|
explicit ReadingModel(BookPositionStore &positions, QObject *parent = nullptr);
|
|
~ReadingModel() override;
|
|
|
|
double progress() const;
|
|
int currentPage() const;
|
|
int totalPages() const;
|
|
int totalPagePairs() const;
|
|
bool pageShift() const;
|
|
bool mangaRTL() const;
|
|
|
|
void setReader(FormatReader *reader);
|
|
|
|
// Called from QML on every page navigation
|
|
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal proportion);
|
|
|
|
// Manga page-pair API
|
|
Q_INVOKABLE QVariantList pagePair(int pairIndex) const;
|
|
Q_INVOKABLE int pairIndexForChunk(int chunkIndex) const;
|
|
Q_INVOKABLE QString imageUrlForChunk(int chunkIndex) const;
|
|
|
|
// Called from MangaPageView when window orientation changes
|
|
Q_INVOKABLE void setMangaLandscape(bool landscape);
|
|
|
|
// Per-book page-shift toggle: when ON, page 1 is shown alone after the cover.
|
|
// currentPairIndex must be the pair the view is currently displaying.
|
|
Q_INVOKABLE void setPageShift(bool shift, int currentPairIndex = 0);
|
|
Q_INVOKABLE void setMangaRTL(bool rtl);
|
|
|
|
signals:
|
|
void currentPageChanged();
|
|
void totalPagesChanged();
|
|
void totalPagePairsChanged();
|
|
void pageShiftChanged();
|
|
void mangaRTLChanged();
|
|
// Fired after setPageShift rebuilds pairs; carries the new pair index to display.
|
|
void pagePairsRebuilt(int newPairIndex);
|
|
|
|
void restoreReady(int chunkIndex);
|
|
|
|
private:
|
|
void loadPages();
|
|
void rebuildPagePairs();
|
|
|
|
FormatReader *m_reader = nullptr;
|
|
int m_currentPage = 0;
|
|
int m_totalPages = 0;
|
|
bool m_mangaLandscape = false;
|
|
bool m_pageShift = true;
|
|
bool m_mangaRTL = true;
|
|
|
|
QVector<PageInfo> m_pages;
|
|
MangaPagination m_pagination;
|
|
qreal m_yOffset = 0.0;
|
|
|
|
BookPositionStore &m_positions;
|
|
};
|
|
|
|
#endif // READINGMODEL_H
|