Ejemplo n.º 1
1
QGraphicsItem *addSmiley() {
    QPen thickPen(Qt::black);
    thickPen.setWidth(2);

    // add face
    QGraphicsEllipseItem *face = new QGraphicsEllipseItem(QRect(-50, -50, 100, 100));
    face->setPen(Qt::NoPen);
    face->setBrush(Qt::yellow);

    // add eyes
    QGraphicsEllipseItem *leftEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face);
    leftEye->setPen(thickPen);
    leftEye->setBrush(Qt::white);
    leftEye->setPos(-15, -25);

    QGraphicsEllipseItem *rightEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face);
    rightEye->setPen(thickPen);
    rightEye->setBrush(Qt::white);
    rightEye->setPos(15, -25);

    // add smile

    QPainterPath smileArc;
    QRect rect(-33, -15, 66, 50);
    smileArc.arcMoveTo(rect, 0);
    smileArc.arcTo(rect, 0, -180);
    QGraphicsPathItem *smile = new QGraphicsPathItem(smileArc, face);
    smile->setPen(thickPen);

    return face;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
void
Canvas::DrawAnnulus(int x, int y,
                    unsigned inner_r, unsigned outer_r,
                    Angle start, Angle end)
  {
  QPainterPath p;
  QRectF ri(x - inner_r, y - inner_r, 2 * inner_r, 2 * inner_r);
  QRectF ro(x - outer_r, y - outer_r, 2 * outer_r, 2 * outer_r);
  // Draw the inner radius of the annulus.
  p.arcMoveTo(ri, start.Degrees());
  p.arcTo(ri, start.Degrees(), end.Degrees() - start.Degrees());
  if (start != end)
    { // Only draw the end caps when needed.
    // The currentPosition() will be at the end of the inner circle. Draw
    // one side of the annulus.
    // \todo This doesn't work because Angle(360) != Angle(0)!
    double xx = (outer_r - inner_r) * cos(end.Radians()) +
                p.currentPosition().rx();
    double yy = (outer_r - inner_r) * -sin(end.Radians()) +
                p.currentPosition().ry();
    p.lineTo(xx, yy);
    }
  else
    p.arcMoveTo(ro, end.Degrees());  // Set up for the outer circle.
  // The currentPosition() will be at the 'end' of the outer circle. Draw the
  // outer to the start.
  p.arcTo(ro, end.Degrees(), start.Degrees() - end.Degrees());
  if (start != end)
    {// And close it off to finish up.
    p.closeSubpath();
    }
  this->pushObject(p, this->pen(), this->brush());
  }
Ejemplo n.º 3
0
void SearchButton::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainterPath myPath;

    int radius = (height() / 5) * 2;
    QRect circle(height() / 3 - 1, height() / 4, radius, radius);
    myPath.addEllipse(circle);

    myPath.arcMoveTo(circle, 300);
    QPointF c = myPath.currentPosition();
    int diff = height() / 7;
    myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(Qt::darkGray, 2));
    painter.drawPath(myPath);

    if (m_menu) {
        QPainterPath dropPath;
        dropPath.arcMoveTo(circle, 320);
        QPointF c = dropPath.currentPosition();
        c = QPointF(c.x() + 3.5, c.y() + 0.5);
        dropPath.moveTo(c);
        dropPath.lineTo(c.x() + 4, c.y());
        dropPath.lineTo(c.x() + 2, c.y() + 2);
        dropPath.closeSubpath();
        painter.setPen(Qt::darkGray);
        painter.setBrush(Qt::darkGray);
        painter.setRenderHint(QPainter::Antialiasing, false);
        painter.drawPath(dropPath);
    }
    painter.end();
}
Ejemplo n.º 4
0
void tst_QPainterPath::arcWinding_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QPointF>("point");
    QTest::addColumn<bool>("inside");

    QPainterPath a;
    a.addEllipse(0, 0, 100, 100);
    a.addRect(50, 50, 100, 100);

    QTest::newRow("Case A (oddeven)") << a << QPointF(55, 55) << false;
    a.setFillRule(Qt::WindingFill);
    QTest::newRow("Case A (winding)") << a << QPointF(55, 55) << true;

    QPainterPath b;
    b.arcMoveTo(0, 0, 100, 100, 10);
    b.arcTo(0, 0, 100, 100, 10, 360);
    b.addRect(50, 50, 100, 100);

    QTest::newRow("Case B (oddeven)") << b << QPointF(55, 55) << false;
    b.setFillRule(Qt::WindingFill);
    QTest::newRow("Case B (winding)") << b << QPointF(55, 55) << false;

    QPainterPath c;
    c.arcMoveTo(0, 0, 100, 100, 0);
    c.arcTo(0, 0, 100, 100, 0, 360);
    c.addRect(50, 50, 100, 100);

    QTest::newRow("Case C (oddeven)") << c << QPointF(55, 55) << false;
    c.setFillRule(Qt::WindingFill);
    QTest::newRow("Case C (winding)") << c << QPointF(55, 55) << false;

    QPainterPath d;
    d.arcMoveTo(0, 0, 100, 100, 10);
    d.arcTo(0, 0, 100, 100, 10, -360);
    d.addRect(50, 50, 100, 100);

    QTest::newRow("Case D (oddeven)") << d << QPointF(55, 55) << false;
    d.setFillRule(Qt::WindingFill);
    QTest::newRow("Case D (winding)") << d << QPointF(55, 55) << true;

    QPainterPath e;
    e.arcMoveTo(0, 0, 100, 100, 0);
    e.arcTo(0, 0, 100, 100, 0, -360);
    e.addRect(50, 50, 100, 100);

    QTest::newRow("Case E (oddeven)") << e << QPointF(55, 55) << false;
    e.setFillRule(Qt::WindingFill);
    QTest::newRow("Case E (winding)") << e << QPointF(55, 55) << true;
}
Ejemplo n.º 5
0
dialogSmithChart::dialogSmithChart(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::dialogSmithChart)
{
  ui->setupUi(this);
  resize(430,400);

  scene = new QGraphicsScene(this);
  ui->graphicsView->setScene(scene);

  QBrush redBrush(Qt::red);
  QBrush blueBrush(Qt::blue);
  QPen blackPen(Qt::black);

  //ell = scene->addEllipse(10,10,100,100,blackPen,redBrush);
  QPainterPath* path = new QPainterPath();
 path->arcMoveTo(0,0,50,50,20);
 path->arcTo(0,0,50,50,20, 90);

 scene->addPath(*path);
 //ui->graphicsView->sc
  //h = 430; w = 400
//  centerX = 195;
//  CenterY = 191;

}
Ejemplo n.º 6
0
void Robotcl::drawRobot(QPainter *painter)
{
    painter->save();
    painter->translate(px,py);

    QPen pen;
    QBrush brush;
    if(team() == Blue)
    {
        if(Field::SelectedRobotID == ID)
            pen.setColor(Qt::white);
        else
            pen.setColor(Qt::blue);
        brush = QBrush(QColor("blue"));
    }
    else if(team()==Yellow)
    {
        if(Field::SelectedRobotID == ID)
            pen.setColor(Qt::white);
        else
            pen.setColor(Qt::yellow);
        brush = QBrush(QColor("Yellow"));
    }

    QPainterPath robotPath;

    robotPath.moveTo(-diagonal/2.0,-diagonal/2.0);
    robotPath.arcMoveTo(-diagonal/2.0,-diagonal/2.0,diagonal,diagonal,0);
    robotPath.arcTo(-diagonal/2.0,-diagonal/2.0,diagonal,diagonal,0,290.0);


    pen.setWidth(10);
    painter->setPen(pen);

    qreal rotateAngle = 35.0;
    painter->rotate(orientation()-rotateAngle);
    painter->fillPath(robotPath,brush);

    painter->rotate(-(orientation()-rotateAngle));
    QRectF rect;

    pen.setWidth(20);
    if(Field::SelectedRobotID == ID)
        pen.setColor(Qt::white);
    else
        pen.setColor(Qt::black);


    painter->setPen(pen);
    painter->setBrush(Qt::NoBrush);
    painter->setFont(QFont("Tahoma",100));



    rect = painter->boundingRect(rect,QString::number(ID));

    painter->scale(1,-1);
    painter->drawText(0,0 ,rect.width() ,rect.height() ,0 ,QString::number(ID));
    painter->restore();
}
Ejemplo n.º 7
0
void tst_QPainterPath::testArcMoveTo()
{
    QFETCH(QRectF, rect);
    QFETCH(qreal, angle);

    QPainterPath path;
    path.arcMoveTo(rect, angle);
    path.arcTo(rect, angle, 30);
    path.arcTo(rect, angle + 30, 30);

    QPointF pos = path.elementAt(0);

    QVERIFY((path.elementCount()-1) % 3 == 0);

    qreal x_radius = rect.width() / 2.0;
    qreal y_radius = rect.height() / 2.0;

    QPointF shouldBe = rect.center()
                       + QPointF(x_radius * cos(ANGLE(angle)), -y_radius * sin(ANGLE(angle)));

    qreal iw = 1 / rect.width();
    qreal ih = 1 / rect.height();

    QVERIFY(pathFuzzyCompare(pos.x() * iw, shouldBe.x() * iw));
    QVERIFY(pathFuzzyCompare(pos.y() * ih, shouldBe.y() * ih));
}
void EllipseObject::updatePath()
{
    QPainterPath path;
    QRectF r = rect();
    path.arcMoveTo(r, 0);
    path.arcTo(r, 0, 360);
    //NOTE: Reverse the path so that the inside area isn't considered part of the ellipse
    path.arcTo(r, 0, -360);
    setObjectPath(path);
}
Ejemplo n.º 9
0
void CircleObject::updatePath()
{
    QPainterPath path;
    QRectF r = rect();
    //Add the center point
    path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002);
    //Add the circle
    path.arcMoveTo(r, 0);
    path.arcTo(r, 0, 360);
    //NOTE: Reverse the path so that the inside area isn't considered part of the circle
    path.arcTo(r, 0, -360);
    setObjectPath(path);
}
Ejemplo n.º 10
0
QPainterPath CircleObject::objectSavePath() const
{
    QPainterPath path;
    QRectF r = rect();
    path.arcMoveTo(r, 0);
    path.arcTo(r, 0, 360);

    qreal s = scale();
    QTransform trans;
    trans.rotate(rotation());
    trans.scale(s,s);
    return trans.map(path);
}
Ejemplo n.º 11
0
//------------------------------------------------------------------------------
void
Canvas::DrawSegment(int x,
                    int y,
                    unsigned radius,
                    Angle start,
                    Angle end,
                    bool horizon)
  {
  QPainterPath p;
  QRectF r(x - radius, y - radius, 2 * radius, 2 * radius);
  p.arcMoveTo(r, start.Degrees());
  p.arcTo(r, start.Degrees(), end.Degrees() - start.Degrees());
  this->pushObject(p, this->pen(), this->brush());
  }
Ejemplo n.º 12
0
void Arc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                QWidget *widget)
{
    QPen paintpen;
    painter->setRenderHint(QPainter::Antialiasing);
    paintpen.setCosmetic(true);
    paintpen.setWidth(1);

    // Draw arc
    if (option->state & QStyle::State_Selected)
    {
        // sets brush for end points
        painter->setBrush(Qt::SolidPattern);
        paintpen.setColor(Qt::red);
        painter->setPen(paintpen);
        painter->drawEllipse(p1, 2, 2);
        painter->drawEllipse(p2, 2, 2);
        painter->drawEllipse(p3, 2, 2);

        // sets pen for arc path
        paintpen.setStyle(Qt::DashLine);
        paintpen.setColor(Qt::black);
        painter->setPen(paintpen);
    }

    else
    {
        painter->setBrush(Qt::SolidPattern);
        paintpen.setColor(Qt::black);
        painter->setPen(paintpen);
        painter->drawEllipse(p1, 2, 2);
        painter->drawEllipse(p2, 2, 2);
        painter->drawEllipse(p3, 2, 2);
    }

    QPainterPath path;
    path.arcMoveTo(circle, startAngle);
    path.arcTo(circle, startAngle, spanAngle);
    painter->setBrush(Qt::NoBrush);
    painter->drawPath(path);
}
Ejemplo n.º 13
0
void CircularIndicatorMeterWidget::paintEvent(QPaintEvent* paintevent)
{
    MeterWidget::paintEvent(paintevent);

    m_MainBrush = QBrush(m_MainColor);
    m_OutlinePen = QPen(m_OutlineColor);
    m_OutlinePen.setWidth(1);
    m_OutlinePen.setStyle(Qt::SolidLine);

    //painter
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    // define scale and location
    painter.translate(m_Width / 2, m_Height / 2);
    painter.scale(m_Width / 200.0, m_Height / 200.0);

    // Draw circular indicator
    // Define coordinates:
    static const QPoint CP_pt1(0, -70);
    static const QPoint CP_pt2(0, -90);
    static const QRectF CP_extRect(-90,-90,180,180);
    static const QRectF CP_intRect(-70,-70,140,140);
    // rotate painter
    painter.save();
    painter.rotate(-m_Angle/2);

    double CPAngle = qBound((float) -1.0, (Value-m_RangeMin) / (m_RangeMax-m_RangeMin), (float) 1.0) * m_Angle;
    QPainterPath CPEmptyPath;
    CPEmptyPath.moveTo(CP_pt1);
    CPEmptyPath.arcMoveTo(CP_intRect, 90 - CPAngle);
    QPainterPath CPIndicatorPath;
    CPIndicatorPath.moveTo(CP_pt1);
    CPIndicatorPath.lineTo(CP_pt2);
    CPIndicatorPath.arcTo(CP_extRect, 90, -1 * CPAngle);
    CPIndicatorPath.lineTo(CPEmptyPath.currentPosition());
    CPIndicatorPath.arcTo(CP_intRect, 90 - CPAngle, CPAngle);
    painter.setBrush(IndicatorGradient);
    painter.setPen(Qt::NoPen);
    painter.drawPath(CPIndicatorPath);
    painter.restore();
}
Ejemplo n.º 14
0
void ShapePaintVisitor::visitPath(const PathShape *shapePath)
{
    m_painter->save();
    m_painter->setRenderHint(QPainter::Antialiasing, true);
    QPainterPath path;
    foreach (const PathShape::Element &element, shapePath->elements()) {
        switch (element.m_elementType) {
        case PathShape::TypeNone:
            // nothing to do
            break;
        case PathShape::TypeMoveto:
            path.moveTo(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size));
            break;
        case PathShape::TypeLineto:
            path.lineTo(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size));
            break;
        case PathShape::TypeArcmoveto:
        {
            QSizeF radius = element.m_size.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size);
            path.arcMoveTo(QRectF(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size) - QPointF(radius.width(), radius.height()),
                                  radius * 2.0),
                           element.m_angle1);
            break;
        }
        case PathShape::TypeArcto:
        {
            QSizeF radius = element.m_size.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size);
            path.arcTo(QRectF(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size) - QPointF(radius.width(), radius.height()),
                              radius * 2.0),
                       element.m_angle1, element.m_angle2);
            break;
        }
        case PathShape::TypeClose:
            path.closeSubpath();
            break;
        }
    }
    m_painter->drawPath(path);
    m_painter->restore();
}
Ejemplo n.º 15
0
//------------------------------------------------------------------------------
void
Canvas::DrawKeyhole(int x, int y,
                    unsigned inner_r, unsigned outer_r,
                    Angle start, Angle end)
  {
  // Make sure that the 'left' angle is first.
  QPainterPath path;
  path.setFillRule(Qt::WindingFill);
  Angle startN = this->normalize(start);
  Angle endN   = this->normalize(end);
  Angle a[4];
  a[2] = (startN > endN) ? startN : endN;
  a[3] = (startN > endN) ? endN : startN;
  a[0] = this->geo2Screen(a[3]);
  a[1] = this->geo2Screen(a[2]);
#ifndef NDEBUG
  std::cerr << __LINE__ << ": "
            << a[0].Degrees() << ", " << a[1].Degrees() << ", "
            << a[2].Degrees() << ", " << a[3].Degrees() << std::endl;
#endif
  // Draw the inner with a segment left out for the cone.
  path.arcMoveTo(this->boundingBox(x, y, inner_r), a[0].Degrees());
  path.arcTo(this->boundingBox(x, y, inner_r),
             a[0].Degrees(), 360.0 - fabs(a[1].Degrees() - a[0].Degrees()));
  // The currentPosition() will be at the end of the inner circle. Draw
  // one side of the cone.
  double xx = (outer_r - inner_r) * cos(a[1].Radians()) +
              path.currentPosition().rx();
  double yy = (outer_r - inner_r) * -sin(a[1].Radians()) +
              path.currentPosition().ry();
  path.lineTo(xx, yy);
  // Draw the outer arc of the cone.
  path.arcTo(this->boundingBox(x, y, outer_r),
             a[1].Degrees(), fabs(a[1].Degrees() - a[0].Degrees()));
  // This will draw the other side of the cone to finish the keyhole.
  path.closeSubpath();
  this->pushObject(path, this->pen(), this->brush());
  }
Ejemplo n.º 16
0
void ShapeSizeVisitor::visitPath(const PathShape *shapePath)
{
    QPainterPath path;
    foreach (const PathShape::Element &element, shapePath->elements()) {
        switch (element.m_elementType) {
        case PathShape::TypeNone:
            // nothing to do
            break;
        case PathShape::TypeMoveto:
            path.moveTo(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size));
            break;
        case PathShape::TypeLineto:
            path.lineTo(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size));
            break;
        case PathShape::TypeArcmoveto:
        {
            QSizeF radius = element.m_size.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size);
            path.arcMoveTo(QRectF(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size) - QPointF(radius.width(), radius.height()),
                                  radius * 2.0),
                           element.m_angle1);
            break;
        }
        case PathShape::TypeArcto:
        {
            QSizeF radius = element.m_size.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size);
            path.arcTo(QRectF(element.m_position.mapScaledTo(m_scaledOrigin, m_originalSize, m_baseSize, m_size) - QPointF(radius.width(), radius.height()),
                              radius * 2.0),
                       element.m_angle1, element.m_angle2);
            break;
        }
        case PathShape::TypeClose:
            path.closeSubpath();
            break;
        }
    }
    m_boundingRect |= path.boundingRect();
}
Ejemplo n.º 17
0
void SunMenuItemView::updateShape()
{
    QPainterPath newPath;

    qreal tmp = qAbs(sweepLength());
    if (width() != 0 && tmp > 0.001)
    {
        qint32 innerRad = innerRadius();
        qint32 outerRadius = innerRad + width();
        QRectF r = QRect(-outerRadius, -outerRadius, outerRadius * 2,
                         outerRadius * 2);

        if (innerRad == 0 && qAbs(sweepLength() - 360) < 0.0001)
        {
            newPath.addEllipse(r);
        }
        else
        {
            newPath.arcMoveTo(r, startAngle());
            newPath.arcTo(r, startAngle(), sweepLength());

            if(innerRad == 0)
            {
                newPath.lineTo(0,0);
            }else
            {
                r = QRect(-innerRad, -innerRad, innerRad * 2, innerRad * 2);
                newPath.arcTo(r, startAngle() + sweepLength(), -sweepLength());
            }
            newPath.closeSubpath();
        }
    }
    //
    setPath(newPath);
    reinitializeDisplayedItemPosition();
}
Ejemplo n.º 18
0
static void qtmDrawRoundedRect(QPainter *p, const QRectF &rect, qreal xRadius, qreal yRadius,
                               Qt::SizeMode mode)
{
  QRectF r = rect.normalized();
  
  if (r.isNull())
    return;
  
  if (mode == Qt::AbsoluteSize) {
    qreal w = r.width() / 2;
    qreal h = r.height() / 2;
    
    xRadius = 100 * qMin(xRadius, w) / w;
    yRadius = 100 * qMin(yRadius, h) / h;
  } else {
    if (xRadius > 100)                          // fix ranges
      xRadius = 100;
    
    if (yRadius > 100)
      yRadius = 100;
  }
  
  QPainterPath path;
  
  if (xRadius <= 0 || yRadius <= 0) {             // add normal rectangle
    path.addRect(r);
  } else {
    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();
    qreal rxx2 = w*xRadius/100;
    qreal ryy2 = h*yRadius/100;
    
#ifdef Q_WS_X11
    // There is a bug (probably in arcTo) for small sizes.
    // We use a rough linear approx.
    rxx2 /= 4;
    ryy2 /= 4;
    path.moveTo(x+rxx2,y);
    path.lineTo(x+w-rxx2, y);
    path.lineTo(x+w, y+ryy2);
    path.lineTo(x+w, y+h-ryy2);    
    path.lineTo(x+w-rxx2, y+h);    
    path.lineTo(x+rxx2, y+h);    
    path.lineTo(x, y+h-ryy2);    
    path.lineTo(x, y+ryy2);    
    path.closeSubpath();
#else
    path.moveTo(x+rxx2,y);
    path.arcMoveTo(x, y, rxx2, ryy2, 90);
    path.arcTo(x, y, rxx2, ryy2, 90, 90);
    path.arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    path.arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    path.arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
    path.closeSubpath();
#endif
  }
  
  p->drawPath(path);
}
Ejemplo n.º 19
0
void shape_cd::draw ( draw_vars& dr, stack&, QGraphicsScene& sc)
{
  shapes* prev = get_prev();
  if(prev && prev->type()== QString("shape_e") && dr.drawAsHorisontal())
  {
    return;
  }
    if ( is_current() ) dr.draw_marker ( sc );

    int nSegments = get_n_segment();

    for ( int i = 0 ; i < nSegments; ++i )
    {
        draw_point p_start = dr.get_p_otn();   //Начальная точка сегмента дуги.
        draw_point delta_p = get_delta_p ( i ) * dr.get_masht() ;
        qreal C = abs ( get_c ( i ) );   //Значение параметра кривизны.
        qreal C_sign = get_c ( i ) / C; //Знак параметра кривизны.
        dr.move_coords ( delta_p );
        draw_point p_end = dr.get_p_otn();    //Конечная точка сегмента дуги.

        if (dr.drawWhisOutPenUpMovement() && !dr.get_pero()) ;
        else if ( get_c ( i ) != 0 )
        {
            qreal D = p_start.dist ( p_end );  //Расстояние между конечными точками сегмента.
            qreal H = C * D / qreal ( 2 ) / qreal ( 127 );   //Высота сегмента.
            qreal R = D * D / ( H * qreal ( 8 ) ) + H / qreal ( 2 ); //Радиус дуги.

            qreal ang = p_start.agnle ( p_end );
            draw_point p_mid_hord = p_start.polar ( ang, D / qreal ( 2 ) );
            draw_point p_center = p_mid_hord.polar ( ang + C_sign * M_PI / qreal ( 2 ), R - H );

            draw_point p_radius ( R, R );
            qreal ang_start = draw_point::rtd ( p_center.agnle ( p_start ) );
            qreal ang_4 = draw_point::rtd ( atan2 ( H, D / qreal ( 2 ) ) );
            qreal ang_number = C_sign * ang_4 * qreal ( 4 );
            if ( is_current() )
            {
                QPen pen( QBrush
                          ( QColor ( draw_vars::s_color_cur ), Qt::SolidPattern ),
                          qreal ( draw_vars::s_width_cur ) ,
                          Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );
                if ( i == get_current())
                    pen.setColor(QColor ( draw_vars::s_color_9d));
                else
                    pen.setColor(QColor ( draw_vars::s_color_cur));
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }

        }
        else
        {
            if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
        }
    }
}
Ejemplo n.º 20
0
static inline QPainterPath headerPath( const QRectF& r, int roundness,
                                       int headerHeight = 10 )
{
    QPainterPath path;
    int xRnd = roundness;
    int yRnd = roundness;
    if( r.width() > r.height() )
    {
        xRnd = int ( roundness * r.height() / r.width() );
    }
    else
    {
        yRnd = int ( roundness * r.width() / r.height() );
    }

    if( xRnd >= 100 )                        // fix ranges
    {
        xRnd = 99;
    }
    if( yRnd >= 100 )
    {
        yRnd = 99;
    }
    if( xRnd <= 0 || yRnd <= 0 )             // add normal rectangle
    {
        path.addRect( r );
        return path;
    }

    QRectF rect = r.normalized();

    if( rect.isNull() )
    {
        return path;
    }

    qreal x = rect.x();
    qreal y = rect.y();
    qreal w = rect.width();
    qreal h = rect.height();
    qreal rxx = w * xRnd / 200;
    qreal ryy = h * yRnd / 200;
    // were there overflows?
    if( rxx < 0 )
    {
        rxx = w / 200 * xRnd;
    }
    if( ryy < 0 )
    {
        ryy = h / 200 * yRnd;
    }
    qreal rxx2 = 2 * rxx;
    qreal ryy2 = 2 * ryy;

    path.arcMoveTo( x, y, rxx2, ryy2, 90 );
    path.arcTo( x, y, rxx2, ryy2, 90, 90 );
    QPointF pt = path.currentPosition();
    path.lineTo( x, pt.y() + headerHeight );
    path.lineTo( x + w, pt.y() + headerHeight );
    path.lineTo( x + w, pt.y() );
    path.arcTo( x + w - rxx2, y, rxx2, ryy2, 0, 90 );
    path.closeSubpath();

    return path;
}
Ejemplo n.º 21
0
QPainterPath RectangleSymbol::painterPath(void)
{
    QPainterPath path;

    QRectF rect(-m_w / 2, -m_h / 2, m_w, m_h);
    QRectF r = rect.normalized();

    if (r.isNull())
        return path;

    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();

    if (m_type == NORMAL || m_rad <= 0) {
        path.addRect(x, y, w, h);
        return path;
    }

    m_rad = qMin(qMin(w / 2, h / 2), m_rad);

    if (m_corners & 2) {
        if (m_type == ROUNDED) {
            path.arcMoveTo(x, y, m_rad, m_rad, 180);
            path.arcTo(x, y, m_rad, m_rad, 180, -90);
        } else {
            path.moveTo(x, y+m_rad);
            path.lineTo(x+m_rad, y);
            path.lineTo(x+w-m_rad, y);
        }
    } else {
        path.moveTo(x, y);
        path.lineTo(x+w-m_rad, y);
    }

    if (m_corners & 1) {
        if (m_type == ROUNDED) {
            path.arcTo(x+w-m_rad, y, m_rad, m_rad, 90, -90);
        } else {
            path.lineTo(x+w, y+m_rad);
            path.lineTo(x+w, y+h-m_rad);
        }
    } else {
        path.lineTo(x+w, y);
        path.lineTo(x+w, y+h-m_rad);
    }

    if (m_corners & 8) {
        if (m_type == ROUNDED) {
            path.arcTo(x+w-m_rad, y+h-m_rad, m_rad, m_rad, 0, -90);
        } else {
            path.lineTo(x+w-m_rad, y+h);
            path.lineTo(x+m_rad, y+h);
        }
    } else {
        path.lineTo(x+w, y+h);
        path.lineTo(x+m_rad, y+h);
    }

    if (m_corners & 4) {
        if (m_type == ROUNDED) {
            path.arcTo(x, y+h-m_rad, m_rad, m_rad, 270, -90);
        } else {
            path.lineTo(x, y+h-m_rad);
        }
    } else {
        path.lineTo(x, y+h);
    }
    path.closeSubpath();

    return path;
}
Ejemplo n.º 22
0
GLuint NaviCubeImplementation::createButtonTex(QtGLWidget* gl, int button) {
	int texSize = m_CubeWidgetSize * m_OverSample;
	QImage image(texSize, texSize, QImage::Format_ARGB32);
	image.fill(qRgba(255, 255, 255, 0));
	QPainter painter;
	painter.begin(&image);

	QTransform transform;
	transform.translate(texSize / 2, texSize / 2);
	transform.scale(texSize / 2, texSize / 2);
	painter.setTransform(transform);

	QPainterPath path;

	float as1 = 0.12f; // arrow size
	float as3 = as1 / 3;

	switch (button) {
	default:
		break;
	case TEX_ARROW_RIGHT:
	case TEX_ARROW_LEFT: {
		QRectF r(-1.00, -1.00, 2.00, 2.00);
		QRectF r0(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r1(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r2(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r3(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r4(r);

		float a0 = 72;
		float a1 = 45;
		float a2 = 38;

		if (TEX_ARROW_LEFT == button) {
			a0 = 180 - a0;
			a1 = 180 - a1;
			a2 = 180 - a2;
		}

		path.arcMoveTo(r0, a1);
		QPointF p0 = path.currentPosition();

		path.arcMoveTo(r2, a2);
		QPointF p1 = path.currentPosition();

		path.arcMoveTo(r4, a1);
		QPointF p2 = path.currentPosition();

		path.arcMoveTo(r1, a0);
		path.arcTo(r1, a0, -(a0 - a1));
		path.lineTo(p0);
		path.lineTo(p1);
		path.lineTo(p2);
		path.arcTo(r3, a1, +(a0 - a1));
		break;
	}
	case TEX_ARROW_EAST: {
		path.moveTo(1, 0);
		path.lineTo(1 - as1, +as1);
		path.lineTo(1 - as1, -as1);
		break;
	}
	case TEX_ARROW_WEST: {
		path.moveTo(-1, 0);
		path.lineTo(-1 + as1, -as1);
		path.lineTo(-1 + as1, +as1);
		break;
	}
	case TEX_ARROW_SOUTH: {
		path.moveTo(0, 1);
		path.lineTo(-as1,1 - as1);
		path.lineTo(+as1,1 - as1);
		break;
	}
	case TEX_ARROW_NORTH: {
		path.moveTo(0, -1);
		path.lineTo(+as1,-1 + as1);
		path.lineTo(-as1,-1 + as1);
		break;
	}
	}

	painter.fillPath(path, Qt::white);

	painter.end();
	//image.save(str(enum2str(button))+str(".png"));

#if !defined(HAVE_QT5_OPENGL)
	return gl->bindTexture(image);
#else
    Q_UNUSED(gl);
    QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored());
    m_glTextures.push_back(texture);
    return texture->textureId();
#endif
}