void UB1HEditableGraphicsCircleItem::setRect(QRectF rect)
{
    prepareGeometryChange();

    int w = rect.width();
    int h = rect.height();

    wIsNeg = (w < 0);
    hIsNeg = (h < 0);

    if(wIsNeg) w = -w;
    if(hIsNeg) h = -h;

    mRadius = qMin(w, h);
    mRadius /= 2;

    setPos(rect.topLeft());

    if(hasGradient()){
        QLinearGradient g(QPointF(), QPointF(mRadius*2, 0));

        g.setColorAt(0, brush().gradient()->stops().at(0).second);
        g.setColorAt(1, brush().gradient()->stops().at(1).second);

        setBrush(g);
    }
}
void UB1HEditableGraphicsSquareItem::setRect(QRectF rect)
{
    prepareGeometryChange();

    setPos(rect.topLeft());

    qreal w = rect.width();
    qreal h = rect.height();

    wIsNeg = w < 0;
    hIsNeg = h < 0;

    if(wIsNeg) w = -w;
    if(hIsNeg) h = -h;

    mSide = qMin(w, h);

    if(hasGradient()){
        QLinearGradient g(QPointF(), QPointF(mSide, 0));

        g.setColorAt(0, brush().gradient()->stops().at(0).second);
        g.setColorAt(1, brush().gradient()->stops().at(1).second);

        setBrush(g);
    }
}
void UBEditableGraphicsRegularShapeItem::updateHandle(UBAbstractHandle *handle)
{
    prepareGeometryChange();

    Delegate()->showFrame(false);

    QPointF diff = handle->pos() - path().boundingRect().topLeft();

    qreal maxSize = handle->radius() * 4;

    if(diff.x() < maxSize) {
        handle->setX(handle->pos().x() + (maxSize - diff.x()));
    }

    if(diff.y() < maxSize) {
        handle->setY(handle->pos().y() + (maxSize - diff.y()));
    }

    updatePath(handle->pos());

    if(hasGradient()) {
        QLinearGradient g(path().boundingRect().topLeft(), path().boundingRect().topRight());

        g.setColorAt(0, brush().gradient()->stops().at(0).second);
        g.setColorAt(1, brush().gradient()->stops().at(1).second);

        setBrush(g);
    }

}
void UB1HEditableGraphicsCircleItem::updateHandle(UBAbstractHandle *handle)
{
    prepareGeometryChange();

    qreal maxSize = handle->radius() * 4;

    qreal r = qMin(handle->pos().x(), handle->pos().y()) / 2;

    if(r >= maxSize){
        mRadius = r;
    }

    getHandle()->setPos(mRadius*2, mRadius*2);

    if(hasGradient()){
        QLinearGradient g(QPointF(), QPointF(mRadius*2, 0));

        g.setColorAt(0, brush().gradient()->stops().at(0).second);
        g.setColorAt(1, brush().gradient()->stops().at(1).second);

        setBrush(g);
    }
}
void UB1HEditableGraphicsSquareItem::updateHandle(UBAbstractHandle *handle)
{
    prepareGeometryChange();

    qreal maxSize = handle->radius() * 4;

    qreal side = qMin(handle->pos().x(), handle->pos().y());

    if(side > maxSize){
        mSide = side;
    }

    getHandle()->setPos(mSide, mSide);

    if(hasGradient()){
        QLinearGradient g(QPointF(), QPointF(mSide, 0));

        g.setColorAt(0, brush().gradient()->stops().at(0).second);
        g.setColorAt(1, brush().gradient()->stops().at(1).second);

        setBrush(g);
    }
}