Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Tweak appearance of compositions so that it's still possib…
…le to see page edges when using a transparent paper style
  • Loading branch information
nyalldawson committed Jan 6, 2014
1 parent d1a3508 commit 0ae2b1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -78,7 +78,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mAtlasPreviewEnabled( false )
, mPreventCursorChange( false )
{
setBackgroundBrush( Qt::gray );
setBackgroundBrush( QColor( 215, 215, 215 ) );
createDefaultPageStyleSymbol();
addPaperItem();

Expand Down Expand Up @@ -2248,7 +2248,7 @@ void QgsComposition::renderPage( QPainter* p, int page )
setBackgroundBrush( Qt::NoBrush );
render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect );
//show background after rendering
setBackgroundBrush( Qt::gray );
setBackgroundBrush( QColor( 215, 215, 215 ) );
setSnapLinesVisible( true );

mPlotStyle = savedPlotStyle;
Expand Down
23 changes: 23 additions & 0 deletions src/core/composer/qgspaperitem.cpp
Expand Up @@ -166,6 +166,24 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
}

painter->save();

if ( mComposition->plotStyle() == QgsComposition::Preview )
{
//if in preview mode, draw page border and shadow so that it's
//still possible to tell where pages with a transparent style begin and end
painter->setRenderHint( QPainter::Antialiasing, false );

//shadow
painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
painter->setPen( Qt::NoPen );
painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) );

//page area
painter->setBrush( QColor( 215, 215, 215 ) );
painter->setPen( QPen( QColor( 100, 100, 100 ) ) );
painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
}

painter->setRenderHint( QPainter::Antialiasing );
mComposition->pageStyleSymbol()->startRender( context );

Expand Down Expand Up @@ -217,6 +235,11 @@ void QgsPaperItem::initialize()
setFlag( QGraphicsItem::ItemIsMovable, false );
setZValue( 0 );

//even though we aren't going to use it to draw the page, set the pen width as 4
//so that the page border and shadow is fully rendered within its scene rect
//(QGraphicsRectItem considers the pen width when calculating an item's scene rect)
setPen( QPen( QBrush( Qt::NoBrush ), 4 ) );

//create a new QgsPaperGrid for this page, and add it to the composition
mPageGrid = new QgsPaperGrid( pos().x(), pos().y(), rect().width(), rect().height(), mComposition );
mComposition->addItem( mPageGrid );
Expand Down

0 comments on commit 0ae2b1a

Please sign in to comment.