void FreeRegionGrabber::grabRect() { QPolygon pol = selection; if ( !pol.isEmpty() ) { grabbing = true; int xOffset = pixmap.rect().x() - pol.boundingRect().x(); int yOffset = pixmap.rect().y() - pol.boundingRect().y(); QPolygon translatedPol = pol.translated(xOffset, yOffset); QPixmap pixmap2(pol.boundingRect().size()); pixmap2.fill(Qt::transparent); QPainter pt; pt.begin(&pixmap2); if (pt.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) { pt.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform, true); pt.setBrush(Qt::black); pt.setPen(QPen(QBrush(Qt::black), 0.5)); pt.drawPolygon(translatedPol); pt.setCompositionMode(QPainter::CompositionMode_SourceIn); } else { pt.setClipRegion(QRegion(translatedPol)); pt.setCompositionMode(QPainter::CompositionMode_Source); } pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect()); pt.end(); emit freeRegionUpdated(pol); emit freeRegionGrabbed(pixmap2); } }
void KSnapshot::grabFreeRegion() { freeRgnGrab = new FreeRegionGrabber(); connect( freeRgnGrab, SIGNAL(freeRegionGrabbed(QPixmap)), SLOT(slotRegionGrabbed(QPixmap)) ); }
void FreeRegionGrabber::keyPressEvent( QKeyEvent* e ) { QPolygon pol = selection; if ( e->key() == Qt::Key_Escape ) { emit freeRegionUpdated( pol ); emit freeRegionGrabbed( QPixmap() ); } else if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) { grabRect(); } else { e->ignore(); } }