Skip to content

Commit

Permalink
Fix missing page shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 19, 2017
1 parent 54acc80 commit b594ecd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion python/core/layout/qgslayoutitempage.sip
Expand Up @@ -91,8 +91,9 @@ will be set to true if string could be successfully interpreted as a
page orientation.
%End

virtual void attemptResize( const QgsLayoutSize &size, bool includesFrame = false );
virtual QRectF boundingRect() const;

virtual void attemptResize( const QgsLayoutSize &size, bool includesFrame = false );

virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;

Expand Down
20 changes: 16 additions & 4 deletions src/core/layout/qgslayoutitempage.cpp
Expand Up @@ -32,10 +32,11 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )
setFlag( QGraphicsItem::ItemIsMovable, false );
setZValue( QgsLayout::ZPage );

// 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 ), layout->pageCollection()->pageShadowWidth() * 2 );
setPen( shadowPen );
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
{
mBoundingRect = QRectF();
prepareGeometryChange();
} );

QFont font;
QFontMetrics fm( font );
Expand Down Expand Up @@ -123,6 +124,17 @@ QgsLayoutItemPage::Orientation QgsLayoutItemPage::decodePageOrientation( const Q
return Landscape;
}

QRectF QgsLayoutItemPage::boundingRect() const
{
if ( mBoundingRect.isNull() )
{
double shadowWidth = mLayout->pageCollection()->pageShadowWidth();
mBoundingRect = rect();
mBoundingRect.adjust( 0, 0, shadowWidth, shadowWidth );
}
return mBoundingRect;
}

void QgsLayoutItemPage::attemptResize( const QgsLayoutSize &size, bool includesFrame )
{
QgsLayoutItem::attemptResize( size, includesFrame );
Expand Down
3 changes: 2 additions & 1 deletion src/core/layout/qgslayoutitempage.h
Expand Up @@ -121,8 +121,8 @@ class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
*/
static QgsLayoutItemPage::Orientation decodePageOrientation( const QString &string, bool *ok SIP_OUT = nullptr );

QRectF boundingRect() const override;
void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;

QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;

public slots:
Expand All @@ -140,6 +140,7 @@ class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
double mMaximumShadowWidth = -1;

std::unique_ptr< QgsLayoutItemPageGrid > mGrid;
mutable QRectF mBoundingRect;

friend class TestQgsLayoutPage;
};
Expand Down

0 comments on commit b594ecd

Please sign in to comment.