QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssingleboxscalebarstyle.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssingleboxscalebarstyle.h
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  //nothing to do...
35 }
36 
37 void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
38 {
39  if ( !mScaleBar )
40  {
41  return;
42  }
44 
45  p->save();
46  p->setPen( mScaleBar->pen() );
47 
48 
49  QList<QPair<double, double> > segmentInfo;
50  mScaleBar->segmentPositions( segmentInfo );
51 
52  bool useColor = true; //alternate brush color/white
53 
54  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
55  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
56  {
57  if ( useColor ) //alternating colors
58  {
59  p->setBrush( mScaleBar->brush() );
60  }
61  else //white
62  {
63  p->setBrush( QColor( 255, 255, 255 ) );
64  }
65 
66  QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() );
67  p->drawRect( segmentRect );
68  useColor = !useColor;
69  }
70 
71  p->restore();
72 
73  //draw labels using the default method
74  drawLabels( p );
75 }
76 
78 {
79  return "Single Box";
80 }
81