QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 : 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 "qgscomposerutils.h"
20 #include <QList>
21 #include <QPainter>
22 
24 {
25 
26 }
27 
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 
63 
64  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
65  for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
66  {
67  //draw top half
68  if ( useColor )
69  {
70  p->setBrush( mScaleBar->brush() );
71  }
72  else //secondary color
73  {
74  p->setBrush( mScaleBar->brush2() );
75  }
76 
77  QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight );
78  p->drawRect( segmentRectTop );
79 
80  //draw bottom half
81  if ( useColor )
82  {
83  //secondary color
84  p->setBrush( mScaleBar->brush2() );
85  }
86  else //primary color
87  {
88  p->setBrush( mScaleBar->brush() );
89  }
90 
91  QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight );
92  p->drawRect( segmentRectBottom );
93  useColor = !useColor;
94  }
95 
96  p->restore();
97 
98  //draw labels using the default method
99  drawLabels( p );
100 }
A scale bar item that can be added to a map composition.
virtual void drawLabels(QPainter *p) const
double boxContentSpace() const
void segmentPositions(QList< QPair< double, double > > &posWidthList) const
Returns the x - positions of the segment borders (in item coordinates) and the width of the segment...
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
void draw(QPainter *p, double xOffset=0) const
Draws the style.
double labelBarSpace() const
Abstraction of composer scale bar style.
QPen pen() const
Returns the pen used for drawing the scalebar.
const QgsComposerScaleBar * mScaleBar
QBrush brush() const
Returns the primary brush for the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.