Commit d9af07d0 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix color picker incorrectly selecting a rect zone after first use.

Might be related to #1191
parent 28314def
......@@ -161,7 +161,8 @@ void ColorPickerWidget::mousePressEvent(QMouseEvent *event)
}
if (m_filterActive) {
m_grabRect = QRect(event->globalPos(), QSize(1, 1));
m_clickPoint = event->globalPos();
m_grabRect = QRect(m_clickPoint, QSize(1, 1));
m_grabRectFrame->setGeometry(m_grabRect);
m_grabRectFrame->show();
}
......@@ -175,6 +176,7 @@ void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event)
m_grabRect.setWidth(event->globalX() - m_grabRect.x());
m_grabRect.setHeight(event->globalY() - m_grabRect.y());
m_grabRect = m_grabRect.normalized();
m_clickPoint = QPoint();
if (m_grabRect.width() * m_grabRect.height() == 0) {
emit colorPicked(m_mouseColor);
......@@ -184,7 +186,6 @@ void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event)
connect(m_grabRectFrame, SIGNAL(getColor()), this, SLOT(slotGetAverageColor()));
m_grabRectFrame->hide();
}
return;
}
QWidget::mouseReleaseEvent(event);
}
......@@ -194,7 +195,7 @@ void ColorPickerWidget::mouseMoveEvent(QMouseEvent *event)
// Draw live rectangle of current color under mouse
m_mouseColor = grabColor(QCursor::pos(), true);
update();
if (m_filterActive) {
if (m_filterActive && !m_clickPoint.isNull()) {
m_grabRect.setWidth(event->globalX() - m_grabRect.x());
m_grabRect.setHeight(event->globalY() - m_grabRect.y());
m_grabRectFrame->setGeometry(m_grabRect.normalized());
......
......@@ -21,6 +21,7 @@
#define COLORPICKERWIDGET_H
#include <QFrame>
#include <QPoint>
#include <QWidget>
class QFrame;
......@@ -75,6 +76,7 @@ private:
bool m_filterActive{false};
QRect m_grabRect;
QPoint m_clickPoint;
QFrame *m_grabRectFrame;
QColor m_mouseColor;
#ifdef Q_WS_X11
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment