mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Screen grabber: Reject small selections (< 2px width/height)
When the user just clicks, or moves the cursor barely (less than 2px), auto reject the region and show no selection.
This commit is contained in:
parent
1149ed1f91
commit
96a1cf93d5
|
@ -21,7 +21,10 @@
|
|||
#include <QPainter>
|
||||
#include <QCursor>
|
||||
|
||||
enum { HandleSize = 10 };
|
||||
enum {
|
||||
HandleSize = 10,
|
||||
MinRectSize = 2,
|
||||
};
|
||||
|
||||
ScreenGrabberChooserRectItem::ScreenGrabberChooserRectItem(QGraphicsScene* scene)
|
||||
{
|
||||
|
@ -62,13 +65,16 @@ QRectF ScreenGrabberChooserRectItem::boundingRect() const
|
|||
return QRectF(0, 0, this->rectWidth, this->rectHeight);
|
||||
}
|
||||
|
||||
void ScreenGrabberChooserRectItem::beginResize()
|
||||
void ScreenGrabberChooserRectItem::beginResize(QPointF mousePos)
|
||||
{
|
||||
this->rectWidth = this->rectHeight = 0;
|
||||
this->state = Resizing;
|
||||
rectWidth = this->rectHeight = 0;
|
||||
mainRect->setRect(QRect());
|
||||
state = Resizing;
|
||||
startPos = mousePos;
|
||||
|
||||
setCursor(QCursor(Qt::CrossCursor));
|
||||
hideHandles();
|
||||
this->mainRect->grabMouse();
|
||||
mainRect->grabMouse();
|
||||
}
|
||||
|
||||
QRect ScreenGrabberChooserRectItem::chosenRect() const
|
||||
|
@ -122,9 +128,9 @@ void ScreenGrabberChooserRectItem::mouseMove(QGraphicsSceneMouseEvent* event)
|
|||
{
|
||||
prepareGeometryChange();
|
||||
QPointF size = event->scenePos() - scenePos();
|
||||
this->mainRect->setRect (0, 0, size.x(), size.y());
|
||||
this->rectWidth = size.x();
|
||||
this->rectHeight = size.y();
|
||||
mainRect->setRect (0, 0, size.x(), size.y());
|
||||
rectWidth = size.x();
|
||||
rectHeight = size.y();
|
||||
|
||||
updateHandlePositions();
|
||||
}
|
||||
|
@ -141,10 +147,21 @@ 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
|
||||
{
|
||||
showHandles();
|
||||
}
|
||||
|
||||
emit regionChosen(chosenRect());
|
||||
this->state = None;
|
||||
this->mainRect->ungrabMouse();
|
||||
showHandles();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
~ScreenGrabberChooserRectItem();
|
||||
|
||||
QRectF boundingRect() const;
|
||||
void beginResize();
|
||||
void beginResize(QPointF mousePos);
|
||||
|
||||
QRect chosenRect() const;
|
||||
|
||||
|
@ -54,6 +54,7 @@ private:
|
|||
State state = None;
|
||||
int rectWidth = 0;
|
||||
int rectHeight = 0;
|
||||
QPointF startPos;
|
||||
|
||||
void forwardMainRectEvent(QEvent* event);
|
||||
void forwardHandleEvent(QGraphicsItem* watched, QEvent* event);
|
||||
|
|
|
@ -179,5 +179,5 @@ void ScreenshotGrabber::beginRectChooser(QGraphicsSceneMouseEvent* event)
|
|||
QPointF pos = event->scenePos();
|
||||
this->chooserRect->setX(pos.x());
|
||||
this->chooserRect->setY(pos.y());
|
||||
this->chooserRect->beginResize();
|
||||
this->chooserRect->beginResize(event->scenePos());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user