Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 : marco.hugentobler@karto.baug.ethz.ch
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( p->pen() );
47 
48  QList<QPair<double, double> > segmentInfo;
49  mScaleBar->segmentPositions( segmentInfo );
50 
51  bool useColor = true; //alternate brush color/white
52 
53  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
54  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
55  {
56  if ( useColor ) //alternating colors
57  {
58  p->setBrush( mScaleBar->brush() );
59  }
60  else //white
61  {
62  p->setBrush( QColor( 255, 255, 255 ) );
63  }
64 
65  QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() );
66  p->drawRect( segmentRect );
67  useColor = !useColor;
68  }
69 
70  p->restore();
71 
72  //draw labels using the default method
73  drawLabels( p );
74 }
75 
77 {
78  return "Single Box";
79 }
80