restore opened file and position
This commit is contained in:
12 files changed
+491
-11
No files matched your search
+127
-4
@@ -1,21 +1,144 @@
|
||||
#include "AppState.h"
|
||||
#include <QSettings>
|
||||
|
||||
AppState::AppState(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString AppState::lastFilePath() const
|
||||
QString AppState::lastFilePath() const { return m_lastFilePath; }
|
||||
|
||||
void AppState::setLastFilePath(const QString &path)
|
||||
{
|
||||
return m_lastFilePath;
|
||||
if (m_lastFilePath == path)
|
||||
return;
|
||||
m_lastFilePath = path;
|
||||
emit lastFilePathChanged();
|
||||
}
|
||||
|
||||
int AppState::lastChapter() const { return m_lastChapter; }
|
||||
|
||||
void AppState::setLastChapter(int chapter)
|
||||
{
|
||||
if (m_lastChapter == chapter)
|
||||
return;
|
||||
m_lastChapter = chapter;
|
||||
emit lastChapterChanged();
|
||||
}
|
||||
|
||||
qreal AppState::lastScrollPosition() const { return m_lastScrollPosition; }
|
||||
|
||||
void AppState::setLastScrollPosition(qreal position)
|
||||
{
|
||||
if (qFuzzyCompare(m_lastScrollPosition, position))
|
||||
return;
|
||||
m_lastScrollPosition = position;
|
||||
emit lastScrollPositionChanged();
|
||||
}
|
||||
|
||||
int AppState::lastScrollIndex() const { return m_lastScrollIndex; }
|
||||
|
||||
void AppState::setLastScrollIndex(int index)
|
||||
{
|
||||
if (m_lastScrollIndex == index)
|
||||
return;
|
||||
m_lastScrollIndex = index;
|
||||
emit lastScrollIndexChanged();
|
||||
}
|
||||
|
||||
qreal AppState::lastScrollOffset() const { return m_lastScrollOffset; }
|
||||
|
||||
void AppState::setLastScrollOffset(qreal offset)
|
||||
{
|
||||
if (qFuzzyCompare(m_lastScrollOffset, offset))
|
||||
return;
|
||||
m_lastScrollOffset = offset;
|
||||
emit lastScrollOffsetChanged();
|
||||
}
|
||||
|
||||
QString AppState::pageFlipMode() const { return m_pageFlipMode; }
|
||||
|
||||
void AppState::setPageFlipMode(const QString &mode)
|
||||
{
|
||||
if (m_pageFlipMode == mode)
|
||||
return;
|
||||
m_pageFlipMode = mode;
|
||||
emit pageFlipModeChanged();
|
||||
}
|
||||
|
||||
int AppState::windowWidth() const { return m_windowWidth; }
|
||||
|
||||
void AppState::setWindowWidth(int width)
|
||||
{
|
||||
if (m_windowWidth == width)
|
||||
return;
|
||||
m_windowWidth = width;
|
||||
emit windowWidthChanged();
|
||||
}
|
||||
|
||||
int AppState::windowHeight() const { return m_windowHeight; }
|
||||
|
||||
void AppState::setWindowHeight(int height)
|
||||
{
|
||||
if (m_windowHeight == height)
|
||||
return;
|
||||
m_windowHeight = height;
|
||||
emit windowHeightChanged();
|
||||
}
|
||||
|
||||
int AppState::windowX() const { return m_windowX; }
|
||||
|
||||
void AppState::setWindowX(int x)
|
||||
{
|
||||
if (m_windowX == x)
|
||||
return;
|
||||
m_windowX = x;
|
||||
emit windowXChanged();
|
||||
}
|
||||
|
||||
int AppState::windowY() const { return m_windowY; }
|
||||
|
||||
void AppState::setWindowY(int y)
|
||||
{
|
||||
if (m_windowY == y)
|
||||
return;
|
||||
m_windowY = y;
|
||||
emit windowYChanged();
|
||||
}
|
||||
|
||||
QUrl AppState::lastFileUrl() const
|
||||
{
|
||||
return QUrl::fromLocalFile(m_lastFilePath);
|
||||
}
|
||||
|
||||
void AppState::save()
|
||||
{
|
||||
// Will use QSettings via TDD
|
||||
QSettings s;
|
||||
s.setValue(QStringLiteral("session/lastFilePath"), m_lastFilePath);
|
||||
s.setValue(QStringLiteral("session/lastChapter"), m_lastChapter);
|
||||
s.setValue(QStringLiteral("session/lastScrollPosition"), m_lastScrollPosition);
|
||||
s.setValue(QStringLiteral("session/lastScrollIndex"), m_lastScrollIndex);
|
||||
s.setValue(QStringLiteral("session/lastScrollOffset"), m_lastScrollOffset);
|
||||
s.setValue(QStringLiteral("preferences/pageFlipMode"), m_pageFlipMode);
|
||||
s.setValue(QStringLiteral("window/width"), m_windowWidth);
|
||||
s.setValue(QStringLiteral("window/height"), m_windowHeight);
|
||||
s.setValue(QStringLiteral("window/x"), m_windowX);
|
||||
s.setValue(QStringLiteral("window/y"), m_windowY);
|
||||
}
|
||||
|
||||
void AppState::restore()
|
||||
{
|
||||
// Will use QSettings via TDD
|
||||
QSettings s;
|
||||
m_lastFilePath = s.value(QStringLiteral("session/lastFilePath"), QString()).toString();
|
||||
m_lastChapter = s.value(QStringLiteral("session/lastChapter"), 0).toInt();
|
||||
m_lastScrollPosition = s.value(QStringLiteral("session/lastScrollPosition"), 0.0).toDouble();
|
||||
m_lastScrollIndex = s.value(QStringLiteral("session/lastScrollIndex"), 0).toInt();
|
||||
m_lastScrollOffset = s.value(QStringLiteral("session/lastScrollOffset"), 0.0).toDouble();
|
||||
m_pageFlipMode = s.value(QStringLiteral("preferences/pageFlipMode"), QStringLiteral("scroll")).toString();
|
||||
m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt();
|
||||
m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt();
|
||||
m_windowX = s.value(QStringLiteral("window/x"), -1).toInt();
|
||||
m_windowY = s.value(QStringLiteral("window/y"), -1).toInt();
|
||||
|
||||
emit stateRestored();
|
||||
}
|
||||
+60
-1
@@ -3,24 +3,83 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
class AppState : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString lastFilePath READ lastFilePath NOTIFY lastFilePathChanged)
|
||||
Q_PROPERTY(QString lastFilePath READ lastFilePath WRITE setLastFilePath NOTIFY lastFilePathChanged)
|
||||
Q_PROPERTY(int lastChapter READ lastChapter WRITE setLastChapter NOTIFY lastChapterChanged)
|
||||
Q_PROPERTY(qreal lastScrollPosition READ lastScrollPosition WRITE setLastScrollPosition NOTIFY lastScrollPositionChanged)
|
||||
Q_PROPERTY(int lastScrollIndex READ lastScrollIndex WRITE setLastScrollIndex NOTIFY lastScrollIndexChanged)
|
||||
Q_PROPERTY(qreal lastScrollOffset READ lastScrollOffset WRITE setLastScrollOffset NOTIFY lastScrollOffsetChanged)
|
||||
Q_PROPERTY(QString pageFlipMode READ pageFlipMode WRITE setPageFlipMode NOTIFY pageFlipModeChanged)
|
||||
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
|
||||
Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
|
||||
Q_PROPERTY(int windowX READ windowX WRITE setWindowX NOTIFY windowXChanged)
|
||||
Q_PROPERTY(int windowY READ windowY WRITE setWindowY NOTIFY windowYChanged)
|
||||
|
||||
public:
|
||||
explicit AppState(QObject *parent = nullptr);
|
||||
|
||||
QString lastFilePath() const;
|
||||
void setLastFilePath(const QString &path);
|
||||
|
||||
int lastChapter() const;
|
||||
void setLastChapter(int chapter);
|
||||
|
||||
qreal lastScrollPosition() const;
|
||||
void setLastScrollPosition(qreal position);
|
||||
|
||||
int lastScrollIndex() const;
|
||||
void setLastScrollIndex(int index);
|
||||
|
||||
qreal lastScrollOffset() const;
|
||||
void setLastScrollOffset(qreal offset);
|
||||
|
||||
QString pageFlipMode() const;
|
||||
void setPageFlipMode(const QString &mode);
|
||||
|
||||
int windowWidth() const;
|
||||
void setWindowWidth(int width);
|
||||
|
||||
int windowHeight() const;
|
||||
void setWindowHeight(int height);
|
||||
|
||||
int windowX() const;
|
||||
void setWindowX(int x);
|
||||
|
||||
int windowY() const;
|
||||
void setWindowY(int y);
|
||||
|
||||
Q_INVOKABLE QUrl lastFileUrl() const;
|
||||
|
||||
Q_INVOKABLE void save();
|
||||
Q_INVOKABLE void restore();
|
||||
|
||||
signals:
|
||||
void lastFilePathChanged();
|
||||
void lastChapterChanged();
|
||||
void lastScrollPositionChanged();
|
||||
void lastScrollIndexChanged();
|
||||
void lastScrollOffsetChanged();
|
||||
void pageFlipModeChanged();
|
||||
void stateRestored();
|
||||
void windowWidthChanged();
|
||||
void windowHeightChanged();
|
||||
void windowXChanged();
|
||||
void windowYChanged();
|
||||
|
||||
private:
|
||||
QString m_lastFilePath;
|
||||
int m_lastChapter = 0;
|
||||
qreal m_lastScrollPosition = 0.0;
|
||||
int m_lastScrollIndex = 0;
|
||||
qreal m_lastScrollOffset = 0.0;
|
||||
QString m_pageFlipMode = QStringLiteral("scroll");
|
||||
int m_windowWidth = 1024;
|
||||
int m_windowHeight = 768;
|
||||
int m_windowX = -1;
|
||||
int m_windowY = -1;
|
||||
};
|
||||
|
||||
#endif // APPSTATE_H
|
||||
@@ -97,6 +97,11 @@ bool BookController::hasBook() const
|
||||
return m_reader != nullptr;
|
||||
}
|
||||
|
||||
QString BookController::currentFilePath() const
|
||||
{
|
||||
return m_currentFilePath;
|
||||
}
|
||||
|
||||
QList<TocEntry> BookController::toc() const
|
||||
{
|
||||
if (m_reader)
|
||||
@@ -139,6 +144,7 @@ void BookController::openBook(const QUrl &fileUrl)
|
||||
}
|
||||
|
||||
m_reader = std::move(reader);
|
||||
m_currentFilePath = filePath;
|
||||
m_bookTitle = m_reader->title();
|
||||
m_bookAuthor = m_reader->author();
|
||||
|
||||
@@ -275,6 +281,7 @@ void BookController::closeBook()
|
||||
m_reader.reset();
|
||||
m_bookTitle.clear();
|
||||
m_bookAuthor.clear();
|
||||
m_currentFilePath.clear();
|
||||
|
||||
if (m_readingModel)
|
||||
m_readingModel->setReader(nullptr);
|
||||
|
||||
@@ -19,6 +19,7 @@ class BookController : public QObject {
|
||||
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
|
||||
Q_PROPERTY(bool hasBook READ hasBook NOTIFY bookChanged)
|
||||
Q_PROPERTY(QList<TocEntry> toc READ toc NOTIFY bookChanged)
|
||||
Q_PROPERTY(QString currentFilePath READ currentFilePath NOTIFY bookChanged)
|
||||
|
||||
public:
|
||||
explicit BookController(QObject *parent = nullptr);
|
||||
@@ -29,6 +30,7 @@ public:
|
||||
QString errorMessage() const;
|
||||
bool hasBook() const;
|
||||
QList<TocEntry> toc() const;
|
||||
QString currentFilePath() const;
|
||||
|
||||
void setReadingModel(ReadingModel *model);
|
||||
|
||||
@@ -55,6 +57,7 @@ private:
|
||||
ReadingModel *m_readingModel = nullptr;
|
||||
QString m_bookTitle;
|
||||
QString m_bookAuthor;
|
||||
QString m_currentFilePath;
|
||||
bool m_loading = false;
|
||||
QString m_errorMessage;
|
||||
#ifdef HAS_QT_DBUS
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
int currentChapter() const;
|
||||
int totalChapters() const;
|
||||
double progress() const;
|
||||
|
||||
void setReader(FormatReader *reader);
|
||||
|
||||
Q_INVOKABLE void nextChapter();
|
||||
@@ -40,7 +39,6 @@ public:
|
||||
signals:
|
||||
void chapterChanged();
|
||||
void totalChaptersChanged();
|
||||
|
||||
private:
|
||||
void loadChapterData(int index);
|
||||
|
||||
|
||||
Reference in new issue
Block a user