Merge branch 'close_book_navigation'
This commit is contained in:
12 files changed
+300
-46
No files matched your search
@@ -27,7 +27,8 @@ AppCoordinator::AppCoordinator(Book &book,
|
||||
, m_appState(appState)
|
||||
, m_settings(settings)
|
||||
{
|
||||
connect(&m_book, &Book::willOpenNewBook, this, &AppCoordinator::onWillOpenNewBook);
|
||||
connect(&m_book, &Book::willOpenNewBook, this, &AppCoordinator::snapshotOutgoingBook);
|
||||
connect(&m_book, &Book::willCloseBook, this, &AppCoordinator::snapshotOutgoingBook);
|
||||
connect(&m_readingModel, &ReadingModel::positionSaved, this, &AppCoordinator::onPositionSaved);
|
||||
connect(&m_book, &Book::bookChanged, this, &AppCoordinator::onBookChanged);
|
||||
|
||||
@@ -35,8 +36,8 @@ AppCoordinator::AppCoordinator(Book &book,
|
||||
this, &AppCoordinator::onAboutToQuit);
|
||||
}
|
||||
|
||||
// Before a new book open: snapshot the outgoing book's progress into the library.
|
||||
void AppCoordinator::onWillOpenNewBook()
|
||||
// Before closing or opening a new book: snapshot the outgoing book's progress into the library.
|
||||
void AppCoordinator::snapshotOutgoingBook()
|
||||
{
|
||||
if (m_book.hasBook())
|
||||
m_historyModel.addOrUpdateBook(m_book.filePath(), m_readingModel.progress());
|
||||
@@ -54,6 +55,7 @@ void AppCoordinator::onBookChanged()
|
||||
{
|
||||
if (!m_book.hasBook()) {
|
||||
m_readingModel.setReader(nullptr);
|
||||
m_uiState.setLastFilePath(QString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void onBookChanged();
|
||||
void onWillOpenNewBook();
|
||||
void snapshotOutgoingBook();
|
||||
void onPositionSaved();
|
||||
void onAboutToQuit();
|
||||
|
||||
|
||||
@@ -66,16 +66,23 @@ void Book::openImpl(const QString &filePath)
|
||||
if (m_reader)
|
||||
emit willOpenNewBook();
|
||||
|
||||
close();
|
||||
|
||||
m_loading = true;
|
||||
emit loadingChanged();
|
||||
|
||||
m_errorMessage.clear();
|
||||
emit errorMessageChanged();
|
||||
|
||||
const int generation = ++m_openGeneration;
|
||||
|
||||
if (!m_loading) {
|
||||
m_loading = true;
|
||||
emit loadingChanged();
|
||||
}
|
||||
|
||||
if (!m_errorMessage.isEmpty()) {
|
||||
m_errorMessage.clear();
|
||||
emit errorMessageChanged();
|
||||
}
|
||||
|
||||
if (m_reader) {
|
||||
m_reader.reset();
|
||||
emit bookChanged();
|
||||
}
|
||||
|
||||
m_openFuture = QtConcurrent::run([this, effectivePath, generation]() {
|
||||
const auto reportError = [this, generation, effectivePath](const QString &err) {
|
||||
QMetaObject::invokeMethod(this, [this, generation, effectivePath, err]() {
|
||||
@@ -115,7 +122,15 @@ void Book::openImpl(const QString &filePath)
|
||||
|
||||
void Book::close()
|
||||
{
|
||||
++m_openGeneration;
|
||||
|
||||
if (m_loading) {
|
||||
m_loading = false;
|
||||
emit loadingChanged();
|
||||
}
|
||||
|
||||
if (!m_reader) return;
|
||||
emit willCloseBook();
|
||||
m_reader.reset();
|
||||
emit bookChanged();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
signals:
|
||||
// Emitted just before replacing the current reader with a new one.
|
||||
void willOpenNewBook();
|
||||
// Emitted just before closing the current reader.
|
||||
void willCloseBook();
|
||||
|
||||
void bookChanged();
|
||||
void loadingChanged();
|
||||
|
||||
+13
-15
@@ -57,17 +57,22 @@ ApplicationWindow {
|
||||
Connections {
|
||||
target: Book
|
||||
function onLoadingChanged() {
|
||||
if (Book.loading) root._bookInitializing = true
|
||||
if (Book.loading)
|
||||
root._bookInitializing = true
|
||||
else if (!Book.hasBook)
|
||||
root._bookInitializing = false
|
||||
}
|
||||
function onErrorMessageChanged() {
|
||||
if (Book.errorMessage !== "") {
|
||||
root._bookInitializing = false
|
||||
root._startupRestore = false
|
||||
UiState.barsVisible = true
|
||||
if (!Book.hasBook && root.currentPage === "reader")
|
||||
root.currentPage = "history"
|
||||
}
|
||||
}
|
||||
function onBookChanged() {
|
||||
if (!Book.hasBook) {
|
||||
if (!Book.hasBook && !Book.loading) {
|
||||
UiState.barsVisible = true
|
||||
if (root.currentPage === "reader")
|
||||
root.currentPage = "history"
|
||||
@@ -106,15 +111,16 @@ ApplicationWindow {
|
||||
root.settingsOpen = true
|
||||
} else {
|
||||
root.settingsOpen = false
|
||||
if (root.currentPage === "reader" && ReadingModel.isTextMode && readerPage.scrollView)
|
||||
readerPage.scrollView.syncScrollPosition()
|
||||
if (Book.hasBook || Book.loading)
|
||||
Book.close()
|
||||
root.currentPage = page
|
||||
}
|
||||
}
|
||||
onOpenFile: {
|
||||
Book.browseAndOpen()
|
||||
}
|
||||
onCloseBook: {
|
||||
Book.close()
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
@@ -201,16 +207,8 @@ ApplicationWindow {
|
||||
function onRestoreReady(chunkIndex) {
|
||||
if (!Book.hasBook) return
|
||||
root._bookInitializing = false
|
||||
if (root._startupRestore) {
|
||||
root._startupRestore = false
|
||||
const savedPage = UiState.lastPage
|
||||
if (savedPage === "history")
|
||||
root.currentPage = savedPage
|
||||
else
|
||||
root.currentPage = "reader"
|
||||
} else {
|
||||
root.currentPage = "reader"
|
||||
}
|
||||
root._startupRestore = false
|
||||
root.currentPage = "reader"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,10 +213,20 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
function resetViewState() {
|
||||
clickDebounce.stop()
|
||||
root.contentReady = false
|
||||
pageArea.pair = []
|
||||
root.currentPair = 0
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Book
|
||||
function onLoadingChanged() {
|
||||
if (Book.loading) root.contentReady = false
|
||||
if (Book.loading) root.resetViewState()
|
||||
}
|
||||
function onBookChanged() {
|
||||
if (!Book.hasBook) root.resetViewState()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,12 +241,23 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
function resetViewState() {
|
||||
restoreTimer.stop();
|
||||
scrollAnimation.stop();
|
||||
root.contentReady = false;
|
||||
root.restoreReady = false;
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Book
|
||||
function onLoadingChanged() {
|
||||
if (Book.loading) {
|
||||
root.contentReady = false;
|
||||
root.restoreReady = false;
|
||||
root.resetViewState();
|
||||
}
|
||||
}
|
||||
function onBookChanged() {
|
||||
if (!Book.hasBook) {
|
||||
root.resetViewState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ Rectangle {
|
||||
signal closeDrawer()
|
||||
signal navigateTo(string page)
|
||||
signal openFile()
|
||||
signal closeBook()
|
||||
|
||||
width: root.sidebarOpen ? ThemeManager.sidebarWidth : 0
|
||||
clip: true
|
||||
@@ -53,13 +52,6 @@ Rectangle {
|
||||
y: ThemeManager.headerHeight
|
||||
width: ThemeManager.sidebarWidth
|
||||
|
||||
SideBarButton {
|
||||
visible: Book.hasBook
|
||||
iconText: "\ue86d"
|
||||
title: "Book"
|
||||
onClicked: root.navigateTo("reader")
|
||||
}
|
||||
|
||||
SideBarButton {
|
||||
iconText: "\ue02f"
|
||||
title: "History"
|
||||
@@ -72,13 +64,6 @@ Rectangle {
|
||||
onClicked: root.openFile()
|
||||
}
|
||||
|
||||
SideBarButton {
|
||||
visible: Book.hasBook
|
||||
iconText: "\ue5cd"
|
||||
title: "Close Book"
|
||||
onClicked: root.closeBook()
|
||||
}
|
||||
|
||||
// Divider
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
|
||||
Reference in new issue
Block a user