diff --git a/lib/imagescaler.cpp b/lib/imagescaler.cpp index 2fc0ca05..7936cb13 100644 --- a/lib/imagescaler.cpp +++ b/lib/imagescaler.cpp @@ -1,228 +1,228 @@ /* Gwenview: an image viewer Copyright 2007 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 "imagescaler.h" // Qt #include #include #include #include // KDE // Local #include #include #undef ENABLE_LOG #undef LOG //#define ENABLE_LOG #ifdef ENABLE_LOG #define LOG(x) qDebug() << x #else #define LOG(x) ; #endif namespace Gwenview { // Amount of pixels to keep so that smooth scale is correct static const int SMOOTH_MARGIN = 3; static inline QRectF scaledRect(const QRectF& rect, qreal factor) { return QRectF(rect.x() * factor, rect.y() * factor, rect.width() * factor, rect.height() * factor); } static inline QRect scaledRect(const QRect& rect, qreal factor) { return scaledRect(QRectF(rect), factor).toAlignedRect(); } struct ImageScalerPrivate { Qt::TransformationMode mTransformationMode; Document::Ptr mDocument; qreal mZoom; QRegion mRegion; }; ImageScaler::ImageScaler(QObject* parent) : QObject(parent) , d(new ImageScalerPrivate) { d->mTransformationMode = Qt::FastTransformation; d->mZoom = 0; } ImageScaler::~ImageScaler() { delete d; } void ImageScaler::setDocument(const Document::Ptr &document) { if (d->mDocument) { disconnect(d->mDocument.data(), nullptr, this, nullptr); } d->mDocument = document; // Used when scaler asked for a down-sampled image connect(d->mDocument.data(), &Document::downSampledImageReady, this, &ImageScaler::doScale); // Used when scaler asked for a full image connect(d->mDocument.data(), &Document::loaded, this, &ImageScaler::doScale); } void ImageScaler::setZoom(qreal zoom) { // If we zoom to 400% or more, then assume the user wants to see the real // pixels, for example to fine tune a crop operation d->mTransformationMode = zoom < 4. ? Qt::SmoothTransformation : Qt::FastTransformation; d->mZoom = zoom; } void ImageScaler::setDestinationRegion(const QRegion& region) { LOG(region); d->mRegion = region; if (d->mRegion.isEmpty()) { return; } if (d->mDocument && d->mZoom > 0) { doScale(); } } void ImageScaler::doScale() { if (d->mZoom < Document::maxDownSampledZoom()) { if (!d->mDocument->prepareDownSampledImageForZoom(d->mZoom)) { LOG("Asked for a down sampled image"); return; } } else if (d->mDocument->image().isNull()) { LOG("Asked for the full image"); d->mDocument->startLoadingFullImage(); return; } LOG("Starting"); Q_FOREACH(const QRect & rect, d->mRegion.rects()) { LOG(rect); scaleRect(rect); } LOG("Done"); } void ImageScaler::scaleRect(const QRect& rect) { const qreal dpr = qApp->devicePixelRatio(); // variables prefixed with dp are in device pixels const QRect dpRect = Gwenview::scaledRect(rect, dpr); const qreal REAL_DELTA = 0.001; if (qAbs(d->mZoom - 1.0) < REAL_DELTA) { QImage tmp = d->mDocument->image().copy(dpRect); tmp.setDevicePixelRatio(dpr); emit scaledRect(rect.left(), rect.top(), tmp); return; } QImage image; qreal zoom; if (d->mZoom < Document::maxDownSampledZoom()) { image = d->mDocument->downSampledImageForZoom(d->mZoom); Q_ASSERT(!image.isNull()); qreal zoom1 = qreal(image.width()) / d->mDocument->width(); zoom = d->mZoom / zoom1; } else { image = d->mDocument->image(); zoom = d->mZoom; } const QRect imageRect = Gwenview::scaledRect(image.rect(), 1.0 / dpr); // If rect contains "half" pixels, make sure sourceRect includes them 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; } // Compute smooth margin bool needsSmoothMargins = d->mTransformationMode == Qt::SmoothTransformation; int sourceLeftMargin, sourceRightMargin, sourceTopMargin, sourceBottomMargin; int destLeftMargin, destRightMargin, destTopMargin, destBottomMargin; if (needsSmoothMargins) { sourceLeftMargin = qMin(sourceRect.left(), SMOOTH_MARGIN); sourceTopMargin = qMin(sourceRect.top(), SMOOTH_MARGIN); sourceRightMargin = qMin(imageRect.right() - sourceRect.right(), SMOOTH_MARGIN); sourceBottomMargin = qMin(imageRect.bottom() - sourceRect.bottom(), SMOOTH_MARGIN); sourceRect.adjust( -sourceLeftMargin, -sourceTopMargin, sourceRightMargin, sourceBottomMargin); destLeftMargin = int(sourceLeftMargin * zoom); destTopMargin = int(sourceTopMargin * zoom); destRightMargin = int(sourceRightMargin * zoom); destBottomMargin = int(sourceBottomMargin * zoom); } else { sourceLeftMargin = sourceRightMargin = sourceTopMargin = sourceBottomMargin = 0; destLeftMargin = destRightMargin = destTopMargin = destBottomMargin = 0; } // destRect is almost like rect, but it contains only "full" pixels QRect destRect = Gwenview::scaledRect(sourceRect, zoom); QRect dpSourceRect = Gwenview::scaledRect(sourceRect, dpr); QRect dpDestRect = Gwenview::scaledRect(dpSourceRect, zoom); QImage tmp; tmp = image.copy(dpSourceRect); tmp = tmp.scaled( dpDestRect.width(), dpDestRect.height(), Qt::IgnoreAspectRatio, // Do not use KeepAspectRatio, it can lead to skipped rows or columns d->mTransformationMode); if (needsSmoothMargins) { tmp = tmp.copy( destLeftMargin * dpr, destTopMargin * dpr, dpDestRect.width() - (destLeftMargin + destRightMargin) * dpr, dpDestRect.height() - (destTopMargin + destBottomMargin) * dpr ); } tmp.setDevicePixelRatio(dpr); emit scaledRect(destRect.left() + destLeftMargin, destRect.top() + destTopMargin, tmp); } } // namespace diff --git a/lib/paintutils.cpp b/lib/paintutils.cpp index 2902bcaf..80a36024 100644 --- a/lib/paintutils.cpp +++ b/lib/paintutils.cpp @@ -1,156 +1,141 @@ /* Gwenview: an image viewer Copyright 2007 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 "paintutils.h" #include // Qt #include #include #include #include namespace Gwenview { namespace PaintUtils { // Copied from KFileItemDelegate QPainterPath roundedRectangle(const QRectF &rect, qreal radius) { QPainterPath path(QPointF(rect.left(), rect.top() + radius)); path.quadTo(rect.left(), rect.top(), rect.left() + radius, rect.top()); // Top left corner path.lineTo(rect.right() - radius, rect.top()); // Top side path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + radius); // Top right corner path.lineTo(rect.right(), rect.bottom() - radius); // Right side path.quadTo(rect.right(), rect.bottom(), rect.right() - radius, rect.bottom()); // Bottom right corner path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - radius); // Bottom left corner path.closeSubpath(); return path; } QPixmap generateFuzzyRect(const QSize& size, const QColor& color, int radius) { QPixmap pix(size); const QColor transparent(0, 0, 0, 0); pix.fill(transparent); QPainter painter(&pix); painter.setRenderHint(QPainter::Antialiasing, true); // Fill middle painter.fillRect(pix.rect().adjusted(radius, radius, -radius, -radius), color); // Corners QRadialGradient gradient; gradient.setColorAt(0, color); gradient.setColorAt(1, transparent); gradient.setRadius(radius); QPoint center; // Top Left center = QPoint(radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, 0, radius, radius, gradient); // Top right center = QPoint(size.width() - radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), 0, radius, radius, gradient); // Bottom left center = QPoint(radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, center.y(), radius, radius, gradient); // Bottom right center = QPoint(size.width() - radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), center.y(), radius, radius, gradient); // Borders QLinearGradient linearGradient; linearGradient.setColorAt(0, color); linearGradient.setColorAt(1, transparent); // Top linearGradient.setStart(0, radius); linearGradient.setFinalStop(0, 0); painter.fillRect(radius, 0, size.width() - 2 * radius, radius, linearGradient); // Bottom linearGradient.setStart(0, size.height() - radius); linearGradient.setFinalStop(0, size.height()); painter.fillRect(radius, int(linearGradient.start().y()), size.width() - 2 * radius, radius, linearGradient); // Left linearGradient.setStart(radius, 0); linearGradient.setFinalStop(0, 0); painter.fillRect(0, radius, radius, size.height() - 2 * radius, linearGradient); // Right linearGradient.setStart(size.width() - radius, 0); linearGradient.setFinalStop(size.width(), 0); painter.fillRect(int(linearGradient.start().x()), radius, radius, size.height() - 2 * radius, linearGradient); return pix; } QColor adjustedHsv(const QColor& color, int deltaH, int deltaS, int deltaV) { int hue, saturation, value; color.getHsv(&hue, &saturation, &value); return QColor::fromHsv( qBound(0, hue + deltaH, 359), qBound(0, saturation + deltaS, 255), qBound(0, value + deltaV, 255) ); } QColor alphaAdjustedF(const QColor& color, qreal alphaF) { QColor tmp = color; tmp.setAlphaF(alphaF); 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/paintutils.h b/lib/paintutils.h index 6f79a7f4..f477f131 100644 --- a/lib/paintutils.h +++ b/lib/paintutils.h @@ -1,74 +1,69 @@ /* Gwenview: an image viewer Copyright 2007 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 PAINTUTILS_H #define PAINTUTILS_H #include #include class QColor; class QPainterPath; class QPixmap; class QRect; class QRectF; class QSize; namespace Gwenview { /** * A collection of independent painting functions */ namespace PaintUtils { /** * Returns a rounded-corner version of @rect. Corner radius is @p radius. * (Copied from KFileItemDelegate) */ GWENVIEWLIB_EXPORT QPainterPath roundedRectangle(const QRectF& rect, qreal radius); /** * Generates a pixmap of size @p size, filled with @p color, whose borders have * been blurred by @p radius pixels. */ GWENVIEWLIB_EXPORT QPixmap generateFuzzyRect(const QSize& size, const QColor& color, int radius); /** * Returns a modified version of @p color, where hue, saturation and value have * been adjusted according to @p deltaH, @p deltaS and @p deltaV. */ GWENVIEWLIB_EXPORT QColor adjustedHsv(const QColor& color, int deltaH, int deltaS, int deltaV); /** * Returns a modified version of @p color, where alpha has been set to @p * alphaF. */ 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 #endif /* PAINTUTILS_H */ diff --git a/lib/redeyereduction/redeyereductionimageoperation.cpp b/lib/redeyereduction/redeyereductionimageoperation.cpp index 5eb9147e..6d1946b5 100644 --- a/lib/redeyereduction/redeyereductionimageoperation.cpp +++ b/lib/redeyereduction/redeyereductionimageoperation.cpp @@ -1,167 +1,167 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2007 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. */ // Self #include "redeyereductionimageoperation.h" // Stdc #include // Qt #include #include #include // KDE #include // Local #include "ramp.h" #include "document/document.h" #include "document/documentjob.h" #include "document/abstractdocumenteditor.h" #include "paintutils.h" namespace Gwenview { class RedEyeReductionJob : public ThreadedDocumentJob { public: RedEyeReductionJob(const QRectF& rectF) : mRectF(rectF) {} void threadedStart() override { if (!checkDocumentEditor()) { return; } QImage img = document()->image(); RedEyeReductionImageOperation::apply(&img, mRectF); document()->editor()->setImage(img); setError(NoError); } private: QRectF mRectF; }; struct RedEyeReductionImageOperationPrivate { QRectF mRectF; QImage mOriginalImage; }; RedEyeReductionImageOperation::RedEyeReductionImageOperation(const QRectF& rectF) : d(new RedEyeReductionImageOperationPrivate) { d->mRectF = rectF; setText(i18n("Reduce Red Eye")); } RedEyeReductionImageOperation::~RedEyeReductionImageOperation() { delete d; } 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)); } void RedEyeReductionImageOperation::undo() { if (!document()->editor()) { qWarning() << "!document->editor()"; return; } QImage img = document()->image(); { 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); finish(true); } /** * This code is inspired from code found in a Paint.net plugin: * http://paintdotnet.forumer.com/viewtopic.php?f=27&t=26193&p=205954&hilit=red+eye#p205954 */ inline qreal computeRedEyeAlpha(const QColor& src) { int hue, sat, value; src.getHsv(&hue, &sat, &value); qreal axs = 1.0; if (hue > 259) { static const Ramp ramp(30, 35, 0., 1.); axs = ramp(sat); } else { const Ramp ramp(hue * 2 + 29, hue * 2 + 40, 0., 1.); axs = ramp(sat); } return qBound(qreal(0.), src.alphaF() * axs, qreal(1.)); } 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; const Ramp radiusRamp( qMin(qreal(radius * 0.7), qreal(radius - 1)), radius, qreal(1.), qreal(0.)); uchar* line = img->scanLine(rect.top()) + rect.left() * 4; for (int y = rect.top(); y < rect.bottom(); ++y, line += img->bytesPerLine()) { QRgb* ptr = (QRgb*)line; for (int x = rect.left(); x < rect.right(); ++x, ++ptr) { const qreal currentRadius = sqrt(pow(y - centerY, 2) + pow(x - centerX, 2)); qreal alpha = radiusRamp(currentRadius); if (qFuzzyCompare(alpha, 0)) { continue; } const QColor src(*ptr); alpha *= computeRedEyeAlpha(src); int r = src.red(); int g = src.green(); int b = src.blue(); QColor dst; // Replace red with green, and blend according to alpha dst.setRed(int((1 - alpha) * r + alpha * g)); dst.setGreen(g); dst.setBlue(b); *ptr = dst.rgba(); } } } } // namespace diff --git a/lib/redeyereduction/redeyereductiontool.cpp b/lib/redeyereduction/redeyereductiontool.cpp index d612353f..91a1a73c 100644 --- a/lib/redeyereduction/redeyereductiontool.cpp +++ b/lib/redeyereduction/redeyereductiontool.cpp @@ -1,243 +1,243 @@ // vim: set tabstop=4 shiftwidth=4 expandtab: /* Gwenview: an image viewer Copyright 2007 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. */ // Self #include "redeyereductiontool.h" // Qt #include #include #include #include #include #include // KDE // Local #include #include "gwenviewconfig.h" #include "paintutils.h" #include "redeyereductionimageoperation.h" #include "ui_redeyereductionwidget.h" namespace Gwenview { struct RedEyeReductionWidget : public QWidget, public Ui_RedEyeReductionWidget { RedEyeReductionWidget() { setupUi(this); QPushButton* okButton = mainDialogButtonBox->button(QDialogButtonBox::Ok); okButton->setIcon(QIcon::fromTheme(QStringLiteral("redeyes"))); okButton->setText(i18n("Reduce Red Eye")); } void showNotSetPage() { // Prevent Close button from turning blue upon accepting helpTextLabel->setFocus(); stackedWidget->setCurrentWidget(notSetPage); } void showMainPage() { stackedWidget->setCurrentWidget(mainPage); } }; struct RedEyeReductionToolPrivate { RedEyeReductionTool* q; RedEyeReductionTool::Status mStatus; QPointF mCenter; int mDiameter; RedEyeReductionWidget* mToolWidget; void setupToolWidget() { mToolWidget = new RedEyeReductionWidget; mToolWidget->showNotSetPage(); QObject::connect(mToolWidget->diameterSpinBox, SIGNAL(valueChanged(int)), q, SLOT(setDiameter(int))); QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::accepted, q, &RedEyeReductionTool::slotApplyClicked); QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::rejected, q, &RedEyeReductionTool::done); QObject::connect(mToolWidget->helpDialogButtonBox, &QDialogButtonBox::rejected, q, &RedEyeReductionTool::done); } QRectF rectF() const { if (mStatus == RedEyeReductionTool::NotSet) { return QRectF(); } return QRectF(mCenter.x() - mDiameter / 2, mCenter.y() - mDiameter / 2, mDiameter, mDiameter); } }; RedEyeReductionTool::RedEyeReductionTool(RasterImageView* view) : AbstractRasterImageViewTool(view) , d(new RedEyeReductionToolPrivate) { d->q = this; d->mDiameter = GwenviewConfig::redEyeReductionDiameter(); d->mStatus = NotSet; d->setupToolWidget(); view->document()->startLoadingFullImage(); } RedEyeReductionTool::~RedEyeReductionTool() { GwenviewConfig::setRedEyeReductionDiameter(d->mDiameter); delete d->mToolWidget; delete d; } void RedEyeReductionTool::paint(QPainter* painter) { if (d->mStatus == NotSet) { return; } 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(), docRectF.top() - docRect.top(), docRectF.width(), docRectF.height() ); RedEyeReductionImageOperation::apply(&img, imgRectF); const QRectF viewRectF = imageView()->mapToView(docRectF); painter->drawImage(viewRectF, img, imgRectF); } void RedEyeReductionTool::mousePressEvent(QGraphicsSceneMouseEvent* event) { if (event->buttons() != Qt::LeftButton || event->modifiers() & Qt::ControlModifier) { event->ignore(); return; } event->accept(); if (d->mStatus == NotSet) { d->mToolWidget->diameterSpinBox->setValue(d->mDiameter); d->mToolWidget->showMainPage(); d->mStatus = Adjusting; } d->mCenter = imageView()->mapToImage(event->pos()); imageView()->update(); } void RedEyeReductionTool::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { event->accept(); if (event->buttons() == Qt::NoButton) { return; } d->mCenter = imageView()->mapToImage(event->pos()); imageView()->update(); } void RedEyeReductionTool::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { // Just prevent the event from reaching the image view event->accept(); } void RedEyeReductionTool::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { if (event->buttons() != Qt::LeftButton) { event->ignore(); return; } event->accept(); emit d->mToolWidget->mainDialogButtonBox->accepted(); } void RedEyeReductionTool::keyPressEvent(QKeyEvent* event) { QDialogButtonBox *buttons; if (d->mStatus == Adjusting) { buttons = d->mToolWidget->mainDialogButtonBox; } else { buttons = d->mToolWidget->helpDialogButtonBox; } switch (event->key()) { case Qt::Key_Escape: event->accept(); emit buttons->rejected(); break; case Qt::Key_Return: case Qt::Key_Enter: { event->accept(); auto focusButton = static_cast(buttons->focusWidget()); if (focusButton && buttons->buttonRole(focusButton) == QDialogButtonBox::RejectRole) { emit buttons->rejected(); } else { emit buttons->accepted(); } break; } default: break; } } void RedEyeReductionTool::toolActivated() { imageView()->setCursor(Qt::CrossCursor); } void RedEyeReductionTool::slotApplyClicked() { QRectF docRectF = d->rectF(); if (!docRectF.isValid()) { qWarning() << "invalid rect"; return; } RedEyeReductionImageOperation* op = new RedEyeReductionImageOperation(docRectF); emit imageOperationRequested(op); d->mStatus = NotSet; d->mToolWidget->showNotSetPage(); } void RedEyeReductionTool::setDiameter(int value) { d->mDiameter = value; imageView()->update(); } QWidget* RedEyeReductionTool::widget() const { return d->mToolWidget; } } // namespace diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 22842897..ad779a7c 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -1,55 +1,54 @@ include(ECMAddTests) macro(gv_add_unit_test _test) ecm_add_test( ${_test}.cpp ${ARGN} TEST_NAME ${_test} LINK_LIBRARIES Qt5::Test gwenviewlib ) add_dependencies(buildtests ${_test}) endmacro(gv_add_unit_test) kde_source_files_enable_exceptions( documenttest.cpp imagemetainfomodeltest.cpp ) include_directories( ${gwenview_SOURCE_DIR} ${importer_SOURCE_DIR} ${EXIV2_INCLUDE_DIR} ) # For config-gwenview.h include_directories( ${gwenview_BINARY_DIR} ) 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() gv_add_unit_test(transformimageoperationtest) gv_add_unit_test(jpegcontenttest) gv_add_unit_test(thumbnailprovidertest testutils.cpp) if (NOT GWENVIEW_SEMANTICINFO_BACKEND_NONE) gv_add_unit_test(semanticinfobackendtest) endif() gv_add_unit_test(timeutilstest) gv_add_unit_test(placetreemodeltest testutils.cpp) gv_add_unit_test(urlutilstest) gv_add_unit_test(historymodeltest) gv_add_unit_test(importertest ${importer_SOURCE_DIR}/importer.cpp ${importer_SOURCE_DIR}/fileutils.cpp ${importer_SOURCE_DIR}/filenameformater.cpp ) gv_add_unit_test(sorteddirmodeltest testutils.cpp) gv_add_unit_test(slidecontainerautotest slidecontainerautotest.cpp) gv_add_unit_test(imagemetainfomodeltest testutils.cpp) gv_add_unit_test(cmsprofiletest testutils.cpp) gv_add_unit_test(recursivedirmodeltest testutils.cpp) gv_add_unit_test(contextmanagertest testutils.cpp) diff --git a/tests/auto/paintutilstest.cpp b/tests/auto/paintutilstest.cpp deleted file mode 100644 index 7978e11e..00000000 --- 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); -} diff --git a/tests/auto/paintutilstest.h b/tests/auto/paintutilstest.h deleted file mode 100644 index 2cb1ebad..00000000 --- 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