Ejemplo n.º 1
0
/**
 * Paint arrow
 */
void drawLineHead (QPainter * painter, QPointF end, double angle, double size, bool figure)
{
    QPointF lineP1 = end + QPointF( sin( angle + Pi / 3) * size, cos( angle + Pi / 3) * size);
    QPointF lineP2 = end + QPointF( sin( angle + Pi - Pi / 3) * size, cos( angle + Pi - Pi / 3) * size);
	QPointF centre = (lineP1 + lineP2 + end)/3;

	if (figure)
	{
		QPainterPath arrow;
		arrow.moveTo (end);
		arrow.quadTo (centre, lineP1);
		arrow.lineTo (lineP2);
		arrow.quadTo (centre, end);

		painter->drawPath (arrow);
	}
	else
	{
		QPolygonF lineHead;
		lineHead.clear();
		lineHead << end << lineP1 << lineP2;
	
		painter->drawPolygon (lineHead);
	}
}
void TaskItemDelegate::paintPriorityHeader(QPainter* painter, const QRectF& rect, const QModelIndex &index) const
{
  painter->save();
  
  //Draw colored gradient as priority background
  QLinearGradient gradient(rect.topLeft(), rect.bottomRight());
  gradient.setColorAt(0, itemPriorityColor(index));
  gradient.setColorAt(1, Qt::transparent);
  
  int h = QApplication::fontMetrics().height();
  QPainterPath path;
  path.moveTo(rect.bottomLeft());
  path.quadTo(rect.bottomLeft()+QPointF(0, -h), rect.bottomLeft()+QPointF(2, -h));
  path.lineTo(rect.bottomRight()-QPointF(2, h));
  path.quadTo(rect.bottomRight()+QPointF(0, -h), rect.bottomRight());
  painter->setBrush(Qt::NoBrush);
  QPen thickPen(itemPriorityColor(index));
  thickPen.setWidth(2);
  painter->setPen(thickPen);
  painter->drawPath(path);
  
  // Draw priority text
  QString priority = index.data(Qt::DisplayRole).toString();
  painter->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
  painter->setBrush(Qt::NoBrush);
  painter->drawText(rect.bottomLeft()+QPoint(MARGIN, -2*MARGIN) ,priority);
 
  painter->restore();
}
Ejemplo n.º 3
0
QPainterPath
TriggerPoint::shape() const
{
  QPainterPath path;
  float line = BasicBox::LINE_WIDTH / 2;
  QPointF adjustX(-line, 0);
  QPointF adjustY(0, -line);
  QRectF rect = boundingRect();
  switch (_abstract->boxExtremity()) {
      case BOX_START:
        path.moveTo(rect.topLeft() + adjustX);
        path.lineTo(rect.bottomLeft() + adjustX + adjustY);
        path.lineTo(rect.bottomRight() + adjustY);
        path.lineTo(rect.bottomRight() + adjustY - QPointF(0, rect.height() / 5.));
        path.quadTo(rect.topRight(), rect.topLeft() + adjustX);
        break;

      case BOX_END:
        path.moveTo(rect.topRight());
        path.lineTo(rect.bottomRight() + adjustY);
        path.lineTo(rect.bottomLeft() + adjustY);
        path.lineTo(rect.bottomLeft() + adjustY - QPointF(0, rect.height() / 5.));
        path.quadTo(rect.topLeft(), rect.topRight());
        break;

      default:
        break;
    }

  return path;
}
Ejemplo n.º 4
0
void EditorArea::paintEdges(QPainter &painter)
{
    bool firstTime = true;

    QVector<int> edgesIds = workspace->getEdgesIds();

    for (int i=0; i < edgesIds.size(); i++) {
        QPoint nodesOfEdge = workspace->getNodesOfEdge(edgesIds[i]);
        QPointF screenXYFirst = graph2screen(workspace->getNodePosition(nodesOfEdge.x()));
        QPointF screenXYSecond = graph2screen(workspace->getNodePosition(nodesOfEdge.y()));
        QPointF screenMidPoint = graph2screen(workspace->getThirdPointPos(edgesIds[i]));

        QPainterPath path;
        path.moveTo(screenXYFirst);
        path.quadTo(screenMidPoint, screenXYSecond);
        path.quadTo(screenMidPoint, screenXYFirst);
        painter.drawPath(path);

        QVector<QPointF> pointsOnBezier;
        QVector<float> sOnEdge;

        for (int k = 0; k < edgeDiscretization + 1; k++) {
            float t = float(k) / edgeDiscretization;
            QPointF coord = (1 - t) * (1 - t) * screenXYFirst + 2 * (1 - t) * t * screenMidPoint + t * t * screenXYSecond;
            pointsOnBezier << coord;
        }

        for (int k = 0; k < pointsOnBezier.size(); k++) {
            if (k == 0) {
                sOnEdge << 0.0;
            } else {
                float sJesima = workspace->distance(pointsOnBezier[k], pointsOnBezier[k - 1]);
                sOnEdge << sJesima;
            }
        }

        for (int k = 1; k < pointsOnBezier.size(); k++) {
            sOnEdge[k] = sOnEdge[k] + sOnEdge[k - 1];
        }

        float length = sOnEdge.last();

        for (int k = 0; k < sOnEdge.size(); k++) {
            sOnEdge[k] = sOnEdge[k] / length;
        }

        sOnBezier.insert(edgesIds[i], sOnEdge);

        if (path.intersects(QRectF(mouseCurrentPos.x() - 7, mouseCurrentPos.y() - 7, 14, 14))) {
            if (firstTime) {
                firstTime = false;
                hitElements.clear();
            }

            QPoint temp(2, edgesIds[i]);
            hitElements.append(temp);
        }
    }
}
Ejemplo n.º 5
0
void
CurrentTrack::drawStatsBackground( QPainter *const p, const QRect &rect )
{
    // draw the complete outline. lots of little steps :) at each corner, leave
    // a 6x6 box. draw a quad bezier curve from the two ends of the lines,
    // through  the original corner

    const qreal leftEdge = m_ratingWidget->boundingRect().right() + standardPadding();
    const qreal rightEdge = rect.right() - standardPadding() / 2;
    const qreal ratingWidgetX = m_ratingWidget->pos().x();
    const qreal ratingWidgetY = m_ratingWidget->pos().y();
    const qreal ratingWidgetH = m_ratingWidget->boundingRect().height();
    QColor topColor = The::paletteHandler()->palette().color( QPalette::Base );
    QColor bottomColor = topColor;
    topColor.setAlpha( 200 );
    bottomColor.setAlpha( 100 );

    QPainterPath statsPath;
    statsPath.moveTo( leftEdge + 6, ratingWidgetY - ratingWidgetH + 8 ); // top left position of the rect, right below the album
    statsPath.lineTo( rightEdge - 6, ratingWidgetY - ratingWidgetH + 8 ); // go right to margin
    statsPath.quadTo( rightEdge, ratingWidgetY - ratingWidgetH + 8,
                      rightEdge, ratingWidgetY - ratingWidgetH + 8 + 6 );
    statsPath.lineTo( rightEdge, ratingWidgetY + ratingWidgetH - 6 ); // go down to bottom right corner
    statsPath.quadTo( rightEdge, ratingWidgetY + ratingWidgetH,
                      rightEdge - 6, ratingWidgetY + ratingWidgetH );
    statsPath.lineTo( ratingWidgetX + 6, ratingWidgetY + ratingWidgetH ); // way bottom left corner
    statsPath.quadTo( ratingWidgetX, ratingWidgetY + ratingWidgetH,
                      ratingWidgetX, ratingWidgetY + ratingWidgetH - 6 );
    statsPath.lineTo( ratingWidgetX, ratingWidgetY + 6 ); // top left of rating widget
    statsPath.quadTo( ratingWidgetX, ratingWidgetY,
                      ratingWidgetX + 6, ratingWidgetY );
    statsPath.lineTo( leftEdge - 6, ratingWidgetY ); // joining of two rects
    statsPath.quadTo( leftEdge, ratingWidgetY,
                      leftEdge, ratingWidgetY - 6 );
    statsPath.lineTo( leftEdge, ratingWidgetY - ratingWidgetH + 8 + 6 ); // back to start
    statsPath.quadTo( leftEdge, ratingWidgetY - ratingWidgetH + 8,
                      leftEdge + 6, ratingWidgetY - ratingWidgetH + 8 );

    // draw just the overlay which is the "header" row, to emphasize that we have 2 rows here
    QPainterPath headerPath;
    headerPath.moveTo( leftEdge + 6, ratingWidgetY - ratingWidgetH + 8 ); // top left position of the rect, right below the album
    headerPath.lineTo( rightEdge - 6, ratingWidgetY - ratingWidgetH + 8 ); // go right to margin
    headerPath.quadTo( rightEdge, ratingWidgetY - ratingWidgetH + 8,
                       rightEdge, ratingWidgetY - ratingWidgetH + 8 + 6 );
    headerPath.lineTo( rightEdge, ratingWidgetY  ); // middle of the right side
    headerPath.lineTo( leftEdge - 6, ratingWidgetY ); // join spot, before quad curve
    headerPath.quadTo( leftEdge, ratingWidgetY,
                       leftEdge, ratingWidgetY - 6 );
    headerPath.lineTo( leftEdge, ratingWidgetY - ratingWidgetH + 8 + 6 ); // curve back through start
    headerPath.quadTo( leftEdge, ratingWidgetY - ratingWidgetH + 8,
                       leftEdge + 6, ratingWidgetY - ratingWidgetH + 8 );

    p->save();
    p->setRenderHint( QPainter::Antialiasing );
    p->fillPath( statsPath, bottomColor );
    p->fillPath( headerPath, topColor );
    p->restore();

}
Ejemplo n.º 6
0
/**
 * Returns a Bézier path from given points.
 * @param points   points which define the Bézier curve
 * @return   cubic Bézier spline
 */
QPainterPath AssociationLine::createBezierCurve(QVector<QPointF> points)
{
    QPainterPath path;
    if (points.size() > 3) {  // cubic Bezier curve(s)
        path.moveTo(points.at(0));
        int i = 1;
        while (i + 2 < points.size()) {
            path.cubicTo(points.at(i), points.at(i+1), points.at(i+2));
            i += 3;
        }
        while (i < points.size()) {  // draw a line if points are not modulo 3
            path.lineTo(points.at(i));
            ++i;
        }
    }
    else {
        if (points.size() == 3) {  // quadratic Bezier curve
            path.moveTo(points.at(0));
            path.quadTo(points.at(1), points.at(2));
        }
        else {  // should not be reached
            QPolygonF polygon(points);
            path.addPolygon(polygon);
        }
    }
    return path;
}
Ejemplo n.º 7
0
void Kompton::Particle::rebuildRepresentation() {
	//prepare a new path
	QPainterPath path;
	path.moveTo(m_line.p1());
	//draw on the path according to the style
	if (m_style == Kompton::PlainStyle) {
		path.lineTo(m_line.p2());
	}
	else if (m_style == Kompton::WigglyStyle) {
		const QPointF start = m_line.p1();
		const QPointF diff = m_line.p2() - start;
		//some constants of the representation
		static const qreal amplitude = 10.0; //maximum wave elongation
		static const qreal wavelength = 20.0;
		//parameters for this wave
		const qreal waveCount = floor(sqrt(diff.x() * diff.x() + diff.y() * diff.y()) / wavelength);
		const QPointF waveDiff = diff / waveCount;
		const qreal slope = atan2(diff.y(), diff.x());
		const QPointF waveElongationVector(amplitude * -sin(slope), amplitude * cos(slope));
		//draw waves
		for (qreal i = 0.0; i < waveCount; ++i) {
			path.quadTo(start + waveDiff * (i + 0.25) + waveElongationVector, start + waveDiff * (i + 0.5));
			path.quadTo(start + waveDiff * (i + 0.75) - waveElongationVector, start + waveDiff * (i + 1.0));
		}
	}
	//make new path active
	setPath(path);
}
Ejemplo n.º 8
0
void Quad_Curve::add_to(bool move, QPainterPath &ppth) const
{
    if ( move )
        ppth.moveTo(begin);

    ppth.quadTo(control,end);
}
Ejemplo n.º 9
0
void EditorArea::paintHighlightingEdge(QPainter& painter)
{
    QMap<QString, int> supportEdges(workspace->getSupportEdges());

    QPoint nodesOfEdge = workspace->getNodesOfEdge(supportEdges.value("highlightingEdge"));
    QPointF screenXYFirst = graph2screen(workspace->getNodePosition(nodesOfEdge.x()));
    QPointF screenXYSecond = graph2screen(workspace->getNodePosition(nodesOfEdge.y()));
    QPointF screenMidPoint = graph2screen(workspace->getThirdPointPos(supportEdges.value("highlightingEdge")));

    QPainterPath path;
    path.moveTo(screenXYFirst);
    path.quadTo(screenMidPoint, screenXYSecond);
    path.quadTo(screenMidPoint, screenXYFirst);
    path.closeSubpath();
    painter.drawPath(path);
}
Ejemplo n.º 10
0
void
drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom, const QColor& gradient2top, const QColor& gradient2bottom )
{
    QPainterPath btnPath;
    const int radius = 3;
    // draw top half gradient
    const int btnCenter = btnRect.bottom() - ( btnRect.height() / 2 );
    btnPath.moveTo( btnRect.left(), btnCenter );
    btnPath.lineTo( btnRect.left(), btnRect.top() + radius );
    btnPath.quadTo( QPoint( btnRect.topLeft() ), QPoint( btnRect.left() + radius, btnRect.top() ) );
    btnPath.lineTo( btnRect.right() - radius, btnRect.top() );
    btnPath.quadTo( QPoint( btnRect.topRight() ), QPoint( btnRect.right(), btnRect.top() + radius ) );
    btnPath.lineTo( btnRect.right(),btnCenter );
    btnPath.lineTo( btnRect.left(), btnCenter );

    QLinearGradient g;
    if ( gradient1bottom.isValid() )
    {
        g.setColorAt( 0, color );
        g.setColorAt( 0.5, gradient1bottom );
        painter->fillPath( btnPath, g );
    }
    else
        painter->fillPath( btnPath, color );
    //painter->setPen( bg.darker() );

    //painter->drawPath( btnPath );

    btnPath = QPainterPath();
    btnPath.moveTo( btnRect.left(), btnCenter );
    btnPath.lineTo( btnRect.left(), btnRect.bottom() - radius );
    btnPath.quadTo( QPoint( btnRect.bottomLeft() ), QPoint( btnRect.left() + radius, btnRect.bottom() ) );
    btnPath.lineTo( btnRect.right() - radius, btnRect.bottom() );
    btnPath.quadTo( QPoint( btnRect.bottomRight() ), QPoint( btnRect.right(), btnRect.bottom() - radius ) );
    btnPath.lineTo( btnRect.right(), btnCenter );
    btnPath.lineTo( btnRect.left(), btnCenter );

    if ( gradient2top.isValid() && gradient2bottom.isValid() )
    {
        g.setColorAt( 0, gradient2top );
        g.setColorAt( 0.5, gradient2bottom );
        painter->fillPath( btnPath, g );
    }
    else
        painter->fillPath( btnPath, color );

}
Ejemplo n.º 11
0
void EditorArea::paintSupportEdges4selecting(QPainter& painter)
{
    QVector<int> supportEdges4selecting(workspace->getSupportEdges4selecting());

    for (int i = 0; i < supportEdges4selecting.size(); i++) {
        QPoint nodesOfEdge = workspace->getNodesOfEdge(supportEdges4selecting[i]);
        QPointF screenXYFirst = graph2screen(workspace->getNodePosition(nodesOfEdge.x()));
        QPointF screenXYSecond = graph2screen(workspace->getNodePosition(nodesOfEdge.y()));
        QPointF screenMidPoint = graph2screen(workspace->getThirdPointPos(supportEdges4selecting[i]));

        QPainterPath path;
        path.moveTo(screenXYFirst);
        path.quadTo(screenMidPoint, screenXYSecond);
        path.quadTo(screenMidPoint, screenXYFirst);
        painter.drawPath(path);
    }
}
    QPainterPath dialogPath( const QRect & rct , int padding ) const
    {
        QPainterPath path;
        path.setFillRule( Qt::WindingFill );

        path.moveTo( rct.width()/2 , padding );
        path.lineTo( rct.width()-padding-ROUNDED_PIXEL , padding );
        path.quadTo( rct.width()-padding , padding , rct.width()-padding , padding+ROUNDED_PIXEL );
        path.lineTo( rct.width()-padding , rct.height()-padding-ROUNDED_PIXEL );
        path.quadTo( rct.width()-padding , rct.height()-padding , rct.width()-padding-ROUNDED_PIXEL , rct.height()-padding );
        path.lineTo( padding+ROUNDED_PIXEL , rct.height()-padding );
        path.quadTo( padding , rct.height()-padding , padding , rct.height()-padding-ROUNDED_PIXEL );
        path.lineTo( padding , padding+ROUNDED_PIXEL );
        path.quadTo( padding , padding , padding+ROUNDED_PIXEL , padding );
        path.lineTo( rct.width()/2 , padding );

        return path;
    }
Ejemplo n.º 13
0
void StylePainterMobile::drawChecker(QPainter* painter, const QRect& rect, const QColor& color) const
{
    painter->setRenderHint(QPainter::Antialiasing, true);
    QPen pen(Qt::darkGray);
    pen.setCosmetic(true);
    painter->setPen(pen);
    painter->scale(rect.width(), rect.height());
    QPainterPath path;
    path.moveTo(0.18, 0.47);
    path.lineTo(0.25, 0.4);
    path.lineTo(0.4, 0.55);
    path.quadTo(0.64, 0.29, 0.78, 0.2);
    path.lineTo(0.8, 0.25);
    path.quadTo(0.53, 0.55, 0.45, 0.75);
    path.closeSubpath();
    painter->setBrush(color);
    painter->drawPath(path);
}
Ejemplo n.º 14
0
static bool parseGlyphPathData(const char *svgPath, const char *svgPathEnd, QPainterPath &path,
                               qreal fontPixelSize, const QPointF &offset, bool hinted)
{
    Q_UNUSED(hinted)
    QPointF p1, p2, firstSubPathPoint;
    qreal *elementValues[] =
        {&p1.rx(), &p1.ry(), &p2.rx(), &p2.ry()};
    const int unitsPerEm = 2048; // See: http://en.wikipedia.org/wiki/Em_%28typography%29
    const qreal resizeFactor = fontPixelSize / unitsPerEm;

    while (svgPath < svgPathEnd) {
        skipSpacesAndComma(svgPath, svgPathEnd);
        const char pathElem = *svgPath++;
        skipSpacesAndComma(svgPath, svgPathEnd);

        if (pathElem != 'Z') {
            char *endStr = 0;
            int elementValuesCount = 0;
            for (int i = 0; i < 4; ++i) { // 4 = size of elementValues[]
                qreal coordinateValue = strtod(svgPath, &endStr);
                if (svgPath == endStr)
                    break;
                if (i % 2) // Flip vertically
                    coordinateValue = -coordinateValue;
                *elementValues[i] = coordinateValue * resizeFactor;
                elementValuesCount++;
                svgPath = endStr;
                skipSpacesAndComma(svgPath, svgPathEnd);
            }
            p1 += offset;
            if (elementValuesCount == 2)
                p2 = firstSubPathPoint;
            else
                p2 += offset;
        }

        switch (pathElem) {
        case 'M':
            firstSubPathPoint = p1;
            path.moveTo(p1);
            break;
        case 'Z':
            path.closeSubpath();
            break;
        case 'L':
            path.lineTo(p1);
            break;
        case 'Q':
            path.quadTo(p1, p2);
            break;
        default:
            return false;
        }
    }
    return true;
}
Ejemplo n.º 15
0
void
CQGroupBox::
drawArcShape(QPainter *painter, double xc, double yc, double r, double startAngle, int sides) const
{
  auto Deg2Rad = [](double d) -> double { return M_PI*d/180.0; };
//auto Rad2Deg = [](double r) -> double { return 180.0*r/M_PI; };

  double x1 = xc - r;
  double y1 = yc - r;
  double x2 = xc + r;
  double y2 = yc + r;

  double xm = (x1 + x2)/2;
  double ym = (y1 + y2)/2;

  double da = 360.0/sides;
  double dc = 360.0/40;

  QPainterPath path;

  for (int i = 0; i < sides; ++i) {
    double angle = startAngle + i*da;

    double a1 = Deg2Rad(angle - dc);
    double a2 = Deg2Rad(angle + dc);

    double c1 = cos(a1), s1 = sin(a1);
    double c2 = cos(a2), s2 = sin(a2);

    QPointF p1(xm + r*c1, ym + r*s1);
    QPointF p2(xm + r*c2, ym + r*s2);

    if (i == 0)
      path.moveTo(p1);
    else
      path.lineTo(p1);

    //---

    QPointF p12 = (p1 + p2)/2;

    double ar = 2*hypot(p1.x() - p12.x(), p1.y() - p12.y())/sides;

    double a = Deg2Rad(angle);

    double c = cos(a), s = sin(a);

    QPointF pq(xm + (r + ar)*c, ym + (r + ar)*s);

    path.quadTo(pq, p2);
  }

  path.closeSubpath();

  painter->drawPath(path);
}
Ejemplo n.º 16
0
QPainterPath strokeToPainterPath(TStroke *stroke) {
  QPainterPath path;
  int i, chunkSize = stroke->getChunkCount();
  for (i = 0; i < chunkSize; i++) {
    const TThickQuadratic *q = stroke->getChunk(i);
    if (i == 0) path.moveTo(toQPointF(q->getThickP0()));
    path.quadTo(toQPointF(q->getThickP1()), toQPointF(q->getThickP2()));
  }
  return path;
}
void ProgressWidgetGraphicsProxy::paintWindowFrame (QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *) {
  QRectF widgetGeometry = windowFrameRect();
  QPainterPath path;
  path.addRect(widgetGeometry);
  path.moveTo(widgetGeometry.topLeft() + QPointF(0, -offset));
  path.quadTo(widgetGeometry.topLeft() + QPointF(-offset, -offset), widgetGeometry.topLeft() + QPointF(-offset, 0));
  path.lineTo(widgetGeometry.bottomLeft() + QPointF(-offset, 0));
  path.quadTo(widgetGeometry.bottomLeft() + QPointF(-offset, offset), widgetGeometry.bottomLeft() + QPointF(0, offset));
  path.lineTo(widgetGeometry.bottomRight() + QPointF(0, offset));
  path.quadTo(widgetGeometry.bottomRight() + QPointF(offset, offset), widgetGeometry.bottomRight() + QPointF(offset, 0));
  path.lineTo(widgetGeometry.topRight() + QPointF(offset, 0));
  path.quadTo(widgetGeometry.topRight() + QPointF(offset, -offset), widgetGeometry.topRight() + QPointF(0, -offset));
  path.lineTo(widgetGeometry.topLeft() + QPointF(0, -offset));

  painter->setPen(Qt::black);
  painter->setBrush(frameColor);
  painter->setRenderHint(QPainter::Antialiasing, true);
  painter->drawPath(path);
  painter->setRenderHint(QPainter::Antialiasing, false);
}
Ejemplo n.º 18
0
void
Context::AppletToolbarBase::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
    Q_UNUSED( option )
    Q_UNUSED( widget )

    painter->save();
    painter->setRenderHint( QPainter::Antialiasing );

    QColor topColor = palette().color( QPalette::Active, QPalette::Button );
    QColor bottomColor = topColor;
    topColor.setAlpha( 200 );
    bottomColor.setAlpha( 100 );
    qreal radius = 3;
    qreal boundWidth = boundingRect().width();
    qreal boundHeight = boundingRect().height();

    // draw top half of rounded applet
    QPainterPath path;
    path.moveTo( 0, boundHeight / 2 );
    path.lineTo( 0, radius );
    path.quadTo( 0, 0, radius, 0 );
    path.lineTo( boundWidth - radius, 0 );
    path.quadTo( boundWidth, 0, boundWidth, radius );
    path.lineTo( boundWidth, boundHeight / 2 );
    path.lineTo( 0, boundHeight / 2 );

    painter->fillPath( path, topColor );
    QPainterPath bottom;
    bottom.moveTo( 0, boundHeight / 2 );
    bottom.lineTo( 0, boundHeight - radius );
    bottom.quadTo( 0, boundHeight, radius, boundHeight );
    bottom.lineTo( boundWidth - radius, boundHeight );
    bottom.quadTo( boundWidth, boundHeight, boundWidth, boundHeight - radius );
    bottom.lineTo( boundWidth, boundHeight / 2 );
    bottom.lineTo( 0, boundHeight / 2 );

    painter->fillPath( bottom, bottomColor );
    painter->restore();
}
Ejemplo n.º 19
0
void ArrowItem::updatePath(const QPointF &endPoint)
{
    const double arrowWidth = 15.0;
    const double headWidth = 40.0;
    const double headLength =
        headWidth / pow(2, 0.5); // aka headWidth / sqrt (2) but this produces a compile error with MSVC++
    const double phi = 15;

    if (!startItem)
        return;

    QPointF startPoint =
        startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
    QLineF line(startPoint, endPoint);
    qreal lineLength = line.length();

    prepareGeometryChange();
    if (lineLength < 30)
        path = QPainterPath();
    else {
        QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);

        QPainterPath centerLine;
        centerLine.moveTo(0, 0);
        centerLine.quadTo(c, QPointF(lineLength, 0));

        double percentage = 1 - headLength / lineLength;
        QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
        QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
        qreal alpha = testLine.angle() - 90;
        QPointF endPoint1 =
            arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
        QPointF endPoint2 =
            arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
        QPointF point1 =
            endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
        QPointF point2 =
            endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));

        path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
        path.quadTo(c, endPoint1);
        path.lineTo(point1);
        path.lineTo(QPointF(lineLength, 0));
        path.lineTo(point2);
        path.lineTo(endPoint2);
        path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
        path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
    }

    setPos(startPoint);
    setTransform(QTransform().rotate(-line.angle()));
}
Ejemplo n.º 20
0
bool BE::Contacts::setPhoto(const QString &path)
{
    QRect r(0,0,160,160);
    QImage  img = QImage( path );
    if (img.isNull())
        return false;
    const float f = qMin( float(img.width())/float(r.width()),
                            float(img.height())/float(r.height()) );
    r.setSize( r.size()*f );
    r.moveTopRight( img.rect().topRight() );
    img = img.copy(r).scaled( QSize(160,160), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);

    img = img.convertToFormat(QImage::Format_ARGB32);

//     if ( !MPC::setting("rgbCover").toBool() )
    {
        int r,g,b;
        palette().color(foregroundRole()).getRgb(&r,&g,&b);

        int n = img.width() * img.height();
        const uchar *bits = img.bits();
        QRgb *pixel = (QRgb*)(const_cast<uchar*>(bits));

        // this creates a (slightly) translucent monochromactic version of the
        // image using the foreground color
        // the gray value is turned into the opacity
        #define ALPHA qAlpha(pixel[i])
        #define GRAY qGray(pixel[i])
        #define OPACITY 224
        if ( qMax( qMax(r,g), b ) > 128 ) // value > 50%, bright foreground
            for (int i = 0; i < n; ++i)
                pixel[i] = qRgba( r,g,b, ( ALPHA * ( (OPACITY*GRAY) / 255 ) ) / 255 );
            else // inverse
            for (int i = 0; i < n; ++i)
                pixel[i] = qRgba( r,g,b, ( ALPHA * ( (OPACITY*(255-GRAY)) / 255 ) ) / 255 );
    }
#if 1
    QPainterPath glasPath;
    glasPath.moveTo( img.rect().topLeft() );
    glasPath.lineTo( img.rect().topRight() );
    glasPath.quadTo( img.rect().center()/2, img.rect().bottomLeft() );

    QPainter p( &img );
    p.setRenderHint( QPainter::Antialiasing );
    p.setPen( Qt::NoPen );
    p.setBrush( QColor(255,255,255,64) );
    p.drawPath(glasPath);
    p.end();
#endif
    m_ui2->photo->setPixmap( QPixmap::fromImage( img ) );
    return true;
}
Ejemplo n.º 21
0
void CCJKShapeLine::DrawArrow(QPainter *painter, ArrowTypeFlag arrowType, const QPointF &p, const QPointF &p1, const QPointF &p2, qreal arrowSize)
{
	CJK_D(CCJKShapeLine);

	QPen pen = d->pen;
	pen.setStyle(Qt::SolidLine);
	pen.setJoinStyle(Qt::MiterJoin);
	painter->setPen(pen);

	switch (arrowType)
	{
	case ArrowArc:
	{
		QPainterPath path;
		path.moveTo(p1);
		path.lineTo(p);
		path.lineTo(p2);
		QPointF c = QPointF((p1.x() + p2.x() + p.x()) / 3, (p1.y() + p2.y() + p.y()) / 3);
		path.quadTo(c, p1);
		painter->drawPath(path);
	}
	break;
	case ArrowLine:
	{
		QBrush brsh(Qt::NoBrush);
		painter->setBrush(brsh);
		pen.setCapStyle(Qt::SquareCap);
		QPainterPath path;
		path.moveTo(p1);
		path.lineTo(p);
		path.lineTo(p2);
		painter->drawPath(path);
	}
	break;
	case ArrowCircle:
	{
		painter->drawEllipse(p, arrowSize / 2, arrowSize / 2);
	}
	break;
	case ArrowTriangle:
	default:
	{
		QPolygonF arrowHead;
		arrowHead << p << p1 << p2;
		painter->drawPolygon(arrowHead);
		break;
	}
	}
	painter->setBrush(d->brush);
	painter->setPen(d->pen);
}
Ejemplo n.º 22
0
QPainterPath Previewer::magnifierPath( const QSize & top , const QRect & rct , int padding ) const
{
    QPainterPath path;
        path.setFillRule( Qt::WindingFill );
        /*! ======= Draw Top of the Magnifier ======= */
        path.moveTo( (rct.width()-top.width())/2 , padding+top.height() );
        path.lineTo( rct.width()/2 , padding );
        path.lineTo( (rct.width()+top.width())/2 , padding+top.height() );
        /*! ========================================= */
        /*! ===== Draw Bottom of the Magnifier ====== */
        path.lineTo( rct.width()-padding-ROUNDED_PIXEL , padding+top.height() );
        path.quadTo( rct.width()-padding , padding+top.height() , rct.width()-padding , padding+top.height()+ROUNDED_PIXEL );
        path.lineTo( rct.width()-padding , rct.height()-padding-ROUNDED_PIXEL );
        path.quadTo( rct.width()-padding , rct.height()-padding , rct.width()-padding-ROUNDED_PIXEL , rct.height()-padding );
        path.lineTo( padding+ROUNDED_PIXEL , rct.height()-padding );
        path.quadTo( padding , rct.height()-padding , padding , rct.height()-padding-ROUNDED_PIXEL );
        path.lineTo( padding , padding+top.height()+ROUNDED_PIXEL );
        path.quadTo( padding , padding+top.height() , padding+ROUNDED_PIXEL , padding+top.height() );
        path.lineTo( (rct.width()-top.width())/2 , padding+top.height() );
        /*! ========================================= */

    return path;
}
Ejemplo n.º 23
0
SCEyeWipeEffectFactory::SCEyeWipeEffectFactory()
    : SCPageEffectFactory(EyeWipeEffectId, i18n("Eye"))
{
    QPainterPath shape;

    //vertical
    shape.moveTo(0, -12);
    shape.quadTo(10, 0, 0, 12);
    shape.quadTo(-10, 0, 0, -12);
    addStrategy(new SCIrisWipeEffectStrategyBase(shape, Vertical, "eyeWipe", "vertical", false));

    //vertical reverse
    addStrategy(new SCIrisWipeEffectStrategyBase(shape, VerticalReverse, "eyeWipe", "vertical", true));

    //horizontal
    shape = QPainterPath();
    shape.moveTo(-12, 0);
    shape.quadTo(0, 10, 12, 0);
    shape.quadTo(0, -10, -12, 0);
    addStrategy(new SCIrisWipeEffectStrategyBase(shape, Horizontal, "eyeWipe", "horizontal", false));

    //horizontal reverse
    addStrategy(new SCIrisWipeEffectStrategyBase(shape, HorizontalReverse, "eyeWipe", "horizontal", true));
}
Ejemplo n.º 24
0
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
{
    const qreal radiusBase = qMax(qreal(1), maxRadius);

    QString key = QLatin1String("WaveUnderline-Bauhaus");

    QPixmap pixmap;
    if (QPixmapCache::find(key, pixmap))
        return pixmap;

    const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio
    const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod);
    const int radius = qFloor(radiusBase);

    QPainterPath path;

    qreal xs = 0;
    qreal ys = radius;

    while (xs < width) {
        xs += halfPeriod;
        ys = -ys;
        path.quadTo(xs - halfPeriod / 2, ys, xs, 0);
    }

    pixmap = QPixmap(width, radius * 2);
    pixmap.fill(Qt::transparent);
    {
        QPen wavePen = pen;
        wavePen.setCapStyle(Qt::SquareCap);

        // This is to protect against making the line too fat, as happens on Mac OS X
        // due to it having a rather thick width for the regular underline.
        const qreal maxPenWidth = .8 * radius;
        if (wavePen.widthF() > maxPenWidth)
            wavePen.setWidth(maxPenWidth);

        QPainter imgPainter(&pixmap);
        imgPainter.setPen(wavePen);
        imgPainter.setRenderHint(QPainter::Antialiasing);
        imgPainter.translate(0, radius);
        imgPainter.drawPath(path);
    }

    QPixmapCache::insert(key, pixmap);

    return pixmap;
}
Ejemplo n.º 25
0
void KisCurvePaintOp::paintLine(KisPaintDeviceSP dab, const KisPaintInformation &pi1, const KisPaintInformation &pi2)
{
    if (!m_painter) {
        m_painter = new KisPainter(dab);
        m_painter->setPaintColor(painter()->paintColor());
    }

    int maxPoints = m_curveProperties.curve_stroke_history_size;

    m_points.append(pi2.pos());

    while (m_points.length() > maxPoints) {
        m_points.removeFirst();
    }

    const qreal additionalScale = KisLodTransform::lodToScale(painter()->device());
    const qreal lineWidth = additionalScale * m_lineWidthOption.apply(pi2, m_curveProperties.curve_line_width);

    QPen pen(QBrush(Qt::white), lineWidth);
    QPainterPath path;

    if (m_curveProperties.curve_paint_connection_line) {
        path.moveTo(pi1.pos());
        path.lineTo(pi2.pos());
        m_painter->drawPainterPath(path, pen);
        path = QPainterPath();
    }

    if (m_points.length() >= maxPoints) {
        // alpha * 0.2;
        path.moveTo(m_points.first());

        if (m_curveProperties.curve_smoothing) {
            path.quadTo(m_points.at(maxPoints / 2), m_points.last());
        }
        else {
            // control point is at 1/3 of the history, 2/3 of the history and endpoint at 3/3
            int step = maxPoints / 3;
            path.cubicTo(m_points.at(step), m_points.at(step + step), m_points.last());
        }

        qreal curveOpacity = m_curvesOpacityOption.apply(pi2, m_curveProperties.curve_curves_opacity);
        m_painter->setOpacity(qRound(255.0 * curveOpacity));
        m_painter->drawPainterPath(path, pen);
        m_painter->setOpacity(255); // full
    }
}
void TransitionItem::drawNormal(QPainter *painter)
{
    QLineF line(mapFromItem(m_from, m_from->boundingRect().center()),
                mapFromItem(m_to, m_to->boundingRect().center()));
    qreal length = line.length();

    QPointF edgeOffset((line.dx() * StateItem::radius) / length,
                       (line.dy() * StateItem::radius) / length);
    m_start = line.p1() + edgeOffset;
    m_end = line.p2() - edgeOffset;

    line = QLineF(m_start, m_end);
    length = line.length();

    QPainterPath path;
    path.moveTo(m_start);
    path.quadTo(m_control, m_end);

    if (isSelected()) {
        QPen pen(Qt::darkGreen);
        pen.setStyle(Qt::DashLine);
        painter->setPen(pen);
        painter->drawLine(m_start, m_control);
        painter->drawLine(m_end, m_control);
    }

    if (!m_isHovering)
        painter->setPen(Qt::black);
    else
        painter->setPen(Qt::blue);

    if (isSelected()) {
        QPen p(painter->pen());
        p.setColor(Qt::red);
        p.setWidth(2);
        painter->setPen(p);
    }

    drawArrow(painter, path, m_end);
    painter->drawPath(path);
    drawFunctions(painter, path);
}
Ejemplo n.º 27
0
QPainterPath
StrokeTool::strokePathQuad(QList<QPointF> *strokePoints) {
    QPainterPath path;
    int pointCount, i = 0;

    if(strokePoints == 0 || (pointCount = strokePoints->size()) == 0)
        return path;

    path.moveTo(strokePoints->at(0));
    if(pointCount == 2) {
        path.lineTo(strokePoints->at(1));
    } else while(i < pointCount) {
            if(pointCount - i == 1)
                break;
            if(pointCount - i == 2) {
                path.lineTo(strokePoints->at(i + 1));
                i += 1;
            } else {
                path.quadTo(strokePoints->at(i + 1), strokePoints->at(i + 2));
                i += 2;
            }
        }
    return path;
}
Ejemplo n.º 28
0
bool QQuickSvgParser::parsePathDataFast(const QString &dataStr, QPainterPath &path)
{
    qreal x0 = 0, y0 = 0;              // starting point
    qreal x = 0, y = 0;                // current point
    char lastMode = 0;
    QPointF ctrlPt;
    const QChar *str = dataStr.constData();
    const QChar *end = str + dataStr.size();

    while (str != end) {
        while (str->isSpace())
            ++str;
        QChar pathElem = *str;
        ++str;
        QChar endc = *end;
        *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringRef cannot guarantee
        QVarLengthArray<qreal, 8> arg;
        parseNumbersArray(str, arg);
        *const_cast<QChar *>(end) = endc;
        if (pathElem == QLatin1Char('z') || pathElem == QLatin1Char('Z'))
            arg.append(0);//dummy
        const qreal *num = arg.constData();
        int count = arg.count();
        while (count > 0) {
            qreal offsetX = x;        // correction offsets
            qreal offsetY = y;        // for relative commands
            switch (pathElem.unicode()) {
            case 'm': {
                if (count < 2) {
                    num++;
                    count--;
                    break;
                }
                x = x0 = num[0] + offsetX;
                y = y0 = num[1] + offsetY;
                num += 2;
                count -= 2;
                path.moveTo(x0, y0);

                 // As per 1.2  spec 8.3.2 The "moveto" commands
                 // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands,
                 // the subsequent pairs shall be treated as implicit 'lineto' commands.
                 pathElem = QLatin1Char('l');
            }
                break;
            case 'M': {
                if (count < 2) {
                    num++;
                    count--;
                    break;
                }
                x = x0 = num[0];
                y = y0 = num[1];
                num += 2;
                count -= 2;
                path.moveTo(x0, y0);

                // As per 1.2  spec 8.3.2 The "moveto" commands
                // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands,
                // the subsequent pairs shall be treated as implicit 'lineto' commands.
                pathElem = QLatin1Char('L');
            }
                break;
            case 'z':
            case 'Z': {
                x = x0;
                y = y0;
                count--; // skip dummy
                num++;
                path.closeSubpath();
            }
                break;
            case 'l': {
                if (count < 2) {
                    num++;
                    count--;
                    break;
                }
                x = num[0] + offsetX;
                y = num[1] + offsetY;
                num += 2;
                count -= 2;
                path.lineTo(x, y);

            }
                break;
            case 'L': {
                if (count < 2) {
                    num++;
                    count--;
                    break;
                }
                x = num[0];
                y = num[1];
                num += 2;
                count -= 2;
                path.lineTo(x, y);
            }
                break;
            case 'h': {
                x = num[0] + offsetX;
                num++;
                count--;
                path.lineTo(x, y);
            }
                break;
            case 'H': {
                x = num[0];
                num++;
                count--;
                path.lineTo(x, y);
            }
                break;
            case 'v': {
                y = num[0] + offsetY;
                num++;
                count--;
                path.lineTo(x, y);
            }
                break;
            case 'V': {
                y = num[0];
                num++;
                count--;
                path.lineTo(x, y);
            }
                break;
            case 'c': {
                if (count < 6) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c1(num[0] + offsetX, num[1] + offsetY);
                QPointF c2(num[2] + offsetX, num[3] + offsetY);
                QPointF e(num[4] + offsetX, num[5] + offsetY);
                num += 6;
                count -= 6;
                path.cubicTo(c1, c2, e);
                ctrlPt = c2;
                x = e.x();
                y = e.y();
                break;
            }
            case 'C': {
                if (count < 6) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c1(num[0], num[1]);
                QPointF c2(num[2], num[3]);
                QPointF e(num[4], num[5]);
                num += 6;
                count -= 6;
                path.cubicTo(c1, c2, e);
                ctrlPt = c2;
                x = e.x();
                y = e.y();
                break;
            }
            case 's': {
                if (count < 4) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c1;
                if (lastMode == 'c' || lastMode == 'C' ||
                    lastMode == 's' || lastMode == 'S')
                    c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
                else
                    c1 = QPointF(x, y);
                QPointF c2(num[0] + offsetX, num[1] + offsetY);
                QPointF e(num[2] + offsetX, num[3] + offsetY);
                num += 4;
                count -= 4;
                path.cubicTo(c1, c2, e);
                ctrlPt = c2;
                x = e.x();
                y = e.y();
                break;
            }
            case 'S': {
                if (count < 4) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c1;
                if (lastMode == 'c' || lastMode == 'C' ||
                    lastMode == 's' || lastMode == 'S')
                    c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
                else
                    c1 = QPointF(x, y);
                QPointF c2(num[0], num[1]);
                QPointF e(num[2], num[3]);
                num += 4;
                count -= 4;
                path.cubicTo(c1, c2, e);
                ctrlPt = c2;
                x = e.x();
                y = e.y();
                break;
            }
            case 'q': {
                if (count < 4) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c(num[0] + offsetX, num[1] + offsetY);
                QPointF e(num[2] + offsetX, num[3] + offsetY);
                num += 4;
                count -= 4;
                path.quadTo(c, e);
                ctrlPt = c;
                x = e.x();
                y = e.y();
                break;
            }
            case 'Q': {
                if (count < 4) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF c(num[0], num[1]);
                QPointF e(num[2], num[3]);
                num += 4;
                count -= 4;
                path.quadTo(c, e);
                ctrlPt = c;
                x = e.x();
                y = e.y();
                break;
            }
            case 't': {
                if (count < 2) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF e(num[0] + offsetX, num[1] + offsetY);
                num += 2;
                count -= 2;
                QPointF c;
                if (lastMode == 'q' || lastMode == 'Q' ||
                    lastMode == 't' || lastMode == 'T')
                    c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
                else
                    c = QPointF(x, y);
                path.quadTo(c, e);
                ctrlPt = c;
                x = e.x();
                y = e.y();
                break;
            }
            case 'T': {
                if (count < 2) {
                    num += count;
                    count = 0;
                    break;
                }
                QPointF e(num[0], num[1]);
                num += 2;
                count -= 2;
                QPointF c;
                if (lastMode == 'q' || lastMode == 'Q' ||
                    lastMode == 't' || lastMode == 'T')
                    c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
                else
                    c = QPointF(x, y);
                path.quadTo(c, e);
                ctrlPt = c;
                x = e.x();
                y = e.y();
                break;
            }
            case 'a': {
                if (count < 7) {
                    num += count;
                    count = 0;
                    break;
                }
                qreal rx = (*num++);
                qreal ry = (*num++);
                qreal xAxisRotation = (*num++);
                qreal largeArcFlag  = (*num++);
                qreal sweepFlag = (*num++);
                qreal ex = (*num++) + offsetX;
                qreal ey = (*num++) + offsetY;
                count -= 7;
                qreal curx = x;
                qreal cury = y;
                pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag),
                        int(sweepFlag), ex, ey, curx, cury);

                x = ex;
                y = ey;
            }
                break;
            case 'A': {
                if (count < 7) {
                    num += count;
                    count = 0;
                    break;
                }
                qreal rx = (*num++);
                qreal ry = (*num++);
                qreal xAxisRotation = (*num++);
                qreal largeArcFlag  = (*num++);
                qreal sweepFlag = (*num++);
                qreal ex = (*num++);
                qreal ey = (*num++);
                count -= 7;
                qreal curx = x;
                qreal cury = y;
                pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag),
                        int(sweepFlag), ex, ey, curx, cury);

                x = ex;
                y = ey;
            }
                break;
            default:
                return false;
            }
            lastMode = pathElem.toLatin1();
        }
    }
    return true;
}
Ejemplo n.º 29
0
/*! Paints the gantt item \a idx using \a painter and \a opt
 */
void ItemDelegate::paintGanttItem( QPainter* painter,
                                   const StyleOptionGanttItem& opt,
                                   const QModelIndex& idx )
{
    if ( !idx.isValid() ) return;
    const ItemType typ = static_cast<ItemType>( idx.model()->data( idx, ItemTypeRole ).toInt() );
    const QString& txt = opt.text;
    QRectF itemRect = opt.itemRect;
    QRectF boundingRect = opt.boundingRect;
    boundingRect.setY( itemRect.y() );
    boundingRect.setHeight( itemRect.height() );
    //qDebug() << "itemRect="<<itemRect<<", boundingRect="<<boundingRect;

    painter->save();

    QPen pen = defaultPen( typ );
    if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
    painter->setPen( pen );
    painter->setBrush( defaultBrush( typ ) );

    qreal pw = painter->pen().width()/2.;
    switch( typ ) {
    case TypeTask:
        if ( itemRect.isValid() ) {
            // TODO
            qreal pw = painter->pen().width()/2.;
            pw-=1;
            QRectF r = itemRect;
            r.translate( 0., r.height()/6. );
            r.setHeight( 2.*r.height()/3. );
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawRect( r );
            bool ok;
            qreal completion = idx.model()->data( idx, KDGantt::TaskCompletionRole ).toDouble( &ok );
            if ( ok ) {
                qreal h = r.height();
                QRectF cr( r.x(), r.y()+h/4. + 1,
                           r.width()*completion/100., h/2. - 2 );
                painter->fillRect( cr, painter->pen().brush() );
            }
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta, txt );
        }
        break;
    case TypeSummary:
        if ( opt.itemRect.isValid() ) {
            // TODO
            pw-=1;
            const QRectF r = QRectF( opt.itemRect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal deltaY = r.height()/2.;
            const qreal deltaX = qMin( r.width()/qreal(2), deltaY );
            path.moveTo( r.topLeft() );
            path.lineTo( r.topRight() );
            path.lineTo( QPointF( r.right(), r.top() + 2.*deltaY ) );
            //path.lineTo( QPointF( r.right()-3./2.*delta, r.top() + delta ) );
            path.quadTo( QPointF( r.right()-.5*deltaX, r.top() + deltaY ), QPointF( r.right()-2.*deltaX, r.top() + deltaY ) );
            //path.lineTo( QPointF( r.left()+3./2.*delta, r.top() + delta ) );
            path.lineTo( QPointF( r.left() + 2.*deltaX, r.top() + deltaY ) );
            path.quadTo( QPointF( r.left()+.5*deltaX, r.top() + deltaY ), QPointF( r.left(), r.top() + 2.*deltaY ) );
            path.closeSubpath();
            painter->setBrushOrigin( itemRect.topLeft() );
            painter->save();
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    case TypeEvent: /* TODO */
        //qDebug() << opt.boundingRect << opt.itemRect;
        if ( opt.boundingRect.isValid() ) {
            const qreal pw = painter->pen().width() / 2. - 1;
            const QRectF r = QRectF( opt.rect ).adjusted( -pw, -pw, pw, pw );
            QPainterPath path;
            const qreal delta = static_cast< int >( r.height() / 2 );
            path.moveTo( delta, 0. );
            path.lineTo( 2.*delta, delta );
            path.lineTo( delta, 2.*delta );
            path.lineTo( 0., delta );
            path.closeSubpath();
            painter->save();
            painter->translate( r.topLeft() );
            painter->translate( 0.5, 0.5 );
            painter->drawPath( path );
            painter->restore();
            Qt::Alignment ta;
            switch( opt.displayPosition ) {
            case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
            case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
            case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
            }
            painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
        }
        break;
    default:
        break;
    }
    painter->restore();
}
Ejemplo n.º 30
0
void ConnectorGraphics::updatePosition()
{
  QPainterPath Path;

  QPointF FromPos;
  QPointF ToPos;

  if (m_FromOutNode == NODE_PROD)
    FromPos = mp_FromItem->getProducedIOPosition();
  else
    FromPos = mp_FromItem->getUpOutIOPosition();

  if (m_ToInNode == NODE_REQ)
    ToPos = mp_ToItem->getRequiredIOPosition();
  else if (m_ToInNode == NODE_US)
    ToPos = mp_ToItem->getUsedIOPosition();
  else
    ToPos = mp_ToItem->getUpInIOPosition();


  Path.moveTo(FromPos);

  // intermediate position helps for correct bezier curve shape
  // and for positionning of variable names as curve label
  QPointF InterPos;


  if (FromPos.y() < ToPos.y()) // "From" slot (source) is upper than "To" slot (destination)
  {

    InterPos = QPointF(FromPos.x()+((ToPos.x()-FromPos.x())/2.0),
                        FromPos.y()+((ToPos.y()-FromPos.y())/2.0));

    Path.quadTo(QPointF(FromPos.x(),InterPos.y()),InterPos);
    Path.quadTo(QPointF(ToPos.x(),InterPos.y()),ToPos);
  }
  else // "From" slot (source) is lower than "To" slot (destination)
  {
    InterPos = QPointF(FromPos.x()+((ToPos.x()-FromPos.x())/2.0)-200,
                       FromPos.y()+((ToPos.y()-FromPos.y())/2.0));

    Path.quadTo(QPointF(FromPos.x()-200,FromPos.y()+200),
                InterPos);
    Path.quadTo(QPointF(ToPos.x()-200,ToPos.y()-200),
                ToPos);
  }

  setPath(Path);



  // variables names
  mp_VarsText->setText(m_Variables.join("\n"));

  QPointF TextPos(InterPos.x()-mp_VarsText->boundingRect().width()/2,
                  InterPos.y()-mp_VarsText->boundingRect().height()/2);

  mp_VarsText->setPos(TextPos);



  // variables names background box
  mp_VarsTextBox->setRect(TextPos.x()-2,TextPos.y()-2,
                          mp_VarsText->boundingRect().width()+4, mp_VarsText->boundingRect().height()+4);
}