Changeset View
Changeset View
Standalone View
Standalone View
tools/kpToolZoom.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | { | 51 | { | ||
52 | QRect normalizedRect; | 52 | QRect normalizedRect; | ||
53 | }; | 53 | }; | ||
54 | 54 | | |||
55 | static void DrawZoomRect (kpImage *destImage, | 55 | static void DrawZoomRect (kpImage *destImage, | ||
56 | const QPoint &topLeft, | 56 | const QPoint &topLeft, | ||
57 | void *userData) | 57 | void *userData) | ||
58 | { | 58 | { | ||
59 | DrawZoomRectPackage *pack = static_cast <DrawZoomRectPackage *> (userData); | 59 | auto *pack = static_cast <DrawZoomRectPackage *> (userData); | ||
60 | 60 | | |||
61 | kpPixmapFX::drawStippleRect(destImage, | 61 | kpPixmapFX::drawStippleRect(destImage, | ||
62 | topLeft.x (), topLeft.y (), pack->normalizedRect.width (), pack->normalizedRect.height (), | 62 | topLeft.x (), topLeft.y (), pack->normalizedRect.width (), pack->normalizedRect.height (), | ||
63 | kpColor::Yellow, | 63 | kpColor::Yellow, | ||
64 | kpColor::Green); | 64 | kpColor::Green); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | 67 | | |||
68 | struct kpToolZoomPrivate | 68 | struct kpToolZoomPrivate | ||
69 | { | 69 | { | ||
70 | bool dragHasBegun, dragCompleted; | 70 | bool dragHasBegun{}, dragCompleted{}; | ||
71 | DrawZoomRectPackage drawPackage; | 71 | DrawZoomRectPackage drawPackage; | ||
72 | }; | 72 | }; | ||
73 | 73 | | |||
74 | kpToolZoom::kpToolZoom (kpToolEnvironment *environ, QWidget *parent) | 74 | kpToolZoom::kpToolZoom (kpToolEnvironment *environ, QWidget *parent) | ||
75 | : kpTool (i18n ("Zoom"), i18n ("Zooms in and out of the image"), | 75 | : kpTool (i18n ("Zoom"), i18n ("Zooms in and out of the image"), | ||
76 | Qt::Key_Z, | 76 | Qt::Key_Z, | ||
77 | environ, parent, "tool_zoom"), | 77 | environ, parent, "tool_zoom"), | ||
78 | d (new kpToolZoomPrivate ()) | 78 | d (new kpToolZoomPrivate ()) | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 157 | { | |||
158 | qCDebug(kpLogTools) << "kpToomZoom::draw() currentPoint=" << currentPoint () | 158 | qCDebug(kpLogTools) << "kpToomZoom::draw() currentPoint=" << currentPoint () | ||
159 | << " lastPoint=" << lastPoint (); | 159 | << " lastPoint=" << lastPoint (); | ||
160 | 160 | | |||
161 | // TODO: Need accidental drag detection from selection tool (when dragging | 161 | // TODO: Need accidental drag detection from selection tool (when dragging | ||
162 | // out new selection) | 162 | // out new selection) | ||
163 | 163 | | |||
164 | if (!d->dragHasBegun) | 164 | if (!d->dragHasBegun) | ||
165 | { | 165 | { | ||
166 | if (thisPoint == startPoint ()) | 166 | if (thisPoint == startPoint ()) { | ||
167 | return; | 167 | return; | ||
168 | } | ||||
168 | 169 | | |||
169 | // Left mouse drags select an area to zoom into. | 170 | // Left mouse drags select an area to zoom into. | ||
170 | // However, it wouldn't make sense to select an area to "zoom out of" | 171 | // However, it wouldn't make sense to select an area to "zoom out of" | ||
171 | // (using the right mouse button). Therefore, make RMB drags do the | 172 | // (using the right mouse button). Therefore, make RMB drags do the | ||
172 | // same as RMB clicks i.e. a simple zoom out, with no "area" to worry | 173 | // same as RMB clicks i.e. a simple zoom out, with no "area" to worry | ||
173 | // about. | 174 | // about. | ||
174 | if (mouseButton () == 1/*RMB*/) | 175 | if (mouseButton () == 1/*RMB*/) { | ||
175 | return; | 176 | return; | ||
177 | } | ||||
176 | 178 | | |||
177 | d->dragHasBegun = true; | 179 | d->dragHasBegun = true; | ||
178 | } | 180 | } | ||
179 | 181 | | |||
180 | 182 | | |||
181 | d->drawPackage.normalizedRect = normalizedRect; | 183 | d->drawPackage.normalizedRect = normalizedRect; | ||
182 | 184 | | |||
183 | kpTempImage newTempImage (false/*always display*/, | 185 | kpTempImage newTempImage (false/*always display*/, | ||
Show All 33 Lines | 214 | { | |||
217 | // event loop tricks. | 219 | // event loop tricks. | ||
218 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | 220 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | ||
219 | 221 | | |||
220 | viewManager ()->invalidateTempImage (); | 222 | viewManager ()->invalidateTempImage (); | ||
221 | 223 | | |||
222 | // Click? | 224 | // Click? | ||
223 | if (!d->dragHasBegun) | 225 | if (!d->dragHasBegun) | ||
224 | { | 226 | { | ||
225 | if (mouseButton () == 0/*LMB*/) | 227 | if (mouseButton () == 0/*LMB*/) { | ||
226 | environ ()->zoomIn (true/*center under cursor*/); | 228 | environ ()->zoomIn (true/*center under cursor*/); | ||
227 | else | 229 | } | ||
230 | else { | ||||
228 | environ ()->zoomOut (false/*don't center under cursor - as is | 231 | environ ()->zoomOut (false/*don't center under cursor - as is | ||
229 | confusing behaviour when zooming | 232 | confusing behaviour when zooming | ||
230 | out*/); | 233 | out*/); | ||
231 | } | 234 | } | ||
235 | } | ||||
232 | // Drag? | 236 | // Drag? | ||
233 | else if (normalizedRect.isValid()) | 237 | else if (normalizedRect.isValid()) | ||
234 | { | 238 | { | ||
235 | environ ()->zoomToRect ( | 239 | environ ()->zoomToRect ( | ||
236 | normalizedRect, | 240 | normalizedRect, | ||
237 | false/*don't account for grips*/, | 241 | false/*don't account for grips*/, | ||
238 | true/*care about width*/, true/*care about height*/); | 242 | true/*care about width*/, true/*care about height*/); | ||
239 | 243 | | |||
240 | d->dragCompleted = true; | 244 | d->dragCompleted = true; | ||
241 | } | 245 | } | ||
242 | } | 246 | } | ||
243 | 247 | | |||
244 | 248 | |