File indexing completed on 2024-05-19 04:29:21

0001 /*
0002  *  SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_GUI_CLIENT_H
0008 #define KIS_GUI_CLIENT_H
0009 
0010 #include <QDockWidget>
0011 #include <QQueue>
0012 #include <QPointer>
0013 
0014 #include <KoToolManager.h>
0015 
0016 #include <kritaui_export.h>
0017 #include <kis_types.h>
0018 
0019 #include "kis_floating_message.h"
0020 
0021 class QPoint;
0022 class KisView;
0023 
0024 class KisCanvas2;
0025 class KisCanvasResourceProvider;
0026 class KisDocument;
0027 class KisFilterManager;
0028 class KisGridManager;
0029 class KisGuidesManager;
0030 class KisImageManager;
0031 class KisNodeManager;
0032 class KisDecorationsManager;
0033 class KisPaintopBox;
0034 class KisSelectionManager;
0035 class KisStatusBar;
0036 class KisUndoAdapter;
0037 class KisZoomManager;
0038 class KisPaintopBox;
0039 class KisActionManager;
0040 class KisInputManager;
0041 class KoUpdater;
0042 class KoProgressUpdater;
0043 class KisMainWindow;
0044 class KoZoomController;
0045 class KoCanvasResourceProvider;
0046 class KisIdleTasksManager;
0047 
0048 /**
0049  * KisViewManager manages the collection of views shown in a single mainwindow.
0050  */
0051 class KRITAUI_EXPORT KisViewManager : public QObject
0052 {
0053 
0054     Q_OBJECT
0055 
0056 public:
0057     /**
0058      * Construct a new view on the krita document.
0059      * @param parent   a parent widget we show ourselves in.
0060      * @param actionCollection an action collection.
0061      */
0062     KisViewManager(QWidget *parent, KisKActionCollection *actionCollection);
0063     ~KisViewManager() override;
0064 
0065     /**
0066      * Retrieves the entire action collection.
0067      */
0068     virtual KisKActionCollection* actionCollection() const;
0069 
0070 public:  // Krita specific interfaces
0071 
0072     void setCurrentView(KisView *view);
0073 
0074     /// Return the image this view is displaying
0075     KisImageWSP image() const;
0076 
0077     KoZoomController *zoomController() const;
0078 
0079     /// The resource provider contains all per-view settings, such as
0080     /// current color, current paint op etc.
0081     KisCanvasResourceProvider *canvasResourceProvider();
0082 
0083     /// Return the canvas base class
0084     KisCanvas2 *canvasBase() const;
0085 
0086     /// Return the actual widget that is displaying the current image
0087     QWidget* canvas() const;
0088 
0089     /// Return the wrapper class around the statusbar
0090     KisStatusBar *statusBar() const;
0091 
0092     KisPaintopBox* paintOpBox() const;
0093 
0094     /// create a new progress updater
0095     QPointer<KoUpdater> createUnthreadedUpdater(const QString &name);
0096     QPointer<KoUpdater> createThreadedUpdater(const QString &name);
0097 
0098     /// The selection manager handles everything action related to
0099     /// selections.
0100     KisSelectionManager *selectionManager();
0101 
0102     /// The node manager handles everything about nodes
0103     KisNodeManager *nodeManager() const;
0104 
0105     KisActionManager *actionManager() const;
0106 
0107     /**
0108      * Convenience method to get at the active node, which may be
0109      * a layer or a mask or a selection
0110      */
0111     KisNodeSP activeNode();
0112 
0113     /// Convenience method to get at the active layer
0114     KisLayerSP activeLayer();
0115 
0116     /// Convenience method to get at the active paint device
0117     KisPaintDeviceSP activeDevice();
0118 
0119     /// The filtermanager handles everything action-related to filters
0120     KisFilterManager *filterManager();
0121 
0122     /// The image manager handles everything action-related to the
0123     /// current image
0124     KisImageManager *imageManager();
0125 
0126     /// Filters events and sends them to canvas actions
0127     KisInputManager *inputManager() const;
0128 
0129     KisIdleTasksManager *idleTasksManager();
0130 
0131     /// Convenience method to get at the active selection (the
0132     /// selection of the current layer, or, if that does not exist,
0133     /// the global selection.
0134     KisSelectionSP selection();
0135 
0136     /// Checks if the current global or local selection is editable
0137     bool selectionEditable();
0138 
0139     /// The undo adapter is used to add commands to the undo stack
0140     KisUndoAdapter *undoAdapter();
0141 
0142     KisDocument *document() const;
0143 
0144     int viewCount() const;
0145 
0146     /**
0147      * @brief blockUntilOperationsFinished blocks the GUI of the application until execution
0148      *        of actions on \p image is finished
0149      * @param image the image which we should wait for
0150      * @return true if the image has finished execution of the actions, false if
0151      *         the user cancelled operation
0152      */
0153     bool blockUntilOperationsFinished(KisImageSP image);
0154 
0155 
0156     /**
0157      * @brief blockUntilOperationsFinished blocks the GUI of the application until execution
0158      *        of actions on \p image is finished. Does *not* provide a "Cancel" button. So the
0159      *        user is forced to wait.
0160      * @param image the image which we should wait for
0161      */
0162     void blockUntilOperationsFinishedForced(KisImageSP image);
0163 
0164     void notifyWorkspaceLoaded();
0165 
0166 public:
0167 
0168     KisGridManager * gridManager() const;
0169     KisGuidesManager * guidesManager() const;
0170 
0171     /// disable and enable toolbar controls. used for disabling them during painting.
0172     void enableControls();
0173     void disableControls();
0174 
0175 
0176     /// shows a floating message in the top right corner of the canvas
0177     void showFloatingMessage(const QString &message, const QIcon& icon, int timeout = 4500,
0178                              KisFloatingMessage::Priority priority = KisFloatingMessage::Medium,
0179                              int alignment = Qt::AlignCenter | Qt::TextWordWrap);
0180 
0181     /// @return the KisMainWindow this view is in, or 0
0182     KisMainWindow *mainWindow() const;
0183 
0184     /**
0185      * Gets the KisMainWindow as a QWidget, useful when you just need it to
0186      * be used as a parent to a dialog or window without needing to include
0187      * `KisMainWindow.h`.
0188      */
0189     QWidget *mainWindowAsQWidget() const;
0190 
0191     /// The QMainWindow associated with this view. This is most likely going to be shell(), but
0192     /// when running as Gemini or Sketch, this will be set to the applications' own QMainWindow.
0193     /// This can be checked by qobject_casting to KisMainWindow to check the difference.
0194     QMainWindow* qtMainWindow() const;
0195 
0196     /// The mainWindow function will return the shell() value, unless this function is called
0197     /// with a non-null value. To make it return shell() again, simply pass null to this function.
0198     void setQtMainWindow(QMainWindow* newMainWindow);
0199 
0200     static void initializeResourceManager(KoCanvasResourceProvider *resourceManager);
0201 
0202 public Q_SLOTS:
0203 
0204     void switchCanvasOnly(bool toggled);
0205     void setShowFloatingMessage(bool show);
0206     void showHideScrollbars();
0207 
0208     /// Visit all managers to update gui elements, e.g. enable / disable actions.
0209     /// This is heavy-duty call, so it uses a compressor.
0210     void updateGUI();
0211 
0212     /// Update the style of all the icons
0213     void updateIcons();
0214 
0215     void slotViewAdded(KisView *view);
0216     void slotViewRemoved(KisView *view);
0217     
0218     void slotActivateTransformTool();
0219 
0220     // Change and update author
0221     void changeAuthorProfile(const QString &profileName);
0222     void slotUpdateAuthorProfileActions();
0223 
0224     void slotToggleFgBg();
0225     void slotResetFgBg();
0226 
0227     // Enable the last set brush outline, or disable it if already enabled
0228     void slotToggleBrushOutline();
0229 
0230     void updatePrintSizeAction(bool canvasMappingMode);
0231     
0232 Q_SIGNALS:
0233 
0234     void floatingMessageRequested(const QString &message, const QString &iconName);
0235     /**
0236      * @brief viewChanged
0237      * sent out when the view has changed.
0238      */
0239     void viewChanged();
0240 
0241     void brushOutlineToggled();
0242 
0243 private Q_SLOTS:
0244 
0245     void slotCreateTemplate();
0246     void slotCreateCopy();
0247     void slotDocumentSaved();
0248     void slotSaveIncremental();
0249     void slotSaveIncrementalBackup();
0250     void showStatusBar(bool toggled);
0251     void toggleTabletLogger();
0252     void openResourcesDirectory();
0253     void guiUpdateTimeout();
0254     void slotUpdatePixelGridAction();
0255     void slotSaveShowRulersState(bool value);
0256     void slotSaveRulersTrackMouseState(bool value);
0257     void slotResetRotation();
0258     void slotResetDisplay();
0259     void slotToggleFullscreen();
0260 private:
0261     void createActions();
0262     void setupManagers();
0263 
0264     QString canonicalPath();
0265 
0266     /// The zoommanager handles everything action-related to zooming
0267     KisZoomManager * zoomManager();
0268 
0269 private:
0270     class KisViewManagerPrivate;
0271     KisViewManagerPrivate * const d;
0272 };
0273 
0274 #endif