Index: scribus/ui/pagepalette_widgets.h =================================================================== --- scribus/ui/pagepalette_widgets.h (revision 27861) +++ scribus/ui/pagepalette_widgets.h (working copy) @@ -206,7 +206,9 @@ int columnAt(QPoint pos); int rowAt(QPoint pos); + int rowContentWidth(int rowId); int rowWidth(int rowId); + int rowStartX(int rowId); QRect rectAt(int row, int col); QSize dummyPageSize(); Index: scribus/ui/pagepalette_widgets.cpp =================================================================== --- scribus/ui/pagepalette_widgets.cpp (revision 27861) +++ scribus/ui/pagepalette_widgets.cpp (working copy) @@ -251,7 +251,21 @@ void PageGrid::setPageInGroup(int amount) { - m_cellsInGroup = amount; + switch (qBound(1, amount, 4)) + { + case 2: + setPageLayout(PageLayout::doublePage); + break; + case 3: + setPageLayout(PageLayout::triplePage); + break; + case 4: + setPageLayout(PageLayout::quadroPage); + break; + default: + setPageLayout(PageLayout::singlePage); + break; + } } void PageGrid::setDocumentPageSize(QSizeF pageSize) @@ -294,25 +308,29 @@ void PageGrid::setPageLayout(PageLayout layout) { - m_pageLayout = layout; - - switch(m_pageLayout) + int cellsInGroup = 1; + switch (layout) { - default: - case PageLayout::singlePage: - m_cellsInGroup = 1; - break; case PageLayout::doublePage: - m_cellsInGroup = 2; + cellsInGroup = 2; break; case PageLayout::triplePage: - m_cellsInGroup = 3; + cellsInGroup = 3; break; case PageLayout::quadroPage: - m_cellsInGroup = 4; + cellsInGroup = 4; + break; + case PageLayout::singlePage: + default: + layout = PageLayout::singlePage; break; } + if (m_pageLayout == layout && m_cellsInGroup == cellsInGroup) + return; + + m_pageLayout = layout; + m_cellsInGroup = cellsInGroup; update(); } @@ -415,7 +433,7 @@ int m_col = -1; - QRect cellRect(m_groupSpace, m_rowSpace + row * (rowHeight() + m_rowSpace), dummyPageSize().width(), rowHeight()); + QRect cellRect(rowStartX(row), m_rowSpace + row * (rowHeight() + m_rowSpace), dummyPageSize().width(), rowHeight()); int width = 0; for (int i = 0; i <= m_cellsInGroup; ++i) @@ -458,16 +476,16 @@ return (m_row < m_rows) ? m_row : m_rows -1; } -int PageGrid::rowWidth(int rowId) +int PageGrid::rowContentWidth(int rowId) { - if(pageCount() == 0 || rowId < 0) return -1; + if (pageCount() == 0 || rowId < 0 || rowId >= rows()) + return -1; int width = 0; - + // Keep dummy slots in the nominal width so incomplete facing rows stay centered as full spreads. for (int i = 0; i < m_cellsInGroup; ++i) { - int id = pageId(rowId, i, false); - + const int id = pageId(rowId, i, false); if (pageInRange(id)) { PageCell *pc = pageList.at(id); @@ -476,21 +494,40 @@ else width += dummyPageSize().width(); - width += m_cellGap; + if (i + 1 < m_cellsInGroup) + width += m_cellGap; + } - }; + return width; +} - width += m_groupSpace * 2; +int PageGrid::rowWidth(int rowId) +{ + const int contentWidth = rowContentWidth(rowId); + if (contentWidth < 0) + return -1; - return width; + // Preserve the historical trailing cell gap used by size calculations. + return contentWidth + m_groupSpace * 2 + m_cellGap; +} + +int PageGrid::rowStartX(int rowId) +{ + if (m_pageLayout != PageLayout::doublePage) + return m_groupSpace; + + const int contentWidth = rowContentWidth(rowId); + if (contentWidth <= 0) + return m_groupSpace; + return qMax(m_groupSpace, (width() - contentWidth) / 2); } QRect PageGrid::rectAt(int row, int col) { if ( row == -1 || col == -1) return QRect(); - QRect cellRect(m_groupSpace, m_rowSpace + row * (rowHeight() + m_rowSpace), dummyPageSize().width(), rowHeight()); + QRect cellRect(rowStartX(row), m_rowSpace + row * (rowHeight() + m_rowSpace), dummyPageSize().width(), rowHeight()); int width = 0; for (int i = 0; i <= m_cellsInGroup; ++i) @@ -799,7 +836,6 @@ void PageGrid::paintEvent(QPaintEvent *event) { - int x = m_groupSpace; int y = m_rowSpace; int offset = 0; QRect selectedPageRect; @@ -815,7 +851,9 @@ // Draw pages for (int r = 0; r < rows(); r++) { - int groupStart = m_groupSpace; + const int rowStart = rowStartX(r); + int x = rowStart; + int groupStart = rowStart; int groupWidth = 0; bool drawGroupRect = false; @@ -851,7 +889,7 @@ offset = m_cellGap; if(isLastRow(r + 1)) - groupStart = m_rtlBinding ? x : m_groupSpace; + groupStart = m_rtlBinding ? x : rowStart; int w = cell->pageWidthByHeight(pageHeight()) + offset; x += w; @@ -868,7 +906,7 @@ // adjust start on first row if first page has an offset if(isFirstRow(r)) - groupStart = m_rtlBinding ? m_groupSpace : x; + groupStart = m_rtlBinding ? rowStart : x; } } @@ -877,7 +915,6 @@ painter.drawRect( QRect(groupStart, y, groupWidth, pageHeight()) ); y += m_rowHeight + m_rowSpace; - x = m_groupSpace; } // Draw selected page