Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/kpAbstractSelectionTool_ResizeScale.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | #include "views/kpView.h" | 52 | #include "views/kpView.h" | ||
53 | #include "views/manager/kpViewManager.h" | 53 | #include "views/manager/kpViewManager.h" | ||
54 | 54 | | |||
55 | 55 | | |||
56 | // private | 56 | // private | ||
57 | int kpAbstractSelectionTool::onSelectionResizeHandle () const | 57 | int kpAbstractSelectionTool::onSelectionResizeHandle () const | ||
58 | { | 58 | { | ||
59 | kpView *v = viewManager ()->viewUnderCursor (); | 59 | kpView *v = viewManager ()->viewUnderCursor (); | ||
60 | if (!v) | 60 | if (!v) { | ||
61 | return 0; | 61 | return 0; | ||
62 | } | ||||
62 | 63 | | |||
63 | return v->mouseOnSelectionResizeHandle (currentViewPoint ()); | 64 | return v->mouseOnSelectionResizeHandle (currentViewPoint ()); | ||
64 | } | 65 | } | ||
65 | 66 | | |||
66 | //--------------------------------------------------------------------- | 67 | //--------------------------------------------------------------------- | ||
67 | 68 | | |||
68 | // private | 69 | // private | ||
69 | void kpAbstractSelectionTool::initResizeScale () | 70 | void kpAbstractSelectionTool::initResizeScale () | ||
Show All 33 Lines | |||||
103 | 104 | | |||
104 | //--------------------------------------------------------------------- | 105 | //--------------------------------------------------------------------- | ||
105 | 106 | | |||
106 | // private | 107 | // private | ||
107 | void kpAbstractSelectionTool::setCursorResizeScale () | 108 | void kpAbstractSelectionTool::setCursorResizeScale () | ||
108 | { | 109 | { | ||
109 | #if DEBUG_KP_TOOL_SELECTION && 0 | 110 | #if DEBUG_KP_TOOL_SELECTION && 0 | ||
110 | qCDebug(kpLogTools) << "\tonSelectionResizeHandle=" | 111 | qCDebug(kpLogTools) << "\tonSelectionResizeHandle=" | ||
111 | << onSelectionResizeHandle () << endl; | 112 | << onSelectionResizeHandle (); | ||
112 | #endif | 113 | #endif | ||
113 | Qt::CursorShape shape = Qt::ArrowCursor; | 114 | Qt::CursorShape shape = Qt::ArrowCursor; | ||
114 | 115 | | |||
115 | switch (onSelectionResizeHandle ()) | 116 | switch (onSelectionResizeHandle ()) | ||
116 | { | 117 | { | ||
117 | case (kpView::Top | kpView::Left): | 118 | case (kpView::Top | kpView::Left): | ||
118 | case (kpView::Bottom | kpView::Right): | 119 | case (kpView::Bottom | kpView::Right): | ||
119 | shape = Qt::SizeFDiagCursor; | 120 | shape = Qt::SizeFDiagCursor; | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 210 | { | |||
210 | // | 211 | // | ||
211 | // Determine new width. | 212 | // Determine new width. | ||
212 | // | 213 | // | ||
213 | 214 | | |||
214 | // Dragging left or right grip? | 215 | // Dragging left or right grip? | ||
215 | // If left, positive X drags decrease width. | 216 | // If left, positive X drags decrease width. | ||
216 | // If right, positive X drags increase width. | 217 | // If right, positive X drags increase width. | ||
217 | int userXSign = 0; | 218 | int userXSign = 0; | ||
218 | if (d->resizeScaleType & kpView::Left) | 219 | if (d->resizeScaleType & kpView::Left) { | ||
219 | userXSign = -1; | 220 | userXSign = -1; | ||
220 | else if (d->resizeScaleType & kpView::Right) | 221 | } | ||
222 | else if (d->resizeScaleType & kpView::Right) { | ||||
221 | userXSign = +1; | 223 | userXSign = +1; | ||
224 | } | ||||
222 | 225 | | |||
223 | // Calcluate new width. | 226 | // Calcluate new width. | ||
224 | *newWidth = originalSelection.width () + | 227 | *newWidth = originalSelection.width () + | ||
225 | userXSign * (currentPoint ().x () - startPoint ().x ()); | 228 | userXSign * (currentPoint ().x () - startPoint ().x ()); | ||
226 | 229 | | |||
227 | // Don't allow new width to be less than that kind of selection type's | 230 | // Don't allow new width to be less than that kind of selection type's | ||
228 | // minimum. | 231 | // minimum. | ||
229 | *newWidth = qMax (originalSelection.minimumWidth (), *newWidth); | 232 | *newWidth = qMax (originalSelection.minimumWidth (), *newWidth); | ||
230 | 233 | | |||
231 | 234 | | |||
232 | // | 235 | // | ||
233 | // Determine new height. | 236 | // Determine new height. | ||
234 | // | 237 | // | ||
235 | 238 | | |||
236 | // Dragging top or bottom grip? | 239 | // Dragging top or bottom grip? | ||
237 | // If top, positive Y drags decrease height. | 240 | // If top, positive Y drags decrease height. | ||
238 | // If bottom, positive Y drags increase height. | 241 | // If bottom, positive Y drags increase height. | ||
239 | int userYSign = 0; | 242 | int userYSign = 0; | ||
240 | if (d->resizeScaleType & kpView::Top) | 243 | if (d->resizeScaleType & kpView::Top) { | ||
241 | userYSign = -1; | 244 | userYSign = -1; | ||
242 | else if (d->resizeScaleType & kpView::Bottom) | 245 | } | ||
246 | else if (d->resizeScaleType & kpView::Bottom) { | ||||
243 | userYSign = +1; | 247 | userYSign = +1; | ||
248 | } | ||||
244 | 249 | | |||
245 | // Calcluate new height. | 250 | // Calcluate new height. | ||
246 | *newHeight = originalSelection.height () + | 251 | *newHeight = originalSelection.height () + | ||
247 | userYSign * (currentPoint ().y () - startPoint ().y ()); | 252 | userYSign * (currentPoint ().y () - startPoint ().y ()); | ||
248 | 253 | | |||
249 | // Don't allow new height to be less than that kind of selection type's | 254 | // Don't allow new height to be less than that kind of selection type's | ||
250 | // minimum. | 255 | // minimum. | ||
251 | *newHeight = qMax (originalSelection.minimumHeight (), *newHeight); | 256 | *newHeight = qMax (originalSelection.minimumHeight (), *newHeight); | ||
Show All 27 Lines | |||||
279 | { | 284 | { | ||
280 | *newY -= (*newHeight - originalSelection.height ()); | 285 | *newY -= (*newHeight - originalSelection.height ()); | ||
281 | } | 286 | } | ||
282 | 287 | | |||
283 | #if DEBUG_KP_TOOL_SELECTION && 1 | 288 | #if DEBUG_KP_TOOL_SELECTION && 1 | ||
284 | qCDebug(kpLogTools) << "\t\tnewX=" << *newX | 289 | qCDebug(kpLogTools) << "\t\tnewX=" << *newX | ||
285 | << " newY=" << *newY | 290 | << " newY=" << *newY | ||
286 | << " newWidth=" << *newWidth | 291 | << " newWidth=" << *newWidth | ||
287 | << " newHeight=" << *newHeight | 292 | << " newHeight=" << *newHeight; | ||
288 | << endl; | | |||
289 | #endif | 293 | #endif | ||
290 | } | 294 | } | ||
291 | 295 | | |||
292 | //--------------------------------------------------------------------- | 296 | //--------------------------------------------------------------------- | ||
293 | 297 | | |||
294 | // private | 298 | // private | ||
295 | void kpAbstractSelectionTool::drawResizeScale ( | 299 | void kpAbstractSelectionTool::drawResizeScale ( | ||
296 | const QPoint &thisPoint, | 300 | const QPoint &thisPoint, | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
365 | // private | 369 | // private | ||
366 | void kpAbstractSelectionTool::cancelResizeScale () | 370 | void kpAbstractSelectionTool::cancelResizeScale () | ||
367 | { | 371 | { | ||
368 | #if DEBUG_KP_TOOL_SELECTION | 372 | #if DEBUG_KP_TOOL_SELECTION | ||
369 | qCDebug(kpLogTools) << "\twas resize/scale sel - kill"; | 373 | qCDebug(kpLogTools) << "\twas resize/scale sel - kill"; | ||
370 | #endif | 374 | #endif | ||
371 | 375 | | |||
372 | // NOP drag? | 376 | // NOP drag? | ||
373 | if (!d->currentResizeScaleCommand) | 377 | if (!d->currentResizeScaleCommand) { | ||
374 | return; | 378 | return; | ||
379 | } | ||||
375 | 380 | | |||
376 | #if DEBUG_KP_TOOL_SELECTION | 381 | #if DEBUG_KP_TOOL_SELECTION | ||
377 | qCDebug(kpLogTools) << "\t\tundo currentResizeScaleCommand"; | 382 | qCDebug(kpLogTools) << "\t\tundo currentResizeScaleCommand"; | ||
378 | #endif | 383 | #endif | ||
379 | d->currentResizeScaleCommand->finalize (); // (unneeded but let's be safe) | 384 | d->currentResizeScaleCommand->finalize (); // (unneeded but let's be safe) | ||
380 | d->currentResizeScaleCommand->unexecute (); | 385 | d->currentResizeScaleCommand->unexecute (); | ||
381 | delete d->currentResizeScaleCommand; | 386 | delete d->currentResizeScaleCommand; | ||
382 | d->currentResizeScaleCommand = nullptr; | 387 | d->currentResizeScaleCommand = nullptr; | ||
383 | } | 388 | } | ||
384 | 389 | | |||
385 | //--------------------------------------------------------------------- | 390 | //--------------------------------------------------------------------- | ||
386 | 391 | | |||
387 | // private | 392 | // private | ||
388 | void kpAbstractSelectionTool::endDrawResizeScale () | 393 | void kpAbstractSelectionTool::endDrawResizeScale () | ||
389 | { | 394 | { | ||
390 | // NOP drag? | 395 | // NOP drag? | ||
391 | if (!d->currentResizeScaleCommand) | 396 | if (!d->currentResizeScaleCommand) { | ||
392 | return; | 397 | return; | ||
398 | } | ||||
393 | 399 | | |||
394 | d->currentResizeScaleCommand->finalize (); | 400 | d->currentResizeScaleCommand->finalize (); | ||
395 | 401 | | |||
396 | addNeedingContentCommand (d->currentResizeScaleCommand); | 402 | addNeedingContentCommand (d->currentResizeScaleCommand); | ||
397 | d->currentResizeScaleCommand = nullptr; | 403 | d->currentResizeScaleCommand = nullptr; | ||
398 | } | 404 | } | ||
399 | 405 | | |||
400 | //--------------------------------------------------------------------- | 406 | //--------------------------------------------------------------------- | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |