Changeset View
Changeset View
Standalone View
Standalone View
tools/flow/kpToolFlowBase.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
53 | #include "widgets/toolbars/options/kpToolWidgetBrush.h" | 53 | #include "widgets/toolbars/options/kpToolWidgetBrush.h" | ||
54 | #include "widgets/toolbars/options/kpToolWidgetEraserSize.h" | 54 | #include "widgets/toolbars/options/kpToolWidgetEraserSize.h" | ||
55 | #include "views/manager/kpViewManager.h" | 55 | #include "views/manager/kpViewManager.h" | ||
56 | 56 | | |||
57 | //--------------------------------------------------------------------- | 57 | //--------------------------------------------------------------------- | ||
58 | 58 | | |||
59 | struct kpToolFlowBasePrivate | 59 | struct kpToolFlowBasePrivate | ||
60 | { | 60 | { | ||
61 | kpToolWidgetBrush *toolWidgetBrush; | 61 | kpToolWidgetBrush *toolWidgetBrush{}; | ||
62 | kpToolWidgetEraserSize *toolWidgetEraserSize; | 62 | kpToolWidgetEraserSize *toolWidgetEraserSize{}; | ||
63 | 63 | | |||
64 | 64 | | |||
65 | // | 65 | // | ||
66 | // Cursor and Brush Data | 66 | // Cursor and Brush Data | ||
67 | // (must be zero if unused) | 67 | // (must be zero if unused) | ||
68 | // | 68 | // | ||
69 | 69 | | |||
70 | kpTempImage::UserFunctionType brushDrawFunc, cursorDrawFunc; | 70 | kpTempImage::UserFunctionType brushDrawFunc{}, cursorDrawFunc{}; | ||
71 | 71 | | |||
72 | // Can't use union since package types contain fields requiring | 72 | // Can't use union since package types contain fields requiring | ||
73 | // constructors. | 73 | // constructors. | ||
74 | kpToolWidgetBrush::DrawPackage brushDrawPackageForMouseButton [2]; | 74 | kpToolWidgetBrush::DrawPackage brushDrawPackageForMouseButton [2]; | ||
75 | kpToolWidgetEraserSize::DrawPackage eraserDrawPackageForMouseButton [2]; | 75 | kpToolWidgetEraserSize::DrawPackage eraserDrawPackageForMouseButton [2]; | ||
76 | 76 | | |||
77 | // Each element points to one of the above (both elements from the same | 77 | // Each element points to one of the above (both elements from the same | ||
78 | // array). | 78 | // array). | ||
79 | void *drawPackageForMouseButton [2]; | 79 | void *drawPackageForMouseButton [2]{}; | ||
80 | 80 | | |||
81 | int brushWidth, brushHeight; | 81 | int brushWidth{}, brushHeight{}; | ||
82 | int cursorWidth, cursorHeight; | 82 | int cursorWidth{}, cursorHeight{}; | ||
83 | 83 | | |||
84 | bool brushIsDiagonalLine; | 84 | bool brushIsDiagonalLine{}; | ||
85 | 85 | | |||
86 | 86 | | |||
87 | kpToolFlowCommand *currentCommand; | 87 | kpToolFlowCommand *currentCommand{}; | ||
88 | }; | 88 | }; | ||
89 | 89 | | |||
90 | //--------------------------------------------------------------------- | 90 | //--------------------------------------------------------------------- | ||
91 | 91 | | |||
92 | kpToolFlowBase::kpToolFlowBase (const QString &text, const QString &description, | 92 | kpToolFlowBase::kpToolFlowBase (const QString &text, const QString &description, | ||
93 | int key, | 93 | int key, | ||
94 | kpToolEnvironment *environ, QObject *parent, const QString &name) | 94 | kpToolEnvironment *environ, QObject *parent, const QString &name) | ||
95 | 95 | | |||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 185 | { | |||
186 | disconnect (d->toolWidgetBrush, &kpToolWidgetBrush::brushChanged, | 186 | disconnect (d->toolWidgetBrush, &kpToolWidgetBrush::brushChanged, | ||
187 | this, &kpToolFlowBase::updateBrushAndCursor); | 187 | this, &kpToolFlowBase::updateBrushAndCursor); | ||
188 | d->toolWidgetBrush = nullptr; | 188 | d->toolWidgetBrush = nullptr; | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | kpViewManager *vm = viewManager (); | 191 | kpViewManager *vm = viewManager (); | ||
192 | Q_ASSERT (vm); | 192 | Q_ASSERT (vm); | ||
193 | 193 | | |||
194 | if (vm->tempImage () && vm->tempImage ()->isBrush ()) | 194 | if (vm->tempImage () && vm->tempImage ()->isBrush ()) { | ||
195 | vm->invalidateTempImage (); | 195 | vm->invalidateTempImage (); | ||
196 | } | ||||
196 | 197 | | |||
197 | if (haveAnyBrushes ()) | 198 | if (haveAnyBrushes ()) { | ||
198 | vm->unsetCursor (); | 199 | vm->unsetCursor (); | ||
200 | } | ||||
199 | 201 | | |||
200 | clearBrushCursorData (); | 202 | clearBrushCursorData (); | ||
201 | } | 203 | } | ||
202 | 204 | | |||
203 | //--------------------------------------------------------------------- | 205 | //--------------------------------------------------------------------- | ||
204 | 206 | | |||
205 | // virtual | 207 | // virtual | ||
206 | void kpToolFlowBase::beginDraw () | 208 | void kpToolFlowBase::beginDraw () | ||
Show All 38 Lines | 246 | { | |||
245 | return drawLine (point, point); | 247 | return drawLine (point, point); | ||
246 | } | 248 | } | ||
247 | 249 | | |||
248 | //--------------------------------------------------------------------- | 250 | //--------------------------------------------------------------------- | ||
249 | 251 | | |||
250 | // virtual | 252 | // virtual | ||
251 | void kpToolFlowBase::draw (const QPoint &thisPoint, const QPoint &lastPoint, const QRect &normalizedRect) | 253 | void kpToolFlowBase::draw (const QPoint &thisPoint, const QPoint &lastPoint, const QRect &normalizedRect) | ||
252 | { | 254 | { | ||
253 | if (!/*virtual*/drawShouldProceed (thisPoint, lastPoint, normalizedRect)) | 255 | if (!/*virtual*/drawShouldProceed (thisPoint, lastPoint, normalizedRect)) { | ||
254 | return; | 256 | return; | ||
257 | } | ||||
255 | 258 | | |||
256 | // sync: remember to restoreFastUpdates() in all exit paths | 259 | // sync: remember to restoreFastUpdates() in all exit paths | ||
257 | viewManager ()->setFastUpdates (); | 260 | viewManager ()->setFastUpdates (); | ||
258 | 261 | | |||
259 | QRect dirtyRect; | 262 | QRect dirtyRect; | ||
260 | 263 | | |||
261 | // TODO: I'm beginning to wonder this drawPoint() "optimization" actually | 264 | // TODO: I'm beginning to wonder this drawPoint() "optimization" actually | ||
262 | // optimises. Is it worth the complexity? Hence drawPoint() impl above. | 265 | // optimises. Is it worth the complexity? Hence drawPoint() impl above. | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
322 | //--------------------------------------------------------------------- | 325 | //--------------------------------------------------------------------- | ||
323 | 326 | | |||
324 | // TODO: maybe the base should be virtual? | 327 | // TODO: maybe the base should be virtual? | ||
325 | kpColor kpToolFlowBase::color (int which) | 328 | kpColor kpToolFlowBase::color (int which) | ||
326 | { | 329 | { | ||
327 | qCDebug(kpLogTools) << "kpToolFlowBase::color (" << which << ")"; | 330 | qCDebug(kpLogTools) << "kpToolFlowBase::color (" << which << ")"; | ||
328 | 331 | | |||
329 | // Pen & Brush | 332 | // Pen & Brush | ||
330 | if (!colorsAreSwapped ()) | 333 | if (!colorsAreSwapped ()) { | ||
331 | return kpTool::color (which); | 334 | return kpTool::color (which); | ||
335 | } | ||||
332 | // only the (Color) Eraser uses the opposite color | 336 | // only the (Color) Eraser uses the opposite color | ||
333 | else | | |||
334 | return kpTool::color (which ? 0 : 1); // don't trust !0 == 1 | 337 | return kpTool::color (which ? 0 : 1); // don't trust !0 == 1 | ||
335 | } | 338 | } | ||
336 | 339 | | |||
337 | //--------------------------------------------------------------------- | 340 | //--------------------------------------------------------------------- | ||
338 | 341 | | |||
339 | // protected | 342 | // protected | ||
340 | kpTempImage::UserFunctionType kpToolFlowBase::brushDrawFunction () const | 343 | kpTempImage::UserFunctionType kpToolFlowBase::brushDrawFunction () const | ||
341 | { | 344 | { | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 452 | { | |||
450 | /* | 453 | /* | ||
451 | * e.g. | 454 | * e.g. | ||
452 | * Width 5: | 455 | * Width 5: | ||
453 | * 0 1 2 3 4 | 456 | * 0 1 2 3 4 | ||
454 | * ^ | 457 | * ^ | ||
455 | * | | 458 | * | | ||
456 | * Center | 459 | * Center | ||
457 | */ | 460 | */ | ||
458 | return QRect (mousePoint.x () - brushWidth / 2, | 461 | return {mousePoint.x () - brushWidth / 2, | ||
459 | mousePoint.y () - brushHeight / 2, | 462 | mousePoint.y () - brushHeight / 2, | ||
460 | brushWidth, | 463 | brushWidth, brushHeight}; | ||
461 | brushHeight); | | |||
462 | } | 464 | } | ||
463 | 465 | | |||
464 | //--------------------------------------------------------------------- | 466 | //--------------------------------------------------------------------- | ||
465 | 467 | | |||
466 | // protected | 468 | // protected | ||
467 | QRect kpToolFlowBase::hotRect () const | 469 | QRect kpToolFlowBase::hotRect () const | ||
468 | { | 470 | { | ||
469 | return hotRectForMousePointAndBrushWidthHeight (currentPoint (), | 471 | return hotRectForMousePointAndBrushWidthHeight (currentPoint (), | ||
470 | d->brushWidth, d->brushHeight); | 472 | d->brushWidth, d->brushHeight); | ||
471 | } | 473 | } | ||
472 | 474 | | |||
473 | //--------------------------------------------------------------------- | 475 | //--------------------------------------------------------------------- | ||
474 | 476 | |