File indexing completed on 2024-05-12 16:01:56

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 public:
0128 
0129     /**
0130      * The zoommanager handles everything action-related to zooming
0131      */
0132     KisZoomManager *zoomManager() const;
0133 
0134     /**
0135      * The CanvasController decorates the canvas with scrollbars
0136      * and knows where to start painting on the canvas widget, i.e.,
0137      * the document offset.
0138      */
0139     KisCanvasController *canvasController() const;
0140     KisCanvasResourceProvider *resourceProvider() const;
0141 
0142     /**
0143      * Filters events and sends them to canvas actions. Shared
0144      * among all the views/canvases
0145      *
0146      * NOTE: May be null while initialization!
0147      */
0148     KisInputManager* globalInputManager() const;
0149 
0150     /**
0151      * @return the canvas object
0152      */
0153     KisCanvas2 *canvasBase() const;
0154 
0155     /// @return the image this view is displaying
0156     KisImageWSP image() const;
0157 
0158 
0159     KisCoordinatesConverter *viewConverter() const;
0160 
0161     void resetImageSizeAndScroll(bool changeCentering,
0162                                  const QPointF &oldImageStillPoint = QPointF(),
0163                                  const QPointF &newImageStillPoint = QPointF());
0164 
0165     void setCurrentNode(KisNodeSP node);
0166     KisNodeSP currentNode() const;
0167     KisLayerSP currentLayer() const;
0168     KisMaskSP currentMask() const;
0169     /**
0170      * @brief softProofing
0171      * @return whether or not we're softproofing in this view.
0172      */
0173     bool softProofing();
0174     /**
0175      * @brief gamutCheck
0176      * @return whether or not we're using gamut warnings in this view.
0177      */
0178     bool gamutCheck();
0179 
0180     /// Convenience method to get at the active selection (the
0181     /// selection of the current layer, or, if that does not exist,
0182     /// the global selection.
0183     KisSelectionSP selection();
0184 
0185     void notifyCurrentStateChanged(bool isCurrent);
0186     bool isCurrent() const;
0187 
0188     void setShowFloatingMessage(bool show);
0189     void showFloatingMessage(const QString &message, const QIcon& icon, int timeout = 4500,
0190                              KisFloatingMessage::Priority priority = KisFloatingMessage::Medium,
0191                              int alignment = Qt::AlignCenter | Qt::TextWordWrap);
0192 
0193     bool canvasIsMirrored() const;
0194 
0195     void syncLastActiveNodeToDocument();
0196 
0197     void saveViewState(KisPropertiesConfiguration &config) const;
0198     void restoreViewState(const KisPropertiesConfiguration &config);
0199 
0200 public Q_SLOTS:
0201 
0202     /**
0203      * Display a message in the status bar (calls QStatusBar::message())
0204      * @todo rename to something more generic
0205      * @param value determines autosaving
0206      */
0207     void slotSavingStatusMessage(const QString &text, int timeout, bool isAutoSaving = false);
0208 
0209     /**
0210      * End of the message in the status bar (calls QStatusBar::clear())
0211      * @todo rename to something more generic
0212      */
0213     void slotClearStatusText();
0214     /**
0215      * @brief slotSoftProofing set whether or not we're softproofing in this view.
0216      * Will be setting the same in the canvas belonging to the view.
0217      */
0218     void slotSoftProofing(bool softProofing);
0219     /**
0220      * @brief slotGamutCheck set whether or not we're gamutchecking in this view.
0221      * Will be setting the same in the vans belonging to the view.
0222      */
0223     void slotGamutCheck(bool gamutCheck);
0224 
0225     bool queryClose();
0226 
0227     void slotScreenChanged();
0228 
0229     void slotThemeChanged(QPalette pal);
0230 
0231 private Q_SLOTS:
0232     void slotContinueAddNode(KisNodeSP newActiveNode);
0233 
0234     void slotImageNodeRemoved(KisNodeSP node);
0235     void slotContinueRemoveNode(KisNodeSP newActiveNode);
0236 
0237 Q_SIGNALS:
0238     // From KisImage
0239     void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
0240     void sigProfileChanged(const KoColorProfile *  profile);
0241     void sigColorSpaceChanged(const KoColorSpace*  cs);
0242     void titleModified(QString,bool);
0243 
0244 protected:
0245 
0246     // QWidget overrides
0247     void dragEnterEvent(QDragEnterEvent *event) override;
0248     void dropEvent(QDropEvent *event) override;
0249     void dragMoveEvent(QDragMoveEvent *event) override;
0250     void closeEvent(QCloseEvent *event) override;
0251 
0252     /**
0253      * Generate a name for this view.
0254      */
0255     QString newObjectName();
0256 
0257 public Q_SLOTS:
0258     void slotLoadingFinished();
0259     void slotSavingFinished();
0260     void slotImageResolutionChanged();
0261     void slotImageSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
0262 
0263 
0264 private:
0265 
0266     class Private;
0267     Private * const d;
0268 
0269     static bool s_firstView;
0270 };
0271 
0272 #endif