Skip to content
Permalink
Browse files

Don't use constant space between pages - doesn't work well for non mm…

… units
  • Loading branch information
nyalldawson committed Jul 22, 2017
1 parent 183a72e commit 1e4c95431c014cb3182411ed10f4eaa5e0f1d4b9
@@ -21,16 +21,6 @@ class QgsLayoutPageCollection : QObject
%End
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/ );
%Docstring
Constructor for QgsLayoutItemPage, with the specified parent ``layout``.
@@ -156,6 +146,18 @@ Size of page shadow, in layout coordinates
:rtype: QPointF
%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:

void changed();
@@ -30,7 +30,7 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )

// 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)
QPen shadowPen( QBrush( Qt::transparent ), QgsLayoutPageCollection::PAGE_SHADOW_WIDTH * 2 );
QPen shadowPen( QBrush( Qt::transparent ), layout->pageCollection()->pageShadowWidth() * 2 );
setPen( shadowPen );

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

//page area
painter->setBrush( QColor( 215, 215, 215 ) );
@@ -48,7 +48,7 @@ void QgsLayoutPageCollection::reflow()
Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{
page->attemptMove( p );
currentY += mLayout->convertToLayoutUnits( page->pageSize() ).height() + SPACE_BETWEEN_PAGES;
currentY += mLayout->convertToLayoutUnits( page->pageSize() ).height() + spaceBetweenPages();
p.setY( currentY );
}
mLayout->updateBounds();
@@ -71,7 +71,7 @@ int QgsLayoutPageCollection::pageNumberForPoint( QPointF point ) const
double startNextPageY = 0;
Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{
startNextPageY += page->rect().height() + SPACE_BETWEEN_PAGES;
startNextPageY += page->rect().height() + spaceBetweenPages();
if ( startNextPageY > point.y() )
break;
pageNumber++;
@@ -90,7 +90,7 @@ QPointF QgsLayoutPageCollection::positionOnPage( QPointF position ) const
Q_FOREACH ( QgsLayoutItemPage *page, mPages )
{
startCurrentPageY = startNextPageY;
startNextPageY += page->rect().height() + SPACE_BETWEEN_PAGES;
startNextPageY += page->rect().height() + spaceBetweenPages();
if ( startNextPageY > position.y() )
break;
pageNumber++;
@@ -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
//top of last page and y coordinate
y = position.y() - ( startNextPageY - SPACE_BETWEEN_PAGES );
y = position.y() - ( startNextPageY - spaceBetweenPages() );
}
else
{
@@ -111,6 +111,16 @@ QPointF QgsLayoutPageCollection::positionOnPage( QPointF position ) const
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
{
return mLayout;
@@ -39,12 +39,6 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject

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.
*/
@@ -162,6 +156,16 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject
*/
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:

/**
@@ -150,7 +150,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
}
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 )
break;
}
@@ -199,7 +199,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
if ( i < endPage )
{
//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();
}
else
@@ -230,7 +230,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
pageCoord += 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;
}

0 comments on commit 1e4c954

Please sign in to comment.
You can’t perform that action at this time.