-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to load external books
- Loading branch information
1 parent
95c8f64
commit 33a2319
Showing
21 changed files
with
525 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
#include "external_book_controller.hpp" | ||
#include <QUuid> | ||
#include <memory> | ||
#include "bookmark.hpp" | ||
#include "external_book_getter.hpp" | ||
#include "fz_utils.hpp" | ||
#include "highlight.hpp" | ||
#include "i_book_service.hpp" | ||
#include "search_options.hpp" | ||
|
||
using namespace application::core; | ||
using application::utility::ExternalBookGetter; | ||
using domain::entities::Bookmark; | ||
using domain::entities::Highlight; | ||
|
||
namespace adapters::controllers | ||
{ | ||
|
||
ExternalBookController::ExternalBookController( | ||
application::IBookService* bookService) : | ||
m_externalBookService(bookService) | ||
{ | ||
connect(m_externalBookService, &application::IBookService::goToPosition, | ||
this, &ExternalBookController::goToPosition); | ||
|
||
connect(m_externalBookService, &application::IBookService::highlightText, | ||
this, | ||
[this](int pageNumber, mupdf::FzQuad quad) | ||
{ | ||
auto rect = utils::fzQuadToQRectF(quad); | ||
QPointF left(rect.left(), rect.center().y()); | ||
QPointF right(rect.right(), rect.center().y()); | ||
|
||
emit selectText(pageNumber, left, right); | ||
}); | ||
|
||
connect(m_externalBookService, | ||
&application::IBookService::noSearchHitsFound, this, | ||
&IBookController::noSearchHitsFound); | ||
} | ||
|
||
void ExternalBookController::setUp(QString filePath) | ||
{ | ||
m_externalBookService->setUp( | ||
std::make_unique<ExternalBookGetter>(filePath)); | ||
} | ||
|
||
mupdf::FzDocument* ExternalBookController::getFzDocument() | ||
{ | ||
return m_externalBookService->getFzDocument(); | ||
} | ||
|
||
void ExternalBookController::search(const QString& text) | ||
{ | ||
m_externalBookService->search(text, m_searchOptions); | ||
} | ||
|
||
void ExternalBookController::clearSearch() | ||
{ | ||
m_externalBookService->clearSearch(); | ||
} | ||
|
||
void ExternalBookController::goToNextSearchHit() | ||
{ | ||
m_externalBookService->goToNextSearchHit(); | ||
} | ||
|
||
void ExternalBookController::goToPreviousSearchHit() | ||
{ | ||
m_externalBookService->goToPreviousSearchHit(); | ||
} | ||
|
||
const QList<Highlight>& ExternalBookController::getHighlights() const | ||
{ | ||
} | ||
|
||
void ExternalBookController::addHighlight(const Highlight& highlight) | ||
{ | ||
Q_UNUSED(highlight); | ||
} | ||
|
||
void ExternalBookController::removeHighlight(const QUuid& uuid) | ||
{ | ||
Q_UNUSED(uuid); | ||
} | ||
|
||
void ExternalBookController::changeHighlightColor(const QUuid& uuid, | ||
const QColor& color) | ||
{ | ||
Q_UNUSED(uuid); | ||
Q_UNUSED(color); | ||
} | ||
|
||
const Highlight* ExternalBookController::getHighlightAtPoint( | ||
const QPointF& point, int page) const | ||
{ | ||
Q_UNUSED(point); | ||
Q_UNUSED(page); | ||
|
||
return nullptr; | ||
} | ||
|
||
const QList<Bookmark>& ExternalBookController::getBookmark() const | ||
{ | ||
} | ||
|
||
QString ExternalBookController::addBookmark(const QString& name, int pageNumber, | ||
float yOffset) | ||
{ | ||
Q_UNUSED(name); | ||
Q_UNUSED(pageNumber); | ||
Q_UNUSED(yOffset); | ||
} | ||
|
||
void ExternalBookController::renameBookmark(const QString& uuid, | ||
const QString& newName) | ||
{ | ||
Q_UNUSED(uuid); | ||
Q_UNUSED(newName); | ||
} | ||
|
||
void ExternalBookController::removeBookmark(const QString& uuid) | ||
{ | ||
Q_UNUSED(uuid); | ||
} | ||
|
||
void ExternalBookController::goToBookmark(const QString& uuid) | ||
{ | ||
Q_UNUSED(uuid); | ||
} | ||
|
||
void ExternalBookController::followLink(const char* uri) | ||
{ | ||
return m_externalBookService->followLink(uri); | ||
} | ||
|
||
QString ExternalBookController::getFilePath() const | ||
{ | ||
return m_externalBookService->getFilePath(); | ||
} | ||
|
||
int ExternalBookController::getPageCount() const | ||
{ | ||
return m_externalBookService->getPageCount(); | ||
} | ||
|
||
void ExternalBookController::setCurrentPage(int newCurrentPage) | ||
{ | ||
m_externalBookService->setCurrentPage(newCurrentPage); | ||
m_searchOptions.currentPage = m_externalBookService->getCurrentPage(); | ||
|
||
emit currentPageChanged(newCurrentPage); | ||
} | ||
|
||
int ExternalBookController::getCurrentPage() const | ||
{ | ||
return m_externalBookService->getCurrentPage(); | ||
} | ||
|
||
float ExternalBookController::getZoom() const | ||
{ | ||
return m_externalBookService->getZoom(); | ||
} | ||
|
||
void ExternalBookController::setZoom(float newZoom) | ||
{ | ||
m_externalBookService->setZoom(newZoom); | ||
emit zoomChanged(newZoom); | ||
} | ||
|
||
bool ExternalBookController::getSearchWholeWords() const | ||
{ | ||
return m_searchOptions.wholeWords; | ||
} | ||
|
||
void ExternalBookController::setSearchWholeWords(bool newSearchWholeWords) | ||
{ | ||
m_searchOptions.wholeWords = newSearchWholeWords; | ||
emit searchWholeWordsChanged(); | ||
} | ||
|
||
bool ExternalBookController::getSearchCaseSensitive() const | ||
{ | ||
return m_searchOptions.caseSensitive; | ||
} | ||
|
||
void ExternalBookController::setSearchCaseSensitive(bool newCaseSensitive) | ||
{ | ||
m_searchOptions.caseSensitive = newCaseSensitive; | ||
emit searchCaseSensitiveChanged(); | ||
} | ||
|
||
bool ExternalBookController::getSearchFromStart() const | ||
{ | ||
return m_searchOptions.fromStart; | ||
} | ||
|
||
void ExternalBookController::setSearchFromStart(bool newSearchFromStart) | ||
{ | ||
m_searchOptions.fromStart = newSearchFromStart; | ||
emit searchFromStartChanged(); | ||
} | ||
|
||
QString ExternalBookController::getColorTheme() | ||
{ | ||
return m_externalBookService->getColorTheme(); | ||
} | ||
|
||
void ExternalBookController::setColorTheme(const QString& colorTheme) | ||
{ | ||
m_externalBookService->setColorTheme(colorTheme); | ||
emit colorThemeChanged(colorTheme); | ||
} | ||
|
||
FilteredTOCModel* ExternalBookController::getTableOfContents() | ||
{ | ||
return m_externalBookService->getTableOfContents(); | ||
} | ||
|
||
data_models::BookmarksProxyModel* ExternalBookController::getBookmarksModel() | ||
{ | ||
return nullptr; | ||
} | ||
|
||
} // namespace adapters::controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
#include <QObject> | ||
#include <QRectF> | ||
#include <QString> | ||
#include "adapters_export.hpp" | ||
#include "bookmarks_model.hpp" | ||
#include "i_book_controller.hpp" | ||
#include "i_book_service.hpp" | ||
#include "search_options.hpp" | ||
#include "toc/filtered_toc_model.hpp" | ||
|
||
namespace adapters::controllers | ||
{ | ||
|
||
/*** | ||
* This class implements the IBookController interface to provide access to a | ||
* book that is not managed by the application, a so called 'external book'. | ||
* | ||
* This usecase occurs when e.g. using 'Open with Librum' from a file manager. | ||
*/ | ||
class ADAPTERS_EXPORT ExternalBookController : public IBookController | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
ExternalBookController(application::IBookService* externalBookService); | ||
|
||
void setUp(QString filePath) override; | ||
mupdf::FzDocument* getFzDocument() override; | ||
|
||
void search(const QString& text) override; | ||
void clearSearch() override; | ||
void goToNextSearchHit() override; | ||
void goToPreviousSearchHit() override; | ||
|
||
const QList<domain::entities::Highlight>& getHighlights() const override; | ||
void addHighlight(const domain::entities::Highlight& highlight) override; | ||
void removeHighlight(const QUuid& uuid) override; | ||
void changeHighlightColor(const QUuid& uuid, const QColor& color) override; | ||
const domain::entities::Highlight* getHighlightAtPoint( | ||
const QPointF& point, int page) const override; | ||
|
||
const QList<domain::entities::Bookmark>& getBookmark() const override; | ||
QString addBookmark(const QString& name, int pageNumber, | ||
float yOffset) override; | ||
void renameBookmark(const QString& uuid, const QString& newName) override; | ||
void removeBookmark(const QString& uuid) override; | ||
void goToBookmark(const QString& uuid) override; | ||
|
||
void followLink(const char* uri) override; | ||
|
||
QString getFilePath() const override; | ||
int getPageCount() const override; | ||
|
||
void setCurrentPage(int newCurrentPage) override; | ||
int getCurrentPage() const override; | ||
|
||
float getZoom() const override; | ||
void setZoom(float newZoom) override; | ||
|
||
bool getSearchWholeWords() const override; | ||
void setSearchWholeWords(bool newSearchWholeWords) override; | ||
|
||
bool getSearchCaseSensitive() const override; | ||
void setSearchCaseSensitive(bool newCaseSensitive) override; | ||
|
||
bool getSearchFromStart() const override; | ||
void setSearchFromStart(bool newSearchFromStart) override; | ||
|
||
QString getColorTheme() override; | ||
void setColorTheme(const QString& colorTheme) override; | ||
|
||
application::core::FilteredTOCModel* getTableOfContents() override; | ||
data_models::BookmarksProxyModel* getBookmarksModel() override; | ||
|
||
private: | ||
application::IBookService* m_externalBookService; | ||
application::core::utils::SearchOptions m_searchOptions; | ||
}; | ||
|
||
} // namespace adapters::controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.