old render cleanup part 1

This commit is contained in:
Agel committed 2026-10-25 14:22:12 +01:00
1 parent 83968646c6
commit acc7e71e7b
38 files changed
+166 -1366

No files matched your search

+8 -54
View File
@@ -1,28 +1,23 @@
#ifndef READINGMODEL_H
#define READINGMODEL_H
#include <QAbstractListModel>
#include <QObject>
#include <QSize>
#include <QString>
#include <QVariantList>
#include <QVector>
#include <memory>
#include "IImageLoader.h"
#include "reading/MangaPagination.h"
#include "reading/MeasurementController.h"
#include "state/BookPositionStore.h"
class FormatReader;
struct ContentChunk {
QString html; // empty when unloaded (lazy streaming)
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)
QString imageUrl; // src of the chunk's img tag (empty for text chunks)
int chapterIndex = 0;
QSize naturalSize;
QString imageUrl;
};
class ReadingModel : public QAbstractListModel {
class ReadingModel : public QObject {
Q_OBJECT
Q_PROPERTY(QString chapterTitle READ chapterTitle NOTIFY chapterChanged)
Q_PROPERTY(int currentChapter READ currentChapter NOTIFY chapterChanged)
@@ -31,28 +26,15 @@ class ReadingModel : public QAbstractListModel {
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
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);
~ReadingModel() override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
QString chapterTitle() const;
int currentChapter() const;
int totalChapters() const;
@@ -60,17 +42,14 @@ public:
int currentPage() const;
int totalPages() const;
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);
// Called from QML on every scroll (real-time)
// Called from QML on every page navigation
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal proportion);
Q_INVOKABLE void nextChapter();
@@ -90,19 +69,9 @@ public:
Q_INVOKABLE void setPageShift(bool shift, int currentPairIndex = 0);
Q_INVOKABLE void setMangaRTL(bool rtl);
// Measurement
Q_INVOKABLE void measure(bool isNew);
// Preferences & state
void setContentWidth(int width);
Q_INVOKABLE void setFontParams(int fontSize, qreal lineSpacing);
void setImageLoader(std::unique_ptr<IImageLoader> loader);
signals:
void chapterChanged();
void totalChaptersChanged();
void measuringChanged();
void totalPixelHeightChanged();
void currentPageChanged();
void totalPagesChanged();
void totalPagePairsChanged();
@@ -113,21 +82,13 @@ signals:
void pagePairsRebuilt(int newPairIndex);
void scrollToChunkRequested(int chunkIndex);
void restoreReady(int chunkIndex, int intraChunkOffset);
private slots:
void onHeightsReady(const QVector<int> &heights, bool isNew);
void restoreReady(int chunkIndex);
private:
static constexpr qreal page_ratio = 1.5;
void loadAllChapters();
void recalculateCurrentPage();
void rebuildPagePairs();
void emitRestoreReady(bool isNew);
FormatReader *m_reader = nullptr;
QString m_coverImageUrl;
int m_currentChapter = 0;
int m_totalChapters = 0;
int m_currentPage = 0;
@@ -141,17 +102,10 @@ private:
QVector<int> m_chapterStartIndices;
QVector<QString> m_chapterTitles;
// Manga page-pair layout. In RTL mode the "left" slot is the later page visually.
MangaPagination m_pagination;
qreal m_totalPixelHeight = 0.0;
qreal m_yOffset = 0.0;
int m_contentWidth = 0;
int m_fontSize = 0;
qreal m_lineSpacing = 0;
BookPositionStore &m_positions;
MeasurementController m_measurer;
};
#endif // READINGMODEL_H