|
QGIS API Documentation
master-59fd5e0
|
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( mScaleBar->pen() ); 00047 00048 00049 QList<QPair<double, double> > segmentInfo; 00050 mScaleBar->segmentPositions( segmentInfo ); 00051 00052 bool useColor = true; //alternate brush color/white 00053 00054 QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin(); 00055 for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) 00056 { 00057 if ( useColor ) //alternating colors 00058 { 00059 p->setBrush( mScaleBar->brush() ); 00060 } 00061 else //white 00062 { 00063 p->setBrush( QColor( 255, 255, 255 ) ); 00064 } 00065 00066 QRectF segmentRect( segmentIt->first + xOffset, barTopPosition, segmentIt->second, mScaleBar->height() ); 00067 p->drawRect( segmentRect ); 00068 useColor = !useColor; 00069 } 00070 00071 p->restore(); 00072 00073 //draw labels using the default method 00074 drawLabels( p ); 00075 } 00076 00077 QString QgsSingleBoxScaleBarStyle::name() const 00078 { 00079 return "Single Box"; 00080 } 00081