QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 "qgscomposition.h"
20 #include <QPainter>
21 
23 {
24  initialize();
25 }
26 
27 QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false )
28 {
29  initialize();
30 }
31 
33 {
34  initialize();
35 }
36 
38 {
39 
40 }
41 
42 void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
43 {
44  Q_UNUSED( itemStyle );
45  Q_UNUSED( pWidget );
46  if ( !painter )
47  {
48  return;
49  }
50 
51  drawBackground( painter );
52 
53  //draw grid
54 
55  if ( mComposition )
56  {
59  {
60  int gridMultiplyX = ( int )( mComposition->snapGridOffsetX() / mComposition->snapGridResolution() );
61  int gridMultiplyY = ( int )( mComposition->snapGridOffsetY() / mComposition->snapGridResolution() );
62  double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution();
63  double currentYCoord;
64  double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();
65 
67  {
68  painter->setPen( mComposition->gridPen() );
69 
70  //draw vertical lines
71 
72 
73  for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
74  {
75  painter->drawLine( QPointF( currentXCoord, 0 ), QPointF( currentXCoord, rect().height() ) );
76  }
77 
78  //draw horizontal lines
79  currentYCoord = minYCoord;
80  for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
81  {
82  painter->drawLine( QPointF( 0, currentYCoord ), QPointF( rect().width(), currentYCoord ) );
83  }
84  }
85  else //'Dots' or 'Crosses'
86  {
87  QPen gridPen = mComposition->gridPen();
88  painter->setPen( gridPen );
89  painter->setBrush( QBrush( gridPen.color() ) );
90  double halfCrossLength = mComposition->snapGridResolution() / 6;
91 
92  for ( ; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution() )
93  {
94  currentYCoord = minYCoord;
95  for ( ; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution() )
96  {
98  {
99  QRectF pieRect( currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF() );
100  painter->drawChord( pieRect, 0, 5760 );
101  }
103  {
104  painter->drawLine( QPointF( currentXCoord - halfCrossLength, currentYCoord ), QPointF( currentXCoord + halfCrossLength, currentYCoord ) );
105  painter->drawLine( QPointF( currentXCoord, currentYCoord - halfCrossLength ), QPointF( currentXCoord, currentYCoord + halfCrossLength ) );
106  }
107  }
108  }
109  }
110  }
111  }
112 }
113 
114 bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const
115 {
116  Q_UNUSED( elem );
117  Q_UNUSED( doc );
118  return true;
119 }
120 
121 bool QgsPaperItem::readXML( const QDomElement& itemElem, const QDomDocument& doc )
122 {
123  Q_UNUSED( itemElem );
124  Q_UNUSED( doc );
125  return true;
126 }
127 
129 {
130  setFlag( QGraphicsItem::ItemIsSelectable, false );
131  setFlag( QGraphicsItem::ItemIsMovable, false );
132  setZValue( 0 );
133 }