void ScreenGrabberChooserRectItem::mouseMoveHandle(int x, int y, QGraphicsSceneMouseEvent* event)
{
    if (this->state != HandleResizing)
        return;

    QPointF delta = event->scenePos() - event->lastScenePos();
    delta.rx() *= qreal(std::abs(x));
    delta.ry() *= qreal(std::abs(y));

    // We increase if the multiplier and the delta have the same sign
    bool increaseX = ((x < 0) == (delta.x() < 0));
    bool increaseY = ((y < 0) == (delta.y() < 0));

    if ((delta.x() < 0 && increaseX) || (delta.x() >= 0 && !increaseX))
    {
        moveBy(delta.x(), 0);
        delta.rx() *= -1;
    }

    if ((delta.y() < 0 && increaseY) || (delta.y() >= 0 && !increaseY))
    {
        moveBy(0, delta.y());
        delta.ry() *= -1;
    }

    //
    this->rectWidth += delta.x();
    this->rectHeight += delta.y();
    this->mainRect->setRect (0, 0, this->rectWidth, this->rectHeight);
    updateHandlePositions();
    emit regionChosen(chosenRect());
}
void ScreenGrabberChooserRectItem::mouseRelease(QGraphicsSceneMouseEvent* event)
{
    if (event->button() == Qt::LeftButton)
    {
        setCursor(QCursor(Qt::OpenHandCursor));

        QPointF delta = (event->scenePos() - startPos);
        if (qAbs(delta.x()) < MinRectSize || qAbs(delta.y()) < MinRectSize)
        {
            rectWidth = rectHeight = 0;
            mainRect->setRect(QRect());
        }
        else
        {
            QRect normalized = chosenRect();

            rectWidth = normalized.width();
            rectHeight = normalized.height();
            setPos(normalized.x(), normalized.y());
            mainRect->setRect(0, 0, rectWidth, rectHeight);

            updateHandlePositions();
            showHandles();
        }

        emit regionChosen(chosenRect());
        state = None;
        mainRect->ungrabMouse();
    }

}
void ScreenGrabberChooserRectItem::mouseMove(QGraphicsSceneMouseEvent* event)
{
    if (this->state == Moving)
    {
        QPointF delta = event->scenePos() - event->lastScenePos();
        moveBy (delta.x(), delta.y());
    }
    else if (this->state == Resizing)
    {
        prepareGeometryChange();
        QPointF size = event->scenePos() - scenePos();
        mainRect->setRect (0, 0, size.x(), size.y());
        rectWidth = size.x();
        rectHeight = size.y();

        updateHandlePositions();
    }
    else
    {
        return;
    }

    emit regionChosen(chosenRect());
}
Ejemplo n.º 4
0
void CropOverlay::selectAll() {
    clear = false;
    selectionRect = imageArea;
    updateHandlePositions();
    update();
}