Ejemplo n.º 1
0
void asciimage::Shape::renderLine(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::LINE);
    Q_ASSERT(points().size() == 2);

    if (scale == 1)
    {
        if (!isStraightLine())
        {
            painter->setRenderHint(QPainter::Antialiasing, true);
        }
        painter->setPen(style.color());
        painter->drawLine(points()[0], points()[1]);
    }
    else
    {
        if (isStraightLine())
        {
            const QRect b = boundingRect();
            painter->setPen(style.color());
            painter->setBrush(style.color());
            painter->drawRect(scaledOuterRect(b, scale));
        }
        else
        {
            painter->setRenderHint(QPainter::Antialiasing, true);
            painter->setPen(QPen(style.color(), scale, Qt::SolidLine, Qt::SquareCap));
            painter->drawLine(p(points()[0], scale), p(points()[1], scale));
        }
    }
}
Ejemplo n.º 2
0
void asciimage::Shape::renderPoint(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::POINT);
    Q_ASSERT(points().size() == 1);

    if (scale == 1)
    {
        painter->setPen(style.color());
        painter->drawPoint(points().first());
    }
    else
    {
        painter->setPen(style.color());
        painter->setBrush(style.color());
        painter->drawRect(scaledOuterRect(boundingRect(), scale));
    }
}
Ejemplo n.º 3
0
void asciimage::Shape::renderEllipse(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::ELLIPSE);
    Q_ASSERT(points().size() >= 3);

    painter->setRenderHint(QPainter::Antialiasing, true);

    const QRect rect = boundingRect();

    if (style.isFilled())
    {
        painter->setPen(style.color());
        painter->setBrush(style.color());
        painter->drawEllipse(scaledOuterRect(rect, scale).adjusted(0,0,1,1));
    }
    else
    {
        painter->setPen(QPen(style.color(), scale));
        painter->drawEllipse(QRectF(scaledOuterRect(rect, scale).adjusted(0, 0, 1, 1)).adjusted(0.5 * scale, 0.5 * scale, -0.5 * scale, -0.5 * scale));
    }
}
Ejemplo n.º 4
0
void asciimage::Shape::renderPolygon(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::POLYGON);

    if (!style.isClosed())
    {
        renderLines(painter, scale, style);
        return;
    }

    Q_ASSERT(points().size() >= 3);

    if (isRectangle() && style.isFilled())
    {
        const QRect b = boundingRect();
        painter->setPen(style.color());
        painter->setBrush(style.color());
        painter->drawRect(scaledOuterRect(b, scale));
    }
    else
    {
        QPolygonF poly;
        for (const QPoint& point : points())
        {
            poly << p(point, scale);
        }
        poly << p(points().first(), scale);

        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setPen(QPen(style.color(), scale, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
        if (style.isFilled())
        {
            painter->setBrush(style.color());
        }
        painter->drawPolygon(poly);
    }
}
Ejemplo n.º 5
0
void asciimage::Shape::renderLines(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::POLYGON);
    Q_ASSERT(points().size() >= 2);
    Q_ASSERT(!style.isClosed());

    QPolygonF lines;
    for (const QPoint& point : points())
    {
        lines << p(point, scale);
    }

    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->setPen(QPen(style.color(), scale, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
    painter->drawPolyline(lines);
}
Ejemplo n.º 6
0
QPointF DragLine::drag(QGraphicsScene *scene, QPointF p0, Style const &s) {
  return drag(scene, p0, s.real("drag-line-width"),
	      s.color("drag-line-color"));
}