Changeset View
Changeset View
Standalone View
Standalone View
lib/redeyereduction/redeyereductiontool.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | */ | 20 | */ | ||
21 | // Self | 21 | // Self | ||
22 | #include "redeyereductiontool.h" | 22 | #include "redeyereductiontool.h" | ||
23 | 23 | | |||
24 | // Qt | 24 | // Qt | ||
25 | #include <QDialogButtonBox> | 25 | #include <QDialogButtonBox> | ||
26 | #include <QGraphicsSceneMouseEvent> | 26 | #include <QGraphicsSceneMouseEvent> | ||
27 | #include <QGuiApplication> | ||||
27 | #include <QPainter> | 28 | #include <QPainter> | ||
28 | #include <QPushButton> | 29 | #include <QPushButton> | ||
29 | #include <QRect> | 30 | #include <QRect> | ||
30 | #include <QDebug> | 31 | #include <QDebug> | ||
31 | 32 | | |||
32 | // KDE | 33 | // KDE | ||
33 | 34 | | |||
34 | // Local | 35 | // Local | ||
Show All 32 Lines | |||||
67 | 68 | | |||
68 | struct RedEyeReductionToolPrivate | 69 | struct RedEyeReductionToolPrivate | ||
69 | { | 70 | { | ||
70 | RedEyeReductionTool* q; | 71 | RedEyeReductionTool* q; | ||
71 | RedEyeReductionTool::Status mStatus; | 72 | RedEyeReductionTool::Status mStatus; | ||
72 | QPointF mCenter; | 73 | QPointF mCenter; | ||
73 | int mDiameter; | 74 | int mDiameter; | ||
74 | RedEyeReductionWidget* mToolWidget; | 75 | RedEyeReductionWidget* mToolWidget; | ||
76 | bool mControlKeyIsDown; | ||||
75 | 77 | | |||
76 | void setupToolWidget() | 78 | void setupToolWidget() | ||
77 | { | 79 | { | ||
78 | mToolWidget = new RedEyeReductionWidget; | 80 | mToolWidget = new RedEyeReductionWidget; | ||
79 | mToolWidget->showNotSetPage(); | 81 | mToolWidget->showNotSetPage(); | ||
80 | QObject::connect(mToolWidget->diameterSpinBox, SIGNAL(valueChanged(int)), | 82 | QObject::connect(mToolWidget->diameterSpinBox, SIGNAL(valueChanged(int)), | ||
81 | q, SLOT(setDiameter(int))); | 83 | q, SLOT(setDiameter(int))); | ||
82 | QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::accepted, | 84 | QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::accepted, | ||
83 | q, &RedEyeReductionTool::slotApplyClicked); | 85 | q, &RedEyeReductionTool::slotApplyClicked); | ||
84 | QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::rejected, | 86 | QObject::connect(mToolWidget->mainDialogButtonBox, &QDialogButtonBox::rejected, | ||
85 | q, &RedEyeReductionTool::done); | 87 | q, &RedEyeReductionTool::done); | ||
86 | QObject::connect(mToolWidget->helpDialogButtonBox, &QDialogButtonBox::rejected, | 88 | QObject::connect(mToolWidget->helpDialogButtonBox, &QDialogButtonBox::rejected, | ||
87 | q, &RedEyeReductionTool::done); | 89 | q, &RedEyeReductionTool::done); | ||
88 | } | 90 | } | ||
89 | 91 | | |||
90 | QRectF rectF() const | 92 | QRectF rectF() const | ||
91 | { | 93 | { | ||
92 | if (mStatus == RedEyeReductionTool::NotSet) { | 94 | if (mStatus == RedEyeReductionTool::NotSet) { | ||
93 | return QRectF(); | 95 | return QRectF(); | ||
94 | } | 96 | } | ||
95 | return QRectF(mCenter.x() - mDiameter / 2, mCenter.y() - mDiameter / 2, mDiameter, mDiameter); | 97 | return QRectF(mCenter.x() - mDiameter / 2, mCenter.y() - mDiameter / 2, mDiameter, mDiameter); | ||
96 | } | 98 | } | ||
99 | | ||||
100 | void updateCursor() | ||||
101 | { | ||||
102 | if (mControlKeyIsDown) { | ||||
103 | q->imageView()->setCursor(q->zoomCursor()); | ||||
104 | } else { | ||||
105 | q->imageView()->setCursor(Qt::CrossCursor); | ||||
106 | } | ||||
107 | } | ||||
97 | }; | 108 | }; | ||
98 | 109 | | |||
99 | RedEyeReductionTool::RedEyeReductionTool(RasterImageView* view) | 110 | RedEyeReductionTool::RedEyeReductionTool(RasterImageView* view) | ||
100 | : AbstractRasterImageViewTool(view) | 111 | : AbstractRasterImageViewTool(view) | ||
101 | , d(new RedEyeReductionToolPrivate) | 112 | , d(new RedEyeReductionToolPrivate) | ||
102 | { | 113 | { | ||
103 | d->q = this; | 114 | d->q = this; | ||
104 | d->mDiameter = GwenviewConfig::redEyeReductionDiameter(); | 115 | d->mDiameter = GwenviewConfig::redEyeReductionDiameter(); | ||
105 | d->mStatus = NotSet; | 116 | d->mStatus = NotSet; | ||
117 | d->mControlKeyIsDown = false; | ||||
106 | d->setupToolWidget(); | 118 | d->setupToolWidget(); | ||
107 | 119 | | |||
108 | view->document()->startLoadingFullImage(); | 120 | view->document()->startLoadingFullImage(); | ||
109 | } | 121 | } | ||
110 | 122 | | |||
111 | RedEyeReductionTool::~RedEyeReductionTool() | 123 | RedEyeReductionTool::~RedEyeReductionTool() | ||
112 | { | 124 | { | ||
113 | GwenviewConfig::setRedEyeReductionDiameter(d->mDiameter); | 125 | GwenviewConfig::setRedEyeReductionDiameter(d->mDiameter); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 172 | if (event->buttons() == Qt::NoButton) { | |||
161 | return; | 173 | return; | ||
162 | } | 174 | } | ||
163 | d->mCenter = imageView()->mapToImage(event->pos()); | 175 | d->mCenter = imageView()->mapToImage(event->pos()); | ||
164 | imageView()->update(); | 176 | imageView()->update(); | ||
165 | } | 177 | } | ||
166 | 178 | | |||
167 | void RedEyeReductionTool::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | 179 | void RedEyeReductionTool::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | ||
168 | { | 180 | { | ||
169 | // Just prevent the event from reaching the image view | 181 | event->ignore(); | ||
170 | event->accept(); | | |||
171 | } | 182 | } | ||
172 | 183 | | |||
173 | void RedEyeReductionTool::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | 184 | void RedEyeReductionTool::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | ||
174 | { | 185 | { | ||
175 | if (event->buttons() != Qt::LeftButton) { | 186 | if (event->buttons() != Qt::LeftButton || event->modifiers() & Qt::ControlModifier) { | ||
176 | event->ignore(); | 187 | event->ignore(); | ||
177 | return; | 188 | return; | ||
178 | } | 189 | } | ||
179 | event->accept(); | 190 | event->accept(); | ||
180 | d->mToolWidget->mainDialogButtonBox->accepted(); | 191 | d->mToolWidget->mainDialogButtonBox->accepted(); | ||
181 | } | 192 | } | ||
182 | 193 | | |||
183 | void RedEyeReductionTool::keyPressEvent(QKeyEvent* event) | 194 | void RedEyeReductionTool::keyPressEvent(QKeyEvent* event) | ||
Show All 10 Lines | 203 | case Qt::Key_Enter: { | |||
194 | auto focusButton = static_cast<QPushButton*>(buttons->focusWidget()); | 205 | auto focusButton = static_cast<QPushButton*>(buttons->focusWidget()); | ||
195 | if (focusButton && buttons->buttonRole(focusButton) == QDialogButtonBox::RejectRole) { | 206 | if (focusButton && buttons->buttonRole(focusButton) == QDialogButtonBox::RejectRole) { | ||
196 | buttons->rejected(); | 207 | buttons->rejected(); | ||
197 | } else if (d->mStatus == Adjusting) { | 208 | } else if (d->mStatus == Adjusting) { | ||
198 | buttons->accepted(); | 209 | buttons->accepted(); | ||
199 | } | 210 | } | ||
200 | break; | 211 | break; | ||
201 | } | 212 | } | ||
213 | case Qt::Key_Control: | ||||
214 | event->accept(); | ||||
215 | d->mControlKeyIsDown = true; | ||||
216 | d->updateCursor(); | ||||
217 | break; | ||||
218 | case Qt::Key_Space: | ||||
219 | event->accept(); | ||||
220 | break; | ||||
202 | default: | 221 | default: | ||
222 | event->ignore(); | ||||
203 | break; | 223 | break; | ||
204 | } | 224 | } | ||
205 | } | 225 | } | ||
206 | 226 | | |||
227 | void RedEyeReductionTool::keyReleaseEvent(QKeyEvent* event) { | ||||
228 | if (event->key() == Qt::Key_Control) { | ||||
229 | d->mControlKeyIsDown = false; | ||||
230 | d->updateCursor(); | ||||
231 | event->accept(); | ||||
232 | } else { | ||||
233 | event->ignore(); | ||||
234 | } | ||||
235 | } | ||||
236 | | ||||
237 | void RedEyeReductionTool::focusInEvent(QFocusEvent* event) | ||||
238 | { | ||||
239 | const bool controlKeyIsCurrentlyDown = QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier; | ||||
240 | if (d->mControlKeyIsDown != controlKeyIsCurrentlyDown) { | ||||
241 | d->mControlKeyIsDown = controlKeyIsCurrentlyDown; | ||||
242 | d->updateCursor(); | ||||
243 | } | ||||
244 | event->accept(); | ||||
245 | } | ||||
246 | | ||||
207 | void RedEyeReductionTool::toolActivated() | 247 | void RedEyeReductionTool::toolActivated() | ||
208 | { | 248 | { | ||
209 | imageView()->setCursor(Qt::CrossCursor); | 249 | d->updateCursor(); | ||
210 | } | 250 | } | ||
211 | 251 | | |||
212 | void RedEyeReductionTool::slotApplyClicked() | 252 | void RedEyeReductionTool::slotApplyClicked() | ||
213 | { | 253 | { | ||
214 | QRectF docRectF = d->rectF(); | 254 | QRectF docRectF = d->rectF(); | ||
215 | if (!docRectF.isValid()) { | 255 | if (!docRectF.isValid()) { | ||
216 | qWarning() << "invalid rect"; | 256 | qWarning() << "invalid rect"; | ||
217 | return; | 257 | return; | ||
Show All 20 Lines |