void EditorMagnifierItem::paint(QPainter *                      painter,
                                const QStyleOptionGraphicsItem *option,
                                QWidget *                       widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    if ( !scene() )
        return;

    QRectF rect = getRect();

    EditorScene *scn = qobject_cast<EditorScene *>( scene() );
    if (rect.isValid() && m_valid && scn)
    {
        updateMask();
        painter->save(); // because clipping is active !!

        QPainterPath clipPath;
        clipPath.addEllipse(getRect().center(), getRect().width() / 2,getRect().width() / 2);
        painter->setClipPath(clipPath);
        painter->setClipping(true);

        // TODO add extracted image to a cache !!!
        QRectF extractRect( rect.translated( pos() - scn->getUnderlayOffset() ) );
        int extractWidth = extractRect.width() / m_magnifyingFactor;
        extractRect.adjust(extractWidth,extractWidth,-extractWidth,-extractWidth);

        QRectF bgRect = scn->getUnderlayImage().rect();

        QRectF croppedRect = extractRect.intersected(bgRect);
        if ( !croppedRect.isNull() )
        {
            QImage background = scn->getUnderlayImage().copy( croppedRect.toRect() );
            QImage mag = background.scaled(rect.size().toSize(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
            painter->drawImage(rect,mag);
        }

        painter->drawPixmap(rect.topLeft(), m_imgMask);
        painter->restore();
    }

    // draw a box if selected
    if( isSelected() )
    {
        painter->save();

        QPen pen;
        pen.setCosmetic(true);
        pen.setColor(Qt::black);
        pen.setWidth(1);
        pen.setStyle(Qt::DotLine);
        painter->setPen(pen);
        painter->drawRect(rect);
        painter->restore();
    }
}
void EditorBlurItem::paint(QPainter *                      painter,
                           const QStyleOptionGraphicsItem *option,
                           QWidget *                       widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    if ( !scene() )
        return;

    QRectF rect( boundingRect() );

    EditorScene *scn = qobject_cast<EditorScene *>( scene() );
    if (rect.isValid() && m_valid && scn)
    {
        QImage background = scn->getUnderlayImage().copy( rect.translated( pos() - scn->getUnderlayOffset() ).toRect() );

        QImage blur = background.scaled(background.size() / 4,Qt::KeepAspectRatio,Qt::SmoothTransformation);
        painter->drawImage(rect,blur);
    }

    // draw a box if selected
    if( isSelected() )
    {
        painter->save();

        QPen pen;
        pen.setCosmetic(true);
        pen.setColor(Qt::black);
        pen.setWidth(1);
        pen.setStyle(Qt::DotLine);
        painter->setPen(pen);
        painter->drawRect(rect);
        painter->restore();
    }
}