Skip to content

Commit

Permalink
Don't use constant space between pages - doesn't work well for non mm…
Browse files Browse the repository at this point in the history
… units
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 183a72e commit 1e4c954
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
22 changes: 12 additions & 10 deletions python/core/layout/qgslayoutpagecollection.sip
Expand Up @@ -21,16 +21,6 @@ class QgsLayoutPageCollection : QObject
%End %End
public: public:


static const double SPACE_BETWEEN_PAGES;
%Docstring
Space between pages in the layout, in layout coordinates
%End

static const double PAGE_SHADOW_WIDTH;
%Docstring
Size of page shadow, in layout coordinates
%End

explicit QgsLayoutPageCollection( QgsLayout *layout /TransferThis/ ); explicit QgsLayoutPageCollection( QgsLayout *layout /TransferThis/ );
%Docstring %Docstring
Constructor for QgsLayoutItemPage, with the specified parent ``layout``. Constructor for QgsLayoutItemPage, with the specified parent ``layout``.
Expand Down Expand Up @@ -156,6 +146,18 @@ Size of page shadow, in layout coordinates
:rtype: QPointF :rtype: QPointF
%End %End


double spaceBetweenPages() const;
%Docstring
Returns the space between pages, in layout units.
:rtype: float
%End

double pageShadowWidth() const;
%Docstring
Returns the size of the page shadow, in layout units.
:rtype: float
%End

signals: signals:


void changed(); void changed();
Expand Down
6 changes: 3 additions & 3 deletions src/core/layout/qgslayoutitempage.cpp
Expand Up @@ -30,7 +30,7 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )


// use a hidden pen to specify the amount the page "bleeds" outside it's scene bounds, // use a hidden pen to specify the amount the page "bleeds" outside it's scene bounds,
// (it's a lot easier than reimplementing boundingRect() just to handle this) // (it's a lot easier than reimplementing boundingRect() just to handle this)
QPen shadowPen( QBrush( Qt::transparent ), QgsLayoutPageCollection::PAGE_SHADOW_WIDTH * 2 ); QPen shadowPen( QBrush( Qt::transparent ), layout->pageCollection()->pageShadowWidth() * 2 );
setPen( shadowPen ); setPen( shadowPen );


QFont font; QFont font;
Expand Down Expand Up @@ -134,8 +134,8 @@ void QgsLayoutItemPage::draw( QgsRenderContext &context, const QStyleOptionGraph
//shadow //shadow
painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) ); painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
painter->drawRect( pageRect.translated( qMin( scale * QgsLayoutPageCollection::PAGE_SHADOW_WIDTH, mMaximumShadowWidth ), painter->drawRect( pageRect.translated( qMin( scale * mLayout->pageCollection()->pageShadowWidth(), mMaximumShadowWidth ),
qMin( scale * QgsLayoutPageCollection::PAGE_SHADOW_WIDTH, mMaximumShadowWidth ) ) ); qMin( scale * mLayout->pageCollection()->pageShadowWidth(), mMaximumShadowWidth ) ) );


//page area //page area
painter->setBrush( QColor( 215, 215, 215 ) ); painter->setBrush( QColor( 215, 215, 215 ) );
Expand Down
18 changes: 14 additions & 4 deletions src/core/layout/qgslayoutpagecollection.cpp
Expand Up @@ -48,7 +48,7 @@ void QgsLayoutPageCollection::reflow()
Q_FOREACH ( QgsLayoutItemPage *page, mPages ) Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{ {
page->attemptMove( p ); page->attemptMove( p );
currentY += mLayout->convertToLayoutUnits( page->pageSize() ).height() + SPACE_BETWEEN_PAGES; currentY += mLayout->convertToLayoutUnits( page->pageSize() ).height() + spaceBetweenPages();
p.setY( currentY ); p.setY( currentY );
} }
mLayout->updateBounds(); mLayout->updateBounds();
Expand All @@ -71,7 +71,7 @@ int QgsLayoutPageCollection::pageNumberForPoint( QPointF point ) const
double startNextPageY = 0; double startNextPageY = 0;
Q_FOREACH ( QgsLayoutItemPage *page, mPages ) Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{ {
startNextPageY += page->rect().height() + SPACE_BETWEEN_PAGES; startNextPageY += page->rect().height() + spaceBetweenPages();
if ( startNextPageY > point.y() ) if ( startNextPageY > point.y() )
break; break;
pageNumber++; pageNumber++;
Expand All @@ -90,7 +90,7 @@ QPointF QgsLayoutPageCollection::positionOnPage( QPointF position ) const
Q_FOREACH ( QgsLayoutItemPage *page, mPages ) Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{ {
startCurrentPageY = startNextPageY; startCurrentPageY = startNextPageY;
startNextPageY += page->rect().height() + SPACE_BETWEEN_PAGES; startNextPageY += page->rect().height() + spaceBetweenPages();
if ( startNextPageY > position.y() ) if ( startNextPageY > position.y() )
break; break;
pageNumber++; pageNumber++;
Expand All @@ -101,7 +101,7 @@ QPointF QgsLayoutPageCollection::positionOnPage( QPointF position ) const
{ {
//y coordinate is greater then the end of the last page, so return distance between //y coordinate is greater then the end of the last page, so return distance between
//top of last page and y coordinate //top of last page and y coordinate
y = position.y() - ( startNextPageY - SPACE_BETWEEN_PAGES ); y = position.y() - ( startNextPageY - spaceBetweenPages() );
} }
else else
{ {
Expand All @@ -111,6 +111,16 @@ QPointF QgsLayoutPageCollection::positionOnPage( QPointF position ) const
return QPointF( position.x(), y ); return QPointF( position.x(), y );
} }


double QgsLayoutPageCollection::spaceBetweenPages() const
{
return mLayout->convertToLayoutUnits( QgsLayoutMeasurement( 10 ) );
}

double QgsLayoutPageCollection::pageShadowWidth() const
{
return spaceBetweenPages() / 2;
}

QgsLayout *QgsLayoutPageCollection::layout() const QgsLayout *QgsLayoutPageCollection::layout() const
{ {
return mLayout; return mLayout;
Expand Down
16 changes: 10 additions & 6 deletions src/core/layout/qgslayoutpagecollection.h
Expand Up @@ -39,12 +39,6 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject


public: public:


//! Space between pages in the layout, in layout coordinates
static constexpr double SPACE_BETWEEN_PAGES = 10;

//! Size of page shadow, in layout coordinates
static constexpr double PAGE_SHADOW_WIDTH = 5; // Must be less than SPACE_BETWEEN_PAGES

/** /**
* Constructor for QgsLayoutItemPage, with the specified parent \a layout. * Constructor for QgsLayoutItemPage, with the specified parent \a layout.
*/ */
Expand Down Expand Up @@ -162,6 +156,16 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject
*/ */
QPointF positionOnPage( QPointF point ) const; QPointF positionOnPage( QPointF point ) const;


/**
* Returns the space between pages, in layout units.
*/
double spaceBetweenPages() const;

/**
* Returns the size of the page shadow, in layout units.
*/
double pageShadowWidth() const;

signals: signals:


/** /**
Expand Down
6 changes: 3 additions & 3 deletions src/gui/layout/qgslayoutruler.cpp
Expand Up @@ -150,7 +150,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
} }
endPage = page; endPage = page;


currentY += layout->pageCollection()->page( startPage )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES; currentY += layout->pageCollection()->page( startPage )->rect().height() + layout->pageCollection()->spaceBetweenPages();
if ( currentY > endY ) if ( currentY > endY )
break; break;
} }
Expand Down Expand Up @@ -199,7 +199,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
if ( i < endPage ) if ( i < endPage )
{ {
//not the last page //not the last page
nextPageStartPos = currentPageY + layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES; nextPageStartPos = currentPageY + layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->spaceBetweenPages();
nextPageStartPixel = mTransform.map( QPointF( 0, nextPageStartPos ) ).y(); nextPageStartPixel = mTransform.map( QPointF( 0, nextPageStartPos ) ).y();
} }
else else
Expand Down Expand Up @@ -230,7 +230,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
pageCoord += mmDisplay; pageCoord += mmDisplay;
totalCoord += mmDisplay; totalCoord += mmDisplay;
} }
currentPageY += layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->SPACE_BETWEEN_PAGES; currentPageY += layout->pageCollection()->page( i )->rect().height() + layout->pageCollection()->spaceBetweenPages();
} }
break; break;
} }
Expand Down

0 comments on commit 1e4c954

Please sign in to comment.