Skip to content

Commit 9878ffe

Browse files
Fixed loading saved page
1 parent b4681f1 commit 9878ffe

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/presentation/desktop/modules/CppElements/document_view.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ DocumentView::DocumentView()
1818
m_contentItem->setParentItem(this);
1919
m_contentItem->setY(0);
2020

21+
// Redraw the page when the height changes
22+
connect(this, &QQuickItem::heightChanged, this, &DocumentView::redrawPages);
23+
2124
// Ensure the content item has the same width as the document view
2225
connect(this, &QQuickItem::implicitWidthChanged, this,
2326
[this]()
@@ -154,14 +157,16 @@ bool DocumentView::setupDefaultPageHeight()
154157
return true;
155158
}
156159

157-
QPair<int, int> DocumentView::getPageSpanToRender() const
160+
QPair<int, int> DocumentView::getPageSpanToRender()
158161
{
159162
if(m_pageHeight == 0)
160163
return {};
161164

162-
int first = m_contentY / ((m_pageHeight + m_spacing) * m_currentZoom);
163-
int pageStep = (m_pageHeight + m_spacing) * m_currentZoom;
164-
int last = ((m_contentY + height()) + pageStep - 1) / pageStep - 1;
165+
double pageStep = (m_pageHeight + m_spacing) * m_currentZoom;
166+
int first = m_contentY / pageStep;
167+
int last = (m_contentY + height()) / pageStep;
168+
169+
qDebug() << "First: " << first << "\tLast: " << last;
165170

166171
// For the case that contentY perfectly aligns with the book
167172
// start (0) or end, we need to add or subtract 1
@@ -275,6 +280,7 @@ void DocumentView::loadDefaultBookData()
275280
return;
276281

277282
// Calculate content y
283+
auto x = m_bookController->getCurrentPage();
278284
auto newContentY = m_bookController->getCurrentPage() *
279285
(m_pageHeight + m_spacing) * m_currentZoom;
280286
setContentY(newContentY);

src/presentation/desktop/modules/CppElements/document_view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PRESENTATION_EXPORT DocumentView : public QQuickItem
5757

5858
private:
5959
void redrawPages();
60-
QPair<int, int> getPageSpanToRender() const;
60+
QPair<int, int> getPageSpanToRender();
6161
bool setupDefaultPageHeight();
6262
void handleScroll(int deltaY, int deltaX);
6363
void moveX(int amount);

0 commit comments

Comments
 (0)