Some fixes for cover page mode

* 1-page shift is now taken into account for size pages.
 Before this change, the last page of a document with an even count of
 pages would have zero height and be displayed 'floating' over the page
 above it.

* Improved code readability by using a variable to store the result of
  the cover page mode check.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/30/head
Mavridis Philippe 4 years ago
parent ea41cd36fb
commit 08380de42c
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -1658,6 +1658,7 @@ void PageView::doTypeAheadSearch()
void PageView::slotRelayoutPages() void PageView::slotRelayoutPages()
// called by: notifySetup, viewportResizeEvent, slotTwoPagesToggled, slotContinuousToggled, updateZoom // called by: notifySetup, viewportResizeEvent, slotTwoPagesToggled, slotContinuousToggled, updateZoom
{ {
bool coverPageMode = ( KpdfSettings::viewColumns() == 2 && KpdfSettings::viewCoverPage() );
// set an empty container if we have no pages // set an empty container if we have no pages
int pageCount = d->items.count(); int pageCount = d->items.count();
if ( pageCount < 1 ) if ( pageCount < 1 )
@ -1688,11 +1689,12 @@ void PageView::slotRelayoutPages()
{ {
// Here we find out column's width and row's height to compute a table // Here we find out column's width and row's height to compute a table
// so we can place widgets 'centered in virtual cells'. // so we can place widgets 'centered in virtual cells'.
int nCols = KpdfSettings::viewColumns(), int pageShift = coverPageMode ? 1 : 0,
nRows = (int)ceil( (float)pageCount / (float)nCols ), nCols = KpdfSettings::viewColumns(),
nRows = (int)ceil( (float)(pageCount + pageShift) / (float)nCols ),
* colWidth = new int[ nCols ], * colWidth = new int[ nCols ],
* rowHeight = new int[ nRows ], * rowHeight = new int[ nRows ],
cIdx = 0, cIdx = pageShift,
rIdx = 0; rIdx = 0;
for ( int i = 0; i < nCols; i++ ) for ( int i = 0; i < nCols; i++ )
colWidth[ i ] = viewportWidth / nCols; colWidth[ i ] = viewportWidth / nCols;
@ -1722,19 +1724,16 @@ void PageView::slotRelayoutPages()
// 2) arrange widgets inside cells // 2) arrange widgets inside cells
int insertX = 0, int insertX = 0,
insertY = 4; // 2 + 4*d->zoomFactor ? insertY = 4; // 2 + 4*d->zoomFactor ?
cIdx = 0; cIdx = pageShift;
rIdx = 0; rIdx = 0;
if( KpdfSettings::viewColumns() == 2 && KpdfSettings::viewCoverPage() )
++cIdx;
for ( iIt = d->items.begin(); iIt != iEnd; ++iIt ) for ( iIt = d->items.begin(); iIt != iEnd; ++iIt )
{ {
PageViewItem * item = *iIt; PageViewItem * item = *iIt;
int cWidth = colWidth[ cIdx ], int cWidth = colWidth[ cIdx ],
rHeight = rowHeight[ rIdx ]; rHeight = rowHeight[ rIdx ];
if( KpdfSettings::viewColumns() == 2 && KpdfSettings::viewCoverPage() && item->pageNumber() == 0 ) // align widget right inside viewport if( coverPageMode && item->pageNumber() == 0 ) // align widget right inside viewport
insertX+=cWidth; insertX+=cWidth;
// center widget inside 'cells' // center widget inside 'cells'
@ -1791,7 +1790,7 @@ void PageView::slotRelayoutPages()
int insertX = 0; int insertX = 0;
cIdx = 0; cIdx = 0;
if( KpdfSettings::viewColumns() == 2 && KpdfSettings::viewCoverPage() && (int)d->document->currentPage() == 0 ) if( coverPageMode && (int)d->document->currentPage() == 0 )
++cIdx; ++cIdx;
for ( iIt = d->items.begin(); iIt != iEnd; ++iIt ) for ( iIt = d->items.begin(); iIt != iEnd; ++iIt )

Loading…
Cancel
Save