Observe buttonless pointer moves to cancel interrupted crop drags
This commit is contained in:
1 parent
803d5f6583
commit
f54aa17e55
1 file changed
+5
-2
@@ -26,7 +26,9 @@ class CropView : public QWidget {
|
||||
public:
|
||||
QImage image;
|
||||
QSize originalSize;
|
||||
explicit CropView(QWidget* parent) : QWidget(parent) { setMinimumSize(320, 320); setCursor(Qt::OpenHandCursor); }
|
||||
explicit CropView(QWidget* parent) : QWidget(parent) {
|
||||
setMinimumSize(320, 320); setMouseTracking(true); setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
QRectF frame() const { const double side = qMin(width(), height()) * 0.8; return {(width()-side)/2, (height()-side)/2, side, side}; }
|
||||
double scale() const { return qMax(frame().width()/originalSize.width(), frame().height()/originalSize.height()) * zoom; }
|
||||
void clamp() {
|
||||
@@ -71,7 +73,8 @@ protected:
|
||||
if (e->button() == Qt::LeftButton && !image.isNull()) { last = e->pos(); dragging = true; setCursor(Qt::ClosedHandCursor); }
|
||||
}
|
||||
void mouseMoveEvent(QMouseEvent* e) override {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "avatar crop move: dragging=%d buttons=%x x=%d y=%d", dragging, unsigned(e->buttons()), e->pos().x(), e->pos().y());
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "avatar crop move: dragging=%d buttons=%x x=%d y=%d",
|
||||
dragging, unsigned(e->buttons()), e->pos().x(), e->pos().y());
|
||||
if (!(e->buttons() & Qt::LeftButton)) { dragging = false; setCursor(Qt::OpenHandCursor); }
|
||||
if (dragging) { offset += e->pos()-last; last = e->pos(); clamp(); update(); }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user