void PrettyPopupMenu::paintEvent( QPaintEvent* e ) { generateSidePixmap(); QPainter p( this ); QRect r = sideImageRect(); r.setTop( r.bottom() - s_sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { QRect drawRect = r.intersect( e->rect() ).intersect( sideImageRect() ); QRect pixRect = drawRect; pixRect.moveBy( -r.left(), -r.top() ); p.drawImage( drawRect.topLeft(), s_sidePixmap, pixRect ); } p.setClipRegion( e->region() ); //NOTE The order is important here. drawContents() must be called before drawPrimitive(), // otherwise we get rendering glitches. drawContents( &p ); style().drawPrimitive( QStyle::PE_PanelPopup, &p, QRect( 0, 0, width(), height() ), colorGroup(), QStyle::Style_Default, QStyleOption( frameWidth(), 0 ) ); }
void PanelKMenu::paintEvent(QPaintEvent * e) { if (sidePixmap.isNull()) { PanelServiceMenu::paintEvent(e); return; } QPainter p(this); p.setClipRegion(e->region()); QStyleOptionFrame frOpt; frOpt.init(this); frOpt.lineWidth = frameWidth(); frOpt.midLineWidth = 0; style()->drawPrimitive( QStyle::PE_FrameMenu, &frOpt, &p, this); QRect r = sideImageRect(); r.setBottom( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { p.drawTiledPixmap( r, sideTilePixmap ); } r = sideImageRect(); r.setTop( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { QRect drawRect = r.intersect( e->rect() ); QRect pixRect = drawRect; pixRect.translate( -r.left(), -r.top() ); p.drawPixmap( drawRect.topLeft(), sidePixmap, pixRect ); } PanelServiceMenu::paintEvent( e ); }
void PanelKMenu::paintEvent(QPaintEvent * e) { if (sidePixmap.isNull()) { PanelServiceMenu::paintEvent(e); return; } QPainter p(this); p.setClipRegion(e->region()); style().drawPrimitive( QStyle::PE_PanelPopup, &p, QRect( 0, 0, width(), height() ), colorGroup(), QStyle::Style_Default, QStyleOption( frameWidth(), 0 ) ); QRect r = sideImageRect(); r.setBottom( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { p.drawTiledPixmap( r, sideTilePixmap ); } r = sideImageRect(); r.setTop( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { QRect drawRect = r.intersect( e->rect() ); QRect pixRect = drawRect; pixRect.moveBy( -r.left(), -r.top() ); p.drawPixmap( drawRect.topLeft(), sidePixmap, pixRect ); } drawContents( &p ); }
QMouseEvent PanelKMenu::translateMouseEvent( QMouseEvent* e ) { QRect side = sideImageRect(); if ( !side.contains( e->pos() ) ) return *e; QPoint newpos( e->pos() ); QApplication::isRightToLeft() ? newpos.setX( newpos.x() - side.width() ) : newpos.setX( newpos.x() + side.width() ); QPoint newglobal( e->globalPos() ); QApplication::isRightToLeft() ? newglobal.setX( newpos.x() - side.width() ) : newglobal.setX( newpos.x() + side.width() ); return QMouseEvent( e->type(), newpos, newglobal, e->button(), e->state() ); }