Save more state on exit
This commit is contained in:
4 files changed
+34
-6
No files matched your search
@@ -149,6 +149,16 @@ void AppState::setLastPage(const QString &page)
|
|||||||
emit lastPageChanged();
|
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)
|
void AppState::addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress)
|
||||||
{
|
{
|
||||||
QString lastOpened = QDateTime::currentDateTime().toString(Qt::ISODate);
|
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/lastScrollIndex"), m_lastScrollIndex);
|
||||||
s.setValue(QStringLiteral("session/lastScrollOffset"), m_lastScrollOffset);
|
s.setValue(QStringLiteral("session/lastScrollOffset"), m_lastScrollOffset);
|
||||||
s.setValue(QStringLiteral("session/lastPage"), m_lastPage);
|
s.setValue(QStringLiteral("session/lastPage"), m_lastPage);
|
||||||
|
s.setValue(QStringLiteral("session/sidebarOpen"), m_sidebarOpen);
|
||||||
s.setValue(QStringLiteral("preferences/pageFlipMode"), m_pageFlipMode);
|
s.setValue(QStringLiteral("preferences/pageFlipMode"), m_pageFlipMode);
|
||||||
s.setValue(QStringLiteral("window/width"), m_windowWidth);
|
s.setValue(QStringLiteral("window/width"), m_windowWidth);
|
||||||
s.setValue(QStringLiteral("window/height"), m_windowHeight);
|
s.setValue(QStringLiteral("window/height"), m_windowHeight);
|
||||||
@@ -256,6 +267,7 @@ void AppState::restore()
|
|||||||
m_lastScrollIndex = s.value(QStringLiteral("session/lastScrollIndex"), 0).toInt();
|
m_lastScrollIndex = s.value(QStringLiteral("session/lastScrollIndex"), 0).toInt();
|
||||||
m_lastScrollOffset = s.value(QStringLiteral("session/lastScrollOffset"), 0.0).toDouble();
|
m_lastScrollOffset = s.value(QStringLiteral("session/lastScrollOffset"), 0.0).toDouble();
|
||||||
m_lastPage = s.value(QStringLiteral("session/lastPage"), QStringLiteral("starter")).toString();
|
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_pageFlipMode = s.value(QStringLiteral("preferences/pageFlipMode"), QStringLiteral("scroll")).toString();
|
||||||
m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt();
|
m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt();
|
||||||
m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt();
|
m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class AppState : public QObject {
|
|||||||
Q_PROPERTY(int windowY READ windowY WRITE setWindowY NOTIFY windowYChanged)
|
Q_PROPERTY(int windowY READ windowY WRITE setWindowY NOTIFY windowYChanged)
|
||||||
Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged)
|
Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged)
|
||||||
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
|
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
|
||||||
|
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AppState(QObject *parent = nullptr);
|
explicit AppState(QObject *parent = nullptr);
|
||||||
@@ -63,6 +64,9 @@ public:
|
|||||||
QString lastPage() const;
|
QString lastPage() const;
|
||||||
void setLastPage(const QString &page);
|
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 addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress);
|
||||||
Q_INVOKABLE void removeLibraryBook(const QString &filePath);
|
Q_INVOKABLE void removeLibraryBook(const QString &filePath);
|
||||||
Q_INVOKABLE QVariantList libraryBooks() const;
|
Q_INVOKABLE QVariantList libraryBooks() const;
|
||||||
@@ -84,6 +88,7 @@ signals:
|
|||||||
void windowYChanged();
|
void windowYChanged();
|
||||||
void libraryBooksChanged();
|
void libraryBooksChanged();
|
||||||
void lastPageChanged();
|
void lastPageChanged();
|
||||||
|
void sidebarOpenChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadLibraryBooks();
|
void loadLibraryBooks();
|
||||||
@@ -100,6 +105,7 @@ private:
|
|||||||
int m_windowY = -1;
|
int m_windowY = -1;
|
||||||
QVariantList m_libraryBooks;
|
QVariantList m_libraryBooks;
|
||||||
QString m_lastPage = QStringLiteral("starter");
|
QString m_lastPage = QStringLiteral("starter");
|
||||||
|
bool m_sidebarOpen = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPSTATE_H
|
#endif // APPSTATE_H
|
||||||
+16
-4
@@ -15,9 +15,11 @@ ApplicationWindow {
|
|||||||
source: "qrc:/Asteria/src/assets/MaterialIconsOutlined-Regular.otf"
|
source: "qrc:/Asteria/src/assets/MaterialIconsOutlined-Regular.otf"
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool sidebarOpen: false
|
property bool sidebarOpen: appState.sidebarOpen
|
||||||
|
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
|
||||||
property string currentPage: "starter"
|
property string currentPage: "starter"
|
||||||
property string pageFlipMode: appState.pageFlipMode
|
property string pageFlipMode: appState.pageFlipMode
|
||||||
|
property bool _restoringState: false
|
||||||
|
|
||||||
onCurrentPageChanged: appState.lastPage = currentPage
|
onCurrentPageChanged: appState.lastPage = currentPage
|
||||||
|
|
||||||
@@ -28,12 +30,15 @@ ApplicationWindow {
|
|||||||
x = appState.windowX
|
x = appState.windowX
|
||||||
y = appState.windowY
|
y = appState.windowY
|
||||||
}
|
}
|
||||||
if (appState.lastFilePath !== "")
|
if (appState.lastFilePath !== "") {
|
||||||
|
window._restoringState = true
|
||||||
bookController.openBook(appState.lastFileUrl())
|
bookController.openBook(appState.lastFileUrl())
|
||||||
|
} else {
|
||||||
var savedPage = appState.lastPage
|
var savedPage = appState.lastPage
|
||||||
if (savedPage === "library" || savedPage === "settings")
|
if (savedPage === "library" || savedPage === "settings")
|
||||||
window.currentPage = savedPage
|
window.currentPage = savedPage
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: geometrySaveTimer
|
id: geometrySaveTimer
|
||||||
@@ -62,14 +67,12 @@ ApplicationWindow {
|
|||||||
onCloseDrawer: window.sidebarOpen = false
|
onCloseDrawer: window.sidebarOpen = false
|
||||||
onNavigateTo: function(page) {
|
onNavigateTo: function(page) {
|
||||||
window.currentPage = page
|
window.currentPage = page
|
||||||
window.sidebarOpen = false
|
|
||||||
}
|
}
|
||||||
onOpenFile: {
|
onOpenFile: {
|
||||||
bookController.browseAndOpen()
|
bookController.browseAndOpen()
|
||||||
}
|
}
|
||||||
onCloseBook: {
|
onCloseBook: {
|
||||||
bookController.closeBook()
|
bookController.closeBook()
|
||||||
window.sidebarOpen = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +131,16 @@ ApplicationWindow {
|
|||||||
Connections {
|
Connections {
|
||||||
target: bookController
|
target: bookController
|
||||||
function onBookReady() {
|
function onBookReady() {
|
||||||
|
if (window._restoringState) {
|
||||||
|
window._restoringState = false
|
||||||
|
var savedPage = appState.lastPage
|
||||||
|
if (savedPage === "library" || savedPage === "settings")
|
||||||
|
window.currentPage = savedPage
|
||||||
|
else
|
||||||
window.currentPage = "reader"
|
window.currentPage = "reader"
|
||||||
|
} else {
|
||||||
|
window.currentPage = "reader"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function onBookChanged() {
|
function onBookChanged() {
|
||||||
if (!bookController.hasBook && window.currentPage === "reader")
|
if (!bookController.hasBook && window.currentPage === "reader")
|
||||||
|
|||||||
@@ -172,8 +172,6 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
readingModel.goToChapter(modelData.chapterIndex)
|
readingModel.goToChapter(modelData.chapterIndex)
|
||||||
sidebar.navigateTo("reader")
|
|
||||||
sidebar.closeDrawer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user