|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgspaperitem.cpp 00003 ------------------- 00004 begin : September 2008 00005 copyright : (C) 2008 by Marco Hugentobler 00006 email : marco dot hugentobler at karto dot baug dot ethz dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "qgspaperitem.h" 00019 #include "qgscomposition.h" 00020 #include <QPainter> 00021 00022 QgsPaperItem::QgsPaperItem( QgsComposition* c ): QgsComposerItem( c, false ) 00023 { 00024 initialize(); 00025 } 00026 00027 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false ) 00028 { 00029 initialize(); 00030 } 00031 00032 QgsPaperItem::QgsPaperItem(): QgsComposerItem( 0, false ) 00033 { 00034 initialize(); 00035 } 00036 00037 QgsPaperItem::~QgsPaperItem() 00038 { 00039 00040 } 00041 00042 void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) 00043 { 00044 Q_UNUSED( itemStyle ); 00045 Q_UNUSED( pWidget ); 00046 if ( !painter ) 00047 { 00048 return; 00049 } 00050 00051 drawBackground( painter ); 00052 00053 //draw grid 00054 00055 if ( mComposition ) 00056 { 00057 if ( mComposition->snapToGridEnabled() && mComposition->plotStyle() == QgsComposition::Preview 00058 && mComposition->snapGridResolution() > 0 ) 00059 { 00060 int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() ); 00061 int gridMultiplyY = ( int )( mComposition->snapGridOffsetY() / mComposition->snapGridResolution() ); 00062 double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution(); 00063 double currentYCoord; 00064 double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution(); 00065 00066 if ( mComposition->gridStyle() == QgsComposition::Solid ) 00067 { 00068 painter->setPen( mComposition->gridPen() ); 00069 00070 //draw vertical lines 00071 00072 00073 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() ) 00074 { 00075 painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) ); 00076 } 00077 00078 //draw horizontal lines 00079 currentYCoord = minYCoord; 00080 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() ) 00081 { 00082 painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) ); 00083 } 00084 } 00085 else //'Dots' or 'Crosses' 00086 { 00087 QPen gridPen = mComposition->gridPen(); 00088 painter->setPen( gridPen ); 00089 painter->setBrush( QBrush( gridPen.color() ) ); 00090 double halfCrossLength = mComposition->snapGridResolution() / 6; 00091 00092 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() ) 00093 { 00094 currentYCoord = minYCoord; 00095 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() ) 00096 { 00097 if ( mComposition->gridStyle() == QgsComposition::Dots ) 00098 { 00099 QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() ); 00100 painter->drawChord( pieRect, 0, 5760 ); 00101 } 00102 else if ( mComposition->gridStyle() == QgsComposition::Crosses ) 00103 { 00104 painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) ); 00105 painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) ); 00106 } 00107 } 00108 } 00109 } 00110 } 00111 } 00112 } 00113 00114 bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const 00115 { 00116 Q_UNUSED( elem ); 00117 Q_UNUSED( doc ); 00118 return true; 00119 } 00120 00121 bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc ) 00122 { 00123 Q_UNUSED( itemElem ); 00124 Q_UNUSED( doc ); 00125 return true; 00126 } 00127 00128 void QgsPaperItem::initialize() 00129 { 00130 setFlag( QGraphicsItem::ItemIsSelectable, false ); 00131 setFlag( QGraphicsItem::ItemIsMovable, false ); 00132 setZValue( 0 ); 00133 }