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();
    }

}
Esempio n. 3
0
void ScreenshotGrabber::acceptRegion()
{
    QRect rect = this->chooserRect->chosenRect();
    if (rect.width() < 1 || rect.height() < 1)
        return;

    // Scale the accepted region from DIPs to actual pixels
    rect.setRect(rect.x() * pixRatio, rect.y() * pixRatio, rect.width() * pixRatio,
                 rect.height() * pixRatio);

    emit regionChosen(rect);
    qDebug() << "Screenshot accepted, chosen region" << rect;
    QPixmap pixmap = this->screenGrab.copy(rect);
    restoreHiddenWindows();
    emit screenshotTaken(pixmap);

    deleteLater();
}
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());
}