diff --git a/lib/imagescaler.cpp b/lib/imagescaler.cpp --- a/lib/imagescaler.cpp +++ b/lib/imagescaler.cpp @@ -170,7 +170,7 @@ QRectF sourceRectF = Gwenview::scaledRect(QRectF(rect), 1.0 / zoom); sourceRectF = sourceRectF.intersected(imageRect); - QRect sourceRect = PaintUtils::containingRect(sourceRectF); + QRect sourceRect = sourceRectF.toAlignedRect(); if (sourceRect.isEmpty()) { return; } diff --git a/lib/paintutils.h b/lib/paintutils.h --- a/lib/paintutils.h +++ b/lib/paintutils.h @@ -62,11 +62,6 @@ */ GWENVIEWLIB_EXPORT QColor alphaAdjustedF(const QColor& color, qreal alphaF); -/** - * Returns the smallest QRect which contains @p rectF - */ -GWENVIEWLIB_EXPORT QRect containingRect(const QRectF& rectF); - } // namespace } // namespace diff --git a/lib/paintutils.cpp b/lib/paintutils.cpp --- a/lib/paintutils.cpp +++ b/lib/paintutils.cpp @@ -137,20 +137,5 @@ return tmp; } -QRect containingRect(const QRectF& rectF) -{ - return QRect( - QPoint( - qRound(floor(rectF.left())), - qRound(floor(rectF.top())) - ), - QPoint( - qRound(ceil(rectF.right() - 1.)), - qRound(ceil(rectF.bottom() - 1.)) - ) - ); - // Note: QRect::right = left + width - 1, while QRectF::right = left + width -} - } // namespace } // namespace diff --git a/lib/redeyereduction/redeyereductionimageoperation.cpp b/lib/redeyereduction/redeyereductionimageoperation.cpp --- a/lib/redeyereduction/redeyereductionimageoperation.cpp +++ b/lib/redeyereduction/redeyereductionimageoperation.cpp @@ -85,7 +85,7 @@ void RedEyeReductionImageOperation::redo() { QImage img = document()->image(); - QRect rect = PaintUtils::containingRect(d->mRectF); + QRect rect = d->mRectF.toAlignedRect(); d->mOriginalImage = img.copy(rect); redoAsDocumentJob(new RedEyeReductionJob(d->mRectF)); } @@ -100,7 +100,7 @@ { QPainter painter(&img); painter.setCompositionMode(QPainter::CompositionMode_Source); - QRect rect = PaintUtils::containingRect(d->mRectF); + QRect rect = d->mRectF.toAlignedRect(); painter.drawImage(rect.topLeft(), d->mOriginalImage); } document()->editor()->setImage(img); @@ -130,7 +130,7 @@ void RedEyeReductionImageOperation::apply(QImage* img, const QRectF& rectF) { - const QRect rect = PaintUtils::containingRect(rectF); + const QRect rect = rectF.toAlignedRect(); const qreal radius = rectF.width() / 2; const qreal centerX = rectF.x() + radius; const qreal centerY = rectF.y() + radius; diff --git a/lib/redeyereduction/redeyereductiontool.cpp b/lib/redeyereduction/redeyereductiontool.cpp --- a/lib/redeyereduction/redeyereductiontool.cpp +++ b/lib/redeyereduction/redeyereductiontool.cpp @@ -123,7 +123,7 @@ QRectF docRectF = d->rectF(); imageView()->document()->waitUntilLoaded(); - QRect docRect = PaintUtils::containingRect(docRectF); + QRect docRect = docRectF.toAlignedRect(); QImage img = imageView()->document()->image().copy(docRect); QRectF imgRectF( docRectF.left() - docRect.left(), diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -28,7 +28,6 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) gv_add_unit_test(imagescalertest testutils.cpp) -gv_add_unit_test(paintutilstest) if (KF5KDcraw_FOUND) gv_add_unit_test(documenttest testutils.cpp) endif() diff --git a/tests/auto/paintutilstest.h b/tests/auto/paintutilstest.h deleted file mode 100644 --- a/tests/auto/paintutilstest.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Gwenview: an image viewer -Copyright 2008 Aurélien Gâteau - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ -#ifndef PAINTUTILSTEST_H -#define PAINTUTILSTEST_H - -// Qt -#include - -// KDE - -class PaintUtilsTest : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void testScaledRect(); - void testScaledRect_data(); -}; - -#endif // PAINTUTILSTEST_H diff --git a/tests/auto/paintutilstest.cpp b/tests/auto/paintutilstest.cpp deleted file mode 100644 --- a/tests/auto/paintutilstest.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -Gwenview: an image viewer -Copyright 2008 Aurélien Gâteau - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ -#include - -#include "../lib/paintutils.h" - -#include "paintutilstest.h" - -QTEST_MAIN(PaintUtilsTest) - -void PaintUtilsTest::testScaledRect_data() -{ - QTest::addColumn("input"); - QTest::addColumn("expected"); - - QTest::newRow("overflow right") << QRectF(1.0, 1.0, 2.7, 3.2) << QRect(1, 1, 3, 4); - QTest::newRow("overflow left") << QRectF(0.5, 1.0, 2.0, 3.2) << QRect(0, 1, 3, 4); - QTest::newRow("overflow both") << QRectF(0.5, 1.0, 2.6, 3.2) << QRect(0, 1, 4, 4); -} - -void PaintUtilsTest::testScaledRect() -{ - QFETCH(QRectF, input); - QFETCH(QRect, expected); - QCOMPARE(Gwenview::PaintUtils::containingRect(input), expected); -}