Commit 2f8f8f5f 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 65c96a7a
Pipeline #81206 passed with stage
in 9 minutes and 8 seconds
......@@ -148,7 +148,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();
}
......@@ -162,6 +163,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);
......@@ -171,7 +173,6 @@ void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event)
connect(m_grabRectFrame, SIGNAL(getColor()), this, SLOT(slotGetAverageColor()));
m_grabRectFrame->hide();
}
return;
}
QWidget::mouseReleaseEvent(event);
}
......@@ -181,7 +182,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());
......
......@@ -8,6 +8,7 @@ SPDX-License-Identifier: LicenseRef-KDE-Accepted-GPL
#define COLORPICKERWIDGET_H
#include <QFrame>
#include <QPoint>
#include <QWidget>
class QFrame;
......@@ -62,6 +63,7 @@ private:
bool m_filterActive{false};
QRect m_grabRect;
QPoint m_clickPoint;
QFrame *m_grabRectFrame;
QColor m_mouseColor;
#ifdef Q_WS_X11
......
Supports Markdown
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