Quantum GIS API Documentation
1.7.4
|
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 <QPainter> 00020 00021 QgsPaperItem::QgsPaperItem( QgsComposition* c ): QgsComposerItem( c, false ) 00022 { 00023 initialize(); 00024 } 00025 00026 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false ) 00027 { 00028 initialize(); 00029 } 00030 00031 QgsPaperItem::QgsPaperItem(): QgsComposerItem( 0, false ) 00032 { 00033 initialize(); 00034 } 00035 00036 QgsPaperItem::~QgsPaperItem() 00037 { 00038 00039 } 00040 00041 void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) 00042 { 00043 if ( !painter ) 00044 { 00045 return; 00046 } 00047 00048 drawBackground( painter ); 00049 00050 //draw grid 00051 00052 if ( mComposition ) 00053 { 00054 if ( mComposition->snapToGridEnabled() && mComposition->plotStyle() == QgsComposition::Preview 00055 && mComposition->snapGridResolution() > 0 ) 00056 { 00057 int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() ); 00058 int gridMultiplyY = ( int )( mComposition->snapGridOffsetY() / mComposition->snapGridResolution() ); 00059 double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution(); 00060 double currentYCoord; 00061 double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution(); 00062 00063 if ( mComposition->gridStyle() == QgsComposition::Solid ) 00064 { 00065 painter->setPen( mComposition->gridPen() ); 00066 00067 //draw vertical lines 00068 00069 00070 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() ) 00071 { 00072 painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) ); 00073 } 00074 00075 //draw horizontal lines 00076 currentYCoord = minYCoord; 00077 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() ) 00078 { 00079 painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) ); 00080 } 00081 } 00082 else //'Dots' or 'Crosses' 00083 { 00084 QPen gridPen = mComposition->gridPen(); 00085 painter->setPen( gridPen ); 00086 painter->setBrush( QBrush( gridPen.color() ) ); 00087 double halfCrossLength = mComposition->snapGridResolution() / 6; 00088 00089 for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() ) 00090 { 00091 currentYCoord = minYCoord; 00092 for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() ) 00093 { 00094 if ( mComposition->gridStyle() == QgsComposition::Dots ) 00095 { 00096 QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() ); 00097 painter->drawChord( pieRect, 0, 5760 ); 00098 } 00099 else if ( mComposition->gridStyle() == QgsComposition::Crosses ) 00100 { 00101 painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) ); 00102 painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) ); 00103 } 00104 } 00105 } 00106 } 00107 } 00108 } 00109 } 00110 00111 bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const 00112 { 00113 return true; 00114 } 00115 00116 bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc ) 00117 { 00118 return true; 00119 } 00120 00121 void QgsPaperItem::initialize() 00122 { 00123 setFlag( QGraphicsItem::ItemIsSelectable, false ); 00124 setFlag( QGraphicsItem::ItemIsMovable, false ); 00125 setZValue( 0 ); 00126 }