145 lines
4.0 KiB
C++
145 lines
4.0 KiB
C++
#include "AppState.h"
|
|
#include <QSettings>
|
|
|
|
AppState::AppState(QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
QString AppState::lastFilePath() const { return m_lastFilePath; }
|
|
|
|
void AppState::setLastFilePath(const QString &path)
|
|
{
|
|
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()
|
|
{
|
|
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()
|
|
{
|
|
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();
|
|
}
|