Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgssingleboxscalebarstyle.h 00003 ------------------ 00004 begin : June 2008 00005 copyright : (C) 2008 by Marco Hugentobler 00006 email : marco.hugentobler@karto.baug.ethz.ch 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include "qgssingleboxscalebarstyle.h" 00018 #include "qgscomposerscalebar.h" 00019 #include <QList> 00020 #include <QPainter> 00021 00022 QgsSingleBoxScaleBarStyle::QgsSingleBoxScaleBarStyle( const QgsComposerScaleBar* bar ): QgsScaleBarStyle( bar ) 00023 { 00024 00025 } 00026 00027 QgsSingleBoxScaleBarStyle::QgsSingleBoxScaleBarStyle(): QgsScaleBarStyle( 0 ) 00028 { 00029 00030 } 00031 00032 QgsSingleBoxScaleBarStyle::~QgsSingleBoxScaleBarStyle() 00033 { 00034 //nothing to do... 00035 } 00036 00037 void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const 00038 { 00039 if ( !mScaleBar ) 00040 { 00041 return; 00042 } 00043 double barTopPosition = mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace(); 00044 00045 p->save(); 00046 p->setPen( p->pen() ); 00047 00048 QList<QPair<double, double> > segmentInfo; 00049 mScaleBar->segmentPositions( segmentInfo ); 00050 00051 bool useColor = true; //alternate brush color/white 00052 00053 QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin(); 00054 for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) 00055 { 00056 if ( useColor ) //alternating colors 00057 { 00058 p->setBrush( mScaleBar->brush() ); 00059 } 00060 else //white 00061 { 00062 p->setBrush( QColor( 255, 255, 255 ) ); 00063 } 00064 00065 QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() ); 00066 p->drawRect( segmentRect ); 00067 useColor = !useColor; 00068 } 00069 00070 p->restore(); 00071 00072 //draw labels using the default method 00073 drawLabels( p ); 00074 } 00075 00076 QString QgsSingleBoxScaleBarStyle::name() const 00077 { 00078 return "Single Box"; 00079 } 00080