Manga rendering mode

This commit is contained in:
Agel committed 2026-05-22 12:10:42 +02:00
1 parent 9167f10b1c
commit e043ded6b1
15 files changed
+935 -253

No files matched your search

+42
View File
@@ -3,7 +3,10 @@
#include <QAbstractListModel>
#include <QFuture>
#include <QPair>
#include <QSize>
#include <QString>
#include <QVector>
#include <memory>
#include "IImageLoader.h"
#include "state/BookPositionStore.h"
@@ -15,6 +18,7 @@ struct ContentChunk {
int chapterIndex = 0; // which chapter owns this chunk
int chunkInChapter = 0; // 0-based index within chapter (-1 for cover)
int pixelHeight = -1; // -1 = not yet measured
QSize naturalSize; // image pixel dimensions (null for text chunks)
};
class ReadingModel : public QAbstractListModel {
@@ -28,12 +32,17 @@ class ReadingModel : public QAbstractListModel {
Q_PROPERTY(bool hasChapters READ hasChapters NOTIFY totalChaptersChanged)
Q_PROPERTY(bool measuring READ measuring NOTIFY measuringChanged)
Q_PROPERTY(qreal totalPixelHeight READ totalPixelHeight NOTIFY totalPixelHeightChanged)
Q_PROPERTY(int totalPagePairs READ totalPagePairs NOTIFY totalPagePairsChanged)
Q_PROPERTY(bool isMangaMode READ isMangaMode NOTIFY isMangaModeChanged)
Q_PROPERTY(bool pageShift READ pageShift NOTIFY pageShiftChanged)
Q_PROPERTY(bool mangaRTL READ mangaRTL NOTIFY mangaRTLChanged)
public:
enum Roles {
ContentRole = Qt::UserRole + 1,
PixelHeightRole = Qt::UserRole + 2,
ChapterRole = Qt::UserRole + 3,
NaturalSizeRole = Qt::UserRole + 4,
};
explicit ReadingModel(BookPositionStore &positions, QObject *parent = nullptr);
@@ -52,6 +61,10 @@ public:
bool hasChapters() const;
bool measuring() const;
qreal totalPixelHeight() const;
int totalPagePairs() const;
bool isMangaMode() const;
bool pageShift() const;
bool mangaRTL() const;
void setReader(FormatReader *reader);
void setCoverImageUrl(const QString &coverImageUrl);
@@ -63,6 +76,19 @@ public:
Q_INVOKABLE void previousChapter();
Q_INVOKABLE void goToChapter(int index);
// 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);
// Measurement
Q_INVOKABLE void measure(bool isNew);
@@ -78,6 +104,12 @@ signals:
void totalPixelHeightChanged();
void currentPageChanged();
void totalPagesChanged();
void totalPagePairsChanged();
void isMangaModeChanged();
void pageShiftChanged();
void mangaRTLChanged();
// Fired after setPageShift rebuilds pairs; carries the new pair index to display.
void pagePairsRebuilt(int newPairIndex);
void scrollToChunkRequested(int chunkIndex);
void restoreReady(int chunkIndex, int intraChunkOffset);
@@ -87,7 +119,9 @@ private:
void loadAllChapters();
void recalculateCurrentPage();
void rebuildPagePairs();
void runMeasurement(const QStringList &htmls, bool isNew);
void emitRestoreReady(bool isNew);
FormatReader *m_reader = nullptr;
QString m_coverImageUrl;
@@ -96,11 +130,19 @@ private:
int m_currentPage = 0;
int m_totalPages = 0;
bool m_measuring = false;
bool m_isMangaMode = false;
bool m_mangaLandscape = false;
bool m_pageShift = true;
bool m_mangaRTL = true;
QVector<ContentChunk> m_chunks;
QVector<int> m_chapterStartIndices;
QVector<QString> m_chapterTitles;
// Manga page pairs: each QPair holds (leftChunkIdx, rightChunkIdx) where rightChunkIdx
// may be -1 for solo pages. In RTL mode the "left" slot is the later page visually.
QVector<QPair<int,int>> m_pagePairs;
qreal m_totalPixelHeight = 0.0;
qreal m_yOffset = 0.0;
int m_contentWidth = 0;