Initial UI
This commit is contained in:
1 parent
4d52c8cc60
commit
3c0037cfc9
29 files changed
+1367
-2
No files matched your search
@@ -0,0 +1,88 @@
|
||||
#include "ReadingModel.h"
|
||||
#include "FormatReader.h"
|
||||
|
||||
ReadingModel::ReadingModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString ReadingModel::chapterTitle() const
|
||||
{
|
||||
return m_chapterTitle;
|
||||
}
|
||||
|
||||
QString ReadingModel::chapterContent() const
|
||||
{
|
||||
return m_chapterContent;
|
||||
}
|
||||
|
||||
int ReadingModel::currentChapter() const
|
||||
{
|
||||
return m_currentChapter;
|
||||
}
|
||||
|
||||
int ReadingModel::totalChapters() const
|
||||
{
|
||||
return m_totalChapters;
|
||||
}
|
||||
|
||||
double ReadingModel::progress() const
|
||||
{
|
||||
if (m_totalChapters == 0)
|
||||
return 0.0;
|
||||
return static_cast<double>(m_currentChapter + 1) / m_totalChapters;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
emit totalChaptersChanged();
|
||||
emit chapterChanged();
|
||||
}
|
||||
|
||||
void ReadingModel::nextChapter()
|
||||
{
|
||||
if (!m_reader || m_currentChapter >= m_totalChapters - 1)
|
||||
return;
|
||||
|
||||
m_currentChapter++;
|
||||
auto chapter = m_reader->loadChapter(m_currentChapter);
|
||||
m_chapterTitle = chapter.title;
|
||||
m_chapterContent = chapter.contentHtml;
|
||||
emit chapterChanged();
|
||||
}
|
||||
|
||||
void ReadingModel::previousChapter()
|
||||
{
|
||||
if (!m_reader || m_currentChapter <= 0)
|
||||
return;
|
||||
|
||||
m_currentChapter--;
|
||||
auto chapter = m_reader->loadChapter(m_currentChapter);
|
||||
m_chapterTitle = chapter.title;
|
||||
m_chapterContent = chapter.contentHtml;
|
||||
emit chapterChanged();
|
||||
}
|
||||
|
||||
void ReadingModel::goToChapter(int index)
|
||||
{
|
||||
if (!m_reader || index < 0 || index >= m_totalChapters)
|
||||
return;
|
||||
|
||||
m_currentChapter = index;
|
||||
auto chapter = m_reader->loadChapter(m_currentChapter);
|
||||
m_chapterTitle = chapter.title;
|
||||
m_chapterContent = chapter.contentHtml;
|
||||
emit chapterChanged();
|
||||
}
|
||||
Reference in new issue
Block a user