예제 #1
0
파일: earrow.cpp 프로젝트: boiarino17/epics
void EArrow::paintEvent( QPaintEvent * ) {
    QPointF p1,p2;
    QLineF polyLine;
    QPainter painter( this );

    painter.setRenderHint( QPainter::Antialiasing );
    painter.setPen( QPen( getLineColor(), getLineSize(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
    painter.setBrush( getBrushColor() );

    int m_margin = 3;

    if (VERTICAL == getArrowDirection()) {
        p1 = QPointF( width()/2, m_margin );
        p2 = QPointF( width()/2, height()-m_margin );
    } else if (RIGTHBOTTOM == getArrowDirection()) {
        p1 = QPointF( m_margin, m_margin );
        p2 = QPointF( width()-m_margin, height()-m_margin );
    } else if (RIGTHTOP == getArrowDirection()) {
        p1 = QPointF( m_margin, height()-m_margin );
        p2 = QPointF( width()-m_margin, m_margin );
    } else { // HORIZONTAL
        p1 = QPointF( m_margin, height()/2 );
        p2 = QPointF( width()-m_margin, height()/2 );
    }

    polyLine = QLineF( p1, p2 );
    painter.drawLine(polyLine);

    if (LEFT == getArrowMode()) {
        painter.drawPolygon( getHead(p1,p2) );
    } else if (RIGTH == getArrowMode()) {
        painter.drawPolygon(getHead(p2,p1));
    } else if (DOUBLE == getArrowMode()) {
        painter.drawPolygon(getHead(p1,p2));
        painter.drawPolygon(getHead(p2,p1));
    }
}
예제 #2
0
void caGraphics::paintEvent( QPaintEvent *event )
{
    Q_UNUSED(event);

    if(thisHide) return;

    int m_margin = 3;
    QPointF p1,p2;
    QPainter painter( this );
    painter.setRenderHint( QPainter::Antialiasing );

    int margin = thisLineSize/2;
    int w = width() - 2 * margin;
    int h = height() - 2 * margin;

// do not increase linesize beyond the canvas size
    if(w <= 0 || h <= 0) {
        setLineSize(thisLineSize-1);
    }
    margin = thisLineSize/2;
    w = width() - 2 * margin;
    h = height() - 2 * margin;
    int x = margin;
    int y = margin;

    if(thisLineStyle == Dash) {
        painter.setPen( QPen( getLineColor(), getLineSize(), Qt::DotLine, Qt::SquareCap) );
    } else if (thisLineStyle == BigDash) {
        painter.setPen( QPen( getLineColor(), getLineSize(), Qt::DashLine, Qt::SquareCap) );
    } else {
        painter.setPen( QPen( getLineColor(), getLineSize(), Qt::SolidLine, Qt::SquareCap) );
    }

    if(thisFillStyle == Filled) {
        painter.setBrush(getForeground());
    }

    if(getForm() == Rectangle) {
        QPolygonF rectangle;
        rectangle.append(QPointF(x,y));
        rectangle.append(QPointF(x+w,y));
        rectangle.append(QPointF(x+w,y+h));
        rectangle.append(QPointF(x,y+h));
        rectangle.append(QPointF(x,y));
        // rotate
        QPolygonF rotated = rotateObject(thisTiltAngle, w, h, thisLineSize, rectangle);
        painter.drawPolygon(rotated);

    } else if(getForm() == Circle) {
        // rotate my calculated ellipse
        QPolygonF rotated = rotateObject(thisTiltAngle, w, h, thisLineSize, drawCircle(x, x+w, y, y+h));
        painter.drawPolygon(rotated);

    } else if(getForm() == Triangle) {
        QPolygonF triangle;
        triangle.append(QPointF(x+w/2,0));
        triangle.append(QPointF(x,y+h));
        triangle.append(QPointF(x+w,y+h));
        triangle.append(QPointF(x+w/2,0));

        // rotate
        QPolygonF rotated = rotateObject(thisTiltAngle, w, h, thisLineSize, triangle);
        painter.drawPolygon(rotated);

    } else if(getForm() == Arc) {
        if(thisFillStyle == Filled) {
            painter.drawPie (x, y, w, h, thisStartAngle * 16, thisSpanAngle * 16);
        } else {
            painter.drawArc (x, y, w, h, thisStartAngle * 16, thisSpanAngle * 16);
        }

    } else if(getForm() == Line) {
        QPolygonF line;
        line.append(QPointF(x,y+h/2));
        line.append(QPointF(x+w,y+h/2));

        // rotate
        QPolygonF rotated = rotateObject(thisTiltAngle, w, h, thisLineSize, line);
        painter.drawPolygon(rotated);

    } else if(getForm() == Arrow) {
        QPolygonF lines;
        QPolygonF head1;
        QPolygonF head2;

        p1 = QPointF( m_margin, height()/2 );
        p2 = QPointF( width()-m_margin, height()/2 );
        lines.append(p1);
        lines.append(p2);

        head1 = getHead(p1,p2);
        if (getArrowMode() == Double) {
            head2 = getHead(p2,p1);
        }

        for(int i=0; i<head1.count(); i++) lines.append(head1.at(i));
        for(int i=0; i<head2.count(); i++) lines.append(head2.at(i));

        // rotate
        QPolygonF rotated = rotateObject(thisTiltAngle, w, h, thisLineSize, lines);
        painter.drawPolygon(rotated);
    }

}