Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/kpAbstractSelectionTool.cpp
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | |||||
137 | 137 | | |||
138 | //--------------------------------------------------------------------- | 138 | //--------------------------------------------------------------------- | ||
139 | 139 | | |||
140 | // protected overrides [base kpTool] | 140 | // protected overrides [base kpTool] | ||
141 | kpToolSelectionEnvironment *kpAbstractSelectionTool::environ () const | 141 | kpToolSelectionEnvironment *kpAbstractSelectionTool::environ () const | ||
142 | { | 142 | { | ||
143 | kpToolEnvironment *e = kpTool::environ (); | 143 | kpToolEnvironment *e = kpTool::environ (); | ||
144 | Q_ASSERT (dynamic_cast <kpToolSelectionEnvironment *> (e)); | 144 | Q_ASSERT (dynamic_cast <kpToolSelectionEnvironment *> (e)); | ||
145 | return static_cast <kpToolSelectionEnvironment *> (e); | 145 | return dynamic_cast <kpToolSelectionEnvironment *> (e); | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | //--------------------------------------------------------------------- | 148 | //--------------------------------------------------------------------- | ||
149 | 149 | | |||
150 | // protected | 150 | // protected | ||
151 | bool kpAbstractSelectionTool::controlOrShiftPressed () const | 151 | bool kpAbstractSelectionTool::controlOrShiftPressed () const | ||
152 | { | 152 | { | ||
153 | return (controlPressed () || shiftPressed ()); | 153 | return (controlPressed () || shiftPressed ()); | ||
154 | } | 154 | } | ||
155 | 155 | | |||
156 | //--------------------------------------------------------------------- | 156 | //--------------------------------------------------------------------- | ||
157 | 157 | | |||
158 | // protected | 158 | // protected | ||
159 | void kpAbstractSelectionTool::pushOntoDocument () | 159 | void kpAbstractSelectionTool::pushOntoDocument () | ||
160 | { | 160 | { | ||
161 | #if DEBUG_KP_TOOL_SELECTION && 1 | 161 | #if DEBUG_KP_TOOL_SELECTION && 1 | ||
162 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::pushOntoDocument() selection=" | 162 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::pushOntoDocument() selection=" | ||
163 | << document ()->selection () << endl; | 163 | << document ()->selection (); | ||
164 | #endif | 164 | #endif | ||
165 | Q_ASSERT (document ()->selection ()); | 165 | Q_ASSERT (document ()->selection ()); | ||
166 | environ ()->deselectSelection (); | 166 | environ ()->deselectSelection (); | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | //--------------------------------------------------------------------- | 169 | //--------------------------------------------------------------------- | ||
170 | 170 | | |||
171 | // protected | 171 | // protected | ||
172 | void kpAbstractSelectionTool::giveContentIfNeeded () | 172 | void kpAbstractSelectionTool::giveContentIfNeeded () | ||
173 | { | 173 | { | ||
174 | kpAbstractSelection *sel = document ()->selection (); | 174 | kpAbstractSelection *sel = document ()->selection (); | ||
175 | Q_ASSERT (sel); | 175 | Q_ASSERT (sel); | ||
176 | 176 | | |||
177 | if (sel->hasContent ()) | 177 | if (sel->hasContent ()) { | ||
178 | return; | 178 | return; | ||
179 | } | ||||
179 | 180 | | |||
180 | if (d->currentSelContentCommand) | 181 | if (d->currentSelContentCommand) { | ||
181 | return; | 182 | return; | ||
183 | } | ||||
182 | 184 | | |||
183 | d->currentSelContentCommand = /*virtual*/newGiveContentCommand (); | 185 | d->currentSelContentCommand = /*virtual*/newGiveContentCommand (); | ||
184 | d->currentSelContentCommand->execute (); | 186 | d->currentSelContentCommand->execute (); | ||
185 | } | 187 | } | ||
186 | 188 | | |||
187 | //--------------------------------------------------------------------- | 189 | //--------------------------------------------------------------------- | ||
188 | 190 | | |||
189 | // protected | 191 | // protected | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
247 | //--------------------------------------------------------------------- | 249 | //--------------------------------------------------------------------- | ||
248 | 250 | | |||
249 | // private | 251 | // private | ||
250 | QString kpAbstractSelectionTool::haventBegunDrawUserMessage () | 252 | QString kpAbstractSelectionTool::haventBegunDrawUserMessage () | ||
251 | { | 253 | { | ||
252 | #if DEBUG_KP_TOOL_SELECTION && 0 | 254 | #if DEBUG_KP_TOOL_SELECTION && 0 | ||
253 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::haventBegunDrawUserMessage()" | 255 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::haventBegunDrawUserMessage()" | ||
254 | " cancelledShapeButStillHoldingButtons=" | 256 | " cancelledShapeButStillHoldingButtons=" | ||
255 | << d->cancelledShapeButStillHoldingButtons | 257 | << d->cancelledShapeButStillHoldingButtons; | ||
256 | << endl; | | |||
257 | #endif | 258 | #endif | ||
258 | 259 | | |||
259 | if (d->cancelledShapeButStillHoldingButtons) | 260 | if (d->cancelledShapeButStillHoldingButtons) { | ||
260 | return i18n ("Let go of all the mouse buttons."); | 261 | return i18n ("Let go of all the mouse buttons."); | ||
262 | } | ||||
261 | 263 | | |||
262 | return operation (calculateDrawType (), HaventBegunDrawUserMessage).toString (); | 264 | return operation (calculateDrawType (), HaventBegunDrawUserMessage).toString (); | ||
263 | } | 265 | } | ||
264 | 266 | | |||
265 | //--------------------------------------------------------------------- | 267 | //--------------------------------------------------------------------- | ||
266 | 268 | | |||
267 | // public virtual [base kpTool] | 269 | // public virtual [base kpTool] | ||
268 | void kpAbstractSelectionTool::begin () | 270 | void kpAbstractSelectionTool::begin () | ||
Show All 39 Lines | |||||
308 | 310 | | |||
309 | // public virtual [base kpTool] | 311 | // public virtual [base kpTool] | ||
310 | void kpAbstractSelectionTool::end () | 312 | void kpAbstractSelectionTool::end () | ||
311 | { | 313 | { | ||
312 | #if DEBUG_KP_TOOL_SELECTION | 314 | #if DEBUG_KP_TOOL_SELECTION | ||
313 | qCDebug(kpLogTools) << "kpAbstractSelectionTool<" << objectName () << ">::end()"; | 315 | qCDebug(kpLogTools) << "kpAbstractSelectionTool<" << objectName () << ">::end()"; | ||
314 | #endif | 316 | #endif | ||
315 | 317 | | |||
316 | if (document ()->selection ()) | 318 | if (document ()->selection ()) { | ||
317 | pushOntoDocument (); | 319 | pushOntoDocument (); | ||
320 | } | ||||
318 | 321 | | |||
319 | 322 | | |||
320 | endCreate (); | 323 | endCreate (); | ||
321 | endMove (); | 324 | endMove (); | ||
322 | endResizeScale (); | 325 | endResizeScale (); | ||
323 | 326 | | |||
324 | 327 | | |||
325 | // (should have been killed by cancelShape() or endDraw()) | 328 | // (should have been killed by cancelShape() or endDraw()) | ||
Show All 22 Lines | |||||
348 | 351 | | |||
349 | // public virtual [base kpTool] | 352 | // public virtual [base kpTool] | ||
350 | void kpAbstractSelectionTool::reselect () | 353 | void kpAbstractSelectionTool::reselect () | ||
351 | { | 354 | { | ||
352 | #if DEBUG_KP_TOOL_SELECTION | 355 | #if DEBUG_KP_TOOL_SELECTION | ||
353 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::reselect()"; | 356 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::reselect()"; | ||
354 | #endif | 357 | #endif | ||
355 | 358 | | |||
356 | if (document ()->selection ()) | 359 | if (document ()->selection ()) { | ||
357 | pushOntoDocument (); | 360 | pushOntoDocument (); | ||
358 | } | 361 | } | ||
362 | } | ||||
359 | 363 | | |||
360 | //--------------------------------------------------------------------- | 364 | //--------------------------------------------------------------------- | ||
361 | 365 | | |||
362 | // protected virtual | 366 | // protected virtual | ||
363 | kpAbstractSelectionTool::DrawType kpAbstractSelectionTool::calculateDrawTypeInsideSelection () const | 367 | kpAbstractSelectionTool::DrawType kpAbstractSelectionTool::calculateDrawTypeInsideSelection () const | ||
364 | { | 368 | { | ||
365 | #if DEBUG_KP_TOOL_SELECTION | 369 | #if DEBUG_KP_TOOL_SELECTION | ||
366 | qCDebug(kpLogTools) << "\t\tis move"; | 370 | qCDebug(kpLogTools) << "\t\tis move"; | ||
367 | #endif | 371 | #endif | ||
368 | return kpAbstractSelectionTool::Move; | 372 | return kpAbstractSelectionTool::Move; | ||
369 | } | 373 | } | ||
370 | 374 | | |||
371 | //--------------------------------------------------------------------- | 375 | //--------------------------------------------------------------------- | ||
372 | 376 | | |||
373 | // protected virtual | 377 | // protected virtual | ||
374 | kpAbstractSelectionTool::DrawType kpAbstractSelectionTool::calculateDrawType () const | 378 | kpAbstractSelectionTool::DrawType kpAbstractSelectionTool::calculateDrawType () const | ||
375 | { | 379 | { | ||
376 | kpAbstractSelection *sel = document ()->selection (); | 380 | kpAbstractSelection *sel = document ()->selection (); | ||
377 | if (!sel) | 381 | if (!sel) { | ||
378 | return Create; | 382 | return Create; | ||
383 | } | ||||
379 | #if DEBUG_KP_TOOL_SELECTION | 384 | #if DEBUG_KP_TOOL_SELECTION | ||
380 | qCDebug(kpLogTools) << "\thas sel region rect=" << sel->boundingRect (); | 385 | qCDebug(kpLogTools) << "\thas sel region rect=" << sel->boundingRect (); | ||
381 | #endif | 386 | #endif | ||
382 | 387 | | |||
383 | if (onSelectionResizeHandle () && !controlOrShiftPressed ()) | 388 | if (onSelectionResizeHandle () && !controlOrShiftPressed ()) { | ||
384 | return ResizeScale; | 389 | return ResizeScale; | ||
385 | else if (sel->contains (currentPoint ())) | 390 | } | ||
391 | | ||||
392 | if (sel->contains (currentPoint ())) { | ||||
386 | return /*virtual*/calculateDrawTypeInsideSelection (); | 393 | return /*virtual*/calculateDrawTypeInsideSelection (); | ||
387 | else | 394 | } | ||
395 | | ||||
388 | return Create; | 396 | return Create; | ||
389 | } | 397 | } | ||
390 | 398 | | |||
391 | //--------------------------------------------------------------------- | 399 | //--------------------------------------------------------------------- | ||
392 | 400 | | |||
393 | // public virtual [base kpTool] | 401 | // public virtual [base kpTool] | ||
394 | void kpAbstractSelectionTool::beginDraw () | 402 | void kpAbstractSelectionTool::beginDraw () | ||
395 | { | 403 | { | ||
396 | #if DEBUG_KP_TOOL_SELECTION | 404 | #if DEBUG_KP_TOOL_SELECTION | ||
397 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::beginDraw() startPoint ()=" | 405 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::beginDraw() startPoint ()=" | ||
398 | << startPoint () | 406 | << startPoint () | ||
399 | << " QCursor::pos() view startPoint=" | 407 | << " QCursor::pos() view startPoint=" | ||
400 | << viewUnderStartPoint ()->mapFromGlobal (QCursor::pos ()) | 408 | << viewUnderStartPoint ()->mapFromGlobal (QCursor::pos ()); | ||
401 | << endl; | | |||
402 | #endif | 409 | #endif | ||
403 | 410 | | |||
404 | // endDraw() and cancelShape() should have taken care of these. | 411 | // endDraw() and cancelShape() should have taken care of these. | ||
405 | ::AssertAllTimersInactive (d); | 412 | ::AssertAllTimersInactive (d); | ||
406 | 413 | | |||
407 | // In case the cursor was wrong to start with | 414 | // In case the cursor was wrong to start with | ||
408 | // (forgot to call kpTool::somethingBelowTheCursorChanged()), | 415 | // (forgot to call kpTool::somethingBelowTheCursorChanged()), | ||
409 | // make sure it is correct during this operation. | 416 | // make sure it is correct during this operation. | ||
Show All 34 Lines | 450 | setUserShapeSize (document ()->selection ()->width (), | |||
444 | document ()->selection ()->height ()); | 451 | document ()->selection ()->height ()); | ||
445 | } | 452 | } | ||
446 | else | 453 | else | ||
447 | { | 454 | { | ||
448 | setUserShapeSize (KP_INVALID_SIZE); | 455 | setUserShapeSize (KP_INVALID_SIZE); | ||
449 | } | 456 | } | ||
450 | 457 | | |||
451 | QString mess = haventBegunDrawUserMessage (); | 458 | QString mess = haventBegunDrawUserMessage (); | ||
452 | if (mess != userMessage ()) | 459 | if (mess != userMessage ()) { | ||
453 | setUserMessage (mess); | 460 | setUserMessage (mess); | ||
454 | } | 461 | } | ||
462 | } | ||||
455 | 463 | | |||
456 | //--------------------------------------------------------------------- | 464 | //--------------------------------------------------------------------- | ||
457 | 465 | | |||
458 | 466 | | |||
459 | // public virtual [base kpTool] | 467 | // public virtual [base kpTool] | ||
460 | void kpAbstractSelectionTool::draw (const QPoint &thisPoint, const QPoint & /*lastPoint*/, | 468 | void kpAbstractSelectionTool::draw (const QPoint &thisPoint, const QPoint & /*lastPoint*/, | ||
461 | const QRect &normalizedRect) | 469 | const QRect &normalizedRect) | ||
462 | { | 470 | { | ||
463 | #if DEBUG_KP_TOOL_SELECTION && 1 | 471 | #if DEBUG_KP_TOOL_SELECTION && 1 | ||
464 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::draw (" << thisPoint | 472 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::draw (" << thisPoint | ||
465 | << ",startPoint=" << startPoint () | 473 | << ",startPoint=" << startPoint () | ||
466 | << ",normalizedRect=" << normalizedRect << ")" << endl; | 474 | << ",normalizedRect=" << normalizedRect << ")"; | ||
467 | #else | 475 | #else | ||
468 | Q_UNUSED (thisPoint); | 476 | Q_UNUSED (thisPoint); | ||
469 | Q_UNUSED (normalizedRect); | 477 | Q_UNUSED (normalizedRect); | ||
470 | #endif | 478 | #endif | ||
471 | 479 | | |||
472 | 480 | | |||
473 | // OPT: return when thisPoint == lastPoint () so that e.g. when creating | 481 | // OPT: return when thisPoint == lastPoint () so that e.g. when creating | ||
474 | // Points sel, press modifiers doesn't add multiple points in same | 482 | // Points sel, press modifiers doesn't add multiple points in same | ||
475 | // place | 483 | // place | ||
476 | 484 | | |||
477 | 485 | | |||
478 | operation (d->drawType, Draw); | 486 | operation (d->drawType, Draw); | ||
479 | } | 487 | } | ||
480 | 488 | | |||
481 | //--------------------------------------------------------------------- | 489 | //--------------------------------------------------------------------- | ||
482 | 490 | | |||
483 | 491 | | |||
484 | // public virtual [base kpTool] | 492 | // public virtual [base kpTool] | ||
485 | void kpAbstractSelectionTool::cancelShape () | 493 | void kpAbstractSelectionTool::cancelShape () | ||
486 | { | 494 | { | ||
487 | #if DEBUG_KP_TOOL_SELECTION | 495 | #if DEBUG_KP_TOOL_SELECTION | ||
488 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::cancelShape() mouseButton=" | 496 | qCDebug(kpLogTools) << "kpAbstractSelectionTool::cancelShape() mouseButton=" | ||
489 | << mouseButton () << endl; | 497 | << mouseButton (); | ||
490 | #endif | 498 | #endif | ||
491 | 499 | | |||
492 | const DrawType oldDrawType = d->drawType; | 500 | const DrawType oldDrawType = d->drawType; | ||
493 | // kpTool::hasBegunDraw() returns false in this method so be consistent | 501 | // kpTool::hasBegunDraw() returns false in this method so be consistent | ||
494 | // and clear "drawType" before dispatching the operation() below. | 502 | // and clear "drawType" before dispatching the operation() below. | ||
495 | d->drawType = None; | 503 | d->drawType = None; | ||
496 | 504 | | |||
497 | 505 | | |||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 579 | #endif | |||
586 | 594 | | |||
587 | 595 | | |||
588 | setUserMessage (haventBegunDrawUserMessage ()); | 596 | setUserMessage (haventBegunDrawUserMessage ()); | ||
589 | 597 | | |||
590 | 598 | | |||
591 | ::AssertAllTimersInactive (d); | 599 | ::AssertAllTimersInactive (d); | ||
592 | 600 | | |||
593 | 601 | | |||
594 | if (mouseButton () == 1/*right*/) | 602 | if (mouseButton () == 1/*right*/) { | ||
595 | popupRMBMenu (); | 603 | popupRMBMenu (); | ||
604 | } | ||||
596 | 605 | | |||
597 | 606 | | |||
598 | // WARNING: Do not place any code after the popupRMBMenu() call | 607 | // WARNING: Do not place any code after the popupRMBMenu() call | ||
599 | // (see the popupRMBMenu() API). | 608 | // (see the popupRMBMenu() API). | ||
600 | } | 609 | } | ||
601 | 610 | | |||
602 | //--------------------------------------------------------------------- | 611 | //--------------------------------------------------------------------- | ||
603 | 612 | | |||
Show All 29 Lines |