Fix boundary bug with pixelate and invert tools (#1957)
* Fix invert tool selection Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix pixelate tool Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
@@ -37,11 +37,7 @@ QString InvertTool::description() const
|
||||
|
||||
QRect InvertTool::boundingRect() const
|
||||
{
|
||||
return QRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()))
|
||||
.normalized();
|
||||
return QRect(points().first, points().second).normalized();
|
||||
}
|
||||
|
||||
CaptureTool* InvertTool::copy(QObject* parent)
|
||||
@@ -53,26 +49,20 @@ CaptureTool* InvertTool::copy(QObject* parent)
|
||||
|
||||
void InvertTool::process(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
QPoint p0 = points().first;
|
||||
QPoint p1 = points().second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
QRect selection = boundingRect();
|
||||
|
||||
// Invert selection
|
||||
QPixmap inv = pixmap.copy(selection);
|
||||
QImage img = inv.toImage();
|
||||
img.invertPixels();
|
||||
|
||||
painter.drawImage(selection, img);
|
||||
painter.drawImage(selection.intersected(pixmap.rect()), img);
|
||||
}
|
||||
|
||||
void InvertTool::drawSearchArea(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
Q_UNUSED(pixmap)
|
||||
painter.fillRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()),
|
||||
QBrush(Qt::black));
|
||||
painter.fillRect(boundingRect(), QBrush(Qt::black));
|
||||
}
|
||||
|
||||
void InvertTool::paintMousePreview(QPainter& painter,
|
||||
|
||||
@@ -18,6 +18,7 @@ QIcon PixelateTool::icon(const QColor& background, bool inEditor) const
|
||||
Q_UNUSED(inEditor)
|
||||
return QIcon(iconPath(background) + "pixelate.svg");
|
||||
}
|
||||
|
||||
QString PixelateTool::name() const
|
||||
{
|
||||
return tr("Pixelate");
|
||||
@@ -35,11 +36,7 @@ QString PixelateTool::description() const
|
||||
|
||||
QRect PixelateTool::boundingRect() const
|
||||
{
|
||||
return QRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()))
|
||||
.normalized();
|
||||
return QRect(points().first, points().second).normalized();
|
||||
}
|
||||
|
||||
CaptureTool* PixelateTool::copy(QObject* parent)
|
||||
@@ -51,12 +48,10 @@ CaptureTool* PixelateTool::copy(QObject* parent)
|
||||
|
||||
void PixelateTool::process(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
QPoint p0 = points().first;
|
||||
QPoint p1 = points().second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
QRect selection = boundingRect().intersected(pixmap.rect());
|
||||
auto pixelRatio = pixmap.devicePixelRatio();
|
||||
QRect selectionScaled =
|
||||
QRect(p0 * pixelRatio, p1 * pixelRatio).normalized();
|
||||
QRect selectionScaled = QRect(selection.topLeft() * pixelRatio,
|
||||
selection.bottomRight() * pixelRatio);
|
||||
|
||||
// If thickness is less than 1, use old blur process
|
||||
if (thickness() <= 1) {
|
||||
@@ -91,11 +86,7 @@ void PixelateTool::process(QPainter& painter, const QPixmap& pixmap)
|
||||
void PixelateTool::drawSearchArea(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
Q_UNUSED(pixmap)
|
||||
painter.fillRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()),
|
||||
QBrush(Qt::black));
|
||||
painter.fillRect(boundingRect(), QBrush(Qt::black));
|
||||
}
|
||||
|
||||
void PixelateTool::paintMousePreview(QPainter& painter,
|
||||
|
||||
Reference in New Issue
Block a user