summaryrefslogtreecommitdiff
path: root/src/getsuyomi.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-29 12:51:41 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-29 12:51:41 -0500
commitdacd752bbf46f2afb08b4b8d730ba3619528dda4 (patch)
tree2554b12d3a6cb6d66fe28a89ccf132f6ae4b4aad /src/getsuyomi.cpp
parent06663d34c7678aa723955e64cd82a2e399c4b8c6 (diff)
Add more functionality in paging.
Diffstat (limited to 'src/getsuyomi.cpp')
-rw-r--r--src/getsuyomi.cpp83
1 files changed, 61 insertions, 22 deletions
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());
}
}