diff --git a/lib/redeyereduction/redeyereductiontool.cpp b/lib/redeyereduction/redeyereductiontool.cpp index 003291bf..805ab48e 100644 --- a/lib/redeyereduction/redeyereductiontool.cpp +++ b/lib/redeyereduction/redeyereductiontool.cpp @@ -1,114 +1,114 @@ // vim: set tabstop=4 shiftwidth=4 noexpandtab: /* 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.moc" // Qt #include #include #include // KDE #include // Local #include "imageview.h" #include "redeyereductionimageoperation.h" -static const int UNINITIALIZED_X = -1; - namespace Gwenview { struct RedEyeReductionToolPrivate { RedEyeReductionTool* mRedEyeReductionTool; + RedEyeReductionTool::Status mStatus; QPoint mCenter; int mRadius; }; RedEyeReductionTool::RedEyeReductionTool(ImageView* view) : AbstractImageViewTool(view) , d(new RedEyeReductionToolPrivate) { d->mRedEyeReductionTool = this; - d->mCenter.setX(UNINITIALIZED_X); d->mRadius = 12; + d->mStatus = NotSet; } RedEyeReductionTool::~RedEyeReductionTool() { delete d; } int RedEyeReductionTool::radius() const { return d->mRadius; } void RedEyeReductionTool::setRadius(int radius) { d->mRadius = radius; imageView()->viewport()->update(); } QRect RedEyeReductionTool::rect() const { - if (d->mCenter.x() == UNINITIALIZED_X) { + if (d->mStatus == NotSet) { return QRect(); } return QRect(d->mCenter.x() - d->mRadius, d->mCenter.y() - d->mRadius, d->mRadius * 2, d->mRadius * 2); } void RedEyeReductionTool::paint(QPainter* painter) { - if (d->mCenter.x() == UNINITIALIZED_X) { + if (d->mStatus == NotSet) { return; } QRect docRect = rect(); QImage img = imageView()->document()->image().copy(docRect); const QRectF viewRectF = imageView()->mapToViewportF(docRect); RedEyeReductionImageOperation::apply(&img, img.rect()); painter->drawImage(viewRectF, img); } void RedEyeReductionTool::mousePressEvent(QMouseEvent* event) { d->mCenter = imageView()->mapToImage(event->pos()); + d->mStatus = Adjusting; imageView()->viewport()->update(); } void RedEyeReductionTool::mouseMoveEvent(QMouseEvent* event) { if (event->buttons() == Qt::NoButton) { return; } d->mCenter = imageView()->mapToImage(event->pos()); imageView()->viewport()->update(); } void RedEyeReductionTool::toolActivated() { imageView()->viewport()->setCursor(Qt::CrossCursor); } } // namespace diff --git a/lib/redeyereduction/redeyereductiontool.h b/lib/redeyereduction/redeyereductiontool.h index b6058862..6b781661 100644 --- a/lib/redeyereduction/redeyereductiontool.h +++ b/lib/redeyereduction/redeyereductiontool.h @@ -1,65 +1,70 @@ // vim: set tabstop=4 shiftwidth=4 noexpandtab: /* 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 REDEYEREDUCTIONTOOL_H #define REDEYEREDUCTIONTOOL_H // Qt // KDE // Local #include class QRect; namespace Gwenview { class ImageView; class RedEyeReductionToolPrivate; class RedEyeReductionTool : public AbstractImageViewTool { Q_OBJECT public: + enum Status { + NotSet, + Adjusting + }; + RedEyeReductionTool(ImageView* parent); ~RedEyeReductionTool(); QRect rect() const; virtual void paint(QPainter*); virtual void mousePressEvent(QMouseEvent*); virtual void mouseMoveEvent(QMouseEvent*); virtual void toolActivated(); int radius() const; public Q_SLOTS: void setRadius(int); private: RedEyeReductionToolPrivate* const d; }; } // namespace #endif /* REDEYEREDUCTIONTOOL_H */