rem: QPainter backBufferPainter (m_backBuffer); QPixmap swapPixmap = UserIcon ("colorbutton_swap_16x16"); backBufferPainter.drawPixmap (swapPixmapRect ().topLeft (), swapPixmap); backBufferPainter.end ();  QBitmap maskBitmap (m_backBuffer->width (), m_backBuffer->height ()); maskBitmap.fill (Qt::color0); m_backBuffer->setMask (maskBitmap);  kpPixmapFX::ensureOpaqueAt (m_backBuffer, swapPixmapRect ().topLeft (), swapPixmap);   backBufferPainter.begin (m_backBuffer); maskBitmap = *m_backBuffer->mask (); QPainter maskBitmapPainter (&maskBitmap);     QRect bgRect = backgroundRect (); if (kpTool::isColorOpaque (m_color [1])) backBufferPainter.fillRect (bgRect, m_color [1]); else backBufferPainter.drawPixmap (bgRect, UserIcon ("color_transparent_26x26")); maskBitmapPainter.fillRect (bgRect, Qt::color1);  QRect fgRect = foregroundRect (); if (kpTool::isColorOpaque (m_color [0])) backBufferPainter.fillRect (fgRect, m_color [0]); else backBufferPainter.drawPixmap (fgRect, UserIcon ("color_transparent_26x26")); maskBitmapPainter.fillRect (fgRect, Qt::color1);  maskBitmapPainter.end (); backBufferPainter.end ();  m_backBuffer->setMask (maskBitmap); p->drawPixmap (contentsRect (), *m_backBuffer);
context: void kpDualColorButton::drawContents (QPainter *p){#if DEBUG_KP_COLOR_TOOL_BAR && 1    kdDebug () << "kpDualColorButton::draw() rect=" << rect ()               << " contentsRect=" << contentsRect ()               << endl;#endif    if (!m_backBuffer ||        m_backBuffer->width () != contentsRect ().width () ||        m_backBuffer->height () != contentsRect ().height ())    {        delete m_backBuffer;        m_backBuffer = new QPixmap (contentsRect ().width (), contentsRect ().height ());    }            QPainter backBufferPainter (m_backBuffer);    QPixmap swapPixmap = UserIcon ("colorbutton_swap_16x16");    backBufferPainter.drawPixmap (swapPixmapRect ().topLeft (), swapPixmap);    backBufferPainter.end ();        QBitmap maskBitmap (m_backBuffer->width (), m_backBuffer->height ());    maskBitmap.fill (Qt::color0/*transparent*/);    m_backBuffer->setMask (maskBitmap);        kpPixmapFX::ensureOpaqueAt (m_backBuffer, swapPixmapRect ().topLeft (), swapPixmap);        backBufferPainter.begin (m_backBuffer);    maskBitmap = *m_backBuffer->mask ();    QPainter maskBitmapPainter (&maskBitmap);        // foreground patch must be drawn after background patch    // as it overlaps on top of background patch        QRect bgRect = backgroundRect ();    if (kpTool::isColorOpaque (m_color [1]))        backBufferPainter.fillRect (bgRect, m_color [1]);    else        backBufferPainter.drawPixmap (bgRect, UserIcon ("color_transparent_26x26"));    maskBitmapPainter.fillRect (bgRect, Qt::color1/*opaque*/);        QRect fgRect = foregroundRect ();    if (kpTool::isColorOpaque (m_color [0]))        backBufferPainter.fillRect (fgRect, m_color [0]);    else        backBufferPainter.drawPixmap (fgRect, UserIcon ("color_transparent_26x26"));    maskBitmapPainter.fillRect (fgRect, Qt::color1/*opaque*/);                maskBitmapPainter.end ();    backBufferPainter.end ();        m_backBuffer->setMask (maskBitmap);    p->drawPixmap (contentsRect (), *m_backBuffer);}