Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgspaperitem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspaperitem.cpp
3  -------------------
4  begin : September 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgspaperitem.h"
19 #include <QPainter>
20 
22 {
23  initialize();
24 }
25 
26 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false )
27 {
28  initialize();
29 }
30 
32 {
33  initialize();
34 }
35 
37 {
38 
39 }
40 
41 void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
42 {
43  if ( !painter )
44  {
45  return;
46  }
47 
48  drawBackground( painter );
49 
50  //draw grid
51 
52  if ( mComposition )
53  {
56  {
57  int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() );
58  int gridMultiplyY = ( int )( mComposition->snapGridOffsetY() / mComposition->snapGridResolution() );
59  double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution();
60  double currentYCoord;
61  double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();
62 
64  {
65  painter->setPen( mComposition->gridPen() );
66 
67  //draw vertical lines
68 
69 
70  for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
71  {
72  painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
73  }
74 
75  //draw horizontal lines
76  currentYCoord = minYCoord;
77  for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
78  {
79  painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) );
80  }
81  }
82  else //'Dots' or 'Crosses'
83  {
84  QPen gridPen = mComposition->gridPen();
85  painter->setPen( gridPen );
86  painter->setBrush( QBrush( gridPen.color() ) );
87  double halfCrossLength = mComposition->snapGridResolution() / 6;
88 
89  for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
90  {
91  currentYCoord = minYCoord;
92  for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
93  {
95  {
96  QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() );
97  painter->drawChord( pieRect, 0, 5760 );
98  }
100  {
101  painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
102  painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
103  }
104  }
105  }
106  }
107  }
108  }
109 }
110 
111 bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const
112 {
113  return true;
114 }
115 
116 bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc )
117 {
118  return true;
119 }
120 
122 {
123  setFlag( QGraphicsItem::ItemIsSelectable, false );
124  setFlag( QGraphicsItem::ItemIsMovable, false );
125  setZValue( 0 );
126 }