a bit of refactor
This commit is contained in:
19 files changed
+546
-232
No files matched your search
@@ -1,10 +1,6 @@
|
||||
#include "ReadingModel.h"
|
||||
#include "FormatReader.h"
|
||||
#include <cmath>
|
||||
#include <QTextDocument>
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QFont>
|
||||
|
||||
ReadingModel::ReadingModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
@@ -74,6 +70,11 @@ int ReadingModel::totalPages() const
|
||||
return m_totalPages;
|
||||
}
|
||||
|
||||
void ReadingModel::setChunkMeasurer(IChunkMeasurer *measurer)
|
||||
{
|
||||
m_chunkMeasurer = measurer;
|
||||
}
|
||||
|
||||
void ReadingModel::setViewportSize(qreal width, qreal height)
|
||||
{
|
||||
bool widthChanged = (width != m_viewportWidth);
|
||||
@@ -99,36 +100,12 @@ void ReadingModel::setScrollInfo(int topChunkIndex, qreal offsetInChunk, bool at
|
||||
|
||||
void ReadingModel::computeChunkHeights()
|
||||
{
|
||||
// Caller passes effective text width:
|
||||
// chunkListView.width - 18 (scrollbar) - 2 * horizontalMargin (delegate padding)
|
||||
qreal textWidth = m_viewportWidth;
|
||||
if (textWidth <= 0)
|
||||
textWidth = 1;
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(16);
|
||||
|
||||
QTextDocument doc;
|
||||
doc.setDefaultFont(font);
|
||||
|
||||
m_chunkHeights.clear();
|
||||
m_chunkHeights.reserve(m_chunks.size());
|
||||
|
||||
for (const QString &chunk : m_chunks) {
|
||||
doc.setHtml(chunk);
|
||||
doc.setTextWidth(textWidth);
|
||||
|
||||
// Apply lineHeight: 1.6 (matching QML Text lineHeight property)
|
||||
QTextBlockFormat fmt;
|
||||
fmt.setLineHeight(160, QTextBlockFormat::ProportionalHeight);
|
||||
QTextCursor cursor(&doc);
|
||||
cursor.select(QTextCursor::Document);
|
||||
cursor.mergeBlockFormat(fmt);
|
||||
|
||||
m_chunkHeights.append(doc.size().height());
|
||||
if (m_chunkMeasurer) {
|
||||
m_chunkHeights = m_chunkMeasurer->measure(m_chunks, m_viewportWidth);
|
||||
} else {
|
||||
m_chunkHeights.assign(m_chunks.size(), 0.0);
|
||||
}
|
||||
|
||||
// Build prefix sums
|
||||
m_chunkOffsets.clear();
|
||||
m_chunkOffsets.reserve(m_chunks.size());
|
||||
qreal offset = 0;
|
||||
|
||||
Reference in new issue
Block a user