@@ -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 << " \t Last: " << 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);
0 commit comments