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

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0003    SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
0004    SPDX-FileCopyrightText: 2010 Benjamin Port <port.benjamin@gmail.com>
0005 
0006    SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 #ifndef KIS_VIEW_H
0009 #define KIS_VIEW_H
0010 
0011 #include <QWidget>
0012 
0013 #include <KoColorSpace.h>
0014 #include <KoColorProfile.h>
0015 
0016 #include <kis_types.h>
0017 #include "kritaui_export.h"
0018 
0019 #include "widgets/kis_floating_message.h"
0020 
0021 class KisDocument;
0022 class KisMainWindow;
0023 class KisCanvasController;
0024 class KisZoomManager;
0025 class KisCanvas2;
0026 class KisViewManager;
0027 class KisDocument;
0028 class KisCanvasResourceProvider;
0029 class KisCoordinatesConverter;
0030 class KisInputManager;
0031 
0032 class KoZoomController;
0033 class KoZoomController;
0034 class KoCanvasResourceProvider;
0035 
0036 // KDE classes
0037 class QAction;
0038 class KisKActionCollection;
0039 class KConfigGroup;
0040 
0041 // Qt classes
0042 class QDragEnterEvent;
0043 class QDragMoveEvent;
0044 class QDropEvent;
0045 class QPrintDialog;
0046 class QCloseEvent;
0047 class QStatusBar;
0048 class QMdiSubWindow;
0049 
0050 /**
0051  * This class is used to display a @ref KisDocument.
0052  *
0053  * Multiple views can be attached to one document at a time.
0054  */
0055 class KRITAUI_EXPORT KisView : public QWidget
0056 {
0057     Q_OBJECT
0058 
0059 public:
0060     /**
0061      * Creates a new view for the document.
0062      */
0063     KisView(KisDocument *document, KisViewManager *viewManager, QWidget *parent = 0);
0064     ~KisView() override;
0065 
0066     // Temporary while teasing apart view and mainwindow
0067     void setViewManager(KisViewManager *view);
0068     KisViewManager *viewManager() const;
0069 
0070 public:
0071 
0072     /**
0073      *  Retrieves the document object of this view.
0074      */
0075     KisDocument *document() const;
0076 
0077     /**
0078      * Deletes the view and creates a new one, displaying @p document,
0079      * in the same sub-window.
0080      *
0081      * @return the new view
0082      */
0083     KisView *replaceBy(KisDocument *document);
0084 
0085     /**
0086      * @return the KisMainWindow in which this view is currently.
0087      */
0088     KisMainWindow *mainWindow() const;
0089 
0090     /**
0091      * Tells this view which subwindow it is part of.
0092      */
0093     void setSubWindow(QMdiSubWindow *subWindow);
0094 
0095     /**
0096      * @return the statusbar of the KisMainWindow in which this view is currently.
0097      */
0098     QStatusBar *statusBar() const;
0099 
0100 
0101 
0102 
0103     /**
0104      * This adds a widget to the statusbar for this view.
0105      * If you use this method instead of using statusBar() directly,
0106      * KisView will take care of removing the items when the view GUI is deactivated
0107      * and readding them when it is reactivated.
0108      * The parameters are the same as QStatusBar::addWidget().
0109      */
0110     void addStatusBarItem(QWidget * widget, int stretch = 0, bool permanent = false);
0111 
0112     /**
0113      * Remove a widget from the statusbar for this view.
0114      */
0115     void removeStatusBarItem(QWidget * widget);
0116 
0117     /**
0118      * Return the zoomController for this view.
0119      */
0120     KoZoomController *zoomController() const;
0121 
0122     /// create a list of actions that when activated will change the unit on the document.
0123     QList<QAction*> createChangeUnitActions(bool addPixelUnit = false);
0124 
0125     void closeView();
0126 
0127     /**
0128      * Returns the current screen that the view belongs to
0129      */
0130     QScreen *currentScreen() const;
0131 
0132 public:
0133 
0134     /**
0135      * The zoommanager handles everything action-related to zooming
0136      */
0137     KisZoomManager *zoomManager() const;
0138 
0139     /**
0140      * The CanvasController decorates the canvas with scrollbars
0141      * and knows where to start painting on the canvas widget, i.e.,
0142      * the document offset.
0143      */
0144     KisCanvasController *canvasController() const;
0145     KisCanvasResourceProvider *resourceProvider() const;
0146 
0147     /**
0148      * Filters events and sends them to canvas actions. Shared
0149      * among all the views/canvases
0150      *
0151      * NOTE: May be null while initialization!
0152      */
0153     KisInputManager* globalInputManager() const;
0154 
0155     /**
0156      * @return the canvas object
0157      */
0158     KisCanvas2 *canvasBase() const;
0159 
0160     /// @return the image this view is displaying
0161     KisImageWSP image() const;
0162 
0163 
0164     KisCoordinatesConverter *viewConverter() const;
0165 
0166     void resetImageSizeAndScroll(bool changeCentering,
0167                                  const QPointF &oldImageStillPoint = QPointF(),
0168                                  const QPointF &newImageStillPoint = QPointF());
0169 
0170     void setCurrentNode(KisNodeSP node);
0171     KisNodeSP currentNode() const;
0172     KisLayerSP currentLayer() const;
0173     KisMaskSP currentMask() const;
0174     /**
0175      * @brief softProofing
0176      * @return whether or not we're softproofing in this view.
0177      */
0178     bool softProofing();
0179     /**
0180      * @brief gamutCheck
0181      * @return whether or not we're using gamut warnings in this view.
0182      */
0183     bool gamutCheck();
0184 
0185     /// Convenience method to get at the active selection (the
0186     /// selection of the current layer, or, if that does not exist,
0187     /// the global selection.
0188     KisSelectionSP selection();
0189 
0190     void notifyCurrentStateChanged(bool isCurrent);
0191     bool isCurrent() const;
0192 
0193     void setShowFloatingMessage(bool show);
0194     void showFloatingMessage(const QString &message, const QIcon& icon, int timeout = 4500,
0195                              KisFloatingMessage::Priority priority = KisFloatingMessage::Medium,
0196                              int alignment = Qt::AlignCenter | Qt::TextWordWrap);
0197 
0198     bool canvasIsMirrored() const;
0199 
0200     void syncLastActiveNodeToDocument();
0201 
0202     void saveViewState(KisPropertiesConfiguration &config) const;
0203     void restoreViewState(const KisPropertiesConfiguration &config);
0204 
0205 public Q_SLOTS:
0206 
0207     /**
0208      * Display a message in the status bar (calls QStatusBar::message())
0209      * @todo rename to something more generic
0210      * @param value determines autosaving
0211      */
0212     void slotSavingStatusMessage(const QString &text, int timeout, bool isAutoSaving = false);
0213 
0214     /**
0215      * End of the message in the status bar (calls QStatusBar::clear())
0216      * @todo rename to something more generic
0217      */
0218     void slotClearStatusText();
0219     /**
0220      * @brief slotSoftProofing set whether or not we're softproofing in this view.
0221      * Will be setting the same in the canvas belonging to the view.
0222      */
0223     void slotSoftProofing(bool softProofing);
0224     /**
0225      * @brief slotGamutCheck set whether or not we're gamutchecking in this view.
0226      * Will be setting the same in the vans belonging to the view.
0227      */
0228     void slotGamutCheck(bool gamutCheck);
0229 
0230     bool queryClose();
0231 
0232     void slotMigratedToScreen(QScreen *screen);
0233     void slotScreenOrResolutionChanged();
0234 
0235     void slotThemeChanged(QPalette pal);
0236 
0237     void slotUpdateDocumentTitle();
0238 
0239 private Q_SLOTS:
0240     void slotContinueAddNode(KisNodeSP newActiveNode);
0241 
0242     void slotImageNodeRemoved(KisNodeSP node);
0243     void slotContinueRemoveNode(KisNodeSP newActiveNode);
0244 
0245 Q_SIGNALS:
0246     // From KisImage
0247     void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
0248     void sigProfileChanged(const KoColorProfile *  profile);
0249     void sigColorSpaceChanged(const KoColorSpace*  cs);
0250 
0251 protected:
0252 
0253     // QWidget overrides
0254     void dragEnterEvent(QDragEnterEvent *event) override;
0255     void dropEvent(QDropEvent *event) override;
0256     void dragMoveEvent(QDragMoveEvent *event) override;
0257     void closeEvent(QCloseEvent *event) override;
0258 
0259     /**
0260      * Generate a name for this view.
0261      */
0262     QString newObjectName();
0263 
0264 public Q_SLOTS:
0265     void slotLoadingFinished();
0266     void slotImageResolutionChanged();
0267     void slotImageSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
0268 
0269 
0270 private:
0271 
0272     class Private;
0273     Private * const d;
0274 
0275     static bool s_firstView;
0276 };
0277 
0278 #endif