QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdoubleboxscalebarstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdoubleboxscalebarstyle.cpp
3  -----------------------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
18 #include "qgscomposerscalebar.h"
19 #include <QList>
20 #include <QPainter>
21 
23 {
24 
25 }
26 
28 {
29 
30 }
31 
33 {
34 
35 }
36 
38 {
39  return "Double Box";
40 }
41 
42 void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
43 {
44  if ( !mScaleBar )
45  {
46  return;
47  }
49  double segmentHeight = mScaleBar->height() / 2;
50 
51  p->save();
52  p->setPen( mScaleBar->pen() );
53 
54  QList<QPair<double, double> > segmentInfo;
55  mScaleBar->segmentPositions( segmentInfo );
56 
57  bool useColor = true; //alternate brush color/white
58 
59 
60 
61  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
62  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
63  {
64  //draw top half
65  if ( useColor )
66  {
67  p->setBrush( mScaleBar->brush() );
68  }
69  else //white
70  {
71  p->setBrush( QColor( 255, 255, 255 ) );
72  }
73 
74  QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight );
75  p->drawRect( segmentRectTop );
76 
77  //draw bottom half
78  if ( useColor )
79  {
80  p->setBrush( QColor( 255, 255, 255 ) );
81  }
82  else //white
83  {
84  p->setBrush( mScaleBar->brush() );
85  }
86 
87  QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight );
88  p->drawRect( segmentRectBottom );
89  useColor = !useColor;
90  }
91 
92  p->restore();
93 
94  //draw labels using the default method
95  drawLabels( p );
96 }