Changeset View
Changeset View
Standalone View
Standalone View
mainWindow/kpMainWindow_Tools.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
70 | #include "kpViewScrollableContainer.h" | 70 | #include "kpViewScrollableContainer.h" | ||
71 | #include "views/kpZoomedView.h" | 71 | #include "views/kpZoomedView.h" | ||
72 | 72 | | |||
73 | //--------------------------------------------------------------------- | 73 | //--------------------------------------------------------------------- | ||
74 | 74 | | |||
75 | // private | 75 | // private | ||
76 | kpToolSelectionEnvironment *kpMainWindow::toolSelectionEnvironment () | 76 | kpToolSelectionEnvironment *kpMainWindow::toolSelectionEnvironment () | ||
77 | { | 77 | { | ||
78 | if (!d->toolSelectionEnvironment) | 78 | if (!d->toolSelectionEnvironment) { | ||
79 | d->toolSelectionEnvironment = new kpToolSelectionEnvironment (this); | 79 | d->toolSelectionEnvironment = new kpToolSelectionEnvironment (this); | ||
80 | } | ||||
80 | 81 | | |||
81 | return d->toolSelectionEnvironment; | 82 | return d->toolSelectionEnvironment; | ||
82 | } | 83 | } | ||
83 | 84 | | |||
84 | //--------------------------------------------------------------------- | 85 | //--------------------------------------------------------------------- | ||
85 | 86 | | |||
86 | // private | 87 | // private | ||
87 | kpToolEnvironment *kpMainWindow::toolEnvironment () | 88 | kpToolEnvironment *kpMainWindow::toolEnvironment () | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 186 | connect (d->toolToolBar, &kpToolToolBar::toolWidgetOptionSelected, | |||
186 | this, &kpMainWindow::updateToolOptionPrevNextActionsEnabled); | 187 | this, &kpMainWindow::updateToolOptionPrevNextActionsEnabled); | ||
187 | 188 | | |||
188 | connect (d->toolToolBar->toolWidgetOpaqueOrTransparent(), | 189 | connect (d->toolToolBar->toolWidgetOpaqueOrTransparent(), | ||
189 | &kpToolWidgetOpaqueOrTransparent::isOpaqueChanged, | 190 | &kpToolWidgetOpaqueOrTransparent::isOpaqueChanged, | ||
190 | this, &kpMainWindow::updateActionDrawOpaqueChecked); | 191 | this, &kpMainWindow::updateActionDrawOpaqueChecked); | ||
191 | 192 | | |||
192 | updateActionDrawOpaqueChecked (); | 193 | updateActionDrawOpaqueChecked (); | ||
193 | 194 | | |||
194 | foreach (kpTool *tool, d->tools) | 195 | for (auto *tool : d->tools) { | ||
195 | d->toolToolBar->registerTool(tool); | 196 | d->toolToolBar->registerTool(tool); | ||
197 | } | ||||
196 | 198 | | |||
197 | // (from config file) | 199 | // (from config file) | ||
198 | readLastTool (); | 200 | readLastTool (); | ||
199 | } | 201 | } | ||
200 | 202 | | |||
201 | //--------------------------------------------------------------------- | 203 | //--------------------------------------------------------------------- | ||
202 | 204 | | |||
203 | // private | 205 | // private | ||
204 | void kpMainWindow::enableToolsDocumentActions (bool enable) | 206 | void kpMainWindow::enableToolsDocumentActions (bool enable) | ||
205 | { | 207 | { | ||
206 | qCDebug(kpLogMainWindow) << "kpMainWindow::enableToolsDocumentsAction(" << enable << ")"; | 208 | qCDebug(kpLogMainWindow) << "kpMainWindow::enableToolsDocumentsAction(" << enable << ")"; | ||
207 | 209 | | |||
208 | d->toolActionsEnabled = enable; | 210 | d->toolActionsEnabled = enable; | ||
209 | 211 | | |||
210 | if (enable && !d->toolToolBar->isEnabled ()) | 212 | if (enable && !d->toolToolBar->isEnabled ()) | ||
211 | { | 213 | { | ||
212 | kpTool *previousTool = d->toolToolBar->previousTool (); | 214 | kpTool *previousTool = d->toolToolBar->previousTool (); | ||
213 | 215 | | |||
214 | // select tool for enabled Tool Box | 216 | // select tool for enabled Tool Box | ||
215 | 217 | | |||
216 | if (previousTool) | 218 | if (previousTool) { | ||
217 | d->toolToolBar->selectPreviousTool (); | 219 | d->toolToolBar->selectPreviousTool (); | ||
220 | } | ||||
218 | else | 221 | else | ||
219 | { | 222 | { | ||
220 | if (d->lastToolNumber >= 0 && d->lastToolNumber < d->tools.count ()) | 223 | if (d->lastToolNumber >= 0 && d->lastToolNumber < d->tools.count ()) { | ||
221 | d->toolToolBar->selectTool (d->tools.at (d->lastToolNumber)); | 224 | d->toolToolBar->selectTool (d->tools.at (d->lastToolNumber)); | ||
222 | else | 225 | } | ||
226 | else { | ||||
223 | d->toolToolBar->selectTool (d->toolPen); | 227 | d->toolToolBar->selectTool (d->toolPen); | ||
224 | } | 228 | } | ||
225 | } | 229 | } | ||
230 | } | ||||
226 | else if (!enable && d->toolToolBar->isEnabled ()) | 231 | else if (!enable && d->toolToolBar->isEnabled ()) | ||
227 | { | 232 | { | ||
228 | // don't have a disabled Tool Box with a checked Tool | 233 | // don't have a disabled Tool Box with a checked Tool | ||
229 | d->toolToolBar->selectTool (nullptr); | 234 | d->toolToolBar->selectTool (nullptr); | ||
230 | } | 235 | } | ||
231 | 236 | | |||
232 | 237 | | |||
233 | d->toolToolBar->setEnabled (enable); | 238 | d->toolToolBar->setEnabled (enable); | ||
234 | 239 | | |||
235 | 240 | | |||
236 | foreach (kpTool *tool, d->tools) | 241 | for (auto *tool : d->tools) | ||
237 | { | 242 | { | ||
238 | kpToolAction *action = tool->action(); | 243 | kpToolAction *action = tool->action(); | ||
239 | if (!enable && action->isChecked()) | 244 | if (!enable && action->isChecked()) { | ||
240 | action->setChecked(false); | 245 | action->setChecked(false); | ||
246 | } | ||||
241 | 247 | | |||
242 | action->setEnabled(enable); | 248 | action->setEnabled(enable); | ||
243 | } | 249 | } | ||
244 | 250 | | |||
245 | 251 | | |||
246 | updateToolOptionPrevNextActionsEnabled (); | 252 | updateToolOptionPrevNextActionsEnabled (); | ||
247 | updateActionDrawOpaqueEnabled (); | 253 | updateActionDrawOpaqueEnabled (); | ||
248 | } | 254 | } | ||
Show All 40 Lines | |||||
289 | // private | 295 | // private | ||
290 | void kpMainWindow::updateActionDrawOpaqueEnabled () | 296 | void kpMainWindow::updateActionDrawOpaqueEnabled () | ||
291 | { | 297 | { | ||
292 | qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueEnabled()"; | 298 | qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueEnabled()"; | ||
293 | 299 | | |||
294 | const bool enable = d->toolActionsEnabled; | 300 | const bool enable = d->toolActionsEnabled; | ||
295 | 301 | | |||
296 | qCDebug(kpLogMainWindow) << "\tenable=" << enable | 302 | qCDebug(kpLogMainWindow) << "\tenable=" << enable | ||
297 | << " tool=" << (tool () ? tool ()->objectName () : 0) | 303 | << " tool=" << (tool () ? tool ()->objectName () : nullptr) | ||
298 | << " (is selection=" << toolIsASelectionTool () << ")" | 304 | << " (is selection=" << toolIsASelectionTool () << ")"; | ||
299 | << endl; | | |||
300 | 305 | | |||
301 | d->actionDrawOpaque->setEnabled (enable && toolIsASelectionTool ()); | 306 | d->actionDrawOpaque->setEnabled (enable && toolIsASelectionTool ()); | ||
302 | } | 307 | } | ||
303 | 308 | | |||
304 | //--------------------------------------------------------------------- | 309 | //--------------------------------------------------------------------- | ||
305 | 310 | | |||
306 | // public | 311 | // public | ||
307 | QActionGroup *kpMainWindow::toolsActionGroup () | 312 | QActionGroup *kpMainWindow::toolsActionGroup () | ||
308 | { | 313 | { | ||
309 | if (!d->toolsActionGroup) | 314 | if (!d->toolsActionGroup) { | ||
310 | d->toolsActionGroup = new QActionGroup (this); | 315 | d->toolsActionGroup = new QActionGroup (this); | ||
316 | } | ||||
311 | 317 | | |||
312 | return d->toolsActionGroup; | 318 | return d->toolsActionGroup; | ||
313 | } | 319 | } | ||
314 | 320 | | |||
315 | //--------------------------------------------------------------------- | 321 | //--------------------------------------------------------------------- | ||
316 | 322 | | |||
317 | // public | 323 | // public | ||
318 | kpTool *kpMainWindow::tool () const | 324 | kpTool *kpMainWindow::tool () const | ||
Show All 32 Lines | |||||
351 | } | 357 | } | ||
352 | 358 | | |||
353 | //--------------------------------------------------------------------- | 359 | //--------------------------------------------------------------------- | ||
354 | 360 | | |||
355 | 361 | | |||
356 | // private | 362 | // private | ||
357 | void kpMainWindow::toolEndShape () | 363 | void kpMainWindow::toolEndShape () | ||
358 | { | 364 | { | ||
359 | if (toolHasBegunShape ()) | 365 | if (toolHasBegunShape ()) { | ||
360 | tool ()->endShapeInternal (); | 366 | tool ()->endShapeInternal (); | ||
361 | } | 367 | } | ||
368 | } | ||||
362 | 369 | | |||
363 | //--------------------------------------------------------------------- | 370 | //--------------------------------------------------------------------- | ||
364 | 371 | | |||
365 | // public | 372 | // public | ||
366 | kpImageSelectionTransparency kpMainWindow::imageSelectionTransparency () const | 373 | kpImageSelectionTransparency kpMainWindow::imageSelectionTransparency () const | ||
367 | { | 374 | { | ||
368 | kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); | 375 | kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); | ||
369 | Q_ASSERT (oot); | 376 | Q_ASSERT (oot); | ||
370 | 377 | | |||
371 | return kpImageSelectionTransparency (oot->isOpaque (), backgroundColor (), d->colorToolBar->colorSimilarity ()); | 378 | return kpImageSelectionTransparency (oot->isOpaque (), backgroundColor (), d->colorToolBar->colorSimilarity ()); | ||
372 | } | 379 | } | ||
373 | 380 | | |||
374 | //--------------------------------------------------------------------- | 381 | //--------------------------------------------------------------------- | ||
375 | 382 | | |||
376 | // public | 383 | // public | ||
377 | void kpMainWindow::setImageSelectionTransparency (const kpImageSelectionTransparency &transparency, bool forceColorChange) | 384 | void kpMainWindow::setImageSelectionTransparency (const kpImageSelectionTransparency &transparency, bool forceColorChange) | ||
378 | { | 385 | { | ||
379 | qCDebug(kpLogMainWindow) << "kpMainWindow::setImageSelectionTransparency() isOpaque=" << transparency.isOpaque () | 386 | qCDebug(kpLogMainWindow) << "kpMainWindow::setImageSelectionTransparency() isOpaque=" << transparency.isOpaque () | ||
380 | << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : 0) | 387 | << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : nullptr) | ||
381 | << " forceColorChange=" << forceColorChange | 388 | << " forceColorChange=" << forceColorChange; | ||
382 | << endl; | | |||
383 | 389 | | |||
384 | kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); | 390 | kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); | ||
385 | Q_ASSERT (oot); | 391 | Q_ASSERT (oot); | ||
386 | 392 | | |||
387 | d->settingImageSelectionTransparency++; | 393 | d->settingImageSelectionTransparency++; | ||
388 | 394 | | |||
389 | oot->setOpaque (transparency.isOpaque ()); | 395 | oot->setOpaque (transparency.isOpaque ()); | ||
390 | if (transparency.isTransparent () || forceColorChange) | 396 | if (transparency.isTransparent () || forceColorChange) | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | |||||
508 | // private | 514 | // private | ||
509 | int kpMainWindow::toolNumber () const | 515 | int kpMainWindow::toolNumber () const | ||
510 | { | 516 | { | ||
511 | int number = 0; | 517 | int number = 0; | ||
512 | for (QList <kpTool *>::const_iterator it = d->tools.constBegin (); | 518 | for (QList <kpTool *>::const_iterator it = d->tools.constBegin (); | ||
513 | it != d->tools.constEnd (); | 519 | it != d->tools.constEnd (); | ||
514 | ++it) | 520 | ++it) | ||
515 | { | 521 | { | ||
516 | if (*it == tool ()) | 522 | if (*it == tool ()) { | ||
517 | return number; | 523 | return number; | ||
524 | } | ||||
518 | 525 | | |||
519 | number++; | 526 | number++; | ||
520 | } | 527 | } | ||
521 | 528 | | |||
522 | return -1; | 529 | return -1; | ||
523 | } | 530 | } | ||
524 | 531 | | |||
525 | //--------------------------------------------------------------------- | 532 | //--------------------------------------------------------------------- | ||
526 | 533 | | |||
527 | // private | 534 | // private | ||
528 | void kpMainWindow::saveLastTool () | 535 | void kpMainWindow::saveLastTool () | ||
529 | { | 536 | { | ||
530 | int number = toolNumber (); | 537 | int number = toolNumber (); | ||
531 | if (number < 0 || number >= d->tools.count ()) | 538 | if (number < 0 || number >= d->tools.count ()) { | ||
532 | return; | 539 | return; | ||
540 | } | ||||
533 | 541 | | |||
534 | 542 | | |||
535 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); | 543 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); | ||
536 | 544 | | |||
537 | cfg.writeEntry (kpSettingLastTool, number); | 545 | cfg.writeEntry (kpSettingLastTool, number); | ||
538 | cfg.sync (); | 546 | cfg.sync (); | ||
539 | } | 547 | } | ||
540 | 548 | | |||
Show All 13 Lines | 561 | bool kpMainWindow::slotDragScroll (const QPoint &docPoint, | |||
554 | const QPoint &docLastPoint, | 562 | const QPoint &docLastPoint, | ||
555 | int zoomLevel, | 563 | int zoomLevel, | ||
556 | bool *scrolled) | 564 | bool *scrolled) | ||
557 | { | 565 | { | ||
558 | Q_UNUSED(docPoint) | 566 | Q_UNUSED(docPoint) | ||
559 | Q_UNUSED(docLastPoint) | 567 | Q_UNUSED(docLastPoint) | ||
560 | 568 | | |||
561 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDragScroll() maybeDragScrolling=" | 569 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDragScroll() maybeDragScrolling=" | ||
562 | << maybeDragScrollingMainView () | 570 | << maybeDragScrollingMainView (); | ||
563 | << endl; | | |||
564 | 571 | | |||
565 | if (maybeDragScrollingMainView ()) | 572 | if (maybeDragScrollingMainView ()) | ||
566 | { | 573 | { | ||
567 | return d->scrollView->beginDragScroll(zoomLevel, scrolled); | 574 | return d->scrollView->beginDragScroll(zoomLevel, scrolled); | ||
568 | } | 575 | } | ||
569 | else | 576 | | ||
570 | { | | |||
571 | return false; | 577 | return false; | ||
572 | } | 578 | } | ||
573 | } | | |||
574 | 579 | | |||
575 | //--------------------------------------------------------------------- | 580 | //--------------------------------------------------------------------- | ||
576 | 581 | | |||
577 | // private slot | 582 | // private slot | ||
578 | bool kpMainWindow::slotEndDragScroll () | 583 | bool kpMainWindow::slotEndDragScroll () | ||
579 | { | 584 | { | ||
580 | // (harmless if haven't started drag scroll) | 585 | // (harmless if haven't started drag scroll) | ||
581 | return d->scrollView->endDragScroll (); | 586 | return d->scrollView->endDragScroll (); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
673 | } | 678 | } | ||
674 | 679 | | |||
675 | //--------------------------------------------------------------------- | 680 | //--------------------------------------------------------------------- | ||
676 | 681 | | |||
677 | // private slot | 682 | // private slot | ||
678 | void kpMainWindow::slotDocResizeMessageChanged (const QString &string) | 683 | void kpMainWindow::slotDocResizeMessageChanged (const QString &string) | ||
679 | { | 684 | { | ||
680 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDocResizeMessageChanged(" << string | 685 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDocResizeMessageChanged(" << string | ||
681 | << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted | 686 | << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted; | ||
682 | << endl; | | |||
683 | 687 | | |||
684 | if (d->docResizeToBeCompleted) | 688 | if (d->docResizeToBeCompleted) { | ||
685 | return; | 689 | return; | ||
690 | } | ||||
686 | 691 | | |||
687 | recalculateStatusBarMessage (); | 692 | recalculateStatusBarMessage (); | ||
688 | } | 693 | } | ||
689 | 694 | | |||
690 | //--------------------------------------------------------------------- | 695 | //--------------------------------------------------------------------- | ||
691 | 696 | | |||
692 | 697 | | |||
693 | // private slot | 698 | // private slot | ||
694 | void kpMainWindow::slotActionPrevToolOptionGroup1 () | 699 | void kpMainWindow::slotActionPrevToolOptionGroup1 () | ||
695 | { | 700 | { | ||
696 | if (!d->toolToolBar->shownToolWidget (0)) | 701 | if (!d->toolToolBar->shownToolWidget (0)) { | ||
697 | return; | 702 | return; | ||
703 | } | ||||
698 | 704 | | |||
699 | // We don't call toolEndShape() here because we want #23 in the file BUGS | 705 | // We don't call toolEndShape() here because we want #23 in the file BUGS | ||
700 | // to later work. | 706 | // to later work. | ||
701 | 707 | | |||
702 | d->toolToolBar->shownToolWidget (0)->selectPreviousOption (); | 708 | d->toolToolBar->shownToolWidget (0)->selectPreviousOption (); | ||
703 | updateToolOptionPrevNextActionsEnabled (); | 709 | updateToolOptionPrevNextActionsEnabled (); | ||
704 | } | 710 | } | ||
705 | 711 | | |||
706 | //--------------------------------------------------------------------- | 712 | //--------------------------------------------------------------------- | ||
707 | 713 | | |||
708 | // private slot | 714 | // private slot | ||
709 | void kpMainWindow::slotActionNextToolOptionGroup1 () | 715 | void kpMainWindow::slotActionNextToolOptionGroup1 () | ||
710 | { | 716 | { | ||
711 | if (!d->toolToolBar->shownToolWidget (0)) | 717 | if (!d->toolToolBar->shownToolWidget (0)) { | ||
712 | return; | 718 | return; | ||
719 | } | ||||
713 | 720 | | |||
714 | // We don't call toolEndShape() here because we want #23 in the file BUGS | 721 | // We don't call toolEndShape() here because we want #23 in the file BUGS | ||
715 | // to later work. | 722 | // to later work. | ||
716 | 723 | | |||
717 | d->toolToolBar->shownToolWidget (0)->selectNextOption (); | 724 | d->toolToolBar->shownToolWidget (0)->selectNextOption (); | ||
718 | updateToolOptionPrevNextActionsEnabled (); | 725 | updateToolOptionPrevNextActionsEnabled (); | ||
719 | } | 726 | } | ||
720 | 727 | | |||
721 | //--------------------------------------------------------------------- | 728 | //--------------------------------------------------------------------- | ||
722 | 729 | | |||
723 | 730 | | |||
724 | // private slot | 731 | // private slot | ||
725 | void kpMainWindow::slotActionPrevToolOptionGroup2 () | 732 | void kpMainWindow::slotActionPrevToolOptionGroup2 () | ||
726 | { | 733 | { | ||
727 | if (!d->toolToolBar->shownToolWidget (1)) | 734 | if (!d->toolToolBar->shownToolWidget (1)) { | ||
728 | return; | 735 | return; | ||
736 | } | ||||
729 | 737 | | |||
730 | // We don't call toolEndShape() here because we want #23 in the file BUGS | 738 | // We don't call toolEndShape() here because we want #23 in the file BUGS | ||
731 | // to later work. | 739 | // to later work. | ||
732 | 740 | | |||
733 | d->toolToolBar->shownToolWidget (1)->selectPreviousOption (); | 741 | d->toolToolBar->shownToolWidget (1)->selectPreviousOption (); | ||
734 | updateToolOptionPrevNextActionsEnabled (); | 742 | updateToolOptionPrevNextActionsEnabled (); | ||
735 | } | 743 | } | ||
736 | 744 | | |||
737 | //--------------------------------------------------------------------- | 745 | //--------------------------------------------------------------------- | ||
738 | 746 | | |||
739 | // private slot | 747 | // private slot | ||
740 | void kpMainWindow::slotActionNextToolOptionGroup2 () | 748 | void kpMainWindow::slotActionNextToolOptionGroup2 () | ||
741 | { | 749 | { | ||
742 | if (!d->toolToolBar->shownToolWidget (1)) | 750 | if (!d->toolToolBar->shownToolWidget (1)) { | ||
743 | return; | 751 | return; | ||
752 | } | ||||
744 | 753 | | |||
745 | // We don't call toolEndShape() here because we want #23 in the file BUGS | 754 | // We don't call toolEndShape() here because we want #23 in the file BUGS | ||
746 | // to later work. | 755 | // to later work. | ||
747 | 756 | | |||
748 | d->toolToolBar->shownToolWidget (1)->selectNextOption (); | 757 | d->toolToolBar->shownToolWidget (1)->selectNextOption (); | ||
749 | updateToolOptionPrevNextActionsEnabled (); | 758 | updateToolOptionPrevNextActionsEnabled (); | ||
750 | } | 759 | } | ||
751 | 760 | | |||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |