Krita Source Code Documentation
Loading...
Searching...
No Matches
KisViewManager.cpp
Go to the documentation of this file.
1/*
2 * This file is part of KimageShop^WKrayon^WKrita
3 *
4 * SPDX-FileCopyrightText: 1999 Matthias Elter <me@kde.org>
5 * SPDX-FileCopyrightText: 1999 Michael Koch <koch@kde.org>
6 * SPDX-FileCopyrightText: 1999 Carsten Pfeiffer <pfeiffer@kde.org>
7 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
8 * SPDX-FileCopyrightText: 2003-2011 Boudewijn Rempt <boud@valdyas.org>
9 * SPDX-FileCopyrightText: 2004 Clarence Dang <dang@kde.org>
10 * SPDX-FileCopyrightText: 2011 José Luis Vergara <pentalis@gmail.com>
11 * SPDX-FileCopyrightText: 2017 L. E. Segovia <amy@amyspark.me>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16
17#include "KisViewManager.h"
18#include <QPrinter>
19
20#include <QAction>
21#include <QApplication>
22#include <QBuffer>
23#include <QByteArray>
24#include <QDeadlineTimer>
25#include <QStandardPaths>
26#include <QScreen>
27#include <QDesktopServices>
28#include <QGridLayout>
29#include <QMainWindow>
30#include <QMenu>
31#include <QMenuBar>
32#include <QMessageBox>
33#include <QObject>
34#include <QPoint>
35#include <QPrintDialog>
36#include <QPushButton>
37#include <QScreen>
38#include <QScrollBar>
39#include <QStatusBar>
40#include <QToolBar>
41#include <QUrl>
42#include <QWidget>
43#include <QActionGroup>
44#include <QRegularExpression>
45
46#include <kactioncollection.h>
47#include <klocalizedstring.h>
48#include <KoResourcePaths.h>
49#include <kselectaction.h>
50
51#include <KoCanvasController.h>
52#include <KoCompositeOp.h>
53#include <KoDockRegistry.h>
55#include <KoFileDialog.h>
56#include <KoProperties.h>
58#include <KoSelection.h>
59#include <KoStore.h>
60#include <KoToolManager.h>
61#include <KoToolRegistry.h>
62#include <KoViewConverter.h>
63#include <KoZoomHandler.h>
64#include <KoPluginLoader.h>
65#include <KoDocumentInfo.h>
67#include <KisResourceLocator.h>
68
70#include "canvas/kis_canvas2.h"
74#include "kis_action_manager.h"
75#include "kis_action.h"
79#include <KoProgressUpdater.h>
80#include "kis_config.h"
81#include "kis_config_notifier.h"
82#include "kis_control_frame.h"
83#include "KisDocument.h"
85#include "kis_filter_manager.h"
86#include "kis_group_layer.h"
87#include <kis_image.h>
88#include "kis_image_manager.h"
89#include <kis_layer.h>
91#include "kis_mask_manager.h"
92#include "kis_mirror_manager.h"
94#include "kis_node.h"
95#include "kis_node_manager.h"
97#include <kis_paint_layer.h>
98#include "kis_paintop_box.h"
100#include "KisPart.h"
101#include <KoUpdater.h>
102#include "kis_selection_mask.h"
104#include "kis_shape_controller.h"
105#include "kis_shape_layer.h"
107#include "kis_statusbar.h"
108#include <KisTemplateCreateDia.h>
109#include <kis_tool_freehand.h>
110#include <kis_undo_adapter.h>
111#include "KisView.h"
112#include "kis_zoom_manager.h"
115#include "kis_icon_utils.h"
116#include "kis_guides_manager.h"
120#include <KisMainWindow.h>
121#include "kis_signals_blocker.h"
122#include "imagesize/imagesize.h"
123#include <KoToolDocker.h>
124#include <KisIdleTasksManager.h>
125#include <KisImageBarrierLock.h>
127#include <kis_selection.h>
128#include <KisUniqueColorSet.h>
129
130#ifdef Q_OS_WIN
132#endif
133
134class BlockingUserInputEventFilter : public QObject
135{
136 bool eventFilter(QObject *watched, QEvent *event) override
137 {
138 Q_UNUSED(watched);
139 if(dynamic_cast<QWheelEvent*>(event)
140 || dynamic_cast<QKeyEvent*>(event)
141 || dynamic_cast<QMouseEvent*>(event)) {
142 return true;
143 }
144 else {
145 return false;
146 }
147 }
148};
149
151{
152
153public:
154
155 KisViewManagerPrivate(KisViewManager *_q, KisKActionCollection *_actionCollection, QWidget *_q_parent)
156 : filterManager(_q)
157 , selectionManager(_q)
158 , statusBar(_q)
159 , controlFrame(_q, _q_parent)
160 , toolManager()
161 , nodeManager(_q)
162 , imageManager(_q)
163 , gridManager(_q)
166 , actionManager(_q, _actionCollection)
169 , guiUpdateCompressor(30, KisSignalCompressor::POSTPONE, _q)
170 , actionCollection(_actionCollection)
171 , mirrorManager(_q)
173 , zoomRotationMessageTimer(Qt::CoarseTimer)
174 {
176 }
177
178public:
192 QActionGroup *wrapAroundAxisActions {nullptr};
197 KisAction *zoomIn {nullptr};
198 KisAction *zoomOut {nullptr};
208
213
214 QScopedPointer<KoProgressUpdater> persistentUnthreadedProgressUpdaterRouter;
216
226 QMainWindow* mainWindow {nullptr};
238
240 KSelectAction *actionAuthor {nullptr}; // Select action for author profile.
242
244 QString zoomMessage;
246
249
275 std::optional<CanvasOnlyOptions> canvasOnlyOptions;
277 bool inCanvasOnlyMode{false};
278
280};
281
282KisViewManager::KisViewManager(QWidget *parent, KisKActionCollection *_actionCollection)
283 : d(new KisViewManagerPrivate(this, _actionCollection, parent))
284{
285 d->actionCollection = _actionCollection;
286 d->mainWindow = dynamic_cast<QMainWindow*>(parent);
288 connect(&d->guiUpdateCompressor, SIGNAL(timeout()), this, SLOT(guiUpdateTimeout()));
289
292
293 // These initialization functions must wait until KisViewManager ctor is complete.
294 d->statusBar.setup();
296 d->statusBar.progressUpdater()->startSubtask(1, "", true);
297 // reset state to "completed"
298 d->persistentImageProgressUpdater->setRange(0,100);
299 d->persistentImageProgressUpdater->setValue(100);
300
302 d->statusBar.progressUpdater()->startSubtask(1, "", true);
303 // reset state to "completed"
304 d->persistentUnthreadedProgressUpdater->setRange(0,100);
306
310 d->persistentUnthreadedProgressUpdaterRouter->setAutoNestNames(true);
312
313 // just a clumsy way to mark the updater as completed, the subtask will
314 // be automatically deleted on completion...
315 d->persistentUnthreadedProgressUpdaterRouter->startSubtask()->setProgress(100);
316
317 d->controlFrame.setup(parent);
318
319
320 //Check to draw scrollbars after "Canvas only mode" toggle is created.
321 this->showHideScrollbars();
322
324
325 connect(&d->toolManager, SIGNAL(inputDeviceChanged(KoInputDevice)),
326 d->controlFrame.paintopBox(), SLOT(slotInputDeviceChanged(KoInputDevice)));
327
328 connect(&d->toolManager, SIGNAL(changedTool(KoCanvasController*)),
329 d->controlFrame.paintopBox(), SLOT(slotToolChanged(KoCanvasController*)));
330
331 connect(&d->nodeManager, SIGNAL(sigNodeActivated(KisNodeSP)),
332 canvasResourceProvider(), SLOT(slotNodeActivated(KisNodeSP)));
333
334 connect(KisPart::instance(), SIGNAL(sigViewAdded(KisView*)), SLOT(slotViewAdded(KisView*)));
335 connect(KisPart::instance(), SIGNAL(sigViewRemoved(KisView*)), SLOT(slotViewRemoved(KisView*)));
336 connect(KisPart::instance(), SIGNAL(sigViewRemoved(KisView*)),
337 d->controlFrame.paintopBox(), SLOT(updatePresetConfig()));
338
339 connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotUpdateAuthorProfileActions()));
340 connect(KisConfigNotifier::instance(), SIGNAL(pixelGridModeChanged()), SLOT(slotUpdatePixelGridAction()));
341
342 connect(&d->toolManager, SIGNAL(createOpacityResource(bool, KoToolBase*)), SLOT(slotCreateOpacityResource(bool, KoToolBase*)));
343
345
346 KisConfig cfg(true);
349 KoColor foreground(Qt::black, cs);
350 d->canvasResourceProvider.setFGColor(cfg.readKoColor("LastForeGroundColor",foreground));
351 KoColor background(Qt::white, cs);
352 d->canvasResourceProvider.setBGColor(cfg.readKoColor("LastBackGroundColor",background));
355
356 // Initialize the old imagesize plugin
357 new ImageSize(this);
358}
359
360
362{
363 KisConfig cfg(false);
364 if (canvasResourceProvider() && canvasResourceProvider()->currentPreset()) {
365 cfg.writeKoColor("LastForeGroundColor",canvasResourceProvider()->fgColor());
366 cfg.writeKoColor("LastBackGroundColor",canvasResourceProvider()->bgColor());
367 }
368
370 cfg.writeKoColors("LastColorHistory", canvasResourceProvider()->colorHistoryColors());
371 }
372
373 cfg.writeEntry("baseLength", KisResourceItemChooserSync::instance()->baseLength());
374 cfg.writeEntry("CanvasOnlyActive", false); // We never restart in CanvasOnlyMode
375 delete d;
376}
377
379
381{
396
397 resourceManager->addActiveCanvasResourceDependency(
401
402 resourceManager->addActiveCanvasResourceDependency(
406
407 resourceManager->addActiveCanvasResourceDependency(
411
412 KSharedConfigPtr config = KSharedConfig::openConfig();
413 KConfigGroup miscGroup = config->group("Misc");
414 const uint handleRadius = miscGroup.readEntry("HandleRadius", 5);
415 resourceManager->setHandleRadius(handleRadius);
416}
417
422
427
429{
430 // WARNING: this slot is called even when a view from another main windows is added!
431 // Don't expect \p view be a child of this view manager!
432
433 if (view->viewManager() == this && viewCount() == 0) {
435 }
436}
437
439{
440 // WARNING: this slot is called even when a view from another main windows is removed!
441 // Don't expect \p view be a child of this view manager!
442
443 if (view->viewManager() == this && viewCount() == 0) {
445 }
446}
447
449{
450 if (d->currentImageView) {
451 d->currentImageView->notifyCurrentStateChanged(false);
452
453 d->currentImageView->canvasBase()->setCursor(QCursor(Qt::ArrowCursor));
454 KisDocument* doc = d->currentImageView->document();
455 if (doc) {
457 doc->disconnect(this);
458 }
459 d->currentImageView->canvasController()->proxyObject->disconnect(&d->statusBar);
462 }
463
464 QPointer<KisView> imageView = qobject_cast<KisView*>(view);
465 d->currentImageView = imageView;
466
467 if (imageView) {
471
472 d->softProof->setChecked(imageView->softProofing());
473 d->gamutCheck->setChecked(imageView->gamutCheck());
474
475 // Wait for the async image to have loaded
476 KisDocument* doc = imageView->document();
477
478 if (KisConfig(true).readEntry<bool>("EnablePositionLabel", false)) {
479 connect(d->currentImageView->canvasController()->proxyObject,
480 SIGNAL(documentMousePositionChanged(QPointF)),
481 &d->statusBar,
482 SLOT(documentMousePositionChanged(QPointF)));
483 }
484
485 KisCanvasController *canvasController = dynamic_cast<KisCanvasController*>(d->currentImageView->canvasController());
486 KIS_ASSERT(canvasController);
487
488 d->viewConnections.addUniqueConnection(&d->nodeManager, SIGNAL(sigNodeActivated(KisNodeSP)), doc->image(), SLOT(requestStrokeEndActiveNode()));
489 d->viewConnections.addUniqueConnection(d->rotateCanvasRight, SIGNAL(triggered()), canvasController, SLOT(rotateCanvasRight15()));
490 d->viewConnections.addUniqueConnection(d->rotateCanvasLeft, SIGNAL(triggered()),canvasController, SLOT(rotateCanvasLeft15()));
491 d->viewConnections.addUniqueConnection(d->resetCanvasRotation, SIGNAL(triggered()),canvasController, SLOT(resetCanvasRotation()));
492
493 d->viewConnections.addUniqueConnection(d->wrapAroundAction, SIGNAL(toggled(bool)), canvasController, SLOT(slotToggleWrapAroundMode(bool)));
494 d->wrapAroundAction->setChecked(canvasController->wrapAroundMode());
495 d->viewConnections.addUniqueConnection(d->wrapAroundHVAxisAction, SIGNAL(triggered()), canvasController, SLOT(slotSetWrapAroundModeAxisHV()));
496 d->wrapAroundHVAxisAction->setChecked(canvasController->wrapAroundModeAxis() == WRAPAROUND_BOTH);
497 d->viewConnections.addUniqueConnection(d->wrapAroundHAxisAction, SIGNAL(triggered()), canvasController, SLOT(slotSetWrapAroundModeAxisH()));
498 d->wrapAroundHAxisAction->setChecked(canvasController->wrapAroundModeAxis() == WRAPAROUND_HORIZONTAL);
499 d->viewConnections.addUniqueConnection(d->wrapAroundVAxisAction, SIGNAL(triggered()), canvasController, SLOT(slotSetWrapAroundModeAxisV()));
500 d->wrapAroundVAxisAction->setChecked(canvasController->wrapAroundModeAxis() == WRAPAROUND_VERTICAL);
501
502 d->viewConnections.addUniqueConnection(d->levelOfDetailAction, SIGNAL(toggled(bool)), canvasController, SLOT(slotToggleLevelOfDetailMode(bool)));
503 d->levelOfDetailAction->setChecked(canvasController->levelOfDetailMode());
504
505 d->viewConnections.addUniqueConnection(d->currentImageView->image(), SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), d->controlFrame.paintopBox(), SLOT(slotColorSpaceChanged(const KoColorSpace*)));
506 d->viewConnections.addUniqueConnection(d->showRulersAction, SIGNAL(toggled(bool)), imageView->zoomManager(), SLOT(setShowRulers(bool)));
507 d->viewConnections.addUniqueConnection(d->rulersTrackMouseAction, SIGNAL(toggled(bool)), imageView->zoomManager(), SLOT(setRulersTrackMouse(bool)));
508 d->viewConnections.addUniqueConnection(d->zoomTo100pct, SIGNAL(triggered()), imageView->zoomManager(), SLOT(zoomTo100()));
509 d->viewConnections.addUniqueConnection(d->zoomIn, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotZoomIn()));
510 d->viewConnections.addUniqueConnection(d->zoomOut, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotZoomOut()));
511 d->viewConnections.addUniqueConnection(d->zoomToFit, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotZoomToFit()));
512 d->viewConnections.addUniqueConnection(d->zoomToFitWidth, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotZoomToFitWidth()));
513 d->viewConnections.addUniqueConnection(d->zoomToFitHeight, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotZoomToFitHeight()));
514 d->viewConnections.addUniqueConnection(d->toggleZoomToFit, SIGNAL(triggered()), imageView->zoomManager(), SLOT(slotToggleZoomToFit()));
515
516 d->viewConnections.addUniqueConnection(d->resetDisplay, SIGNAL(triggered()), imageView->viewManager(), SLOT(slotResetDisplay()));
517
518 d->viewConnections.addConnection(imageView->canvasController(),
520 this,
521 [this](bool value) {
522 QSignalBlocker b(d->viewPrintSize);
523 d->viewPrintSize->setChecked(value);
524 });
525 d->viewPrintSize->setChecked(imageView->canvasController()->usePrintResolutionMode());
526 d->viewConnections.addUniqueConnection(d->viewPrintSize, &KisAction::toggled,
527 imageView->canvasController(), &KisCanvasController::setUsePrintResolutionMode);
528
529 d->viewConnections.addUniqueConnection(imageView->canvasController(),
531 imageView->zoomManager()->zoomAction(),
533 imageView->zoomManager()->zoomAction()->setUsePrintResolutionMode(imageView->canvasController()->usePrintResolutionMode());
534 d->viewConnections.addUniqueConnection(imageView->zoomManager()->zoomAction(),
536 imageView->canvasController(),
538
539 d->viewConnections.addUniqueConnection(d->softProof, SIGNAL(toggled(bool)), view, SLOT(slotSoftProofing(bool)) );
540 d->viewConnections.addUniqueConnection(d->gamutCheck, SIGNAL(toggled(bool)), view, SLOT(slotGamutCheck(bool)) );
541
542 // set up progress reporting
544 d->viewConnections.addUniqueConnection(&d->statusBar, SIGNAL(sigCancellationRequested()), doc->image(), SLOT(requestStrokeCancellation()));
545
546 d->viewConnections.addUniqueConnection(d->showPixelGrid, SIGNAL(toggled(bool)), canvasController, SLOT(slotTogglePixelGrid(bool)));
547
548 imageView->zoomManager()->setShowRulers(d->showRulersAction->isChecked());
549 imageView->zoomManager()->setRulersTrackMouse(d->rulersTrackMouseAction->isChecked());
550
552 }
553
554 d->filterManager.setView(imageView);
555 d->selectionManager.setView(imageView);
556 d->guidesManager.setView(imageView);
557 d->nodeManager.setView(imageView);
558 d->imageManager.setView(imageView);
559 d->canvasControlsManager.setView(imageView);
560 d->actionManager.setView(imageView);
561 d->gridManager.setView(imageView);
562 d->statusBar.setView(imageView);
564 d->mirrorManager.setView(imageView);
565 // the tool manager is initialized the latest, since
566 // it may activate some tools which will request canvas
567 // managers
568 d->toolManager.setCurrentCanvas(imageView ? imageView->canvasController() : nullptr);
569
570 if (d->currentImageView) {
571 d->currentImageView->notifyCurrentStateChanged(true);
572 d->currentImageView->canvasController()->activate();
573 d->currentImageView->canvasController()->setFocus();
574
576 image(), SIGNAL(sigSizeChanged(QPointF,QPointF)),
577 canvasResourceProvider(), SLOT(slotImageSizeChanged()));
578
580 image(), SIGNAL(sigResolutionChanged(double,double)),
581 canvasResourceProvider(), SLOT(slotOnScreenResolutionChanged()));
582
584 image(), SIGNAL(sigNodeChanged(KisNodeSP)),
585 this, SLOT(updateGUI()));
586
588 d->currentImageView->canvasController()->proxyObject,
592 }
593
595
598
599 Q_EMIT viewChanged();
600}
601
603{
604 if (document()) {
605 return document()->image();
606 }
607 return 0;
608}
609
614
616{
617 if (d && d->currentImageView) {
618 return d->currentImageView->canvasBase();
619 }
620 return 0;
621}
622
624{
625 if (d && d->currentImageView && d->currentImageView->canvasBase()->canvasWidget()) {
626 return d->currentImageView->canvasBase()->canvasWidget();
627 }
628 return 0;
629}
630
632{
633 return &d->statusBar;
634}
635
640
642{
643 return d->persistentUnthreadedProgressUpdaterRouter->startSubtask(1, name, false);
644}
645
647{
648 return d->statusBar.progressUpdater()->startSubtask(1, name, false);
649}
650
655
660
665
670
672{
673 if (d->currentImageView) {
674 return d->currentImageView->zoomManager();
675 }
676 return 0;
677}
678
683
688
693
698
703
705{
706 if (d->currentImageView) {
707 return d->currentImageView->selection();
708 }
709 return 0;
710
711}
712
714{
715 KisLayerSP layer = activeLayer();
716 if (layer) {
717 KisSelectionMaskSP mask = layer->selectionMask();
718 if (mask) {
719 return mask->isEditable();
720 }
721 }
722 // global selection is always editable
723 return true;
724}
725
727{
728 if (!document()) return 0;
729
731 Q_ASSERT(image);
732
733 return image->undoAdapter();
734}
735
737{
738 KisConfig cfg(true);
739
740 d->saveIncremental = actionManager()->createAction("save_incremental_version");
741 connect(d->saveIncremental, SIGNAL(triggered()), this, SLOT(slotSaveIncremental()));
742
743 d->saveIncrementalBackup = actionManager()->createAction("save_incremental_backup");
744 connect(d->saveIncrementalBackup, SIGNAL(triggered()), this, SLOT(slotSaveIncrementalBackup()));
745
746 connect(mainWindow(), SIGNAL(documentSaved()), this, SLOT(slotDocumentSaved()));
747
748 d->saveIncremental->setEnabled(false);
749 d->saveIncrementalBackup->setEnabled(false);
750
751 KisAction *tabletDebugger = actionManager()->createAction("tablet_debugger");
752 connect(tabletDebugger, SIGNAL(triggered()), this, SLOT(toggleTabletLogger()));
753
754 d->createTemplate = actionManager()->createAction("create_template");
755 connect(d->createTemplate, SIGNAL(triggered()), this, SLOT(slotCreateTemplate()));
756
757 d->createCopy = actionManager()->createAction("create_copy");
758 connect(d->createCopy, SIGNAL(triggered()), this, SLOT(slotCreateCopy()));
759
760 d->openResourcesDirectory = actionManager()->createAction("open_resources_directory");
761 connect(d->openResourcesDirectory, SIGNAL(triggered()), SLOT(openResourcesDirectory()));
762
763 d->rotateCanvasRight = actionManager()->createAction("rotate_canvas_right");
764 d->rotateCanvasLeft = actionManager()->createAction("rotate_canvas_left");
765 d->resetCanvasRotation = actionManager()->createAction("reset_canvas_rotation");
766 d->wrapAroundAction = actionManager()->createAction("wrap_around_mode");
767 d->wrapAroundHVAxisAction = actionManager()->createAction("wrap_around_hv_axis");
768 d->wrapAroundHAxisAction = actionManager()->createAction("wrap_around_h_axis");
769 d->wrapAroundVAxisAction = actionManager()->createAction("wrap_around_v_axis");
770 d->wrapAroundAxisActions = new QActionGroup(this);
774 d->levelOfDetailAction = actionManager()->createAction("level_of_detail_mode");
775 d->softProof = actionManager()->createAction("softProof");
776 d->gamutCheck = actionManager()->createAction("gamutCheck");
777
778 KisAction *tAction = actionManager()->createAction("showStatusBar");
779 tAction->setChecked(cfg.showStatusBar());
780 connect(tAction, SIGNAL(toggled(bool)), this, SLOT(showStatusBar(bool)));
781
782 tAction = actionManager()->createAction("view_show_canvas_only");
783 tAction->setChecked(false);
784 tAction->setAutoRepeat(false);
785 connect(tAction, SIGNAL(toggled(bool)), this, SLOT(switchCanvasOnly(bool)));
786
787 //Workaround, by default has the same shortcut as mirrorCanvas
788 KisAction *a = dynamic_cast<KisAction*>(actionCollection()->action("format_italic"));
789 if (a) {
790 a->setDefaultShortcut(QKeySequence());
791 }
792
793 actionManager()->createAction("ruler_pixel_multiple2");
794 d->showRulersAction = actionManager()->createAction("view_ruler");
795 d->showRulersAction->setChecked(cfg.showRulers());
796 connect(d->showRulersAction, SIGNAL(toggled(bool)), SLOT(slotSaveShowRulersState(bool)));
797
798 d->rulersTrackMouseAction = actionManager()->createAction("rulers_track_mouse");
799 d->rulersTrackMouseAction->setChecked(cfg.rulersTrackMouse());
800 connect(d->rulersTrackMouseAction, SIGNAL(toggled(bool)), SLOT(slotSaveRulersTrackMouseState(bool)));
801
802 d->zoomTo100pct = actionManager()->createAction("zoom_to_100pct");
803
806
807 d->zoomToFit = actionManager()->createAction("zoom_to_fit");
808 d->zoomToFitWidth = actionManager()->createAction("zoom_to_fit_width");
809 d->zoomToFitHeight = actionManager()->createAction("zoom_to_fit_height");
810 d->toggleZoomToFit = actionManager()->createAction("toggle_zoom_to_fit");
811
812 d->resetDisplay = actionManager()->createAction("reset_display");
813
814 d->viewPrintSize = actionManager()->createAction("view_print_size");
815
816 d->actionAuthor = new KSelectAction(KisIconUtils::loadIcon("im-user"), i18n("Active Author Profile"), this);
817 connect(d->actionAuthor, SIGNAL(textTriggered(QString)), this, SLOT(changeAuthorProfile(QString)));
818 actionCollection()->addAction("settings_active_author", d->actionAuthor);
820
821 d->showPixelGrid = actionManager()->createAction("view_pixel_grid");
823
824 d->toggleBrushOutline = actionManager()->createAction("toggle_brush_outline");
825 connect(d->toggleBrushOutline, SIGNAL(triggered(bool)), this, SLOT(slotToggleBrushOutline()));
826
827}
828
830{
831 // Create the managers for filters, selections, layers etc.
832 // XXX: When the current layer changes, call updateGUI on all
833 // managers
834
836
838
840
842
844
846
848
850
852}
853
858
860{
861 return &d->nodeManager;
862}
863
865{
866 return &d->toolManager;
867}
868
873
875{
876 return &d->gridManager;
877}
878
883
885{
886 if (d->currentImageView && d->currentImageView->document()) {
887 return d->currentImageView->document();
888 }
889 return 0;
890}
891
893{
894 KisMainWindow *mw = qobject_cast<KisMainWindow*>(d->mainWindow);
895 if (mw) {
896 return mw->viewCount();
897 }
898 return 0;
899}
900
902{
903 const int busyWaitDelay = 1000;
905 dialog.blockIfImageIsBusy();
906
907 return dialog.result() == QDialog::Accepted;
908}
909
910
915
920
922{
923 if (!document()) return;
924 KisTemplateCreateDia::createTemplate( QStringLiteral("templates/"), ".kra", document(), mainWindow());
925}
926
928{
929 KisDocument *srcDoc = document();
930 if (!srcDoc) return;
931
932 if (!this->blockUntilOperationsFinished(srcDoc->image())) return;
933
934 KisDocument *doc = 0;
935 {
936 KisImageReadOnlyBarrierLock l(srcDoc->image());
937 doc = srcDoc->clone(true);
938 }
940
941 QString name = srcDoc->documentInfo()->aboutInfo("name");
942 if (name.isEmpty()) {
943 name = document()->path();
944 }
945 name = i18n("%1 (Copy)", name);
946 doc->documentInfo()->setAboutInfo("title", name);
947 doc->resetPath();
948
950 KisMainWindow *mw = qobject_cast<KisMainWindow*>(d->mainWindow);
952}
953
954
956{
957 if (d->mainWindow)
958 return d->mainWindow;
959
960 //Fallback for when we have not yet set the main window.
961 QMainWindow* w = qobject_cast<QMainWindow*>(qApp->activeWindow());
962 if(w)
963 return w;
964
965 return mainWindow();
966}
967
968void KisViewManager::setQtMainWindow(QMainWindow* newMainWindow)
969{
970 d->mainWindow = newMainWindow;
971}
972
974{
975 d->saveIncremental->setEnabled(true);
976 d->saveIncrementalBackup->setEnabled(true);
977}
978
980{
981#ifdef Q_OS_ANDROID
982 QString path = QFileInfo(document()->localFilePath()).canonicalPath();
983 // if the path is based on a document tree then a directory would be returned. So check if it exists and more
984 // importantly check if we have permissions
985 if (QDir(path).exists()) {
986 return path;
987 } else {
988 KoFileDialog dialog(nullptr, KoFileDialog::ImportDirectory, "OpenDirectory");
989 dialog.setDirectoryUrl(QUrl(document()->localFilePath()));
990 return dialog.filename();
991 }
992#else
993 return QFileInfo(document()->localFilePath()).canonicalPath();
994#endif
995}
996
998{
999 if (!document()) return;
1000
1001 if (document()->path().isEmpty()) {
1002 KisMainWindow *mw = qobject_cast<KisMainWindow*>(d->mainWindow);
1003 mw->saveDocument(document(), true, false);
1004 return;
1005 }
1006
1007 bool foundVersion;
1008 bool fileAlreadyExists;
1009 bool isBackup;
1010 QString version = "000";
1011 QString newVersion;
1012 QString letter;
1013 QString path = canonicalPath();
1014
1015 QString fileName = QFileInfo(document()->localFilePath()).fileName();
1016
1017 // Find current version filenames
1018 // v v Regexp to find incremental versions in the filename, taking our backup scheme into account as well
1019 // Considering our incremental version and backup scheme, format is filename_001~001.ext
1020 QRegularExpression regex("_(\\d{1,4})([a-z])?([\\.|~])");
1021 QRegularExpressionMatch match;
1022 foundVersion = fileName.contains(regex, &match);
1023 isBackup = foundVersion ? match.captured(3) == "~" : false;
1024
1025 // If the filename has a version, prepare it for incrementation
1026 if (foundVersion) {
1027 version = match.captured(1);
1028 letter = match.captured(2);
1029 } else {
1030 // ...else, simply add a version to it so the next loop works
1031 QRegularExpression regex2("\\.\\w{2,4}$"); // Heuristic to find file extension
1032 QRegularExpressionMatch match = regex2.match(fileName);
1033 QString extensionPlusVersion = match.captured(0);
1034 extensionPlusVersion.prepend(version);
1035 extensionPlusVersion.prepend("_");
1036 fileName.replace(regex2, extensionPlusVersion);
1037 }
1038
1039 // Prepare the base for new version filename
1040 int intVersion = version.toInt(0);
1041 ++intVersion;
1042 QString baseNewVersion = QString::number(intVersion);
1043 while (baseNewVersion.length() < version.length()) {
1044 baseNewVersion.prepend("0");
1045 }
1046
1047 // Check if the file exists under the new name and search until options are exhausted (test appending a to z)
1048 do {
1049 newVersion = baseNewVersion;
1050 newVersion.prepend("_");
1051 if (!letter.isNull()) newVersion.append(letter);
1052 if (isBackup) {
1053 newVersion.append("~");
1054 } else {
1055 newVersion.append(".");
1056 }
1057 fileName.replace(regex, newVersion);
1058 fileAlreadyExists = QFileInfo(path + '/' + fileName).exists();
1059 if (fileAlreadyExists) {
1060 if (!letter.isNull()) {
1061 char letterCh = letter.at(0).toLatin1();
1062 ++letterCh;
1063 letter = QString(QChar(letterCh));
1064 } else {
1065 letter = 'a';
1066 }
1067 }
1068 } while (fileAlreadyExists && letter != "{"); // x, y, z, {...
1069
1070 if (letter == "{") {
1071 QMessageBox::critical(mainWindow(), i18nc("@title:window", "Couldn't save incremental version"), i18n("Alternative names exhausted, try manually saving with a higher number"));
1072 return;
1073 }
1074 QString newFilePath = path + '/' + fileName;
1075 document()->setFileBatchMode(true);
1076 document()->saveAs(newFilePath, document()->mimeType(), true);
1077 document()->setFileBatchMode(false);
1078 KisPart::instance()->queueAddRecentURLToAllMainWindowsOnFileSaved(QUrl::fromLocalFile(newFilePath),
1079 QUrl::fromLocalFile(document()->path()));
1080}
1081
1083{
1084 if (!document()) return;
1085
1086 if (document()->path().isEmpty()) {
1087 KisMainWindow *mw = qobject_cast<KisMainWindow*>(d->mainWindow);
1088 mw->saveDocument(document(), true, false);
1089 return;
1090 }
1091
1092 bool workingOnBackup;
1093 bool fileAlreadyExists;
1094 QString version = "000";
1095 QString newVersion;
1096 QString letter;
1097 QString path = canonicalPath();
1098 QString fileName = QFileInfo(document()->localFilePath()).fileName();
1099
1100 // First, discover if working on a backup file, or a normal file
1101 QRegularExpression regex("~(\\d{1,4})([a-z])?\\.");
1102 QRegularExpressionMatch match;
1103 workingOnBackup = fileName.contains(regex, &match);
1104
1105 if (workingOnBackup) {
1106 // Try to save incremental version (of backup), use letter for alt versions
1107 version = match.captured(1);
1108 letter = match.captured(2);
1109
1110 // Prepare the base for new version filename
1111 int intVersion = version.toInt(0);
1112 ++intVersion;
1113 QString baseNewVersion = QString::number(intVersion);
1114 QString backupFileName = document()->localFilePath();
1115 while (baseNewVersion.length() < version.length()) {
1116 baseNewVersion.prepend("0");
1117 }
1118
1119 // Check if the file exists under the new name and search until options are exhausted (test appending a to z)
1120 do {
1121 newVersion = baseNewVersion;
1122 newVersion.prepend("~");
1123 if (!letter.isNull()) newVersion.append(letter);
1124 newVersion.append(".");
1125 backupFileName.replace(regex, newVersion);
1126 fileAlreadyExists = QFile(path + '/' + backupFileName).exists();
1127 if (fileAlreadyExists) {
1128 if (!letter.isNull()) {
1129 char letterCh = letter.at(0).toLatin1();
1130 ++letterCh;
1131 letter = QString(QChar(letterCh));
1132 } else {
1133 letter = 'a';
1134 }
1135 }
1136 } while (fileAlreadyExists && letter != "{"); // x, y, z, {...
1137
1138 if (letter == "{") {
1139 QMessageBox::critical(mainWindow(), i18nc("@title:window", "Couldn't save incremental backup"), i18n("Alternative names exhausted, try manually saving with a higher number"));
1140 return;
1141 }
1142 QFile::copy(path + '/' + fileName, path + '/' + backupFileName);
1143 document()->saveAs(path + '/' + fileName, document()->mimeType(), true);
1144 }
1145 else { // if NOT working on a backup...
1146 // Navigate directory searching for latest backup version, ignore letters
1147 const quint8 HARDCODED_DIGIT_COUNT = 3;
1148 QString baseNewVersion = "000";
1149 QString backupFileName = QFileInfo(document()->localFilePath()).fileName();
1150 QRegularExpression regex2("\\.\\w{2,4}$"); // Heuristic to find file extension
1151 QRegularExpressionMatch match = regex2.match(fileName);
1152 QString extensionPlusVersion = match.captured(0);
1153 extensionPlusVersion.prepend(baseNewVersion);
1154 extensionPlusVersion.prepend("~");
1155 backupFileName.replace(regex2, extensionPlusVersion);
1156
1157 // Save version with 1 number higher than the highest version found ignoring letters
1158 do {
1159 newVersion = baseNewVersion;
1160 newVersion.prepend("~");
1161 newVersion.append(".");
1162 backupFileName.replace(regex, newVersion);
1163 fileAlreadyExists = QFile(path + '/' + backupFileName).exists();
1164 if (fileAlreadyExists) {
1165 // Prepare the base for new version filename, increment by 1
1166 int intVersion = baseNewVersion.toInt(0);
1167 ++intVersion;
1168 baseNewVersion = QString::number(intVersion);
1169 while (baseNewVersion.length() < HARDCODED_DIGIT_COUNT) {
1170 baseNewVersion.prepend("0");
1171 }
1172 }
1173 } while (fileAlreadyExists);
1174
1175 // Save both as backup and on current file for interapplication workflow
1176 document()->setFileBatchMode(true);
1177 QFile::copy(path + '/' + fileName, path + '/' + backupFileName);
1178 document()->saveAs(path + '/' + fileName, document()->mimeType(), true);
1179 document()->setFileBatchMode(false);
1180 }
1181}
1182
1184{
1185 // prevents possible crashes, if somebody changes the paintop during dragging by using the mousewheel
1186 // this is for Bug 250944
1187 // the solution blocks all wheel, mouse and key event, while dragging with the freehand tool
1188 // see KisToolFreehand::initPaint() and endPaint()
1189 d->controlFrame.paintopBox()->installEventFilter(&d->blockingEventFilter);
1190 Q_FOREACH (QObject* child, d->controlFrame.paintopBox()->children()) {
1191 child->installEventFilter(&d->blockingEventFilter);
1192 }
1193}
1194
1196{
1197 d->controlFrame.paintopBox()->removeEventFilter(&d->blockingEventFilter);
1198 Q_FOREACH (QObject* child, d->controlFrame.paintopBox()->children()) {
1199 child->removeEventFilter(&d->blockingEventFilter);
1200 }
1201}
1202
1204{
1205 KisMainWindow *mw = mainWindow();
1206 if(mw && mw->statusBar()) {
1207 mw->statusBar()->setVisible(toggled);
1208 KisConfig cfg(false);
1209 cfg.setShowStatusBar(toggled);
1210 }
1211}
1212
1214{
1215 d->canvasStateInNormalMode.clear();
1217 d->canvasOnlyOptions = std::nullopt;
1218}
1219
1221{
1222 if (toggled == d->inCanvasOnlyMode) {
1224 return;
1225 }
1226
1227 KisConfig cfg(false);
1229
1230 if(!main) {
1231 dbgUI << "Unable to switch to canvas-only mode, main window not found";
1233 return;
1234 }
1235
1236#ifdef Q_OS_ANDROID
1237 // On Android, expanded tool bars will crash when canvas-only mode is
1238 // toggled. To avoid this, we go looking for expanded toolbars and close
1239 // them instead of switching the mode and hitting a crash. Note that this
1240 // only works properly because we turn off main window animations on
1241 // Android, since that means clicking the extension button will instantly
1242 // hide the menu. With animations, the user could still trigger a crash if
1243 // they tried switching the mode while the extension animation is running.
1244 QList<QToolBar *> toolBars = main->findChildren<QToolBar *>();
1245 bool wasToolBarPopupOpen = false;
1246 for (QToolBar *toolBar : toolBars) {
1247 for (QToolButton *button : toolBar->findChildren<QToolButton *>(QStringLiteral("qt_toolbar_ext_button"))) {
1248 if (button->isChecked()) {
1249 wasToolBarPopupOpen = true;
1250 button->click();
1251 }
1252 }
1253 }
1254
1255 if(wasToolBarPopupOpen) {
1257 return;
1258 }
1259#endif
1260
1261 cfg.writeEntry("CanvasOnlyActive", toggled);
1262 d->inCanvasOnlyMode = toggled;
1264
1266
1267 if (toggled) {
1268 d->canvasStateInNormalMode = qtMainWindow()->saveState();
1269 } else {
1270 d->canvasStateInCanvasOnlyMode = qtMainWindow()->saveState();
1271 d->canvasOnlyOptions = options;
1272 }
1273
1274 const bool toggleFullscreen = (options.hideTitlebarFullscreen && !cfg.fullscreenMode());
1275 const bool useCanvasOffsetCompensation = d->currentImageView &&
1276 d->currentImageView->canvasController() &&
1277 d->currentImageView->isMaximized() &&
1278 !main->canvasDetached();
1279
1280 if (useCanvasOffsetCompensation) {
1281 // The offset is calculated in two steps; this is the first step.
1282 if (toggled) {
1312 QPoint origin;
1313 if (toggleFullscreen) {
1314 // We're windowed, so also capture the position of the window in the screen.
1315 origin = main->geometry().topLeft() - main->screen()->geometry().topLeft();
1316 }
1318 } else {
1319 // Restore the original canvas position. The result is more stable if we pan before showing the UI elements.
1320 d->currentImageView->canvasController()->pan(- d->canvasOnlyOffsetCompensation);
1321 }
1322 }
1323
1324 if (options.hideStatusbarFullscreen) {
1325 if (main->statusBar()) {
1326 if (!toggled) {
1327 if (main->statusBar()->dynamicPropertyNames().contains("wasvisible")) {
1328 if (main->statusBar()->property("wasvisible").toBool()) {
1329 main->statusBar()->setVisible(true);
1330 }
1331 }
1332 }
1333 else {
1334 main->statusBar()->setProperty("wasvisible", main->statusBar()->isVisible());
1335 main->statusBar()->setVisible(false);
1336 }
1337 }
1338 }
1339
1340 if (options.hideDockersFullscreen) {
1341 KisAction* action = qobject_cast<KisAction*>(main->actionCollection()->action("view_toggledockers"));
1342 if (action) {
1343 action->setCheckable(true);
1344 if (toggled) {
1345 if (action->isChecked()) {
1346 cfg.setShowDockers(action->isChecked());
1347 action->setChecked(false);
1348 } else {
1349 cfg.setShowDockers(false);
1350 }
1351 } else {
1352 action->setChecked(cfg.showDockers());
1353 }
1354 }
1355 }
1356
1357 // QT in windows does not return to maximized upon 4th tab in a row
1358 // https://bugreports.qt.io/browse/QTBUG-57882, https://bugreports.qt.io/browse/QTBUG-52555, https://codereview.qt-project.org/#/c/185016/
1359 if (toggleFullscreen) {
1360 if(toggled) {
1361 main->setWindowState( main->windowState() | Qt::WindowFullScreen);
1362 } else {
1363 main->setWindowState( main->windowState() & ~Qt::WindowFullScreen);
1364 }
1365 }
1366
1367 if (options.hideMenuFullscreen) {
1368 if (!toggled) {
1369 if (main->menuBar()->dynamicPropertyNames().contains("wasvisible")) {
1370 if (main->menuBar()->property("wasvisible").toBool()) {
1371 main->menuBar()->setVisible(true);
1372 }
1373 }
1374 }
1375 else {
1376 main->menuBar()->setProperty("wasvisible", main->menuBar()->isVisible());
1377 main->menuBar()->setVisible(false);
1378 }
1379 }
1380
1381 if (options.hideToolbarFullscreen) {
1382 // We already went searching for these on Android above.
1383#ifndef Q_OS_ANDROID
1384 QList<QToolBar*> toolBars = main->findChildren<QToolBar*>();
1385#endif
1386 Q_FOREACH (QToolBar* toolbar, toolBars) {
1387 if (!toggled) {
1388 if (toolbar->dynamicPropertyNames().contains("wasvisible")) {
1389 if (toolbar->property("wasvisible").toBool()) {
1390 toolbar->setVisible(true);
1391 }
1392 }
1393 }
1394 else {
1395 toolbar->setProperty("wasvisible", toolbar->isVisible());
1396 toolbar->setVisible(false);
1397 }
1398 }
1399 }
1400
1402
1403 if (toggled) {
1404 if (!d->canvasStateInCanvasOnlyMode.isEmpty() &&
1406 *d->canvasOnlyOptions == options) {
1407
1417 QTimer::singleShot(0, this, [this] () {
1418 this->mainWindow()->restoreState(d->canvasStateInCanvasOnlyMode);
1419 });
1420 }
1421
1422 // show a fading heads-up display about the shortcut to go back
1423 showFloatingMessage(i18n("Going into Canvas-Only mode.\nPress %1 to go back.",
1424 actionCollection()->action("view_show_canvas_only")->shortcut().toString(QKeySequence::NativeText)), QIcon(),
1425 2000,
1427 }
1428 else {
1429 if (!d->canvasStateInNormalMode.isEmpty()) {
1430 main->restoreState(d->canvasStateInNormalMode);
1431 }
1432 }
1433
1434 if (useCanvasOffsetCompensation && toggled) {
1435 const KoZoomMode::Mode mode = d->currentImageView->canvasController()->zoomState().mode;
1436
1437 const bool allowedZoomMode =
1438 (mode == KoZoomMode::ZOOM_CONSTANT) ||
1439 (mode == KoZoomMode::ZOOM_HEIGHT);
1440
1441 if (allowedZoomMode) {
1442 // Defer the pan action until the layout is fully settled in (including the menu bars, etc.).
1443 QTimer::singleShot(0, this, [this] () {
1444 // Compensate by the difference of (after - before) layout.
1446 d->currentImageView->canvasController()->pan(d->canvasOnlyOffsetCompensation);
1447 });
1448 } else {
1449 // Nothing to restore.
1450 d->canvasOnlyOffsetCompensation = QPoint();
1451 }
1452 }
1453}
1454
1456{
1457 QAction *action = actionManager()->actionByName(QStringLiteral("view_show_canvas_only"));
1458 if (action && action->isChecked() != d->inCanvasOnlyMode) {
1459 QSignalBlocker blocker(action);
1460 action->setChecked(d->inCanvasOnlyMode);
1461 }
1462}
1463
1468
1470{
1471 QString resourcePath = KisResourceLocator::instance()->resourceLocationBase();
1472#ifdef Q_OS_WIN
1473
1474 QString folderInStandardAppData;
1475 QString folderInPrivateAppData;
1476 KoResourcePaths::getAllUserResourceFoldersLocationsForWindowsStore(folderInStandardAppData, folderInPrivateAppData);
1477
1478 if (!folderInPrivateAppData.isEmpty()) {
1479
1480 const auto pathToDisplay = [](const QString &path) {
1481 // Due to how Unicode word wrapping works, the string does not
1482 // wrap after backslashes in Qt 5.12. We don't want the path to
1483 // become too long, so we add a U+200B ZERO WIDTH SPACE to allow
1484 // wrapping. The downside is that we cannot let the user select
1485 // and copy the path because it now contains invisible unicode
1486 // code points.
1487 // See: https://bugreports.qt.io/browse/QTBUG-80892
1488 return QDir::toNativeSeparators(path).replace(QChar('\\'), QStringLiteral(u"\\\u200B"));
1489 };
1490
1491 QMessageBox mbox(qApp->activeWindow());
1492 mbox.setIcon(QMessageBox::Information);
1493 mbox.setWindowTitle(i18nc("@title:window resource folder", "Open Resource Folder"));
1494 // Similar text is also used in kis_dlg_preferences.cc
1495
1496 mbox.setText(i18nc("@info resource folder",
1497 "<p>You are using the Microsoft Store package version of Krita. "
1498 "Even though Krita can be configured to place resources under the "
1499 "user AppData location, Windows may actually store the files "
1500 "inside a private app location.</p>\n"
1501 "<p>You should check both locations to determine where "
1502 "the files are located.</p>\n"
1503 "<p><b>User AppData</b>:<br/>\n"
1504 "%1</p>\n"
1505 "<p><b>Private app location</b>:<br/>\n"
1506 "%2</p>",
1507 pathToDisplay(folderInStandardAppData),
1508 pathToDisplay(folderInPrivateAppData)
1509 ));
1510 mbox.setTextInteractionFlags(Qt::NoTextInteraction);
1511
1512 const auto *btnOpenUserAppData = mbox.addButton(i18nc("@action:button resource folder", "Open in &user AppData"), QMessageBox::AcceptRole);
1513 const auto *btnOpenPrivateAppData = mbox.addButton(i18nc("@action:button resource folder", "Open in &private app location"), QMessageBox::AcceptRole);
1514
1515 mbox.addButton(QMessageBox::Close);
1516 mbox.setDefaultButton(QMessageBox::Close);
1517 mbox.exec();
1518
1519 if (mbox.clickedButton() == btnOpenPrivateAppData) {
1520 resourcePath = folderInPrivateAppData;
1521 } else if (mbox.clickedButton() == btnOpenUserAppData) {
1522 // no-op: resourcePath = resourceDir.absolutePath();
1523 } else {
1524 return;
1525 }
1526
1527
1528 }
1529#endif
1530 QDesktopServices::openUrl(QUrl::fromLocalFile(resourcePath));
1531}
1532
1534{
1535 if (mainWindow()) {
1537 Q_FOREACH (QDockWidget* dock, dockers) {
1538 KoDockWidgetTitleBar* titlebar = dynamic_cast<KoDockWidgetTitleBar*>(dock->titleBarWidget());
1539 if (titlebar) {
1540 titlebar->updateIcons();
1541 }
1542 if (qobject_cast<KoToolDocker*>(dock)) {
1543 // Tool options widgets icons are updated by KoToolManager
1544 continue;
1545 }
1546 QObjectList objects;
1547 objects.append(dock);
1548 while (!objects.isEmpty()) {
1549 QObject* object = objects.takeFirst();
1550 objects.append(object->children());
1552 }
1553 }
1554 }
1555}
1556
1565
1566void KisViewManager::showFloatingMessage(const QString &message, const QIcon& icon, int timeout, KisFloatingMessage::Priority priority, int alignment)
1567{
1568 if (!d->currentImageView) return;
1569 d->currentImageView->showFloatingMessage(message, icon, timeout, priority, alignment);
1570
1571 Q_EMIT floatingMessageRequested(message, icon.name());
1572}
1573
1575{
1576 d->zoomMessage = message;
1578}
1579
1585
1587{
1588 int timeoutMsec = 500;
1589
1590 if (d->zoomRotationMessageTimer.hasExpired()) {
1591 messageToClear.clear();
1592 }
1593 d->zoomRotationMessageTimer.setRemainingTime(timeoutMsec);
1594
1595 QString message;
1596 bool haveZoomMessage = !d->zoomMessage.isEmpty();
1597 bool haveRotationMessage = !d->rotationMessage.isEmpty();
1598 if (haveZoomMessage) {
1599 if (haveRotationMessage) {
1600 message = QStringLiteral("%1\n%2").arg(d->zoomMessage, d->rotationMessage);
1601 } else {
1602 message = d->zoomMessage;
1603 }
1604 } else if (haveRotationMessage) {
1605 message = d->rotationMessage;
1606 } else {
1607 return;
1608 }
1609
1610 showFloatingMessage(message, QIcon(), timeoutMsec, KisFloatingMessage::Low, Qt::AlignCenter);
1611}
1612
1614{
1615 return qobject_cast<KisMainWindow*>(d->mainWindow);
1616}
1617
1619{
1620 return mainWindow();
1621}
1622
1623
1625{
1626 if (!d->currentImageView) return;
1627 if (!d->currentImageView->canvasController()) return;
1628
1629 KisConfig cfg(true);
1630 bool toggled = actionCollection()->action("view_show_canvas_only")->isChecked();
1631
1632 if ( (toggled && cfg.hideScrollbarsFullscreen()) || (!toggled && cfg.hideScrollbars()) ) {
1633 d->currentImageView->canvasController()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1634 d->currentImageView->canvasController()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1635 } else {
1636 d->currentImageView->canvasController()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
1637 d->currentImageView->canvasController()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
1638 }
1639}
1640
1642{
1643 KisConfig cfg(false);
1644 cfg.setShowRulers(value);
1645}
1646
1652
1654{
1655 d->showFloatingMessage = show;
1656}
1657
1658void KisViewManager::changeAuthorProfile(const QString &profileName)
1659{
1660 KConfigGroup appAuthorGroup(KSharedConfig::openConfig(), "Author");
1661 if (profileName.isEmpty() || profileName == i18nc("choice for author profile", "Anonymous")) {
1662 appAuthorGroup.writeEntry("active-profile", "");
1663 } else {
1664 appAuthorGroup.writeEntry("active-profile", profileName);
1665 }
1666 appAuthorGroup.sync();
1667 Q_FOREACH (KisDocument *doc, KisPart::instance()->documents()) {
1669 }
1670}
1671
1673{
1674 Q_ASSERT(d->actionAuthor);
1675 if (!d->actionAuthor) {
1676 return;
1677 }
1678 d->actionAuthor->clear();
1679 d->actionAuthor->addAction(i18nc("choice for author profile", "Anonymous"));
1680
1681 KConfigGroup authorGroup(KSharedConfig::openConfig(), "Author");
1682 QStringList profiles = authorGroup.readEntry("profile-names", QStringList());
1683 QString authorInfo = KoResourcePaths::getAppDataLocation() + "/authorinfo/";
1684 QStringList filters = QStringList() << "*.authorinfo";
1685 QDir dir(authorInfo);
1686 Q_FOREACH(QString entry, dir.entryList(filters)) {
1687 int ln = QString(".authorinfo").size();
1688 entry.chop(ln);
1689 if (!profiles.contains(entry)) {
1690 profiles.append(entry);
1691 }
1692 }
1693 Q_FOREACH (const QString &profile , profiles) {
1694 d->actionAuthor->addAction(profile);
1695 }
1696
1697 KConfigGroup appAuthorGroup(KSharedConfig::openConfig(), "Author");
1698 QString profileName = appAuthorGroup.readEntry("active-profile", "");
1699
1700 if (profileName == "anonymous" || profileName.isEmpty()) {
1701 d->actionAuthor->setCurrentItem(0);
1702 } else if (profiles.contains(profileName)) {
1703 d->actionAuthor->setCurrentAction(profileName);
1704 }
1705}
1706
1716
1718{
1719 if(d->toolManager.activeToolId() == "KisToolTransform") {
1720 KoToolBase* tool = d->toolManager.toolById(canvasBase(), "KisToolTransform");
1721
1722 QSet<KoShape*> dummy;
1723 // Start a new stroke
1724 tool->deactivate();
1725 tool->activate(dummy);
1726 } else {
1727 d->toolManager.switchToolRequested("KisToolTransform");
1728 }
1729}
1730
1746
1748{
1749 KisConfig cfg(true);
1750
1751 OutlineStyle style;
1752
1753 if (cfg.newOutlineStyle() != OUTLINE_NONE) {
1754 style = OUTLINE_NONE;
1756 } else {
1757 style = cfg.lastUsedOutlineStyle();
1759 }
1760
1761 cfg.setNewOutlineStyle(style);
1762
1763 Q_EMIT brushOutlineToggled();
1764}
1765
1767{
1768 KisCanvasController *canvasController = d->currentImageView->canvasController();
1769 canvasController->resetCanvasRotation();
1770}
1771
1773{
1774 KisCanvasController *canvasController = d->currentImageView->canvasController();
1775 canvasController->resetCanvasRotation();
1776 canvasController->mirrorCanvas(false);
1778}
1779
1780void KisViewManager::slotCreateOpacityResource(bool isOpacityPresetMode, KoToolBase *tool)
1781{
1782 if (isOpacityPresetMode) {
1784 }
1785 else {
1787 }
1788}
float value(const T *src, size_t ch)
qreal u
QList< QString > QStringList
@ WRAPAROUND_HORIZONTAL
@ WRAPAROUND_BOTH
@ WRAPAROUND_VERTICAL
unsigned int uint
bool eventFilter(QObject *watched, QEvent *event) override
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
void setView(QPointer< KisView > imageView)
KisAction * createAction(const QString &name)
KisAction * actionByName(const QString &name) const
KisAction * createStandardAction(KStandardAction::StandardAction, const QObject *receiver, const char *member)
void setDefaultShortcut(const QKeySequence &shortcut)
WrapAroundAxis wrapAroundModeAxis() const
void setUsePrintResolutionMode(bool value)
void sigUsePrintResolutionModeChanged(bool value)
void setup(KisActionManager *actionManager)
void setView(QPointer< KisView >imageView)
void setColorHistoryColors(const QList< KoColor > &colors)
void setResourceManager(KoCanvasResourceProvider *resourceManager)
void addProxy(KoProgressProxy *proxy)
void removeProxy(KoProgressProxy *proxy)
static KisConfigNotifier * instance()
bool hideScrollbars(bool defaultValue=false) const
void setShowDockers(const bool value) const
void setShowStatusBar(const bool value) const
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:904
void writeKoColors(const QString &name, const QList< KoColor > &colors) const
bool fullscreenMode(bool defaultValue=false) const
bool pixelGridEnabled(bool defaultValue=false) const
void setRulersTrackMouse(bool value) const
bool hideScrollbarsFullscreen(bool defaultValue=false) const
bool showCanvasMessages(bool defaultValue=false) const
QList< KoColor > readKoColors(const QString &name) const
OutlineStyle lastUsedOutlineStyle(bool defaultValue=false) const
KoColor readKoColor(const QString &name, const KoColor &color=KoColor()) const
OutlineStyle newOutlineStyle(bool defaultValue=false) const
void setNewOutlineStyle(OutlineStyle style)
void setShowRulers(bool rulers) const
bool showDockers(bool defaultValue=false) const
bool useOpenGL(bool defaultValue=false) const
bool rulersTrackMouse(bool defaultValue=false) const
bool showStatusBar(bool defaultValue=false) const
bool showRulers(bool defaultValue=false) const
void setLastUsedOutlineStyle(OutlineStyle style)
void writeKoColor(const QString &name, const KoColor &color) const
KisPaintopBox * paintopBox()
void setup(QWidget *parent)
void setView(QPointer< KisView > imageView)
void setup(KisActionManager *actionManager)
void setFileBatchMode(const bool batchMode)
KoDocumentInfo * documentInfo() const
KisImageSP image
QString localFilePath() const
bool saveAs(const QString &path, const QByteArray &mimeType, bool showWarnings, KisPropertiesConfigurationSP exportConfiguration=0)
QString path() const
KisDocument * clone(bool addStorage=false)
creates a clone of the document and returns it. Please make sure that you hold all the necessary lock...
void setup(KisKActionCollection *ac, KisActionManager *actionManager)
void setView(QPointer< KisView >imageView)
void setView(QPointer< KisView >imageView)
void setup(KisActionManager *actionManager)
void setView(QPointer< KisView > view)
void setup(KisActionManager *actionManager)
void setImage(KisImageSP image)
void setView(QPointer< KisView >imageView)
void setup(KisActionManager *actionManager)
KisUndoAdapter * undoAdapter() const
KisCompositeProgressProxy * compositeProgressProxy()
Definition kis_image.cc:772
Central object to manage canvas input.
static KisInputProfileManager * instance()
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
QAction * action(int index) const
Main window for Krita.
KisView * addViewAndNotifyLoadingCompleted(KisDocument *document, QMdiSubWindow *subWindow=0)
QList< QDockWidget * > dockWidgets() const
Return the list of dock widgets belonging to this main window.
bool saveDocument(KisDocument *document, bool saveas, bool isExporting, bool isAdvancedExporting=false)
int viewCount() const
void setView(QPointer< KisView > imageView)
void setup(KisKActionCollection *collection)
KisLayerSP activeLayer()
void setView(QPointer< KisView >imageView)
void setup(KisKActionCollection *collection, KisActionManager *actionManager)
KisNodeSP activeNode()
Convenience function to get the active layer or mask.
KisPaintDeviceSP activePaintDevice()
Get the paint device the user wants to paint on now.
static KisPart * instance()
Definition KisPart.cpp:131
void addDocument(KisDocument *document, bool notify=true)
Definition KisPart.cpp:210
void queueAddRecentURLToAllMainWindowsOnFileSaved(QUrl url, QUrl oldUrl=QUrl())
Definition KisPart.cpp:605
QString resourceLocationBase() const
resourceLocationBase is the place where all resource storages (folder, bundles etc....
static KisResourceLocator * instance()
void setup(KisActionManager *actionManager)
void setView(QPointer< KisView >imageView)
void addUniqueConnection(Sender sender, Signal signal, Receiver receiver, Method method)
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
void setView(QPointer< KisView > imageView)
void hideAllStatusBarItems()
void showAllStatusBarItems()
KoProgressUpdater * progressUpdater()
static void createTemplate(const QString &templatesResourcePath, const char *suffix, KisDocument *document, QWidget *parent=0)
The KisTextPropertyManager class.
void setCanvasResourceProvider(KisCanvasResourceProvider *provider)
setCanvasResourceProvider set the canvas resource provider.
QScopedPointer< KoProgressUpdater > persistentUnthreadedProgressUpdaterRouter
QPointer< KisFloatingMessage > savedFloatingMessage
KisSignalAutoConnectionsStore viewConnections
BlockingUserInputEventFilter blockingEventFilter
KisCanvasControlsManager canvasControlsManager
QPointer< KoUpdater > persistentUnthreadedProgressUpdater
KisViewManagerPrivate(KisViewManager *_q, KisKActionCollection *_actionCollection, QWidget *_q_parent)
QPointer< KoUpdater > persistentImageProgressUpdater
KisDecorationsManager paintingAssistantsManager
KisCanvasResourceProvider canvasResourceProvider
KoCanvasResourceProvider canvasResourceManager
bool blockUntilOperationsFinishedImpl(KisImageSP image, bool force)
std::optional< CanvasOnlyOptions > canvasOnlyOptions
KisTextPropertiesManager textPropertyManager
void slotUpdatePixelGridAction()
bool blockUntilOperationsFinished(KisImageSP image)
blockUntilOperationsFinished blocks the GUI of the application until execution of actions on image is...
KisMainWindow * mainWindow() const
KisDocument * document() const
static void initializeResourceManager(KoCanvasResourceProvider *resourceManager)
KisFilterManager * filterManager()
The filtermanager handles everything action-related to filters.
void slotSaveRulersTrackMouseState(bool value)
int viewCount() const
KisActionManager * actionManager() const
void floatingMessageRequested(const QString &message, const QString &iconName)
void updateIcons()
Update the style of all the icons.
KisIdleTasksManager * idleTasksManager()
KisCanvas2 * canvasBase() const
Return the canvas base class.
void switchCanvasOnly(bool toggled)
KisNodeSP activeNode()
KisUndoAdapter * undoAdapter()
The undo adapter is used to add commands to the undo stack.
void showFloatingZoomMessage(const QString &message)
void slotActivateTransformTool()
void setCurrentView(KisView *view)
KoToolManager * toolManager() const
void brushOutlineToggled()
void setQtMainWindow(QMainWindow *newMainWindow)
KisImageManager * imageManager()
void handleFloatingZoomRotationMessage(QString &messageToClear)
KisSelectionSP selection()
void setShowFloatingMessage(bool show)
void slotUpdateAuthorProfileActions()
void enableControls()
disable and enable toolbar controls. used for disabling them during painting.
void updateCanvasOnlyActionState()
QPointer< KoUpdater > createThreadedUpdater(const QString &name)
QWidget * canvas() const
Return the actual widget that is displaying the current image.
void viewChanged()
viewChanged sent out when the view has changed.
KisLayerSP activeLayer()
Convenience method to get at the active layer.
KisPaintDeviceSP activeDevice()
Convenience method to get at the active paint device.
void slotViewAdded(KisView *view)
void blockUntilOperationsFinishedForced(KisImageSP image)
blockUntilOperationsFinished blocks the GUI of the application until execution of actions on image is...
virtual KisKActionCollection * actionCollection() const
void slotSaveIncrementalBackup()
void showStatusBar(bool toggled)
KisInputManager * inputManager() const
Filters events and sends them to canvas actions.
QPointer< KoUpdater > createUnthreadedUpdater(const QString &name)
create a new progress updater
QMainWindow * qtMainWindow() const
~KisViewManager() override
KisViewManagerPrivate *const d
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.
void slotSaveShowRulersState(bool value)
QString canonicalPath()
KisSelectionManager * selectionManager()
void slotViewRemoved(KisView *view)
KisGuidesManager * guidesManager() const
QWidget * mainWindowAsQWidget() const
void slotCreateOpacityResource(bool isOpacityPresetMode, KoToolBase *tool)
KisImageWSP image() const
Return the image this view is displaying.
KisViewManager(QWidget *parent, KisKActionCollection *actionCollection)
static void testingInitializeOpacityToPresetResourceConverter(KoCanvasResourceProvider *resourceManager)
void showFloatingRotationMessage(const QString &message)
KisGridManager * gridManager() const
KisZoomManager * zoomManager()
The zoommanager handles everything action-related to zooming.
KisCanvasResourceProvider * canvasResourceProvider()
KisStatusBar * statusBar() const
Return the wrapper class around the statusbar.
KisTextPropertiesManager * textPropertyManager() const
void changeAuthorProfile(const QString &profileName)
KisPaintopBox * paintOpBox() const
bool selectionEditable()
Checks if the current global or local selection is editable.
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
QPointer< KisViewManager > viewManager
Definition KisView.cpp:129
void effectiveZoomChanged(qreal zoom)
void addActiveCanvasResourceDependency(KoActiveCanvasResourceDependencySP dep)
void setBackgroundColor(const KoColor &color)
void setForegroundColor(const KoColor &color)
void addResourceUpdateMediator(KoResourceUpdateMediatorSP mediator)
void addDerivedResourceConverter(KoDerivedResourceConverterSP converter)
A custom title bar for dock widgets.
void setAboutInfo(const QString &info, const QString &data)
QString aboutInfo(const QString &info) const
QPointer< KoUpdater > startSubtask(int weight=1, const QString &name=QString(), bool isPersistent=false)
static void getAllUserResourceFoldersLocationsForWindowsStore(QString &standardLocation, QString &privateLocation)
getAllAppDataLocationsForWindowsStore Use this to get both private and general appdata folders which ...
static QString getAppDataLocation()
virtual void activate(const QSet< KoShape * > &shapes)
virtual void deactivate()
KoToolBase * toolById(KoCanvasBase *canvas, const QString &id) const
void switchToolRequested(const QString &id)
void setConverter(KoDerivedResourceConverterSP converter, KoToolBase *tool)
void setAbstractResource(KoAbstractCanvasResourceInterfaceSP abstractResource, KoToolBase *tool)
void setCurrentCanvas(KoCanvasController *controller)
Set the active canvas when the owning view manager changes its current view.
QString activeToolId() const
Returns the toolId of the currently active tool.
void initializeToolActions()
void sigUsePrintResolutionModeChanged(bool value)
void setUsePrintResolutionMode(bool value)
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24
@ ZOOM_HEIGHT
zoom pageheight
Definition KoZoomMode.h:27
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define dbgUI
Definition kis_debug.h:56
OutlineStyle
Definition kis_global.h:53
@ OUTLINE_NONE
Definition kis_global.h:54
QSharedPointer< T > toQShared(T *ptr)
QString button(const QWheelEvent &ev)
int main(int argc, char **argv)
Definition main.cpp:26
QIcon loadIcon(const QString &name)
void updateIconCommon(QObject *object)
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
bool isEditable(bool checkVisibility=true) const
virtual KisSelectionMaskSP selectionMask() const
Definition kis_layer.cc:504
static KisResourceItemChooserSync * instance()
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())