[QGIS Commit] r8681 - in branches/advanced_printing_branch/src/app: . composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jun 28 09:07:36 EDT 2008


Author: mhugent
Date: 2008-06-28 09:07:36 -0400 (Sat, 28 Jun 2008)
New Revision: 8681

Added:
   branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp
   branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.h
   branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.cpp
   branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.h
   branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.cpp
   branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.h
Modified:
   branches/advanced_printing_branch/src/app/CMakeLists.txt
   branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
   branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
Log:
Delegate painting of scale bars to subclasses to make writing of new styles easier

Modified: branches/advanced_printing_branch/src/app/CMakeLists.txt
===================================================================
--- branches/advanced_printing_branch/src/app/CMakeLists.txt	2008-06-27 15:29:28 UTC (rev 8680)
+++ branches/advanced_printing_branch/src/app/CMakeLists.txt	2008-06-28 13:07:36 UTC (rev 8681)
@@ -65,6 +65,9 @@
   composer/qgscomposermapwidget.cpp
   composer/qgscomposerscalebar.cpp
   composer/qgscomposerscalebarwidget.cpp
+  composer/qgsscalebarstyle.cpp
+  composer/qgssingleboxscalebarstyle.cpp
+  composer/qgsticksmiddlescalebarstyle.cpp
   #composer/qgscomposervectorlegend.cpp
   composer/qgscomposerview.cpp
   composer/qgscomposition.cpp

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp	2008-06-27 15:29:28 UTC (rev 8680)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp	2008-06-28 13:07:36 UTC (rev 8681)
@@ -16,41 +16,33 @@
 
 #include "qgscomposerscalebar.h"
 #include "qgscomposermap.h"
+#include "qgsscalebarstyle.h"
+#include "qgssingleboxscalebarstyle.h"
+#include "qgsticksmiddlescalebarstyle.h"
 #include "qgsrect.h"
 #include <QFontMetricsF>
 #include <QPainter>
 #include <cmath>
 
-QgsComposerScaleBar::QgsComposerScaleBar(QgsComposition* composition): QgsComposerItem(composition), mComposerMap(0), mStyle(QgsComposerScaleBar::Single_Box), mSegmentMM(0.0)
+QgsComposerScaleBar::QgsComposerScaleBar(QgsComposition* composition): QgsComposerItem(composition), mComposerMap(0), mStyle(0), mSegmentMM(0.0)
 {
   applyDefaultSettings();
 }
 
 QgsComposerScaleBar::~QgsComposerScaleBar()
 {
-
+  delete mStyle;
 }
 
 void QgsComposerScaleBar::paint (QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget)
 {
-  //calculate top level of the bar
-  QFontMetricsF labelFontMetrics(mFont);
-  double barTopPosition = fontHeight() + mLabelBarSpace + mBoxContentSpace;
-
-  switch(mStyle)
+  if(!mStyle)
     {
-    case QgsComposerScaleBar::Single_Box:
-      drawScaleBarSingleBox(painter, barTopPosition);
-      break;
-    case QgsComposerScaleBar::Bar_Ticks_Middle:
-      drawScaleBarTicksMiddle(painter, barTopPosition);
-      break;
-    default:
-      break;
+      return;
     }
 
-  drawLabels(painter);
-
+  mStyle->draw(painter);
+  
   //draw frame and selection boxes if necessary
   drawFrame(painter);
   if(isSelected())
@@ -111,10 +103,12 @@
 
   mNumMapUnitsPerScaleBarUnit = 1.0;
 
+  //style
+  delete mStyle;
+  mStyle = new QgsSingleBoxScaleBarStyle(this);
+
   mHeight = 5;
 
-  mStyle = QgsComposerScaleBar::Single_Box;
-
   mPen = QPen(QColor(0, 0, 0));
   mPen.setWidthF(1.0);
 
@@ -142,154 +136,17 @@
   adjustBoxSize();
 }
 
-void QgsComposerScaleBar::drawLabels(QPainter* p)
+void QgsComposerScaleBar::adjustBoxSize()
 {
-  if(!p)
+  if(!mStyle)
     {
       return;
     }
-
-  p->save();
   
-  QFont labelFont(mFont);
-  labelFont.setPointSizeF(mFont.pointSizeF());
-
-  p->setFont(labelFont);
-
-  double mCurrentXCoord = mPen.widthF() + mBoxContentSpace;
-
-  //draw labels of the left segments
-  for(int i = 0; i < mNumSegmentsLeft; ++i)
-    {
-      mCurrentXCoord += mSegmentMM / mNumSegmentsLeft;
-    }
-
-  double currentLabelNumber = 0.0;
-
-  //draw labels of the right segments
-  for(int i = 0; i < mNumSegments; ++i)
-    {
-      p->drawText(QPointF(mCurrentXCoord, fontHeight() + mBoxContentSpace), QString::number(currentLabelNumber / mNumMapUnitsPerScaleBarUnit));
-      mCurrentXCoord += mSegmentMM;
-      currentLabelNumber += mNumUnitsPerSegment;
-    }
-  
-  p->drawText(QPointF(mCurrentXCoord, fontHeight() + mBoxContentSpace), QString::number(currentLabelNumber / mNumMapUnitsPerScaleBarUnit) + " " + mUnitLabeling);
-  p->restore();
+  QRectF box = mStyle->calculateBoxSize();
+  setSceneRect(box);
 }
 
-void QgsComposerScaleBar::drawScaleBarSingleBox(QPainter* p, double barTopPosition) const
-{
-  if(!p)
-    {
-      return;
-    }
-
-  p->save();
-
-  //mHeight, mBrush, mPen
-  p->setPen(mPen);
-
-  double mCurrentXCoord = mPen.widthF() + mBoxContentSpace;
-
-  bool useColor = true; //alternate brush color/white
-
-  //draw the left segments
-  for(int i = 0; i < mNumSegmentsLeft; ++i)
-    {
-      if(useColor) //alternating colors
-	{
-	  p->setBrush(mBrush);
-	}
-      else //white
-	{
-	  p->setBrush(QColor(255, 255, 255));
-	}
-      QRectF segmentRect(mCurrentXCoord, barTopPosition, mSegmentMM/mNumSegmentsLeft, mHeight);
-      p->drawRect(segmentRect);
-      mCurrentXCoord += mSegmentMM / mNumSegmentsLeft;
-      useColor = !useColor;
-    }
-  
-  //draw the right segments
-  for(int i = 0; i < mNumSegments; ++i)
-    {
-      if(useColor) //alternating colors
-	{
-	  p->setBrush(mBrush);
-	}
-      else //white
-	{
-	  p->setBrush(QColor(255, 255, 255));
-	}
-
-      QRectF segmentRect(mCurrentXCoord, barTopPosition, mSegmentMM, mHeight);
-      p->drawRect(segmentRect);
-      mCurrentXCoord += mSegmentMM;
-      useColor = !useColor;
-    }
-
-  p->restore();
-}
-
-void QgsComposerScaleBar::drawScaleBarTicksMiddle(QPainter* p, double barTopPosition) const
-{
-  if(!p)
-    {
-      return;
-    }
-  
-  p->save();
-
-  //mHeight, mBrush, mPen
-  p->setPen(mPen);
-
-  double mCurrentXCoord = mPen.widthF() + mBoxContentSpace;
-
-  //draw the left segments
-  for(int i = 0; i < mNumSegmentsLeft; ++i)
-    {
-      p->drawLine(mCurrentXCoord, barTopPosition, mCurrentXCoord, barTopPosition + mHeight);
-      p->drawLine(mCurrentXCoord, barTopPosition + mHeight/2, mCurrentXCoord + mSegmentMM / mNumSegmentsLeft, barTopPosition + mHeight/2);
-      mCurrentXCoord += mSegmentMM / mNumSegmentsLeft;
-    }
-
-  p->drawLine(mCurrentXCoord, barTopPosition, mCurrentXCoord, barTopPosition + mHeight);
-  
-  //draw the right segments
-  for(int i = 0; i < mNumSegments; ++i)
-    {
-      p->drawLine(mCurrentXCoord, barTopPosition, mCurrentXCoord, barTopPosition + mHeight);
-      p->drawLine(mCurrentXCoord, barTopPosition + mHeight/2.0, mCurrentXCoord + mSegmentMM, barTopPosition + mHeight/2.0);
-      mCurrentXCoord += mSegmentMM;
-    }
-
-  p->drawLine(mCurrentXCoord, barTopPosition, mCurrentXCoord, barTopPosition + mHeight);
-  p->restore();
-}
-
-void QgsComposerScaleBar::adjustBoxSize()
-{
-  int numFullSegments = mNumSegments;
-  if(mNumSegmentsLeft > 0)
-    {
-      ++numFullSegments;
-    }
-
-  //consider width of largest label
-  double largestLabelNumber = mNumSegments * mNumUnitsPerSegment / mNumMapUnitsPerScaleBarUnit;
-  QString largestLabel = QString::number(largestLabelNumber) + " " + mUnitLabeling;
-  double largestLabelWidth = QFontMetricsF(mFont).width(largestLabel);
-
-  double width = numFullSegments * mSegmentMM + 2 * mPen.widthF() + largestLabelWidth + 2 * mBoxContentSpace;
-  double height = mHeight + mLabelBarSpace + 2 * mBoxContentSpace + QFontMetrics(mFont).height();
-
-  
-
-  QRectF sceneBox(transform().dx(), transform().dy(), width, height);
-  setSceneRect(sceneBox);
-}
-
 void QgsComposerScaleBar::update()
 {
   adjustBoxSize();
@@ -308,569 +165,40 @@
   update();
 }
 
-
-#if 0
-#include "qgscomposerscalebar.h"
-#include "qgscomposermap.h"
-#include "qgsproject.h"
-
-#include <QFontDialog>
-#include <QPainter>
-#include <QGraphicsScene>
-
-#include <cmath>
-#include <iostream>
-
-//can we/should we remove the x and y parameters?
-QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id, 
-	                                            int x, int y )
-    : QWidget(composition),
-    QgsComposerItem(0),
-    mComposition(composition),
-    mMap(0),
-    mBrush(QColor(150,150,150))
+void QgsComposerScaleBar::segmentPositions(QList<QPair<double, double> >& posWidthList) const
 {
-  setupUi(this);
-
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
-#endif
-
-  mId = id;
-  setSelected(false);
-
-  mMapCanvas = mComposition->mapCanvas();
-
-  QGraphicsRectItem::setPos(x, y);
-
-  init();
-
-  // Set map to the first available if any
-  std::vector < QgsComposerMap * >maps = mComposition->maps();
-  if (maps.size() > 0)
+  posWidthList.clear();
+  double mCurrentXCoord = mPen.widthF() + mBoxContentSpace;
+  
+  //left segments
+  for(int i = 0; i < mNumSegmentsLeft; ++i)
     {
-      mMap = maps[0]->id();
+      posWidthList.push_back(qMakePair(mCurrentXCoord, mSegmentMM / mNumSegmentsLeft));
+      mCurrentXCoord += mSegmentMM / mNumSegmentsLeft;
     }
-  // Set default according to the map
-  QgsComposerMap *map = mComposition->map(mMap);
-  if (map)
-    {
-      mMapUnitsPerUnit = 1.;
-      mUnitLabel = "m";
 
-      // make one segment cca 1/10 of map width and it will be 1xxx, 2xxx or 5xxx
-      double mapwidth = 1. * map->QGraphicsRectItem::rect().width() / map->scale();
-
-      mSegmentLength = mapwidth / 10;
-
-      int powerOf10 = int (pow(10.0, int (log(mSegmentLength) / log(10.0)))); // from scalebar plugin
-
-      int isize = (int) ceil(mSegmentLength / powerOf10);
-
-      if (isize == 3)
-        isize = 2;
-      else if (isize == 4)
-        isize = 5;
-      else if (isize > 5 && isize < 8)
-        isize = 5;
-      else if (isize > 7)
-        isize = 10;
-
-      mSegmentLength = isize * powerOf10;
-
-      // the scale bar will take cca 1/4 of the map width
-      // But always have at least one segment.
-      mNumSegments = std::max(1, (int) (mapwidth / 4 / mSegmentLength));
-
-      int segsize = (int) (mSegmentLength * map->scale());
-
-      int fontsize = segsize / 3;
-
-      if(fontsize < 6)
-      {
-        fontsize = 6;
-      }
-
-      mFont.setPointSize(fontsize);
-  } else
+  //right segments
+  for(int i = 0; i < mNumSegments; ++i)
     {
-      mFont.setPointSize(6);
-      mMapUnitsPerUnit = 1.;
-      mUnitLabel = "m";
-      mSegmentLength = 1000.;
-      mNumSegments = 5;
+      posWidthList.push_back(qMakePair(mCurrentXCoord, mSegmentMM));
+      mCurrentXCoord += mSegmentMM;
     }
-
-  // Calc size
-  recalculate();
-
-  // Add to scene
-  mComposition->canvas()->addItem(this);
-
-  QGraphicsRectItem::show();
-  QGraphicsRectItem::update();
-
-  writeSettings();
 }
 
-QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id ) 
-    : QgsComposerItem(0),
-    mComposition(composition),
-    mMap(0),
-    mBrush(QColor(150,150,150))
+void QgsComposerScaleBar::setStyle(const QString& styleName)
 {
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
-#endif
+  delete mStyle;
+  mStyle = 0;
 
-  setupUi(this);
-
-  mId = id;
-  setSelected(false);
-
-  mMapCanvas = mComposition->mapCanvas();
-
-  init();
-
-  readSettings();
-
-  // Calc size
-  recalculate();
-
-  // Add to scene
-  mComposition->canvas()->addItem(this);
-
-  QGraphicsRectItem::show();
-  QGraphicsRectItem::update();
-}
-
-void QgsComposerScalebar::init(void)
-{
-  mUnitLabel = "m";
-
-  // Rectangle
-  QGraphicsRectItem::setZValue(50);
-//    setActive(true);
-
-  // Default value (map units?) for the scalebar border
-  mPen.setWidthF(.5);
-
-  // Plot style
-  setPlotStyle(QgsComposition::Preview);
-
-  connect(mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)));
-}
-
-QgsComposerScalebar::~QgsComposerScalebar()
-{
-  std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
-  QGraphicsRectItem::hide();
-}
-
-#define FONT_WORKAROUND_SCALE 10
-QRectF QgsComposerScalebar::render(QPainter * p)
-{
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::render() "<< std::endl;
-#endif
-
-  // Painter can be 0, create dummy to avoid many if below
-  QPainter *painter;
-  QPixmap *pixmap=NULL;
-  if (p)
-  {
-      painter = p;
-  }else
-  {
-    pixmap = new QPixmap(1, 1);
-    painter = new QPainter(pixmap);
-  }
-#ifdef QGISDEBUG
-  std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
-#endif
-
-  QgsComposerMap *map = mComposition->map(mMap); //Get the topmost map from the composition
-
-  double segwidth;
-  if(map)
-  {
-    segwidth = (mSegmentLength * map->scale());  //width of one segment
-  }
-  else //if there is no map, make up a segment width
-  {
-    segwidth = mSegmentLength/100;
-  }
-  double width = (segwidth * mNumSegments); //width of whole scalebar
-  double barLx = -width / 2; //x offset to the left
-
-  double barHeight = (25.4 * mComposition->scale() * mFont.pointSize() / 72);
-
-  double tickSize = barHeight * 1.5; //ticks go from the base of the bar to 1/2 the bar's height above it
-
-  // Draw background rectangle
-  painter->setPen(QPen(QColor(255, 255, 255), 0));
-  painter->setBrush(QBrush(QColor(255, 255, 255), Qt::SolidPattern));
-  painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
-
-  // set the painter to have grey background and black border
-  painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
-  painter->setBrush(QBrush(QColor(127, 127, 127)));//default to solid brush
-
-  // fill every other segment with grey
-  for (int i = 0; i < mNumSegments; i += 2)
-  {
-    painter->drawRect(QRectF(barLx + ((double)i * segwidth), -barHeight, segwidth, barHeight));
-  }
-
-  // draw a box around the all of the segments
-  painter->setBrush(Qt::NoBrush);
-  painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
-
-  // set up the pen to draw the tick marks
-  painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
-
-  // draw the tick marks
-  for (int i = 0; i <= mNumSegments; i++)
-  {
-    painter->drawLine(QLineF(barLx + ((double)i * segwidth), 0, barLx + (i * segwidth), -tickSize));
-  }
-
-
-  // labels
-
-  // Font size in canvas units
-  float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
-
-
-  // Create QFontMetrics so we can correctly place the text
-  QFont font(mFont);
-  font.setPointSizeFloat(size);
-  QFontMetrics metrics(font);
-
-  font.setPointSizeFloat(size * FONT_WORKAROUND_SCALE); //hack to work around Qt font bug
-
-  if (plotStyle() == QgsComposition::Postscript)
-  {
-    font.setPointSizeF(metrics.ascent() * 72.0 / mComposition->resolution() * FONT_WORKAROUND_SCALE);
-  }
-
-  painter->setFont(font);
-
-  // Not sure about Style Strategy, QFont::PreferMatch?
-  font.setStyleStrategy((QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias));
-
-  double offset = .5 * tickSize; //vertical offset above the top of the tick marks
-  double textRightOverhang=0;//amount the label text hangs over the right edge of the scalebar - used for the bounding box
-
-  for (int i = 0; i <= mNumSegments; i++)
-  {
-    int lab = (int) ((double)i * mSegmentLength / mMapUnitsPerUnit);
-
-    QString txt = QString::number(lab);
-    double shift = (double)metrics.width(txt) / 2;
-
-    if (i == mNumSegments) //on the last label, append the appropriate unit symbol
+  //switch depending on style name
+  if(styleName == tr("Single Box"))
     {
-      txt.append(" " + mUnitLabel);
-      textRightOverhang = (double)metrics.width(txt) - shift;
+      mStyle = new QgsSingleBoxScaleBarStyle(this);
     }
-
-    double x = barLx + (i * segwidth) - shift; //figure out the bottom left corner and draw the text
-    double y = -tickSize - offset - metrics.descent();
-
-    painter->save();
-    painter->scale(1./FONT_WORKAROUND_SCALE, 1./FONT_WORKAROUND_SCALE);
-    painter->drawText(QPointF(x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE), txt);
-    painter->restore();
-
-  }//end of label drawing
-
-  double totalHeight = tickSize + offset + metrics.height();
-
-  if (!p)
+  else if(styleName == tr("Bar Ticks Middle"))
     {
-      delete painter;
-      delete pixmap;
+      mStyle = new QgsTicksMiddleScaleBarStyle(this);
     }
-
-//Add the 1/2 the pen width to get the full bounding box
-return QRectF(barLx - (mPen.widthF()/2), -totalHeight, width + textRightOverhang, totalHeight + (mPen.widthF()/2));
 }
 
-void QgsComposerScalebar::paint(QPainter * painter, const QStyleOptionGraphicsItem * itemStyle, QWidget * pWidget)
-{
-#ifdef QGISDEBUG
-  std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
-#endif
-  setRect(render(painter));
 
-  // Show selected / Highlight
-  if (isSelected() && plotStyle() == QgsComposition::Preview)
-    {
-      painter->setPen(mComposition->selectionPen());
-      painter->setBrush(mComposition->selectionBrush());
-
-      double s = mComposition->selectionBoxSize();
-      QRectF r = boundingRect();
-
-      painter->drawRect(QRectF(r.x(), r.y(), s, s));
-      painter->drawRect(QRectF(r.x() + r.width() - s, r.y(), s, s));
-      painter->drawRect(QRectF(r.x() + r.width() - s, r.y() + r.height() - s, s, s));
-      painter->drawRect(QRectF(r.x(), r.y() + r.height() - s, s, s));
-    }
-}
-
-/*
-void QgsComposerScalebar::drawShape ( QPainter & painter )
-{
-    paint ( painter );
-}
-*/
-void QgsComposerScalebar::on_mFontButton_clicked(void)
-{
-  bool result;
-
-  mFont = QFontDialog::getFont(&result, mFont, this);
-
-  if (result)
-    {
-      recalculate();
-      QGraphicsRectItem::update();
-      QGraphicsRectItem::scene()->update();
-      writeSettings();
-    }
-}
-
-void QgsComposerScalebar::on_mUnitLabelLineEdit_editingFinished()
-{
-  mUnitLabel = mUnitLabelLineEdit->text();
-  recalculate();
-  QGraphicsRectItem::update();
-  QGraphicsRectItem::scene()->update();
-  writeSettings();
-}
-
-void QgsComposerScalebar::on_mMapComboBox_activated(int i)
-{
-  mMap = mMaps[i];
-  recalculate();
-  QGraphicsRectItem::update();
-  QGraphicsRectItem::scene()->update();
-  writeSettings();
-}
-
-void QgsComposerScalebar::mapChanged(int id)
-{
-  if (id != mMap)
-    return;
-  recalculate();
-  QGraphicsRectItem::update();
-  QGraphicsRectItem::scene()->update();
-}
-
-void QgsComposerScalebar::sizeChanged()
-{
-  mSegmentLength = mSegmentLengthLineEdit->text().toDouble();
-  mNumSegments = mNumSegmentsLineEdit->text().toInt();
-  mPen.setWidthF(mLineWidthSpinBox->value());
-  mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
-  recalculate();
-  QGraphicsRectItem::update();
-  QGraphicsRectItem::scene()->update();
-  writeSettings();
-}
-
-void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged()
-{
-  sizeChanged();
-}
-
-void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_editingFinished()
-{
-  sizeChanged();
-}
-
-void QgsComposerScalebar::on_mNumSegmentsLineEdit_editingFinished()
-{
-  sizeChanged();
-}
-
-void QgsComposerScalebar::on_mSegmentLengthLineEdit_editingFinished()
-{
-  sizeChanged();
-}
-/*
-void QgsComposerScalebar::moveBy(double x, double y)
-{
-  std::cout << "QgsComposerScalebar::move" << std::endl;
-  QGraphicsItem::moveBy(x, y);
-
-  recalculate();
-  //writeSettings(); // not necessary called by composition
-}*/
-
-void QgsComposerScalebar::recalculate(void)
-{
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::recalculate" << std::endl;
-#endif
-
-  // !!! prepareGeometryChange() MUST BE called before the value returned by areaPoints() changes
-  //Is this still true after the port to GraphicsView?
-  QGraphicsRectItem::prepareGeometryChange();
-
-  setRect(render(0));
-
-  QGraphicsItem::update();
-}
-
-QPolygonF QgsComposerScalebar::areaPoints(void) const
-{
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
-#endif
-
-  QRectF r = QGraphicsRectItem::rect();
-  QPolygonF pa;
-  pa << QPointF(r.x(), r.y());
-  pa << QPointF(r.x() + r.width(), r.y());
-  pa << QPointF(r.x() + r.width(), r.y() + r.height());
-  pa << QPointF(r.x(), r.y() + r.height());
-  return pa;
-}
-
-void QgsComposerScalebar::setOptions(void)
-{
-  mSegmentLengthLineEdit->setText(QString::number(mSegmentLength));
-  mNumSegmentsLineEdit->setText(QString::number(mNumSegments));
-  mUnitLabelLineEdit->setText(mUnitLabel);
-  mMapUnitsPerUnitLineEdit->setText(QString::number(mMapUnitsPerUnit));
-
-  mLineWidthSpinBox->setValue(mPen.widthF());
-
-  // Maps
-  mMapComboBox->clear();
-  std::vector < QgsComposerMap * >maps = mComposition->maps();
-
-  mMaps.clear();
-
-  bool found = false;
-  mMapComboBox->insertItem("", 0);
-  mMaps.push_back(0);
-  for (int i = 0; i < (int)maps.size(); i++)
-    {
-      mMapComboBox->insertItem(maps[i]->name(), i + 1);
-      mMaps.push_back(maps[i]->id());
-
-      if (maps[i]->id() == mMap)
-        {
-          found = true;
-          mMapComboBox->setCurrentItem(i + 1);
-        }
-    }
-
-  if (!found)
-    {
-      mMap = 0;
-      mMapComboBox->setCurrentItem(0);
-    }
-}
-
-void QgsComposerScalebar::setSelected(bool s)
-{
-  setSelected(s);
-  QGraphicsRectItem::update(); // show highlight
-}
-
-bool QgsComposerScalebar::selected(void)
-{
-  return isSelected();
-}
-
-QWidget *QgsComposerScalebar::options(void)
-{
-  setOptions();
-  return (dynamic_cast < QWidget * >(this));
-}
-
-bool QgsComposerScalebar::writeSettings(void)
-{
-#ifdef QGISDEBUG
-  std::cout << "QgsComposerScalebar::writeSettings" << std::endl;
-#endif
-
-  QString path;
-  path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
-
-  QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QGraphicsRectItem::x()));
-  QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QGraphicsRectItem::y()));
-
-  QgsProject::instance()->writeEntry("Compositions", path + "map", mMap);
-
-  QgsProject::instance()->writeEntry("Compositions", path + "unit/label", mUnitLabel);
-  QgsProject::instance()->writeEntry("Compositions", path + "unit/mapunits", mMapUnitsPerUnit);
-
-  QgsProject::instance()->writeEntry("Compositions", path + "segmentsize", mSegmentLength);
-  QgsProject::instance()->writeEntry("Compositions", path + "numsegments", mNumSegments);
-
-  QgsProject::instance()->writeEntry("Compositions", path + "font/size", mFont.pointSize());
-  QgsProject::instance()->writeEntry("Compositions", path + "font/family", mFont.family());
-  QgsProject::instance()->writeEntry("Compositions", path + "font/weight", mFont.weight());
-  QgsProject::instance()->writeEntry("Compositions", path + "font/underline", mFont.underline());
-  QgsProject::instance()->writeEntry("Compositions", path + "font/strikeout", mFont.strikeOut());
-
-  QgsProject::instance()->writeEntry("Compositions", path + "pen/width", (double) mPen.widthF());
-
-  return true;
-}
-
-bool QgsComposerScalebar::readSettings(void)
-{
-  bool ok;
-  QString path;
-  path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
-
-  double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "x", 0, &ok));
-  double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "y", 0, &ok));
-  QGraphicsRectItem::setPos(x, y);
-
-  mMap = QgsProject::instance()->readNumEntry("Compositions", path + "map", 0, &ok);
-  mUnitLabel = QgsProject::instance()->readEntry("Compositions", path + "unit/label", "???", &ok);
-  mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path + "unit/mapunits", 1., &ok);
-
-  mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path + "segmentsize", 1000., &ok);
-  mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path + "numsegments", 5, &ok);
-
-  mFont.setFamily(QgsProject::instance()->readEntry("Compositions", path + "font/family", "", &ok));
-  mFont.setPointSize(QgsProject::instance()->readNumEntry("Compositions", path + "font/size", 10, &ok));
-  mFont.setWeight(QgsProject::instance()->readNumEntry("Compositions", path + "font/weight", (int) QFont::Normal, &ok));
-  mFont.setUnderline(QgsProject::instance()->readBoolEntry("Compositions", path + "font/underline", false, &ok));
-  mFont.setStrikeOut(QgsProject::instance()->readBoolEntry("Compositions", path + "font/strikeout", false, &ok));
-
-  mPen.setWidthF(QgsProject::instance()->readDoubleEntry("Compositions", path + "pen/width", 1, &ok));
-
-  recalculate();
-
-  return true;
-}
-
-bool QgsComposerScalebar::removeSettings(void)
-{
-  std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl;
-
-  QString path;
-  path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId);
-  return QgsProject::instance()->removeEntry("Compositions", path);
-}
-
-bool QgsComposerScalebar::writeXML(QDomNode & node, QDomDocument & document, bool temp)
-{
-  return true;
-}
-
-bool QgsComposerScalebar::readXML(QDomNode & node)
-{
-  return true;
-}
-
-#endif //0

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h	2008-06-27 15:29:28 UTC (rev 8680)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h	2008-06-28 13:07:36 UTC (rev 8681)
@@ -21,6 +21,7 @@
 #include <QPen>
 
 class QgsComposerMap;
+class QgsScaleBarStyle;
 
 class QgsComposerScaleBar: public QObject, public QgsComposerItem
 {
@@ -29,15 +30,6 @@
  
 public:
 
-  enum Style
-    {
-      Bar_Ticks_Down,
-      Bar_Ticks_Middle,
-      Bar_Ticks_Up,
-      Single_Box,
-      Double_Box,
-    };
-
   QgsComposerScaleBar(QgsComposition* composition);
   ~QgsComposerScaleBar();
 
@@ -81,11 +73,22 @@
   double boxContentSpace() const {return mBoxContentSpace;}
   void setBoxContentSpace(double space){mBoxContentSpace = space;}
 
+  double segmentMM() const {return mSegmentMM;}
+
   /**Apply default settings (scale bar 1/5 of map item width)*/
   void applyDefaultSettings();
 
-  void setStyle(QgsComposerScaleBar::Style style){mStyle = style;}
+  /**Sets style by name
+   possibilities are: */
+  void setStyle(const QString& styleName);
 
+  /**Returns the x - positions of the segment borders (in item coordinates) and the width 
+   of the segment*/
+  void segmentPositions(QList<QPair<double, double> >& posWidthList) const; 
+
+  /**Returns height of mFont in points*/
+  double fontHeight() const;
+
   /**Sets box size suitable to content*/
   void adjustBoxSize();
 
@@ -121,7 +124,7 @@
   /**Height of bars/lines*/
   double mHeight;
   /**Scalebar style*/
-  QgsComposerScaleBar::Style mStyle;
+  QgsScaleBarStyle* mStyle;
   
   /**Space between bar and Text labels*/
   double mLabelBarSpace;
@@ -134,155 +137,8 @@
 
   /**Calculates with of a segment in mm and stores it in mSegmentMM*/
   void refreshSegmentMM();
-  
-  /**Draw text labels using the current font*/
-  void drawLabels(QPainter* p);
-
-  /**Draws this bar using single box style
-   @param barTopPosition Item coordinates of the bar top. Necessary because of Labels*/
-  void drawScaleBarSingleBox(QPainter* p, double barTopPosition) const;
-
-  void drawScaleBarTicksMiddle(QPainter* p, double barTopPosition) const;
-
-  /**Returns height of font considering font scale factor for the given painter*/
-  double fontHeight() const;
 };
 
 #endif //QGSCOMPOSERSCALEBAR_H
 
-#if 0
 
-#include "ui_qgscomposerscalebarbase.h"
-#include "qgscomposeritem.h"
-#include <QAbstractGraphicsShapeItem>
-#include <QRect>
-#include <QPen>
-
-class QgsMapCanvas;
-class QgsComposition;
-class QBrush;
-class QDomNode;
-class QDomDocument;
-class QFont;
-class QPainter;
-class QPen;
-
-/** \class QgsComposerScalebar
- *  \brief Object representing map window. 
- */
-// NOTE: QgsComposerScalebarBase must be first, otherwise does not compile
-class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public QgsComposerItem
-{
-    Q_OBJECT
-
-public:
-    /** \brief Constructor  
-     *  \param id object id
-     *  \param fontSize font size in typographic points!
-     */
-    QgsComposerScalebar( QgsComposition *composition, int id, int x, int y );
-
-    /** \brief Constructor. Settings are read from project. 
-     *  \param id object id
-     */
-    QgsComposerScalebar( QgsComposition *composition, int id );
-    ~QgsComposerScalebar();
-
-    /** \brief Initialise GUI etc., shared by constructors. */
-    void init(void);
-
-    // Reimplement QgsComposerItem:
-    void setSelected( bool s );
-    bool selected( void );
-    QWidget *options ( void );
-    bool writeSettings ( void );
-    bool readSettings ( void );
-    bool removeSettings ( void );
-    bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
-    bool readXML( QDomNode & node );
-     
-    /** \brief Draw to paint device, internal use 
-     *  \param painter painter or 0
-     *  \return bounding box 
-     */
-    QRectF render (QPainter *painter);
-
-    /** \brief Reimplementation of QGraphicsItem::paint - draw on canvas */
-    void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
-
-    //void drawShape(QPainter&);
-    QPolygonF areaPoints() const;
-    
-    /** \brief Calculate size according to current settings */
-    void recalculate ( void );
-    
-    /** \brief Set values in GUI to current values */
-    void setOptions ( void );
-
-    // Move to position
-//    void moveBy ( double x, double y );
-
-public slots:
-    // Open font dialog
-    void on_mFontButton_clicked ( void );
-
-    // Title changed
-    void on_mUnitLabelLineEdit_editingFinished ( void );
-
-    // Size changed
-    void on_mLineWidthSpinBox_valueChanged ( void );
-    void on_mMapUnitsPerUnitLineEdit_editingFinished ( void );
-    void on_mNumSegmentsLineEdit_editingFinished ( void );
-    void on_mSegmentLengthLineEdit_editingFinished ( void );
-    
-    // Called by GUI when map selection changed
-    void on_mMapComboBox_activated ( int i );
-
-    // Called when map was changed
-    void mapChanged ( int id );
-
-private:
-    // Pointer to composition
-    QgsComposition *mComposition;
-    
-    // Pointer to map canvas
-    QgsMapCanvas *mMapCanvas;
-    
-    // Composer map id or 0
-    int mMap;
-
-    // Vector of map id for maps in combobox
-    std::vector<int> mMaps;
-
-    // Number of map units in scalebar unit
-    double mMapUnitsPerUnit;
-
-    // Unit label
-    QString mUnitLabel;
-
-    // Font. Font size in typographic points!
-    QFont mFont;
-
-    // Pen
-    QPen mPen;
-
-    // Brush
-    QBrush mBrush;
-
-    // Number of parts 
-    int mNumSegments;
-
-    // Segment size in map units
-    double mSegmentLength;
-
-    // Height of scalebar box in canvas units (box style only)
-    double mHeight;
-
-    // Margin
-    int mMargin;
-
-    // Size changed
-    void sizeChanged ( void );
-};
-
-#endif //0

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp	2008-06-27 15:29:28 UTC (rev 8680)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp	2008-06-28 13:07:36 UTC (rev 8681)
@@ -25,8 +25,8 @@
 {
   setupUi(this);
 
-  mStyleComboBox->insertItem(0, tr("Single_Box"));
-  mStyleComboBox->insertItem(1, tr("Bar_Ticks_Middle"));
+  mStyleComboBox->insertItem(0, tr("Single Box"));
+  mStyleComboBox->insertItem(1, tr("Bar Ticks Middle"));
 
   setGuiElements(); //set the GUI elements to the state of scaleBar
 }
@@ -300,15 +300,7 @@
       return;
     }
 
-  if(text == tr("Single_Box"))
-    {
-      mComposerScaleBar->setStyle(QgsComposerScaleBar::Single_Box);
-    }
-
-  else if(text == tr("Bar_Ticks_Middle"))
-    {
-      mComposerScaleBar->setStyle(QgsComposerScaleBar::Bar_Ticks_Middle);
-    }
+  mComposerScaleBar->setStyle(text);
   mComposerScaleBar->update();
 }
 

Added: branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,111 @@
+/***************************************************************************
+                            qgsscalebarstyle.cpp
+                            --------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsscalebarstyle.h"
+#include "qgscomposerscalebar.h"
+#include <QFontMetricsF>
+#include <QPainter>
+
+QgsScaleBarStyle::QgsScaleBarStyle(const QgsComposerScaleBar* bar):  mScaleBar(bar)
+{
+
+}
+
+QgsScaleBarStyle::QgsScaleBarStyle(): mScaleBar(0)
+{
+
+}
+ 
+QgsScaleBarStyle::~QgsScaleBarStyle()
+{
+
+}
+
+void QgsScaleBarStyle::drawLabels(QPainter* p) const
+{
+  if(!p || !mScaleBar)
+    {
+      return;
+    }
+
+  p->save();
+
+  p->setFont(mScaleBar->font());
+
+  //double mCurrentXCoord = mScaleBar->pen().widthF() + mScaleBar->boxContentSpace();
+  QList<QPair<double, double> > segmentInfo;
+  mScaleBar->segmentPositions(segmentInfo);
+
+  double currentLabelNumber = 0.0;
+
+  int nSegmentsLeft = mScaleBar->numSegmentsLeft();
+  int segmentCounter = 0;
+
+  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
+  for(; segmentIt != segmentInfo.constEnd(); ++segmentIt)
+    {
+      if(segmentCounter == 0 && nSegmentsLeft > 0)
+	{
+	  //label first left segment
+	  p->drawText(QPointF(segmentIt->first, mScaleBar->fontHeight() + mScaleBar->boxContentSpace()), QString::number(mScaleBar->numUnitsPerSegment() / mScaleBar->numMapUnitsPerScaleBarUnit()));
+	}
+
+      if(segmentCounter >= nSegmentsLeft)
+	{
+	  p->drawText(QPointF(segmentIt->first, mScaleBar->fontHeight() + mScaleBar->boxContentSpace()), QString::number(currentLabelNumber / mScaleBar->numMapUnitsPerScaleBarUnit()));
+	  currentLabelNumber += mScaleBar->numUnitsPerSegment();
+	}
+      ++segmentCounter;
+    }
+
+  //also draw the last label
+  if(!segmentInfo.isEmpty())
+    {
+      p->drawText(QPointF(segmentInfo.last().first + mScaleBar->segmentMM(), mScaleBar->fontHeight() + mScaleBar->boxContentSpace()), QString::number(currentLabelNumber / mScaleBar->numMapUnitsPerScaleBarUnit()) + " " + mScaleBar->unitLabeling()); 
+    }
+
+  p->restore();
+}
+
+QRectF QgsScaleBarStyle::calculateBoxSize() const
+{
+  if(!mScaleBar)
+    {
+      return QRectF();
+    }
+
+  //consider width of largest label
+  double largestLabelNumber = mScaleBar->numSegments() * mScaleBar->numUnitsPerSegment() / mScaleBar->numMapUnitsPerScaleBarUnit();
+  QString largestLabel = QString::number(largestLabelNumber) + " " + mScaleBar->unitLabeling();
+  double largestLabelWidth = QFontMetricsF(mScaleBar->font()).width(largestLabel);
+
+  //add all the segment length
+  double totalBarLength = 0;
+  
+  QList< QPair<double, double> > segmentList;
+  mScaleBar->segmentPositions(segmentList);
+
+  QList< QPair<double, double> >::const_iterator segmentIt = segmentList.constBegin();
+  for(; segmentIt != segmentList.constEnd(); ++segmentIt)
+    {
+      totalBarLength += segmentIt->second;
+    }
+
+  double width =  totalBarLength + 2 * mScaleBar->pen().widthF() + largestLabelWidth + 2 * mScaleBar->boxContentSpace();
+  double height = mScaleBar->height() + mScaleBar->labelBarSpace() + 2 * mScaleBar->boxContentSpace() + mScaleBar->fontHeight();
+
+  return QRectF(mScaleBar->transform().dx(), mScaleBar->transform().dy(), width, height);
+}

Added: branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.h	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.h	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,47 @@
+/***************************************************************************
+                            qgsscalebarstyle.h
+                            ------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSSCALEBARSTYLE_H
+#define QGSSCALEBARSTYLE_H
+
+#include <QIcon>
+#include <QRectF>
+
+class QgsComposerScaleBar;
+class QPainter;
+
+/**Abstraction of composer scale bar style. Subclasses draw themselves, have the 
+possibility to implement custom labeling and calculate corresponding box size*/
+class QgsScaleBarStyle
+{
+ public:
+  QgsScaleBarStyle(const QgsComposerScaleBar* bar);
+  virtual ~QgsScaleBarStyle();
+
+  virtual void draw(QPainter* p) const = 0; //to do by every subclass
+  virtual void drawLabels(QPainter* p) const; //default implementation provided
+  virtual QRectF calculateBoxSize() const; //default implementation provided
+  virtual QString name() const = 0; //return name of the style
+  //virtual QIcon styleIcon() const = 0;
+
+ private:
+  QgsScaleBarStyle(); //default constructor forbidden
+
+ protected:
+  const QgsComposerScaleBar* mScaleBar;
+};
+
+#endif

Added: branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.cpp	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.cpp	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,80 @@
+/***************************************************************************
+                            qgssingleboxscalebarstyle.h
+                            ------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgssingleboxscalebarstyle.h"
+#include "qgscomposerscalebar.h"
+#include <QList>
+#include <QPainter>
+
+QgsSingleBoxScaleBarStyle::QgsSingleBoxScaleBarStyle(const QgsComposerScaleBar* bar): QgsScaleBarStyle(bar)
+{
+
+}
+
+QgsSingleBoxScaleBarStyle::QgsSingleBoxScaleBarStyle(): QgsScaleBarStyle(0)
+{
+
+}
+
+QgsSingleBoxScaleBarStyle::~QgsSingleBoxScaleBarStyle()
+{
+  //nothing to do...
+}
+
+void QgsSingleBoxScaleBarStyle::draw(QPainter* p) const
+{
+  if(!mScaleBar)
+    {
+      return;
+    }
+  double barTopPosition = mScaleBar->fontHeight() + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
+
+  p->save();
+  p->setPen(p->pen());
+
+  QList<QPair<double, double> > segmentInfo;
+  mScaleBar->segmentPositions(segmentInfo);
+  
+  bool useColor = true; //alternate brush color/white
+
+  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
+  for(; segmentIt != segmentInfo.constEnd(); ++segmentIt)
+    {
+      if(useColor) //alternating colors
+	{
+	  p->setBrush(mScaleBar->brush());
+	}
+      else //white
+	{
+	  p->setBrush(QColor(255, 255, 255));
+	}
+
+      QRectF segmentRect(segmentIt->first, barTopPosition, segmentIt->second, mScaleBar->height());
+      p->drawRect(segmentRect);
+      useColor = !useColor;
+    }
+
+  p->restore();
+
+  //draw labels using the default method
+  drawLabels(p);
+}
+
+QString QgsSingleBoxScaleBarStyle::name() const
+{
+  return "Single Box";
+}
+

Added: branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.h	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgssingleboxscalebarstyle.h	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,38 @@
+/***************************************************************************
+                            qgssingleboxscalebarstyle.h
+                            ------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSSINGLEBOXSCALEBARSTYLE_H
+#define QGSSINGLEBOXSCALEBARSTYLE_H
+
+#include "qgsscalebarstyle.h"
+
+/**Scalebar style that draws a single box with alternating
+ color for the segments*/
+class QgsSingleBoxScaleBarStyle: public QgsScaleBarStyle
+{
+ public:
+  QgsSingleBoxScaleBarStyle(const QgsComposerScaleBar* bar);
+  ~QgsSingleBoxScaleBarStyle();
+
+  QString name() const;
+
+  void draw(QPainter* p) const;
+
+ private:
+  QgsSingleBoxScaleBarStyle(); //forbidden
+};
+
+#endif 

Added: branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.cpp	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.cpp	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,76 @@
+/***************************************************************************
+                            qgsticksmiddlescalebarstyle.cpp
+                            -------------------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsticksmiddlescalebarstyle.h"
+#include "qgscomposerscalebar.h"
+#include <QPainter>
+
+QgsTicksMiddleScaleBarStyle::QgsTicksMiddleScaleBarStyle(const QgsComposerScaleBar* bar): QgsScaleBarStyle(bar)
+{
+
+}
+
+QgsTicksMiddleScaleBarStyle::QgsTicksMiddleScaleBarStyle(): QgsScaleBarStyle(0)
+{
+
+}
+
+QgsTicksMiddleScaleBarStyle::~QgsTicksMiddleScaleBarStyle()
+{
+
+}
+
+QString QgsTicksMiddleScaleBarStyle::name() const
+{
+  return "Bar Ticks Middle";
+}
+
+void QgsTicksMiddleScaleBarStyle::draw(QPainter* p) const
+{
+  if(!mScaleBar)
+    {
+      return;
+    }
+  double barTopPosition = mScaleBar->fontHeight() + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
+  double middlePosition = barTopPosition + mScaleBar->height()/2.0;
+
+  p->save();
+  p->setPen(mScaleBar->pen());
+
+  QList<QPair<double, double> > segmentInfo;
+  mScaleBar->segmentPositions(segmentInfo);
+
+  QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
+  for(; segmentIt != segmentInfo.constEnd(); ++segmentIt)
+    {
+      p->drawLine(segmentIt->first, barTopPosition, segmentIt->first, barTopPosition + mScaleBar->height());
+      p->drawLine(segmentIt->first, middlePosition,  + segmentIt->first + mScaleBar->segmentMM(), middlePosition); 
+    }
+
+  //draw last tick
+  if(!segmentInfo.isEmpty())
+    {
+      double lastTickPositionX = segmentInfo.last().first + mScaleBar->segmentMM();
+      p->drawLine(lastTickPositionX, barTopPosition, lastTickPositionX, barTopPosition + mScaleBar->height());
+    }
+
+  p->restore();
+
+  //draw labels using the default method
+  drawLabels(p);
+}
+
+

Added: branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.h	                        (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsticksmiddlescalebarstyle.h	2008-06-28 13:07:36 UTC (rev 8681)
@@ -0,0 +1,36 @@
+/***************************************************************************
+                            qgsticksmiddlescalebarstyle.h
+                            -----------------------------
+    begin                : June 2008
+    copyright            : (C) 2008 by Marco Hugentobler
+    email                : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSTICKSMIDDLESCALEBARSTYLE_H
+#define QGSTICKSMIDDLESCALEBARSTYLE_H 
+
+#include "qgsscalebarstyle.h"
+
+class QgsTicksMiddleScaleBarStyle: public QgsScaleBarStyle
+{
+  public:
+  QgsTicksMiddleScaleBarStyle(const QgsComposerScaleBar* bar);
+  ~QgsTicksMiddleScaleBarStyle();
+
+  QString name() const;
+
+  void draw(QPainter* p) const;
+
+ private:
+  QgsTicksMiddleScaleBarStyle(); //forbidden
+};
+
+#endif 



More information about the QGIS-commit mailing list