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) | ||
184 | { | 195 | { | ||
185 | QDialogButtonBox *buttons = d->mToolWidget->mainDialogButtonBox; | 196 | QDialogButtonBox *buttons = d->mToolWidget->mainDialogButtonBox; | ||
186 | switch (event->key()) { | 197 | switch (event->key()) { | ||
187 | case Qt::Key_Escape: | 198 | case Qt::Key_Escape: | ||
188 | event->accept(); | 199 | event->accept(); | ||
189 | buttons->rejected(); | 200 | buttons->rejected(); | ||
190 | break; | 201 | break; | ||
191 | case Qt::Key_Return: | 202 | case Qt::Key_Return: | ||
192 | case Qt::Key_Enter: | 203 | case Qt::Key_Enter: | ||
193 | event->accept(); | 204 | event->accept(); | ||
194 | if (d->mStatus == Adjusting) { | 205 | if (d->mStatus == Adjusting) { | ||
195 | buttons->accepted(); | 206 | buttons->accepted(); | ||
196 | } | 207 | } | ||
197 | break; | 208 | break; | ||
209 | case Qt::Key_Control: | ||||
210 | event->accept(); | ||||
211 | d->mControlKeyIsDown = true; | ||||
212 | d->updateCursor(); | ||||
213 | break; | ||||
198 | default: | 214 | default: | ||
215 | event->ignore(); | ||||
199 | break; | 216 | break; | ||
200 | } | 217 | } | ||
201 | } | 218 | } | ||
202 | 219 | | |||
220 | void RedEyeReductionTool::keyReleaseEvent(QKeyEvent* event) { | ||||
221 | if (event->key() == Qt::Key_Control) { | ||||
222 | d->mControlKeyIsDown = false; | ||||
223 | d->updateCursor(); | ||||
224 | event->accept(); | ||||
225 | } else { | ||||
226 | event->ignore(); | ||||
227 | } | ||||
228 | } | ||||
229 | | ||||
230 | void RedEyeReductionTool::focusInEvent(QFocusEvent* event) | ||||
231 | { | ||||
232 | const bool controlKeyIsCurrentlyDown = QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier; | ||||
233 | if (d->mControlKeyIsDown != controlKeyIsCurrentlyDown) { | ||||
234 | d->mControlKeyIsDown = controlKeyIsCurrentlyDown; | ||||
235 | d->updateCursor(); | ||||
236 | } | ||||
237 | event->accept(); | ||||
238 | } | ||||
239 | | ||||
203 | void RedEyeReductionTool::toolActivated() | 240 | void RedEyeReductionTool::toolActivated() | ||
204 | { | 241 | { | ||
205 | imageView()->setCursor(Qt::CrossCursor); | 242 | d->updateCursor(); | ||
206 | } | 243 | } | ||
207 | 244 | | |||
208 | void RedEyeReductionTool::slotApplyClicked() | 245 | void RedEyeReductionTool::slotApplyClicked() | ||
209 | { | 246 | { | ||
210 | QRectF docRectF = d->rectF(); | 247 | QRectF docRectF = d->rectF(); | ||
211 | if (!docRectF.isValid()) { | 248 | if (!docRectF.isValid()) { | ||
212 | qWarning() << "invalid rect"; | 249 | qWarning() << "invalid rect"; | ||
213 | return; | 250 | return; | ||
Show All 20 Lines |