예제 #1
0
void graph2_1::paintEvent(QPaintEvent *)
{
    /***********�����α߿���������**************/
    QPainter *painter=new QPainter(this);
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->drawRect(10,10,380,230);
    QPoint beginPoint(50,200);
    QPoint xEndPoint(xEndX,xEndY);
    QPoint yEndPoint(yEndX,yEndY);
    painter->drawLine(beginPoint,xEndPoint);
    painter->drawLine(beginPoint,yEndPoint);

    //*****************����������ͷ*********/
    int xOffset=13;
    brush.setColor(Qt::black);
    brush.setStyle(Qt::SolidPattern);
    painter->setBrush(brush);

    QPoint xarrowRightPoint(xEndX+xOffset,xEndY);
    QPoint xarrowTopPoint(xEndX,-xOffset*tan(PI/6)+xEndY);
    QPoint xarrowBotPoint(xEndX,xOffset*tan(PI/6)+xEndY);
    static const QPoint xarrowPoints[3] = {
    xarrowRightPoint,xarrowTopPoint,xarrowBotPoint,
    };
    painter->drawPolygon(xarrowPoints,3);

    QPoint yarrowTopPoint(yEndX,yEndY-xOffset);
    QPoint yarrowRightPoint(xOffset*tan(PI/6)+yEndX,yEndY);
    QPoint yarrowLeftPoint(-xOffset*tan(PI/6)+yEndX,yEndY);
    static const QPoint yarrowPoints[3] = {
    yarrowTopPoint,yarrowLeftPoint,yarrowRightPoint,
    };
    painter->drawPolygon(yarrowPoints,3);
    painter->setBrush(Qt::NoBrush);

    /************��ע������**********/
    painter->drawText(xEndX,xEndY+20,tr("HZ"));
    //painter->rotate(270);
    painter->drawText(yEndY,yEndX+20,tr("dB"));
    //painter->rotate(90);


    /*************************/
    QVector<qreal> dashes;
    qreal space = 3;
    dashes << 5 << space << 5 << space;
    pen.setDashPattern(dashes);
    pen.setWidth(2);
    pen.setColor(Qt::blue);
    painter->setPen(pen);

    QPoint point5(90,200);
    QPoint point6(100,155);
    QPoint point7(250,110);
    QPoint point8(300,80);

    painter->drawPath(drawBezierCurve(point5,point6));
    painter->drawPath(drawBezierCurve(point6,point7));
    painter->drawPath(drawBezierCurve(point7,point8));
}
예제 #2
0
static inline void
line8(Imaging im, int x0, int y0, int x1, int y1, int ink)
{
    int i, n, e;
    int dx, dy;
    int xs, ys;

    /* normalize coordinates */
    dx = x1-x0;
    if (dx < 0)
        dx = -dx, xs = -1;
    else
        xs = 1;
    dy = y1-y0;
    if (dy < 0)
        dy = -dy, ys = -1;
    else
        ys = 1;

    n = (dx > dy) ? dx : dy;

    if (dx == 0)

        /* vertical */
        for (i = 0; i < dy; i++) {
            point8(im, x0, y0, ink);
            y0 += ys;
        }

    else if (dy == 0)

        /* horizontal */
        for (i = 0; i < dx; i++) {
            point8(im, x0, y0, ink);
            x0 += xs;
        }

    else if (dx > dy) {

        /* bresenham, horizontal slope */
        n = dx;
        dy += dy;
        e = dy - dx;
        dx += dx;

        for (i = 0; i < n; i++) {
            point8(im, x0, y0, ink);
            if (e >= 0) {
                y0 += ys;
                e -= dx;
            }
            e += dy;
            x0 += xs;
        }

    } else {

        /* bresenham, vertical slope */
        n = dy;
        dx += dx;
        e = dx - dy;
        dy += dy;

        for (i = 0; i < n; i++) {
            point8(im, x0, y0, ink);
            if (e >= 0) {
                x0 += xs;
                e -= dy;
            }
            e += dx;
            y0 += ys;
        }

    }
}