void LegendGroup::updateModel() {
	QList<QGraphicsItem*> pool;
	for (auto l : legends) { removeFromGroup(l); pool.append(l); }
	for (auto t : texts) { removeFromGroup(t); pool.append(t); }
	for (auto l : pool) delete l;
	legends.clear();
	texts.clear();
	for (int i=0; i<model->rowCount(); i++) {
		auto marker = model->at(i);
		QString l = marker->label() + "\t:  " + QString::number(marker->count());
		QColor color1 = marker->color1();
		QColor color2 = marker->color2();
		int type = marker->activeType();
		if (0 == type) {
			QRectF r = MarkerItem::rectFromClick(origin + QPointF(0, (mySize*2 + myPenWidth + 10) * (i+1)), mySize);
			QLineF l(r.topLeft(), r.bottomRight());
			auto marker = new ArrowItem(l);
			marker->setArrowhead(ArrowHead::Start);
			marker->setColor1(color1);
			marker->setColor2(color2);
			marker->setPenWidth(myPenWidth);
			legends.append(marker);
			addToGroup(marker);
		}
		else if (1 == type) {
			auto marker = new RectItem(MarkerItem::rectFromClick(origin + QPointF(0, (mySize*2 + myPenWidth + 10) * (i+1)), mySize));
			marker->setColor1(color1);
			marker->setColor2(color2);
			marker->setPenWidth(myPenWidth);
			legends.append(marker);
			addToGroup(marker);
		}
		else {
			auto marker = new EllipseItem(MarkerItem::rectFromClick(origin + QPointF(0, (mySize*2 + myPenWidth + 10) * (i+1)), mySize));
			marker->setColor1(color1);
			marker->setColor2(color2);
			marker->setPenWidth(myPenWidth);
			legends.append(marker);
			addToGroup(marker);
		}
		auto label = new RichTextItem(l);
		label->setFont(myFont);
		label->setFontSize(myFontSize);
		label->setKeyPressFunc([this](QKeyEvent* event) { updateRect(); });
		label->setTextInteractionFlags(Qt::TextEditorInteraction);
		label->setFlag(QGraphicsItem::ItemIsFocusable);
		QPointF textPos = legends.at(i)->boundingRect().center() + 
			QPointF(legends.at(i)->boundingRect().width()/2+20, -label->boundingRect().height()*0.5);
		label->setPos(textPos);
		label->setZValue(1000);
		texts.append(label);
		addToGroup(label);
	}
	calculatePos();
}
void paint() {
  static const int ox = 150;
  static const int oy = 150;

  static const int hl = 46;
  static const int ml = 74;
  static const int sl = 120;

  int i;

  beginPaint();

  clearDevice();

  // circle
  setPenWidth(2);
  setPenColor(BLACK);
  setBrushColor(WHITE);
  ellipse(25, 25, 275, 275);

  // label
  setPenWidth(1);
  setPenColor(BLACK);
  for (i = 0; i < 12; ++i) {
    moveTo(ox + 115 * sin(RAD(180 - i * 30)), oy + 115 * cos(RAD(180 - i * 30)));
    lineTo(ox + 125 * sin(RAD(180 - i * 30)), oy + 125 * cos(RAD(180 - i * 30)));
  }

  // hour
  setPenWidth(8);
  setPenColor(BLACK);
  moveTo(ox, oy);
  lineTo(ox + hl * sin(RAD(180 - h * 30)), oy + hl * cos(RAD(180 - h * 30)));

  // minute
  setPenWidth(4);
  setPenColor(GREEN);
  moveTo(ox, oy);
  lineTo(ox + ml * sin(RAD(180 - m * 6)), oy + ml * cos(RAD(180 - m * 6)));

  // second
  setPenWidth(2);
  setPenColor(RED);
  moveTo(ox, oy);
  lineTo(ox + sl * sin(RAD(180 - s * 6)), oy + sl * cos(RAD(180 - s * 6)));

  endPaint();
}
void ToolOptionWidget::onToolPropertyChanged( ToolType, ToolPropertyType ePropertyType )
{
    const Properties& p = editor()->tools()->currentTool()->properties;

    switch ( ePropertyType )
    {
        case WIDTH:
            setPenWidth( p.width );
            break;
        case FEATHER:
            setPenFeather( p.feather );
            break;
        case PRESSURE:
            setPressure( p.pressure );
            break;
        case INVISIBILITY:
            setPenInvisibility( p.invisibility );
            break;
        case PRESERVEALPHA:
            setPreserveAlpha( p.preserveAlpha );
            break;
        case VECTORMERGE:
            setVectorMergeEnabled(p.vectorMergeEnabled);
            break;
        case ANTI_ALIASING:
            setAA(p.useAA);
            break;
        case INTERPOLATION:
            setInpolLevel(p.inpolLevel);
            break;
    }
}
void ToolOptionWidget::updateUI()
{
    BaseTool* currentTool = editor()->tools()->currentTool();
    Q_ASSERT( currentTool );

    disableAllOptions();

    mSizeSlider->setVisible( currentTool->isPropertyEnabled( WIDTH ) );
    mBrushSpinBox->setVisible( currentTool->isPropertyEnabled( WIDTH) );
    mFeatherSlider->setVisible( currentTool->isPropertyEnabled( FEATHER ) );
    mUseFeatherBox->setVisible( currentTool->isPropertyEnabled( FEATHER ) );
    mFeatherSpinBox->setVisible( currentTool->isPropertyEnabled( FEATHER) );
    mUseBezierBox->setVisible( currentTool->isPropertyEnabled( BEZIER ) );
    mUsePressureBox->setVisible( currentTool->isPropertyEnabled( PRESSURE ) );
    mMakeInvisibleBox->setVisible( currentTool->isPropertyEnabled( INVISIBILITY ) );
    mPreserveAlphaBox->setVisible( currentTool->isPropertyEnabled( PRESERVEALPHA ) );

    const Properties& p = currentTool->properties;

    setPenWidth( p.width );
    setPenFeather( p.feather );
    setPressure( p.pressure );
    setPenInvisibility( p.invisibility );
    setPreserveAlpha( p.preserveAlpha );
}
Exemple #5
0
void Item::setPenBrush(const QString& penStyle, int width, const QString& penColor, const QString& brushStyle, const QString& brushColor)
{
	setPenStyle(penStyle);
	setPenWidth(width);
	setPenColor(penColor);
	setBrushStyle(brushStyle);
	setBrushColor(brushColor);
}
void DrawingPolyItem::setPen(const QPen& pen)
{
	setPenColor(pen.brush().color());
	setPenWidth(pen.widthF());
	setPenStyle(pen.style());
	setPenCapStyle(pen.capStyle());
	setPenJoinStyle(pen.joinStyle());
}
QVariant DrawingPolyItem::aboutToChangeEvent(Reason reason, const QVariant& value)
{
	if (reason == UnitsChange)
	{
		DrawingUnits newUnits = (DrawingUnits)value.toInt();
		qreal scaleFactor = Drawing::unitsScale(units(), newUnits);

		setPenWidth(penWidth() * scaleFactor);
	}

	return value;
}
Exemple #8
0
int RenderArea::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setFillRule((*reinterpret_cast< Qt::FillRule(*)>(_a[1]))); break;
        case 1: setFillGradient((*reinterpret_cast< const QColor(*)>(_a[1])),(*reinterpret_cast< const QColor(*)>(_a[2]))); break;
        case 2: setPenWidth((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: setPenColor((*reinterpret_cast< const QColor(*)>(_a[1]))); break;
        case 4: setRotationAngle((*reinterpret_cast< int(*)>(_a[1]))); break;
        }
        _id -= 5;
    }
    return _id;
}
void DrawingPolyItem::readXmlAttributes(QXmlStreamReader& xmlReader, const QList<DrawingItem*>& items)
{
	QXmlStreamAttributes attributes = xmlReader.attributes();

	DrawingItem::readXmlAttributes(xmlReader, items);

	if (attributes.hasAttribute("penColor"))
		setPenColor(Drawing::colorFromString(attributes.value("penColor").toString()));
	if (attributes.hasAttribute("penWidth"))
		setPenWidth(attributes.value("penWidth").toString().toDouble());
	if (attributes.hasAttribute("penStyle"))
		setPenStyle((Qt::PenStyle)attributes.value("penStyle").toString().toUInt());
	if (attributes.hasAttribute("penCapStyle"))
		setPenCapStyle((Qt::PenCapStyle)attributes.value("penCapStyle").toString().toUInt());
	if (attributes.hasAttribute("penJoinStyle"))
		setPenJoinStyle((Qt::PenJoinStyle)attributes.value("penJoinStyle").toString().toUInt());
}
void ToolOptionWidget::onToolPropertyChanged( ToolType, ToolPropertyType ePropertyType )
{
    const Properties& p = editor()->tools()->currentTool()->properties;

    switch ( ePropertyType )
    {
        case WIDTH:
            setPenWidth( p.width );
            break;
        case FEATHER:
            setPenFeather( p.feather );
            break;
        case PRESSURE:
            setPressure( p.pressure );
            break;
        case INVISIBILITY:
            setPenInvisibility( p.invisibility );
            break;
        case PRESERVEALPHA:
            setPreserveAlpha( p.preserveAlpha );
            break;
    }
}
Exemple #11
0
void ToolOptionWidget::updateUI()
{
    BaseTool* currentTool = editor()->tools()->currentTool();
    Q_ASSERT( currentTool );

    disableAllOptions();

    mSizeSlider->setVisible( currentTool->isPropertyEnabled( WIDTH ) );
    mBrushSpinBox->setVisible( currentTool->isPropertyEnabled( WIDTH) );
    mFeatherSlider->setVisible( currentTool->isPropertyEnabled( FEATHER ) );
    mUseFeatherBox->setVisible( currentTool->isPropertyEnabled( FEATHER ) );
    mFeatherSpinBox->setVisible( currentTool->isPropertyEnabled( FEATHER) );
    mUseBezierBox->setVisible( currentTool->isPropertyEnabled( BEZIER ) );
    mUsePressureBox->setVisible( currentTool->isPropertyEnabled( PRESSURE ) );
    mMakeInvisibleBox->setVisible( currentTool->isPropertyEnabled( INVISIBILITY ) );
    mPreserveAlphaBox->setVisible( currentTool->isPropertyEnabled( PRESERVEALPHA ) );
    mUseAABox->setVisible(currentTool->isPropertyEnabled( ANTI_ALIASING ) );
    mInpolLevelsBox->setVisible(currentTool->isPropertyEnabled( INTERPOLATION ) );

    auto currentLayerType = editor()->layers()->currentLayer()->type();

    if(currentLayerType == Layer::VECTOR)
    {
        mVectorMergeBox->setVisible( currentTool->isPropertyEnabled( VECTORMERGE) );
    }

    const Properties& p = currentTool->properties;

    setPenWidth( p.width );
    setPenFeather( p.feather );
    setPressure( p.pressure );
    setPenInvisibility( p.invisibility );
    setPreserveAlpha( p.preserveAlpha );
    setVectorMergeEnabled( p.vectorMergeEnabled );
    setAA(p.useAA);
    setInpolLevel(p.inpolLevel);
}
Exemple #12
0
NodeConnectorView::NodeConnectorView(bool isOutput, QGraphicsItem* parent)
    : QGraphicsWidget(parent, 0)
    , mRect(NodeStyle::SocketSize)
    , mPen(NodeStyle::SocketPen)
    , mAnimation(this, "penWidth")
    , mTemporaryLink(nullptr)
    , mHoveredConnector(nullptr)
    , mAnnotation(new QGraphicsSimpleTextItem(this))
    , mIsOutput(isOutput)
{
    setBrushGradient(Qt::white, Qt::black);
    setPenWidth(NodeStyle::NodeSocketPenWidth);
    setAnnotation(QString());
    setCursor(Qt::PointingHandCursor);

    setAcceptHoverEvents(true);

    mAnimation.setDuration(250);
    mAnimation.setEasingCurve(QEasingCurve::InOutQuad);
    mAnimation.setStartValue(penWidth());

    connect(this, SIGNAL(draggingLinkDropped(QGraphicsWidget*, QGraphicsWidget*)),
        Controller::instancePtr(), SLOT(draggingLinkDropped(QGraphicsWidget*, QGraphicsWidget*)));
}
Exemple #13
0
void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
{
  QPainter* p = c.painter();
  if ( !p )
  {
    return;
  }

  //get sum of values
  QList<double> values;
  double currentVal = 0;
  double valSum = 0;
  int valCount = 0;

  QList<int>::const_iterator catIt = s.categoryIndices.constBegin();
  for ( ; catIt != s.categoryIndices.constEnd(); ++catIt )
  {
    currentVal = att[*catIt].toDouble();
    values.push_back( currentVal );
    valSum += currentVal;
    if ( currentVal ) valCount++;
  }

  //draw the slices
  double totalAngle = 0;
  double currentAngle;

  //convert from mm / map units to painter units
  QSizeF spu = sizePainterUnits( s.size, s, c );
  double w = spu.width();
  double h = spu.height();

  double baseX = position.x();
  double baseY = position.y() - h;

  mPen.setColor( s.penColor );
  setPenWidth( mPen, s, c );
  p->setPen( mPen );

  // there are some values > 0 available
  if ( valSum > 0 )
  {
    QList<double>::const_iterator valIt = values.constBegin();
    QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
    for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
    {
      currentAngle =  *valIt / valSum * 360 * 16;
      mCategoryBrush.setColor( *colIt );
      p->setBrush( mCategoryBrush );
      // if only 1 value is > 0, draw a circle
      if ( valCount == 1 )
      {
        p->drawEllipse( baseX, baseY, w, h );
      }
      else
      {
        p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
      }
      totalAngle += currentAngle;
    }
  }
  else // valSum > 0
  {
    // draw empty circle if no values are defined at all
    mCategoryBrush.setColor( Qt::transparent );
    p->setBrush( mCategoryBrush );
    p->drawEllipse( baseX, baseY, w, h );
  }
}
void DrawingBoard::mouseReleaseEvent(QMouseEvent *event)
{
    if(myLine){
        if (event->button() == Qt::LeftButton && drawing) {
           // backUp.push_back(image);
            store();

            drawLineThru(startPoint, event->pos());
istore();
            drawing = false;
            }
        else if (event->button() == Qt::RightButton) {
           // QString str1 = QString::number(myPenWidth);
           // myPenWidth = 1;
           // QString str2 = QString::(myPenColor);

           // myPenColor = Qt::red;
            bool ok;
            int newWidth = QInputDialog::getInt(this, tr("Line Size"),
                                                tr("Select the size of line:"),
                                                penWidth(),
                                                1, 50, 1, &ok);
              // bool ok;
            //QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
                       //                             tr("Season:"), items, 0, false, &ok);

            if (ok){
                setPenWidth(newWidth);
               // statusBar()->showMessage(tr("qweewqewdasdsakdl"));
            }
        }
    }
    else  if(myRect){
          if ((event->buttons() & Qt::LeftButton) && drawing){
             // backUp.push_back(image);
            // store();

          drawRectTo(event->pos());
        //   istore();
          drawing = false;

          }
          else if (event->button() == Qt::RightButton) {

              bool ok;
              int newWidth = QInputDialog::getInt(this, tr("Rectangle border size"),
                                                  tr("Select the size of the border:"),
                                                  penWidth(),
                                                  1, 50, 1, &ok);
                // bool ok;
              //QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
                         //                             tr("Season:"), items, 0, false, &ok);

              if (ok){
                  setPenWidth(newWidth);
                 // statusBar()->showMessage(tr("qweewqewdasdsakdl"));
              }
          }
      }

    else if(myText){
        if ((event->buttons() & Qt::LeftButton) && drawing){
           // backUp.push_back(image);
            store();

        drawTexts(event->pos(),QString::fromStdString(text));
        istore();
        drawing = false;

        }
        else if (event->button() == Qt::RightButton) {
           // QString str =QString::fromStdString(text);
            bool ok;
            QString txt = QInputDialog::getText(this, tr("Enter the text you want to print"),
                                                 tr("Message"), QLineEdit::Normal,tr("Type your message"),
                                                  &ok);
            if (ok){
                text=txt.toStdString();
                //text=txt;
        }}
    }
    else if(myPen)
    {
    if (event->button() == Qt::LeftButton && drawing) {
       // backUp.push_back(image);
        store();

        drawLineTo(event->pos());
istore();
        drawing = false;
    }
    else if (event->button() == Qt::RightButton) {

        bool ok;
        int newWidth = QInputDialog::getInt(this, tr("Pen Size"),
                                            tr("Select the size of pen:"),
                                            penWidth(),
                                            1, 50, 1, &ok);
          // bool ok;
          // QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
                       //                         tr("Season:"), items, 0, false, &ok);

        if (ok){
            setPenWidth(newWidth);
           // statusBar()->showMessage(tr("qweewqewdasdsakdl"));
        }
        //QMessageBox::about(this, tr("Pen tool properties"),
             //   tr("You have Clicked right button. To draw Please press left button on mouse"));
    }
    }
    else if(mypLine){
        if (event->button() == Qt::LeftButton && drawing) {
           // backUp.push_back(image);
            store();

            drawLineTemp(startPoint, event->pos());
            istore();
            drawing = false;
            }
        else if (event->button() == Qt::RightButton) {
            bool ok;
            int newWidth = QInputDialog::getInt(this, tr("Select polyline Size"),
                                                tr("Select the size of Polyline:"),
                                                penWidth(),
                                                1, 50, 1, &ok);
            if (ok)
                setPenWidth(newWidth);
          //  QMessageBox::about(this, tr("PolyLine tool properties"),
            //        tr("You have Clicked right button. To draw Please press left button on mouse"));
        }
    }
    else if(myRub)
    {
    if (event->button() == Qt::LeftButton && drawing) {
      //  backUp.push_back(image);
        store();

        erase(event->pos());//to change
istore();
        drawing = false;
    }
    else if (event->button() == Qt::RightButton) {

        bool ok;
        int newWidth = QInputDialog::getInt(this, tr("Eraser Size"),
                                            tr("Select the size of Eraser:"),
                                            rubWidth(),
                                            1, 50, 1, &ok);
        if (ok)
            setRubWidth(newWidth);
    }
    }
    else
    {
        if (event->button() == Qt::LeftButton) {
        QMessageBox::about(this, tr("Mouse Event detection"),
                tr("You have Clicked Left Button. Now, close and select your preferences"));
    }

        else if (event->button() == Qt::RightButton) {

            QMessageBox::about(this, tr("Mouse Event1 detection"),
                    tr("You have Clicked right button. Now, close and select your preferences to see the properties of tool"));
        }

}
}
void QgsHistogramDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiagramSettings& s, QPointF position )
{
  QPainter* p = c.painter();
  if ( !p )
  {
    return;
  }

  QList<double> values;
  double maxValue = 0;

  QgsExpressionContext expressionContext = c.expressionContext();
  expressionContext.setFeature( feature );
  if ( !feature.fields().isEmpty() )
    expressionContext.setFields( feature.fields() );

  Q_FOREACH ( const QString& cat, s.categoryAttributes )
  {
    QgsExpression* expression = getExpression( cat, expressionContext );
    double currentVal = expression->evaluate( &expressionContext ).toDouble();
    values.push_back( currentVal );
    maxValue = qMax( currentVal, maxValue );
  }

  double scaledMaxVal = sizePainterUnits( maxValue * mScaleFactor, s, c );

  double currentOffset = 0;
  double scaledWidth = sizePainterUnits( s.barWidth, s, c );

  double baseX = position.x();
  double baseY = position.y();

  mPen.setColor( s.penColor );
  setPenWidth( mPen, s, c );
  p->setPen( mPen );

  QList<double>::const_iterator valIt = values.constBegin();
  QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
  for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
  {
    double length = sizePainterUnits( *valIt * mScaleFactor, s, c );

    mCategoryBrush.setColor( *colIt );
    p->setBrush( mCategoryBrush );

    switch ( s.diagramOrientation )
    {
      case QgsDiagramSettings::Up:
        p->drawRect( baseX + currentOffset, baseY, scaledWidth, length * -1 );
        break;

      case QgsDiagramSettings::Down:
        p->drawRect( baseX + currentOffset, baseY - scaledMaxVal, scaledWidth, length );
        break;

      case QgsDiagramSettings::Right:
        p->drawRect( baseX, baseY - currentOffset, length, scaledWidth * -1 );
        break;

      case QgsDiagramSettings::Left:
        p->drawRect( baseX + scaledMaxVal, baseY - currentOffset, 0 - length, scaledWidth * -1 );
        break;
    }

    currentOffset += scaledWidth;
  }
}
Exemple #16
0
void QgsTextDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiagramSettings& s, QPointF position )
{
  QPainter* p = c.painter();
  if ( !p )
  {
    return;
  }

  //convert from mm / map units to painter units
  QSizeF spu = sizePainterUnits( s.size, s, c );
  double w = spu.width();
  double h = spu.height();

  double baseX = position.x();
  double baseY = position.y() - h;

  QVector<QPointF> textPositions; //midpoints for text placement
  int nCategories = s.categoryAttributes.size();
  for ( int i = 0; i < nCategories; ++i )
  {
    if ( mOrientation == Horizontal )
    {
      textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) );
    }
    else //vertical
    {
      textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) );
    }
  }

  mPen.setColor( s.penColor );
  setPenWidth( mPen, s, c );
  p->setPen( mPen );
  mBrush.setColor( s.backgroundColor );
  p->setBrush( mBrush );

  //draw shapes and separator lines first
  if ( mShape == Circle )
  {
    p->drawEllipse( baseX, baseY, w, h );

    //draw separator lines
    QList<QPointF> intersect; //intersections between shape and separation lines
    QPointF center( baseX + w / 2.0, baseY + h / 2.0 );
    double r1 = w / 2.0;
    double r2 = h / 2.0;

    for ( int i = 1; i < nCategories; ++i )
    {
      if ( mOrientation == Horizontal )
      {
        lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect );
      }
      else //vertical
      {
        lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect );
      }
      if ( intersect.size() > 1 )
      {
        p->drawLine( intersect.at( 0 ), intersect.at( 1 ) );
      }
    }
  }
  else if ( mShape == Rectangle )
  {
    p->drawRect( QRectF( baseX, baseY, w, h ) );
    for ( int i = 1; i < nCategories; ++i )
    {
      if ( mOrientation == Horizontal )
      {
        p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) );
      }
      else
      {
        p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) );
      }
    }
  }
  else //triangle
  {
    QPolygonF triangle;
    triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY );
    p->drawPolygon( triangle );

    QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h );
    QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY );
    QPointF intersectionPoint1, intersectionPoint2;

    for ( int i = 1; i < nCategories; ++i )
    {
      if ( mOrientation == Horizontal )
      {
        QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY );
        if ( baseX + w / nCategories * i < baseX + w / 2.0 )
        {
          verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
        }
        else
        {
          verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 );
        }
        p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 );
      }
      else //vertical
      {
        QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i );
        horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 );
        horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 );
        p->drawLine( intersectionPoint1, intersectionPoint2 );
      }
    }
  }

  //draw text
  QFont sFont = scaledFont( s, c );
  QFontMetricsF fontMetrics( sFont );
  p->setFont( sFont );

  QgsExpressionContext expressionContext = c.expressionContext();
  expressionContext.setFeature( feature );
  if ( feature.fields() )
    expressionContext.setFields( *feature.fields() );

  for ( int i = 0; i < textPositions.size(); ++i )
  {
    QgsExpression* expression = getExpression( s.categoryAttributes.at( i ), expressionContext );
    QString val = expression->evaluate( &expressionContext ).toString();

    //find out dimesions
    double textWidth = fontMetrics.width( val );
    double textHeight = fontMetrics.height();

    mPen.setColor( s.categoryColors.at( i ) );
    p->setPen( mPen );
    QPointF position = textPositions.at( i );

    // Calculate vertical placement
    double xOffset = 0;

    switch ( s.labelPlacementMethod )
    {
      case QgsDiagramSettings::Height:
        xOffset = textHeight / 2.0;
        break;

      case QgsDiagramSettings::XHeight:
        xOffset = fontMetrics.xHeight();
        break;
    }
    p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
  }
}