diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 28b7747c..80a513c5 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -55,6 +55,68 @@ void MainWindowViewer::afterLaunchTasks() whatsNewController.showWhatsNewIfNeeded(this); } +void MainWindowViewer::applySavedReaderMode() +{ + Configuration &config = Configuration::getConfiguration(); + const bool manga = config.getDoubleMangaPage(); + const bool continuousScroll = config.getContinuousScroll(); + viewer->setMangaWithoutStoringSetting(manga); + viewer->setContinuousScrollWithoutStoringSetting(continuousScroll); + syncModeActions(manga, continuousScroll); +} + +void MainWindowViewer::applyLibraryReaderMode(YACReader::FileType type) +{ + Configuration &config = Configuration::getConfiguration(); + bool manga = false; + bool continuousScroll = config.getContinuousScroll(); + + switch (type) { + case YACReader::FileType::Manga: + manga = true; + break; + case YACReader::FileType::WebComic: + continuousScroll = true; + break; + case YACReader::FileType::Comic: + case YACReader::FileType::WesternManga: + case YACReader::FileType::Yonkoma: + default: + break; + } + + viewer->setMangaWithoutStoringSetting(manga); + viewer->setContinuousScrollWithoutStoringSetting(continuousScroll); + syncModeActions(manga, continuousScroll); +} + +void MainWindowViewer::syncModeActions(bool manga, bool continuousScroll) +{ + doubleMangaPageAction->setChecked(manga); + + if (continuousScroll) { + continuousScrollAction->setChecked(true); + } else { + switch (Configuration::getConfiguration().getFitMode()) { + case YACReader::FitMode::ToWidth: + adjustWidthAction->setChecked(true); + break; + case YACReader::FitMode::ToHeight: + adjustHeightAction->setChecked(true); + break; + case YACReader::FitMode::FullRes: + adjustToFullSizeAction->setChecked(true); + break; + case YACReader::FitMode::FullPage: + default: + fitToPageAction->setChecked(true); + break; + } + } + + doubleMangaPageSwitch(); +} + MainWindowViewer::~MainWindowViewer() { delete settings; @@ -810,12 +872,7 @@ void MainWindowViewer::open(QString path, ComicDB &comic, QList &siblin else setWindowTitle("YACReader - " + fi.fileName()); - auto type = comic.info.type.value(); - // TODO: support comic.info.type by adjusting the scrolling and double page mode behaviour depending on the actual type, for now type is mapped to manga mode - auto isManga = type == YACReader::FileType::Manga; - - viewer->setMangaWithoutStoringSetting(isManga); - doubleMangaPageAction->setChecked(isManga); + applyLibraryReaderMode(comic.info.type.value()); viewer->open(path, comic); enableActions(); @@ -855,7 +912,6 @@ void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId, YACR void MainWindowViewer::openComicFromPath(QString pathFile) { - doubleMangaPageAction->setChecked(Configuration::getConfiguration().getDoubleMangaPage()); openComic(pathFile); isClient = false; // this method is used for direct openings updatePrevNextActions(!previousComicPath.isEmpty(), !nextComicPath.isEmpty()); @@ -876,6 +932,7 @@ void MainWindowViewer::openComic(QString pathFile) setWindowTitle("YACReader - " + fi.fileName()); enableActions(); + applySavedReaderMode(); viewer->open(pathFile); Configuration::getConfiguration().updateOpenRecentList(fi.absoluteFilePath()); @@ -901,6 +958,7 @@ void MainWindowViewer::openFolderFromPath(QString pathDir) setWindowTitle("YACReader - " + fi.fileName()); enableActions(); + applySavedReaderMode(); viewer->open(pathDir); Configuration::getConfiguration().updateOpenRecentList(fi.absoluteFilePath()); @@ -916,6 +974,7 @@ void MainWindowViewer::openFolderFromPath(QString pathDir, QString atFileName) setWindowTitle("YACReader - " + fi.fileName()); enableActions(); + applySavedReaderMode(); QDir d(pathDir); d.setFilter(QDir::Files | QDir::NoDotAndDotDot); diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 24b6a4f7..b1c1b5d0 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -174,6 +174,9 @@ private: void setActionsEnabled(bool enabled); void setMglassActionsEnabled(bool enabled); void setLoadedComicActionsEnabled(bool enabled); + void syncModeActions(bool manga, bool continuousScroll); + void applySavedReaderMode(); + void applyLibraryReaderMode(YACReader::FileType type); //! Manejadores de evento: // void resizeEvent(QResizeEvent * event); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 5a0334cf..c2b310cf 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -111,10 +111,10 @@ Viewer::Viewer(QWidget *parent) doublePageSwitch(); if (Configuration::getConfiguration().getDoubleMangaPage()) - doubleMangaPageSwitch(); + setMangaModeImpl(true, false); if (Configuration::getConfiguration().getContinuousScroll()) - setContinuousScroll(true); + setContinuousScrollImpl(true, false); createConnections(); @@ -1188,41 +1188,49 @@ void Viewer::doublePageSwitch() Configuration::getConfiguration().setDoublePage(doublePage); } -void Viewer::setContinuousScroll(bool enabled) +void Viewer::setContinuousScrollImpl(bool enabled, bool persistSettings) { if (continuousScroll == enabled) { return; } + continuousScroll = enabled; - Configuration::getConfiguration().setContinuousScroll(continuousScroll); + if (persistSettings) { + Configuration::getConfiguration().setContinuousScroll(continuousScroll); + } if (continuousScroll) { continuousViewModel->setZoomFactor(zoom); if (render->hasLoadedComic()) { continuousViewModel->setViewportSize(viewport()->width(), viewport()->height()); continuousViewModel->setNumPages(render->numPages()); - // set the current page as model state before any layout/scroll happens lastCenterPage = render->getIndex(); continuousViewModel->setAnchorPage(lastCenterPage); - // pick up sizes of pages already in the buffer probeContinuousBufferedPages(); - // trigger a render cycle so new pages arrive via pageRendered signal render->update(); setActiveWidget(continuousWidget); scrollToCurrentContinuousPage(); continuousWidget->update(); viewport()->update(); } - // if no comic is loaded, messageLabel stays as the active widget } else { lastCenterPage = -1; if (render->hasLoadedComic()) { updatePage(); } - // if no comic is loaded, messageLabel stays as the active widget } } +void Viewer::setContinuousScrollWithoutStoringSetting(bool enabled) +{ + setContinuousScrollImpl(enabled, false); +} + +void Viewer::setContinuousScroll(bool enabled) +{ + setContinuousScrollImpl(enabled, true); +} + void Viewer::onContinuousScroll(int value) { if (!continuousScroll || !render->hasLoadedComic() || applyingContinuousModelState) { @@ -1345,21 +1353,32 @@ void Viewer::onRenderPageChanged(int page) scrollToCurrentContinuousPage(); } -void Viewer::setMangaWithoutStoringSetting(bool manga) +void Viewer::setMangaModeImpl(bool manga, bool persistSettings) { + if (doubleMangaPage == manga) { + return; + } + doubleMangaPage = manga; + + if (persistSettings) { + Configuration &config = Configuration::getConfiguration(); + config.setDoubleMangaPage(doubleMangaPage); + goToFlow->updateConfig(config.getSettings()); + } + render->setManga(manga); goToFlow->setFlowRightToLeft(doubleMangaPage); } +void Viewer::setMangaWithoutStoringSetting(bool manga) +{ + setMangaModeImpl(manga, false); +} + void Viewer::doubleMangaPageSwitch() { - doubleMangaPage = !doubleMangaPage; - render->doubleMangaPageSwitch(); - Configuration &config = Configuration::getConfiguration(); - config.setDoubleMangaPage(doubleMangaPage); - goToFlow->setFlowRightToLeft(doubleMangaPage); - goToFlow->updateConfig(config.getSettings()); + setMangaModeImpl(!doubleMangaPage, true); } void Viewer::resetContent() diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 62071d11..5936ea0b 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -86,6 +86,7 @@ public slots: void save(); void doublePageSwitch(); void setMangaWithoutStoringSetting(bool manga); + void setContinuousScrollWithoutStoringSetting(bool enabled); void doubleMangaPageSwitch(); void resetContent(); void setLoadingMessage(); @@ -202,6 +203,8 @@ private: void onNumPagesReady(unsigned int numPages); void onRenderPageChanged(int page); void setActiveWidget(QWidget *w); + void setContinuousScrollImpl(bool enabled, bool persistSettings); + void setMangaModeImpl(bool manga, bool persistSettings); //! Mouse handler std::unique_ptr mouseHandler;