diff --git a/lib/redeyereduction/redeyereductiontool.cpp b/lib/redeyereduction/redeyereductiontool.cpp index 3c070fe6..2d7e51e0 100644 --- a/lib/redeyereduction/redeyereductiontool.cpp +++ b/lib/redeyereduction/redeyereductiontool.cpp @@ -1,225 +1,233 @@ // 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() { - dialogButtonBox->button(QDialogButtonBox::Ok)->hide(); + // Prevent Close button from turning blue upon accepting + helpTextLabel->setFocus(); + stackedWidget->setCurrentWidget(notSetPage); } void showMainPage() { - dialogButtonBox->button(QDialogButtonBox::Ok)->show(); 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->dialogButtonBox, SIGNAL(accepted()), - q, SLOT(slotApplyClicked())); - QObject::connect(mToolWidget->dialogButtonBox, SIGNAL(rejected()), - q, SIGNAL(done())); + 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); 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(); - d->mToolWidget->dialogButtonBox->accepted(); + d->mToolWidget->mainDialogButtonBox->accepted(); } void RedEyeReductionTool::keyPressEvent(QKeyEvent* event) { - QDialogButtonBox *buttons = d->mToolWidget->findChild(); + QDialogButtonBox *buttons = d->mToolWidget->mainDialogButtonBox; switch (event->key()) { case Qt::Key_Escape: event->accept(); buttons->rejected(); break; case Qt::Key_Return: case Qt::Key_Enter: event->accept(); - buttons->accepted(); + if (d->mStatus == Adjusting) { + 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/lib/redeyereduction/redeyereductiontool.h b/lib/redeyereduction/redeyereductiontool.h index 0e6088e9..3dfe8850 100644 --- a/lib/redeyereduction/redeyereductiontool.h +++ b/lib/redeyereduction/redeyereductiontool.h @@ -1,78 +1,79 @@ // 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. */ #ifndef REDEYEREDUCTIONTOOL_H #define REDEYEREDUCTIONTOOL_H #include // Qt // KDE // Local #include namespace Gwenview { class AbstractImageOperation; class RasterImageView; struct RedEyeReductionToolPrivate; class GWENVIEWLIB_EXPORT RedEyeReductionTool : public AbstractRasterImageViewTool { Q_OBJECT public: enum Status { NotSet, Adjusting }; explicit RedEyeReductionTool(RasterImageView* parent); ~RedEyeReductionTool() override; void paint(QPainter*) override; void mousePressEvent(QGraphicsSceneMouseEvent*) override; void mouseMoveEvent(QGraphicsSceneMouseEvent*) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override; void keyPressEvent(QKeyEvent*) override; void toolActivated() override; + void slotApplyClicked(); + QWidget* widget() const override; Q_SIGNALS: void done(); void imageOperationRequested(AbstractImageOperation*); private Q_SLOTS: void setDiameter(int); - void slotApplyClicked(); private: RedEyeReductionToolPrivate* const d; }; } // namespace #endif /* REDEYEREDUCTIONTOOL_H */ diff --git a/lib/redeyereduction/redeyereductionwidget.ui b/lib/redeyereduction/redeyereductionwidget.ui index ed8e1708..61611a3d 100644 --- a/lib/redeyereduction/redeyereductionwidget.ui +++ b/lib/redeyereduction/redeyereductionwidget.ui @@ -1,116 +1,228 @@ RedEyeReductionWidget 0 0 638 56 - + - 0 + 1 - + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + - Size + Size: diameterSlider + + + 0 + 0 + + + + + 120 + 0 + + 2 99 Qt::Horizontal 2 99 + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 12 + 20 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + - diameterSpinBox - label - diameterSlider - + + + 0 + + + 0 + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + Click on a red eye and choose a size, or double-click to correct instantly. + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 12 + 20 + + + + + + + + QDialogButtonBox::Close + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + - - - - QDialogButtonBox::Close|QDialogButtonBox::Ok - - - diameterSlider valueChanged(int) diameterSpinBox setValue(int) 96 27 183 27 diameterSpinBox valueChanged(int) diameterSlider setValue(int) 183 27 96 27