From d30e46eacbcb671d09adb990cf81c8d79a5531ca Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov Date: Fri, 5 Jan 2024 16:24:12 +0900 Subject: [PATCH 1/5] Added Zoom and Y Offset to books metadata --- src/domain/entities/book.cpp | 20 ++++++++++++++++++++ src/domain/entities/book.hpp | 6 ++++++ src/domain/value_objects/book_meta_data.hpp | 5 ++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/domain/entities/book.cpp b/src/domain/entities/book.cpp index 8954fa2bf..c29442d5b 100644 --- a/src/domain/entities/book.cpp +++ b/src/domain/entities/book.cpp @@ -364,6 +364,26 @@ void Book::setColorTheme(const QString& newColorTheme) m_metaData.colorTheme = newColorTheme; } +int Book::getZoom() const +{ + return m_metaData.zoom; +} + +void Book::setZoom(int newZoom) +{ + m_metaData.zoom = newZoom; +} + +float Book::getYOffset() const +{ + return m_metaData.yOffset; +} + +void Book::setYOffset(float newYOffset) +{ + m_metaData.yOffset = newYOffset; +} + QString Book::getFileHash() const { return m_metaData.fileHash; diff --git a/src/domain/entities/book.hpp b/src/domain/entities/book.hpp index adb31d57a..f8c98893b 100644 --- a/src/domain/entities/book.hpp +++ b/src/domain/entities/book.hpp @@ -83,6 +83,12 @@ class DOMAIN_EXPORT Book QString getColorTheme() const; void setColorTheme(const QString& newColorTheme); + int getZoom() const; + void setZoom(int newZoom); + + float getYOffset() const; + void setYOffset(float newYOffset); + QString getFileHash() const; void setFileHash(const QString& newFileHash); diff --git a/src/domain/value_objects/book_meta_data.hpp b/src/domain/value_objects/book_meta_data.hpp index 9e4e10d17..769f72389 100644 --- a/src/domain/value_objects/book_meta_data.hpp +++ b/src/domain/value_objects/book_meta_data.hpp @@ -27,6 +27,8 @@ struct DOMAIN_EXPORT BookMetaData QString coverPath; QString colorTheme; QString fileHash; + int zoom; + float yOffset; bool operator==(const BookMetaData& rhs) const { @@ -48,7 +50,8 @@ struct DOMAIN_EXPORT BookMetaData coverLastModified.toSecsSinceEpoch() == rhs.coverLastModified.toSecsSinceEpoch() && hasCover == rhs.hasCover && coverPath == coverPath && - colorTheme == rhs.colorTheme && fileHash == rhs.fileHash; + colorTheme == rhs.colorTheme && fileHash == rhs.fileHash && + zoom == rhs.zoom && yOffset == rhs.yOffset; } }; From 84a6200bc40ddb0f8f5d4b9ad39f363b141d7da8 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov Date: Sat, 6 Jan 2024 12:33:31 +0900 Subject: [PATCH 2/5] Changed Zoom field's type to float --- src/domain/entities/book.cpp | 2 +- src/domain/entities/book.hpp | 2 +- src/domain/value_objects/book_meta_data.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/domain/entities/book.cpp b/src/domain/entities/book.cpp index c29442d5b..dec1a54db 100644 --- a/src/domain/entities/book.cpp +++ b/src/domain/entities/book.cpp @@ -369,7 +369,7 @@ int Book::getZoom() const return m_metaData.zoom; } -void Book::setZoom(int newZoom) +void Book::setZoom(float newZoom) { m_metaData.zoom = newZoom; } diff --git a/src/domain/entities/book.hpp b/src/domain/entities/book.hpp index f8c98893b..b094e2eb4 100644 --- a/src/domain/entities/book.hpp +++ b/src/domain/entities/book.hpp @@ -84,7 +84,7 @@ class DOMAIN_EXPORT Book void setColorTheme(const QString& newColorTheme); int getZoom() const; - void setZoom(int newZoom); + void setZoom(float newZoom); float getYOffset() const; void setYOffset(float newYOffset); diff --git a/src/domain/value_objects/book_meta_data.hpp b/src/domain/value_objects/book_meta_data.hpp index 769f72389..dbe863c3e 100644 --- a/src/domain/value_objects/book_meta_data.hpp +++ b/src/domain/value_objects/book_meta_data.hpp @@ -27,7 +27,7 @@ struct DOMAIN_EXPORT BookMetaData QString coverPath; QString colorTheme; QString fileHash; - int zoom; + float zoom; float yOffset; bool operator==(const BookMetaData& rhs) const From 4f58a8faa52b3efd99d440a94658a86b3c141a1c Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov Date: Mon, 8 Jan 2024 18:57:21 +0900 Subject: [PATCH 3/5] Made Zoom and Y Offset of books save locally --- src/adapters/controllers/library_controller.cpp | 6 ++++++ .../interfaces/controllers/i_library_controller.hpp | 2 ++ src/domain/entities/book.cpp | 10 +++++++++- src/domain/entities/book.hpp | 2 +- src/domain/value_objects/book_meta_data.hpp | 4 ++-- src/presentation/readingPage/MReadingPage.qml | 8 +++++--- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/adapters/controllers/library_controller.cpp b/src/adapters/controllers/library_controller.cpp index b6b7baaaf..950e53e43 100644 --- a/src/adapters/controllers/library_controller.cpp +++ b/src/adapters/controllers/library_controller.cpp @@ -206,6 +206,12 @@ int LibraryController::updateBook(const QString& uuid, case MetaProperty::LastModified: updatedBook.setLastOpened(QDateTime::fromString(value.toString())); break; + case MetaProperty::Zoom: + updatedBook.setZoom(static_cast(value.toDouble())); + break; + case MetaProperty::YOffset: + updatedBook.setYOffset(static_cast(value.toDouble())); + break; case MetaProperty::Invalid: return static_cast(BookOperationStatus::PropertyDoesNotExist); break; diff --git a/src/adapters/interfaces/controllers/i_library_controller.hpp b/src/adapters/interfaces/controllers/i_library_controller.hpp index b07f4203e..b0a38a88f 100644 --- a/src/adapters/interfaces/controllers/i_library_controller.hpp +++ b/src/adapters/interfaces/controllers/i_library_controller.hpp @@ -46,6 +46,8 @@ class ADAPTERS_EXPORT ILibraryController : public QObject CurrentPage, AddedToLibrary, LastModified, + Zoom, + YOffset, Invalid }; Q_ENUM(MetaProperty); diff --git a/src/domain/entities/book.cpp b/src/domain/entities/book.cpp index dec1a54db..17eb51e77 100644 --- a/src/domain/entities/book.cpp +++ b/src/domain/entities/book.cpp @@ -364,7 +364,7 @@ void Book::setColorTheme(const QString& newColorTheme) m_metaData.colorTheme = newColorTheme; } -int Book::getZoom() const +float Book::getZoom() const { return m_metaData.zoom; } @@ -541,6 +541,10 @@ void Book::update(const Book& other) m_metaData.colorTheme = other.getColorTheme(); if(m_metaData.fileHash != other.getFileHash()) m_metaData.fileHash = other.getFileHash(); + if(m_metaData.zoom != other.getZoom()) + m_metaData.zoom = other.getZoom(); + if(m_metaData.yOffset != other.getYOffset()) + m_metaData.yOffset = other.getYOffset(); if(!tagsAreTheSame(other.getTags())) m_tags = other.getTags(); @@ -653,6 +657,8 @@ QByteArray Book::toJson() const { "coverPath", getCoverPath() }, { "colorTheme", getColorTheme() }, { "fileHash", getFileHash() }, + { "zoom", getZoom() }, + { "yOffset", getYOffset() }, { "existsOnlyOnClient", existsOnlyOnClient() }, { "tags", serializeTags() }, { "highlights", serializeHighlights() }, @@ -749,6 +755,8 @@ BookMetaData Book::getBookMetaDataFromJson(const QJsonObject& jsonBook) .coverPath = jsonBook["coverPath"].toString(), .colorTheme = jsonBook["colorTheme"].toString(), .fileHash = jsonBook["fileHash"].toString(), + .zoom = static_cast(jsonBook["zoom"].toDouble()), + .yOffset = static_cast(jsonBook["yOffset"].toDouble()), }; // Specify that the dates are UTC, else Qt thinks its local time diff --git a/src/domain/entities/book.hpp b/src/domain/entities/book.hpp index b094e2eb4..7e090071c 100644 --- a/src/domain/entities/book.hpp +++ b/src/domain/entities/book.hpp @@ -83,7 +83,7 @@ class DOMAIN_EXPORT Book QString getColorTheme() const; void setColorTheme(const QString& newColorTheme); - int getZoom() const; + float getZoom() const; void setZoom(float newZoom); float getYOffset() const; diff --git a/src/domain/value_objects/book_meta_data.hpp b/src/domain/value_objects/book_meta_data.hpp index dbe863c3e..679c8e1f8 100644 --- a/src/domain/value_objects/book_meta_data.hpp +++ b/src/domain/value_objects/book_meta_data.hpp @@ -27,8 +27,8 @@ struct DOMAIN_EXPORT BookMetaData QString coverPath; QString colorTheme; QString fileHash; - float zoom; - float yOffset; + float zoom = 1.0; + float yOffset = 0.0; bool operator==(const BookMetaData& rhs) const { diff --git a/src/presentation/readingPage/MReadingPage.qml b/src/presentation/readingPage/MReadingPage.qml index f59526aa8..88a163973 100644 --- a/src/presentation/readingPage/MReadingPage.qml +++ b/src/presentation/readingPage/MReadingPage.qml @@ -18,7 +18,7 @@ Page { } Component.onCompleted: root.forceActiveFocus() - Component.onDestruction: internal.saveCurrentPage() + Component.onDestruction: internal.saveCurrentBookState() // Save the current page every 5s automatically Timer { @@ -27,7 +27,7 @@ Page { repeat: true running: true - onTriggered: internal.saveCurrentPage() + onTriggered: internal.saveCurrentBookState() } Shortcut { @@ -363,13 +363,15 @@ Page { documentView.setPage(BookController.pageCount - 1) } - function saveCurrentPage() { + function saveCurrentBookState() { let currentPage = BookController.currentPage if (currentPage === internal.prevCurrentPage) return var operationsMap = {} operationsMap[LibraryController.MetaProperty.CurrentPage] = currentPage + operationsMap[LibraryController.MetaProperty.Zoom] = BookController.zoom + operationsMap[LibraryController.MetaProperty.YOffset] = documentView.getYOffset() LibraryController.updateBook(Globals.selectedBook.uuid, operationsMap) internal.prevCurrentPage = currentPage From b2c1c6b023f65b2530d9583c58657d0e9ef796c5 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov Date: Sat, 13 Jan 2024 18:16:03 +0900 Subject: [PATCH 4/5] Made zoom saved and loaded locally --- src/adapters/DTOs/book_dto.hpp | 4 ++++ src/adapters/controllers/library_controller.cpp | 2 ++ src/application/services/book_service.cpp | 6 ++++-- src/application/services/book_service.hpp | 1 - src/presentation/readingPage/MDocumentView.qml | 9 ++++----- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/adapters/DTOs/book_dto.hpp b/src/adapters/DTOs/book_dto.hpp index efbe80029..aa4af48b0 100644 --- a/src/adapters/DTOs/book_dto.hpp +++ b/src/adapters/DTOs/book_dto.hpp @@ -33,6 +33,8 @@ struct ADAPTERS_EXPORT BookDto Q_PROPERTY(QString lastOpened MEMBER lastOpened) Q_PROPERTY(QString coverPath MEMBER coverPath) Q_PROPERTY(bool downloaded MEMBER downloaded) + Q_PROPERTY(float zoom MEMBER zoom) + Q_PROPERTY(float yOffset MEMBER yOffset) public: QString uuid; @@ -53,6 +55,8 @@ struct ADAPTERS_EXPORT BookDto QString lastOpened; QString coverPath; bool downloaded; + float zoom; + float yOffset; QList tags; }; diff --git a/src/adapters/controllers/library_controller.cpp b/src/adapters/controllers/library_controller.cpp index 950e53e43..66f2af316 100644 --- a/src/adapters/controllers/library_controller.cpp +++ b/src/adapters/controllers/library_controller.cpp @@ -364,6 +364,8 @@ void LibraryController::addBookMetaDataToDto(const Book& book, BookDto& bookDto) bookDto.bookReadingProgress = book.getBookReadingProgress(); bookDto.coverPath = pathWithScheme; bookDto.downloaded = book.isDownloaded(); + bookDto.zoom = book.getZoom(); + bookDto.yOffset = book.getYOffset(); bookDto.addedToLibrary = book.getAddedToLibrary().toLocalTime().toString( Book::dateTimeStringFormat); diff --git a/src/application/services/book_service.cpp b/src/application/services/book_service.cpp index 8a79091fa..e8ee42a42 100644 --- a/src/application/services/book_service.cpp +++ b/src/application/services/book_service.cpp @@ -215,12 +215,14 @@ void BookService::setCurrentPage(int newCurrentPage) float BookService::getZoom() const { - return m_zoom; + auto book = getBook(); + return book->getZoom(); } void BookService::setZoom(float newZoom) { - m_zoom = newZoom; + auto book = getBook(); + book->setZoom(newZoom); } QString BookService::getColorTheme() diff --git a/src/application/services/book_service.hpp b/src/application/services/book_service.hpp index 5bce65411..f2245c1ca 100644 --- a/src/application/services/book_service.hpp +++ b/src/application/services/book_service.hpp @@ -61,7 +61,6 @@ class BookService : public IBookService ILibraryService* m_libraryService; std::unique_ptr m_fzDocument = nullptr; std::unique_ptr m_bookSearcher = nullptr; - float m_zoom = 1; QUuid m_uuid; std::unique_ptr m_TOCModel; diff --git a/src/presentation/readingPage/MDocumentView.qml b/src/presentation/readingPage/MDocumentView.qml index 7e2816e0a..cb87cc8ec 100644 --- a/src/presentation/readingPage/MDocumentView.qml +++ b/src/presentation/readingPage/MDocumentView.qml @@ -27,11 +27,10 @@ Pane { } Component.onCompleted: { - BookController.zoom = SettingsController.appearanceSettings.DefaultZoom / 100 - } - - Component.onDestruction: { - BookController.zoom = 1 + if (BookController.zoom === 0) { + BookController.zoom = SettingsController.appearanceSettings.DefaultZoom / 100 + } + zoom(BookController.zoom) } Connections { From f72bbc31984bb6323d42a44bbb77f2e80c878666 Mon Sep 17 00:00:00 2001 From: Dmitry Fedorov Date: Fri, 19 Jan 2024 21:00:13 +0900 Subject: [PATCH 5/5] Changed condition by which zoom is set when opening books --- src/presentation/readingPage/MDocumentView.qml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/presentation/readingPage/MDocumentView.qml b/src/presentation/readingPage/MDocumentView.qml index cb87cc8ec..452efa33f 100644 --- a/src/presentation/readingPage/MDocumentView.qml +++ b/src/presentation/readingPage/MDocumentView.qml @@ -28,9 +28,10 @@ Pane { Component.onCompleted: { if (BookController.zoom === 0) { - BookController.zoom = SettingsController.appearanceSettings.DefaultZoom / 100 + zoom(SettingsController.appearanceSettings.DefaultZoom / 100) + } else { + zoom(BookController.zoom) } - zoom(BookController.zoom) } Connections {