QPixmap PostEffect::process(const QPixmap &in, int effect) { QPixmap pix; switch (effect) { case EFFECT_DROP_SHADOW: { //pix = shadoizePixmap(in); pix = drawShadowedPixmap(in); break; } case EFFECT_POLAROID_DROP_SHADOW: { //pix = shadoizePixmapWithBorder(in); pix = drawShadowedPixmap( addBorderToPixmap(in,defaultBorderColor,defaultBorderSize) ); break; } case EFFECT_PROGRESSIVE_EDGE: { pix = progressivePixmap(in); break; } case EFFECT_TORN_EDGE: { pix = tornEdgePixmap(in); break; } case EFFECT_NONE: default: { pix = in; break; } } return pix; }
void EWASiteDrawer::makeThumbnailFromImage( QPixmap& srcImg, qreal blurR ) { int iW = srcImg.width(); int iH = srcImg.height(); int iDstDemension = EWAApplication::getScreenSize().width()/5; if( qMax( iW, iH ) > iDstDemension ) { srcImg = iW >= iH ? srcImg.scaledToWidth( iDstDemension, Qt::SmoothTransformation ) : srcImg.scaledToHeight( iDstDemension, Qt::SmoothTransformation ); } QPixmap res( srcImg.width() + blurR + blurR, srcImg.height() + blurR + blurR); res.fill( QToolTip::palette().color( QPalette::Inactive, QPalette::AlternateBase ) ); QPainter p( &res ); p.setRenderHints( EWAApplication::getRenderHints() ); drawShadowedPixmap( &p, srcImg, (res.width()-srcImg.width())/2-blurR/2, (res.height()-srcImg.height())/2-blurR/2, false ); srcImg = res.copy(); }
// algorithm from Greenshot - http://getgreenshot.org/ static QPixmap CreateTornEdge(const QPixmap& sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange) { QPixmap returnImage( sourceImage.width(), sourceImage.height() ); returnImage.fill (Qt::transparent); QPainterPath path; int horizontalRegions = (int)(sourceImage.width() / horizontalToothRange); int verticalRegions = (int)(sourceImage.height() / verticalToothRange); // Start QPointF previousEndingPoint = QPointF( horizontalToothRange, MiscFunctions::random(1, toothHeight) ); QPointF newEndingPoint; // Top path.moveTo(previousEndingPoint); for (int i = 0; i < horizontalRegions; i++) { int x = (int)previousEndingPoint.x() + horizontalToothRange; int y = MiscFunctions::random(1, toothHeight); newEndingPoint = QPointF(x, y); //path.lineTo(previousEndingPoint, newEndingPoint); path.lineTo(newEndingPoint); previousEndingPoint = newEndingPoint; } // Right for (int i = 0; i < verticalRegions; i++) { int x = sourceImage.width() - MiscFunctions::random(1, toothHeight); int y = (int)previousEndingPoint.y() + verticalToothRange; newEndingPoint = QPointF(x, y); path.lineTo(newEndingPoint); previousEndingPoint = newEndingPoint; } // Bottom for (int i = 0; i < horizontalRegions; i++) { int x = (int)previousEndingPoint.x() - horizontalToothRange; int y = sourceImage.height() - MiscFunctions::random(1, toothHeight); newEndingPoint = QPointF(x, y); path.lineTo(newEndingPoint); previousEndingPoint = newEndingPoint; } // Left for (int i = 0; i < verticalRegions; i++) { int x = MiscFunctions::random(1, toothHeight); int y = (int)previousEndingPoint.y() - verticalToothRange; newEndingPoint = QPointF(x, y); path.lineTo(newEndingPoint); previousEndingPoint = newEndingPoint; } path.closeSubpath(); QPainter painter(&returnImage); painter.setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing, true); painter.setClipPath(path); painter.drawPixmap(0,0,sourceImage); return drawShadowedPixmap(returnImage); }