QGIS API Documentation  2.8.2-Wien
 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 "qgscomposerutils.h"
20 #include <QList>
21 #include <QPainter>
22 
24 {
25 
26 }
27 
28 QgsDoubleBoxScaleBarStyle::QgsDoubleBoxScaleBarStyle(): QgsScaleBarStyle( 0 )
29 {
30 
31 }
32 
34 {
35 
36 }
37 
39 {
40  return "Double Box";
41 }
42 
43 void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
44 {
45  if ( !mScaleBar )
46  {
47  return;
48  }
50  double segmentHeight = mScaleBar->height() / 2;
51 
52  p->save();
53  //antialiasing on
54  p->setRenderHint( QPainter::Antialiasing, true );
55  p->setPen( mScaleBar->pen() );
56 
57  QList<QPair<double, double> > segmentInfo;
58  mScaleBar->segmentPositions( segmentInfo );
59 
60  bool useColor = true; //alternate brush color/white
61 
62  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
63  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
64  {
65  //draw top half
66  if ( useColor )
67  {
68  p->setBrush( mScaleBar->brush() );
69  }
70  else //secondary color
71  {
72  p->setBrush( mScaleBar->brush2() );
73  }
74 
75  QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight );
76  p->drawRect( segmentRectTop );
77 
78  //draw bottom half
79  if ( useColor )
80  {
81  //secondary color
82  p->setBrush( mScaleBar->brush2() );
83  }
84  else //primary color
85  {
86  p->setBrush( mScaleBar->brush() );
87  }
88 
89  QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight );
90  p->drawRect( segmentRectBottom );
91  useColor = !useColor;
92  }
93 
94  p->restore();
95 
96  //draw labels using the default method
97  drawLabels( p );
98 }