22 #include <QGraphicsRectItem>
23 #include <QGraphicsView>
30 setFlag( QGraphicsItem::ItemIsSelectable,
false );
31 setFlag( QGraphicsItem::ItemIsMovable,
false );
40 void QgsPaperGrid::paint( QPainter* painter,
const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
42 Q_UNUSED( itemStyle );
59 painter->setRenderHint( QPainter::Antialiasing,
false );
63 painter->setPen( mComposition->
gridPen() );
66 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->
snapGridResolution() )
68 painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
72 currentYCoord = minYCoord;
73 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->
snapGridResolution() )
75 painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) );
80 QPen gridPen = mComposition->
gridPen();
81 painter->setPen( gridPen );
82 painter->setBrush( QBrush( gridPen.color() ) );
83 double halfCrossLength = 1;
90 QList<QGraphicsView*> viewList = scene()->views();
91 if ( viewList.size() > 0 )
93 QGraphicsView* currentView = viewList.at( 0 );
94 if ( currentView->isVisible() )
97 halfCrossLength = 1 / currentView->transform().m11();
107 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->
snapGridResolution() )
109 currentYCoord = minYCoord;
110 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->
snapGridResolution() )
112 painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
113 painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
131 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height,
QgsComposition* composition ):
QgsComposerItem( x, y, width, height, composition, false ),
132 mPageGrid( 0 ), mPageMargin( 0 )
138 mPageGrid( 0 ), mPageMargin( 0 )
148 void QgsPaperItem::paint( QPainter* painter,
const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
150 Q_UNUSED( itemStyle );
158 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
174 painter->setRenderHint( QPainter::Antialiasing,
false );
177 painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
178 painter->setPen( Qt::NoPen );
179 painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) );
182 painter->setBrush( QColor( 215, 215, 215 ) );
183 painter->setPen( QPen( QColor( 100, 100, 100 ) ) );
184 painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
187 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
189 painter->setRenderHint( QPainter::Antialiasing );
192 calculatePageMargin();
193 QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin * dotsPerMM, mPageMargin * dotsPerMM,
194 ( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) );
195 QList<QPolygonF> rings;
213 void QgsPaperItem::calculatePageMargin()
233 Q_UNUSED( itemElem );
242 mPageGrid->setRect( 0, 0, rect().width(), rect().height() );
243 mPageGrid->setPos( pos().x(), pos().y() );
246 void QgsPaperItem::initialize()
248 setFlag( QGraphicsItem::ItemIsSelectable,
false );
249 setFlag( QGraphicsItem::ItemIsMovable,
false );
255 setPen( QPen( QBrush( Qt::NoBrush ), 4 ) );