QPointF PHIBaseItem::adjustedPos() const
{
    QRectF br=boundingRect();
    if ( hasGraphicEffect() ) {
        switch ( _effect->graphicsType() ) {
        case PHIEffect::GTShadow: {
            QColor c;
            qreal offx, offy, radius;
            _effect->shadow( c, offx, offy, radius );
            QPixmapDropShadowFilter f;
            f.setOffset( offx, offy );
            f.setBlurRadius( radius );
            QRectF r=f.boundingRectFor( br );
            if ( r.x()<0 ) br.setX( br.x()+r.x() );
            if ( r.y()<0 ) br.setY( br.y()+r.y() );
            break;
        }
        case PHIEffect::GTColorize: {
           break;
        }
        case PHIEffect::GTBlur: {
            qreal radius;
            _effect->blur( radius );
            QPixmapBlurFilter f;
            f.setRadius( radius );
            f.setBlurHints( QGraphicsBlurEffect::AnimationHint );
            QRectF r=f.boundingRectFor( br );
            br.setX( br.x()+r.x()+1 );
            br.setY( br.y()+r.y()+1 );
            break;
        }
        case PHIEffect::GTReflection: {
            break;
        }
        default:;
        }
    }
    QTransform t=computeTransformation( false );
    return t.map( br.topLeft() );
}
Exemple #2
0
void tst_QPixmapFilter::dropShadowBoundingRectFor()
{
    QPixmapDropShadowFilter filter;
    filter.setBlurRadius(0);

    QCOMPARE(filter.blurRadius(), 0.);

    const QRectF rect1(0, 0, 50, 50);
    const QRectF rect2(30, 20, 10, 40);
    const QRectF rect3(2.2, 6.3, 11.4, 47.5);

    filter.setOffset(QPointF(0,0));
    QCOMPARE(filter.boundingRectFor(rect1), rect1);
    QCOMPARE(filter.boundingRectFor(rect2), rect2);
    QCOMPARE(filter.boundingRectFor(rect3), rect3);

    filter.setOffset(QPointF(1,1));
    QCOMPARE(filter.offset(), QPointF(1, 1));
    QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(0, 0, 1, 1));
    QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(0, 0, 1, 1));
    QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(0, 0, 1, 1));

    filter.setOffset(QPointF(-1,-1));
    QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(-1, -1, 0, 0));
    QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(-1, -1, 0, 0));
    QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(-1, -1, 0, 0));

    filter.setBlurRadius(2);
    filter.setOffset(QPointF(0,0));
    qreal delta = 2;
    QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(-delta, -delta, delta, delta));
    QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(-delta, -delta, delta, delta));
    QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(-delta, -delta, delta, delta));

    filter.setOffset(QPointF(1,1));
    QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(-delta + 1, -delta + 1, delta + 1, delta + 1));
    QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(-delta + 1, -delta + 1, delta + 1, delta + 1));
    QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(-delta + 1, -delta + 1, delta + 1, delta + 1));

    filter.setOffset(QPointF(-10,-10));
    QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(-delta - 10, -delta - 10, 0, 0));
    QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(-delta - 10, -delta - 10, 0, 0));
    QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(-delta - 10, -delta - 10, 0, 0));
}