diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/archive.cpp | 10 | ||||
-rw-r--r-- | src/getsuyomi.cpp | 83 | ||||
-rw-r--r-- | src/getsuyomi.hpp | 1 | ||||
-rw-r--r-- | src/main_window.cpp | 59 | ||||
-rw-r--r-- | src/main_window.hpp | 9 |
5 files changed, 125 insertions, 37 deletions
diff --git a/src/archive.cpp b/src/archive.cpp index 1ce79b4..468efed 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -81,7 +81,6 @@ fud::FudStatus ZipArchive::populate() return FudStatus::Failure; } size_t numEntries = static_cast<size_t>(numEntriesResult); - qDebug("%zu pages", numEntries); struct NameIndex { std::string name; @@ -103,7 +102,7 @@ fud::FudStatus ZipArchive::populate() static_assert(ZIP_STAT_NAME != 0); static_assert(ZIP_STAT_SIZE != 0); static_assert(ZIP_STAT_INDEX != 0); - // auto* nameCString = zip_get_name(m_archive, idx, ZIP_FL_ENC_RAW); + auto* nameCString = stats.name; if (nameCString == nullptr) { zip_error_t* error = zip_get_error(m_archive); @@ -112,7 +111,6 @@ fud::FudStatus ZipArchive::populate() } std::string name{nameCString}; if (name.empty() || name.back() == '/') { - qDebug("Directory %s", name.empty() ? "N/A" : nameCString); continue; } @@ -120,7 +118,6 @@ fud::FudStatus ZipArchive::populate() m_pages.emplace_back(std::nullopt); } - if (m_pages.empty()) { return FudStatus::Empty; } @@ -144,13 +141,11 @@ fud::FudStatus ZipArchive::populate() ArchiveResult ZipArchive::getPage(size_t page) { - qDebug("Getting page %zu", page); if (page > m_sortedIndices.size()) { return ArchiveResult::error(ArchiveError::BadIndex); } if (m_pages[page] != std::nullopt) { - qDebug("Page found %zu", page); return ArchiveResult::okay(std::cref(*m_pages[page])); } @@ -163,9 +158,7 @@ ArchiveResult ZipArchive::getPage(size_t page) QByteArray data; data.resize(static_cast<qsizetype>(m_fileSizes[page])); - // auto index = m_sortedIndices[page]; - qDebug("Reading in page data"); auto bytesRead = zip_fread(file, data.data(), static_cast<size_t>(data.size())); zip_fclose(file); file = nullptr; @@ -175,7 +168,6 @@ ArchiveResult ZipArchive::getPage(size_t page) } m_pages[page] = QImage(); - qDebug("Loading QImage from page data"); auto loaded = m_pages[page]->loadFromData(data); if (!loaded) { qWarning("Failed to load QImage"); diff --git a/src/getsuyomi.cpp b/src/getsuyomi.cpp index 4e1e91e..0472496 100644 --- a/src/getsuyomi.cpp +++ b/src/getsuyomi.cpp @@ -1,10 +1,16 @@ #include "getsuyomi.hpp" + #include "main_window.hpp" +#include <algorithm> + namespace getsuyomi { Getsuyomi::Getsuyomi() { + // m_pageLeft.setContentsMargins(0, 1, 0, 1); + // m_pageRight.setContentsMargins(0, 1, 0, 1); + m_layout = new QHBoxLayout(); m_layout->addStretch(); @@ -14,47 +20,51 @@ Getsuyomi::Getsuyomi() m_layout->addStretch(); + // m_layout->setContentsMargins(0, 1, 0, 1); + setLayout(m_layout); } -Getsuyomi::~Getsuyomi() { +Getsuyomi::~Getsuyomi() +{ if (m_archive != nullptr) { delete m_archive; } } -void Getsuyomi::setArchive(Archive* archive) { +void Getsuyomi::setArchive(Archive* archive) +{ if (archive == m_archive) { return; } - delete(m_archive); + delete (m_archive); m_archive = archive; m_pageNumber = 0; setPages(); } -void Getsuyomi::next() { +void Getsuyomi::next() +{ auto numPages = m_archive->numPages(); size_t increment = 1; if (m_pageLayout != PageLayout::Single) { increment = 2; } - if ((m_pageNumber + increment) >= numPages) - { + if ((m_pageNumber + increment) >= numPages) { return; } m_pageNumber += increment; setPages(); } -void Getsuyomi::back() { +void Getsuyomi::back() +{ // auto numPages = m_archive->numPages(); size_t decrement = 1; if (m_pageLayout != PageLayout::Single) { decrement = 2; } - if (m_pageNumber < decrement) - { + if (m_pageNumber < decrement) { m_pageNumber = 0; decrement = 0; } @@ -62,12 +72,22 @@ void Getsuyomi::back() { setPages(); } -void Getsuyomi::setPages() { +void Getsuyomi::setPageLayout(PageLayout newPageLayout) +{ + m_pageLayout = newPageLayout; + setPages(); +} + +void Getsuyomi::setPages() +{ m_pageLeft.setPixmap(QPixmap()); m_pageRight.setPixmap(QPixmap()); - switch (m_pageLayout) - { + if (m_archive == nullptr) { + return; + } + + switch (m_pageLayout) { case PageLayout::Dual: return setPagesDual(); case PageLayout::Manga: @@ -78,38 +98,57 @@ void Getsuyomi::setPages() { } } -void Getsuyomi::setPagesNormal() { +void Getsuyomi::setPagesNormal() +{ auto page1 = m_archive->getPage(m_pageNumber); auto& label1 = m_pageLeft; if (page1.isOkay()) { label1.setPixmap(QPixmap::fromImage(page1.getOkay())); + label1.resize(label1.pixmap().size()); } } -void Getsuyomi::setPagesDual() { +void Getsuyomi::setPagesDual() +{ auto& label1 = m_pageLeft; auto& label2 = m_pageRight; setPages(label1, label2); } -void Getsuyomi::setPagesManga() { +void Getsuyomi::setPagesManga() +{ auto& label1 = m_pageRight; auto& label2 = m_pageLeft; setPages(label1, label2); } -void Getsuyomi::setPages(QLabel& label1, QLabel& label2) { +void Getsuyomi::setPages(QLabel& label1, QLabel& label2) +{ auto page1 = m_archive->getPage(m_pageNumber); auto page2 = m_archive->getPage(m_pageNumber + 1); - if (page1.isOkay()) { - label1.setPixmap(QPixmap::fromImage(page1.getOkay())); - } + const bool okay1 = page1.isOkay(); + const bool okay2 = page2.isOkay(); - - if (page2.isOkay()) { - label2.setPixmap(QPixmap::fromImage(page1.getOkay())); + if (okay1 && okay2) { + label1.setPixmap(QPixmap::fromImage(page1.getOkay())); + label2.setPixmap(QPixmap::fromImage(page2.getOkay())); + auto label1Size = label1.pixmap().size(); + auto label2Size = label2.pixmap().size(); + if (label1Size.height() <= label2Size.height()) { + label1.resize(label1Size); + label1.resize(label1Size); + } else { + label1.resize(label2Size); + label1.resize(label2Size); + } + } else if (okay1) { + label1.setPixmap(QPixmap::fromImage(page1.getOkay())); + label1.resize(label1.pixmap().size()); + } else if (okay2) { + label2.setPixmap(QPixmap::fromImage(page2.getOkay())); + label2.resize(label2.pixmap().size()); } } diff --git a/src/getsuyomi.hpp b/src/getsuyomi.hpp index 8fb9f4a..abf8a72 100644 --- a/src/getsuyomi.hpp +++ b/src/getsuyomi.hpp @@ -31,6 +31,7 @@ class Getsuyomi : public QWidget { void setArchive(Archive* archive); void next(); void back(); + void setPageLayout(PageLayout newPageLayout); private: void setPages(); diff --git a/src/main_window.cpp b/src/main_window.cpp index 4feb240..a554358 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -86,6 +86,27 @@ void GetsuyomiApp::createActions() m_backAction->setShortcuts(backShortcuts); m_backAction->setStatusTip(tr("Back")); connect(m_backAction, &QAction::triggered, this, &GetsuyomiApp::back); + + m_setSinglePageLayout = new QAction(QIcon("../resources/pageSingle.png"), tr("Single Page Layout"), this); + m_setSinglePageLayout->setShortcut(QKeySequence{Qt::Key_S}); + m_setSinglePageLayout->setStatusTip(tr("Set Single Page Layout")); + connect(m_setSinglePageLayout, &QAction::triggered, this, &GetsuyomiApp::setSinglePageLayout); + + m_setDualPageLayout = new QAction(QIcon("../resources/pageDual.png"), tr("Dual Page Layout"), this); + m_setDualPageLayout->setShortcut(QKeySequence{Qt::Key_D}); + m_setDualPageLayout->setStatusTip(tr("Set Dual Page Layout")); + connect(m_setDualPageLayout, &QAction::triggered, this, &GetsuyomiApp::setDualPageLayout); + + m_setMangaLayout = new QAction(QIcon("../resources/pageManga.png"), tr("Manga Page Layout"), this); + m_setMangaLayout->setShortcut(QKeySequence{Qt::Key_M}); + m_setMangaLayout->setStatusTip(tr("Set Manga Page Layout")); + connect(m_setMangaLayout, &QAction::triggered, this, &GetsuyomiApp::setMangaLayout); + + m_setPageLayoutGroup = new QActionGroup(this); + m_setPageLayoutGroup->addAction(m_setSinglePageLayout); + m_setPageLayoutGroup->addAction(m_setDualPageLayout); + m_setPageLayoutGroup->addAction(m_setMangaLayout); + m_setPageLayoutGroup->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive); } void GetsuyomiApp::createMenus() @@ -101,6 +122,12 @@ void GetsuyomiApp::createToolBar() m_toolBar = addToolBar(tr("&Navigation")); m_toolBar->addAction(m_backAction); m_toolBar->addAction(m_nextAction); + + m_toolBar->addSeparator(); + + m_toolBar->addAction(m_setSinglePageLayout); + m_toolBar->addAction(m_setDualPageLayout); + m_toolBar->addAction(m_setMangaLayout); } void GetsuyomiApp::openFile() @@ -174,16 +201,38 @@ void GetsuyomiApp::quit() void GetsuyomiApp::next() { - qDebug("Next"); m_getsuyomi->next(); } void GetsuyomiApp::back() { - qDebug("Back"); m_getsuyomi->back(); } +void GetsuyomiApp::setSinglePageLayout() +{ + m_getsuyomi->setPageLayout(PageLayout::Single); + m_setSinglePageLayout->setEnabled(false); + m_setDualPageLayout->setEnabled(true); + m_setMangaLayout->setEnabled(true); +} + +void GetsuyomiApp::setDualPageLayout() +{ + m_getsuyomi->setPageLayout(PageLayout::Dual); + m_setSinglePageLayout->setEnabled(true); + m_setDualPageLayout->setEnabled(false); + m_setMangaLayout->setEnabled(true); +} + +void GetsuyomiApp::setMangaLayout() +{ + m_getsuyomi->setPageLayout(PageLayout::Manga); + m_setSinglePageLayout->setEnabled(true); + m_setDualPageLayout->setEnabled(true); + m_setMangaLayout->setEnabled(false); +} + void GetsuyomiApp::closeEvent(QCloseEvent* event) { writeSettings(); @@ -197,7 +246,6 @@ void GetsuyomiApp::readSettings() restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("windowState").toByteArray()); m_lastOpenedDirectory = settings.value("lastOpenedDirectory", QDir::homePath()).toString(); - qDebug("ReadSettings - last directory is %s", qPrintable(m_lastOpenedDirectory)); } void GetsuyomiApp::writeSettings() @@ -207,7 +255,6 @@ void GetsuyomiApp::writeSettings() settings.setValue("windowState", saveState()); settings.setValue("lastOpenedDirectory", m_lastOpenedDirectory); settings.sync(); - qDebug() << "Called writeSettings, last dir is " << settings.value("lastOpenedDirectory"); } std::optional<std::string> getEnvVar(const char* envVar) @@ -233,7 +280,7 @@ void getEnvVar(const std::string envVar, std::string& envValue, const char* back } else { envValue = *envValueOpt; } - qDebug("%s is %s", envVar.c_str(), envValue.c_str()); + // qDebug("%s is %s", envVar.c_str(), envValue.c_str()); } GetEnvResult getEnvironment() @@ -246,7 +293,7 @@ GetEnvResult getEnvironment() return GetEnvResult::error(FudStatus::Failure); } config.home = *homeOpt; - qDebug("Home is %s", config.home.c_str()); + // qDebug("Home is %s", config.home.c_str()); /* If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. */ const std::string XdgDataHome{"XDG_DATA_HOME"}; diff --git a/src/main_window.hpp b/src/main_window.hpp index 98af5a2..55b200d 100644 --- a/src/main_window.hpp +++ b/src/main_window.hpp @@ -43,6 +43,11 @@ class GetsuyomiApp : public QMainWindow { QAction* m_nextAction{nullptr}; QAction* m_backAction{nullptr}; + QAction* m_setSinglePageLayout{nullptr}; + QAction* m_setDualPageLayout{nullptr}; + QAction* m_setMangaLayout{nullptr}; + QActionGroup* m_setPageLayoutGroup{nullptr}; + QMenu* m_menuBar{nullptr}; QToolBar* m_toolBar{nullptr}; @@ -59,6 +64,10 @@ class GetsuyomiApp : public QMainWindow { void next(); void back(); + + void setSinglePageLayout(); + void setDualPageLayout(); + void setMangaLayout(); }; } // namespace getsuyomi |