added txt support

This commit is contained in:
Agel committed 2026-03-15 22:18:26 +01:00
1 parent 64a70bc4cf
commit 21656a3e9c
10 files changed
+441 -120

No files matched your search

+43 -22
View File
@@ -2,20 +2,38 @@
#include "FormatReader.h"
ReadingModel::ReadingModel(QObject *parent)
: QObject(parent)
: QAbstractListModel(parent)
{
}
int ReadingModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_chunks.size();
}
QVariant ReadingModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_chunks.size())
return {};
if (role == ContentRole)
return m_chunks.at(index.row());
return {};
}
QHash<int, QByteArray> ReadingModel::roleNames() const
{
return {{ContentRole, "content"}};
}
QString ReadingModel::chapterTitle() const
{
return m_chapterTitle;
}
QString ReadingModel::chapterContent() const
{
return m_chapterContent;
}
int ReadingModel::currentChapter() const
{
return m_currentChapter;
@@ -33,19 +51,28 @@ double ReadingModel::progress() const
return static_cast<double>(m_currentChapter + 1) / m_totalChapters;
}
void ReadingModel::loadChapterData(int index)
{
beginResetModel();
m_chunks.clear();
m_chapterTitle.clear();
if (m_reader && index >= 0 && index < m_totalChapters) {
auto chapter = m_reader->loadChapter(index);
m_chapterTitle = chapter.title;
m_chunks = chapter.contentChunks;
}
endResetModel();
}
void ReadingModel::setReader(FormatReader *reader)
{
m_reader = reader;
m_currentChapter = 0;
m_totalChapters = reader ? reader->chapterCount() : 0;
m_chapterTitle.clear();
m_chapterContent.clear();
if (m_reader && m_totalChapters > 0) {
auto chapter = m_reader->loadChapter(0);
m_chapterTitle = chapter.title;
m_chapterContent = chapter.contentHtml;
}
loadChapterData(0);
emit totalChaptersChanged();
emit chapterChanged();
@@ -57,9 +84,7 @@ void ReadingModel::nextChapter()
return;
m_currentChapter++;
auto chapter = m_reader->loadChapter(m_currentChapter);
m_chapterTitle = chapter.title;
m_chapterContent = chapter.contentHtml;
loadChapterData(m_currentChapter);
emit chapterChanged();
}
@@ -69,9 +94,7 @@ void ReadingModel::previousChapter()
return;
m_currentChapter--;
auto chapter = m_reader->loadChapter(m_currentChapter);
m_chapterTitle = chapter.title;
m_chapterContent = chapter.contentHtml;
loadChapterData(m_currentChapter);
emit chapterChanged();
}
@@ -81,8 +104,6 @@ void ReadingModel::goToChapter(int index)
return;
m_currentChapter = index;
auto chapter = m_reader->loadChapter(m_currentChapter);
m_chapterTitle = chapter.title;
m_chapterContent = chapter.contentHtml;
loadChapterData(m_currentChapter);
emit chapterChanged();
}