Quantum GIS API Documentation  1.8
src/core/composer/qgspaperitem.cpp
Go to the documentation of this file.
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   Q_UNUSED( itemStyle );
00044   Q_UNUSED( pWidget );
00045   if ( !painter )
00046   {
00047     return;
00048   }
00049 
00050   drawBackground( painter );
00051 
00052   //draw grid
00053 
00054   if ( mComposition )
00055   {
00056     if ( mComposition->snapToGridEnabled() && mComposition->plotStyle() ==  QgsComposition::Preview
00057          && mComposition->snapGridResolution() > 0 )
00058     {
00059       int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() );
00060       int gridMultiplyY = ( int )( mComposition->snapGridOffsetY() / mComposition->snapGridResolution() );
00061       double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution();
00062       double currentYCoord;
00063       double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();
00064 
00065       if ( mComposition->gridStyle() == QgsComposition::Solid )
00066       {
00067         painter->setPen( mComposition->gridPen() );
00068 
00069         //draw vertical lines
00070 
00071 
00072         for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
00073         {
00074           painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
00075         }
00076 
00077         //draw horizontal lines
00078         currentYCoord = minYCoord;
00079         for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
00080         {
00081           painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) );
00082         }
00083       }
00084       else //'Dots' or 'Crosses'
00085       {
00086         QPen gridPen = mComposition->gridPen();
00087         painter->setPen( gridPen );
00088         painter->setBrush( QBrush( gridPen.color() ) );
00089         double halfCrossLength = mComposition->snapGridResolution() / 6;
00090 
00091         for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
00092         {
00093           currentYCoord = minYCoord;
00094           for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
00095           {
00096             if ( mComposition->gridStyle() == QgsComposition::Dots )
00097             {
00098               QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() );
00099               painter->drawChord( pieRect, 0, 5760 );
00100             }
00101             else if ( mComposition->gridStyle() == QgsComposition::Crosses )
00102             {
00103               painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
00104               painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
00105             }
00106           }
00107         }
00108       }
00109     }
00110   }
00111 }
00112 
00113 bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const
00114 {
00115   Q_UNUSED( elem );
00116   Q_UNUSED( doc );
00117   return true;
00118 }
00119 
00120 bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc )
00121 {
00122   Q_UNUSED( itemElem );
00123   Q_UNUSED( doc );
00124   return true;
00125 }
00126 
00127 void QgsPaperItem::initialize()
00128 {
00129   setFlag( QGraphicsItem::ItemIsSelectable, false );
00130   setFlag( QGraphicsItem::ItemIsMovable, false );
00131   setZValue( 0 );
00132 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines