rem: QPen XORpen = pen; XORpen.setColor (Qt::white);
add: if (painter.isActive ()) { QPen XORpen = painter.pen (); XORpen.setColor (Qt::white);
context: static QPixmap pixmap (const QPixmap &oldPixmap,                       const QPointArray &points, const QRect &rect,                       const QPen &pen, const QBrush &brush,                       enum kpToolPolygon::Mode mode, bool final = true){    QPixmap pixmap = oldPixmap;#if DEBUG_KPTOOL_LINE    kdDebug () << "kptoolpolygon.cpp: pixmap(): points=" << pointArrayToString (points) << endl;#endif    QPointArray pointsInRect = points;    pointsInRect.detach ();    pointsInRect.translate (-rect.x (), -rect.y ());        QPainter painter (&pixmap);    painter.setPen (pen);    painter.setBrush (brush);        switch (mode)    {    case kpToolPolygon::Line:    case kpToolPolygon::Polyline:        painter.drawPolyline (pointsInRect);        break;    case kpToolPolygon::Polygon:        // TODO: why aren't the ends rounded?        painter.drawPolygon (pointsInRect);        if (!final)        {            int count = pointsInRect.count ();                        if (count > 2)            {                QPen XORpen = pen;                XORpen.setColor (Qt::white);                                painter.setPen (XORpen);                painter.setRasterOp (Qt::XorROP);                            painter.drawLine (pointsInRect [0], pointsInRect [count - 1]);            }        }        break;    case kpToolPolygon::Curve:        int numPoints = pointsInRect.count ();        QPointArray pa (4);                pa [0] = pointsInRect [0];        pa [3] = pointsInRect [1];                switch (numPoints)        {        case 2:            pa [1] = pointsInRect [0];            pa [2] = pointsInRect [1];            break;        case 3:            pa [1] = pa [2] = pointsInRect [2];            break;        case 4:            pa [1] = pointsInRect [2];            pa [2] = pointsInRect [3];        }                painter.drawCubicBezier (pa);    }    painter.end ();    return pixmap;}