diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-18 21:59:54 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-18 21:59:54 -0500 |
commit | fa4b4097d3283e1d6e6376c70910e245f0b1f6ec (patch) | |
tree | 74dff4ded82d3f4854b3f10d5dd2e5be1f69b95e /src/getsuyomi.cpp | |
parent | 04dbfdc97e94e6f477675b9d3135164752a7cfef (diff) |
Save progress of qt6 implementation.
Diffstat (limited to 'src/getsuyomi.cpp')
-rw-r--r-- | src/getsuyomi.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/getsuyomi.cpp b/src/getsuyomi.cpp new file mode 100644 index 0000000..11f273b --- /dev/null +++ b/src/getsuyomi.cpp @@ -0,0 +1,106 @@ +#include "getsuyomi.hpp" +#include "main_window.hpp" + +namespace getsuyomi { + +Getsuyomi::Getsuyomi() +{ + m_layout = new QVBoxLayout(); + + m_layout->addWidget(&m_pageLeft); + m_layout->addWidget(&m_pageRight); + + setLayout(m_layout); +} + +void Getsuyomi::setArchive(Archive* archive) { + if (archive == m_archive) { + return; + } + delete(m_archive); + m_archive = archive; + m_pageNumber = 0; + setPages(); +} + +void Getsuyomi::next() { + auto numPages = m_archive->numPages(); + size_t increment = 1; + if (m_pageLayout != PageLayout::Single) { + increment = 2; + } + if ((m_pageNumber + increment) >= numPages) + { + return; + } + m_pageNumber += increment; + setPages(); +} + +void Getsuyomi::back() { + auto numPages = m_archive->numPages(); + size_t decrement = 1; + if (m_pageLayout != PageLayout::Single) { + decrement = 2; + } + if (m_pageNumber < decrement) + { + m_pageNumber = 0; + decrement = 0; + } + m_pageNumber -= decrement; + setPages(); +} + +void Getsuyomi::setPages() { + m_pageLeft.setPixmap(QPixmap()); + m_pageRight.setPixmap(QPixmap()); + + switch (m_pageLayout) + { + case PageLayout::Dual: + return setPagesDual(); + case PageLayout::Manga: + return setPagesManga(); + case PageLayout::Single: + default: + return setPagesNormal(); + } +} + +void Getsuyomi::setPagesNormal() { + auto page1 = m_archive->getPage(m_pageNumber); + auto& label1 = m_pageLeft; + + if (page1.isOkay()) { + label1.setPixmap(QPixmap::fromImage(page1.getOkay())); + } +} + +void Getsuyomi::setPagesDual() { + auto& label1 = m_pageLeft; + auto& label2 = m_pageRight; + setPages(label1, label2); +} + +void Getsuyomi::setPagesManga() { + auto& label1 = m_pageRight; + auto& label2 = m_pageLeft; + setPages(label1, 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())); + } + + + if (page2.isOkay()) { + label2.setPixmap(QPixmap::fromImage(page1.getOkay())); + } +} + +} // namespace getsuyomi |