Save more state on exit

This commit is contained in:
Agel committed 2026-03-20 17:02:09 +01:00
1 parent 0411de6174
commit d42b313d77
4 files changed
+38 -10

No files matched your search

+12
View File
@@ -149,6 +149,16 @@ void AppState::setLastPage(const QString &page)
emit lastPageChanged();
}
bool AppState::sidebarOpen() const { return m_sidebarOpen; }
void AppState::setSidebarOpen(bool open)
{
if (m_sidebarOpen == open)
return;
m_sidebarOpen = open;
emit sidebarOpenChanged();
}
void AppState::addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress)
{
QString lastOpened = QDateTime::currentDateTime().toString(Qt::ISODate);
@@ -239,6 +249,7 @@ void AppState::save()
s.setValue(QStringLiteral("session/lastScrollIndex"), m_lastScrollIndex);
s.setValue(QStringLiteral("session/lastScrollOffset"), m_lastScrollOffset);
s.setValue(QStringLiteral("session/lastPage"), m_lastPage);
s.setValue(QStringLiteral("session/sidebarOpen"), m_sidebarOpen);
s.setValue(QStringLiteral("preferences/pageFlipMode"), m_pageFlipMode);
s.setValue(QStringLiteral("window/width"), m_windowWidth);
s.setValue(QStringLiteral("window/height"), m_windowHeight);
@@ -256,6 +267,7 @@ void AppState::restore()
m_lastScrollIndex = s.value(QStringLiteral("session/lastScrollIndex"), 0).toInt();
m_lastScrollOffset = s.value(QStringLiteral("session/lastScrollOffset"), 0.0).toDouble();
m_lastPage = s.value(QStringLiteral("session/lastPage"), QStringLiteral("starter")).toString();
m_sidebarOpen = s.value(QStringLiteral("session/sidebarOpen"), false).toBool();
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();
+6
View File
@@ -21,6 +21,7 @@ class AppState : public QObject {
Q_PROPERTY(int windowY READ windowY WRITE setWindowY NOTIFY windowYChanged)
Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged)
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
public:
explicit AppState(QObject *parent = nullptr);
@@ -63,6 +64,9 @@ public:
QString lastPage() const;
void setLastPage(const QString &page);
bool sidebarOpen() const;
void setSidebarOpen(bool open);
Q_INVOKABLE void addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress);
Q_INVOKABLE void removeLibraryBook(const QString &filePath);
Q_INVOKABLE QVariantList libraryBooks() const;
@@ -84,6 +88,7 @@ signals:
void windowYChanged();
void libraryBooksChanged();
void lastPageChanged();
void sidebarOpenChanged();
private:
void loadLibraryBooks();
@@ -100,6 +105,7 @@ private:
int m_windowY = -1;
QVariantList m_libraryBooks;
QString m_lastPage = QStringLiteral("starter");
bool m_sidebarOpen = false;
};
#endif // APPSTATE_H