KisView.h 8.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
   Copyright (C) 2007 Thomas Zander <zander@kde.org>
   Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/
21 22
#ifndef KIS_VIEW_H
#define KIS_VIEW_H
23 24 25 26 27 28 29

#include <QWidget>

#include <KoColorSpace.h>
#include <KoColorProfile.h>

#include <kis_types.h>
30
#include "kritaui_export.h"
31

32 33
#include "widgets/kis_floating_message.h"

34 35 36 37 38 39 40 41 42 43
class KisDocument;
class KisMainWindow;
class KisPrintJob;
class KisCanvasController;
class KisZoomManager;
class KisCanvas2;
class KisViewManager;
class KisDocument;
class KisCanvasResourceProvider;
class KisCoordinatesConverter;
44
class KisInputManager;
45 46 47 48

class KoZoomController;
class KoZoomController;
struct KoPageLayout;
49
class KoCanvasResourceProvider;
50 51

// KDE classes
52
class QAction;
53
class KActionCollection;
54
class KConfigGroup;
55 56 57

// Qt classes
class QDragEnterEvent;
58
class QDragMoveEvent;
59 60 61
class QDropEvent;
class QPrintDialog;
class QCloseEvent;
Sven Langkamp's avatar
Sven Langkamp committed
62
class QStatusBar;
63
class QMdiSubWindow;
64 65 66 67 68 69 70 71 72 73 74 75 76 77

/**
 * This class is used to display a @ref KisDocument.
 *
 * Multiple views can be attached to one document at a time.
 */
class KRITAUI_EXPORT KisView : public QWidget
{
    Q_OBJECT

public:
    /**
     * Creates a new view for the document.
     */
78
    KisView(KisDocument *document, KisViewManager *viewManager, QWidget *parent = 0);
79
    ~KisView() override;
80

81 82 83 84 85 86 87 88 89 90 91 92 93 94
    // Temporary while teasing apart view and mainwindow
    void setViewManager(KisViewManager *view);
    KisViewManager *viewManager() const;

public:

    /**
     *  Retrieves the document object of this view.
     */
    KisDocument *document() const;

    /**
     * Reset the view to show the given document.
     */
95
    void setDocument(KisDocument *document);
96 97 98 99 100 101 102 103 104 105 106

    /**
     * Tells this view that its document has got deleted (called internally)
     */
    void setDocumentDeleted();

    /**
     * In order to print the document represented by this view a new print job should
     * be constructed that is capable of doing the printing.
     * The default implementation returns 0, which silently cancels printing.
     */
107
    KisPrintJob * createPrintJob();
108 109 110 111

    /**
     * Create a QPrintDialog based on the @p printJob
     */
112
    QPrintDialog *createPrintDialog(KisPrintJob *printJob, QWidget *parent);
113 114 115 116

    /**
     * @return the KisMainWindow in which this view is currently.
     */
117
    KisMainWindow *mainWindow() const;
118

119 120 121 122 123
    /**
     * Tells this view which subwindow it is part of.
     */
    void setSubWindow(QMdiSubWindow *subWindow);

124 125 126
    /**
     * @return the statusbar of the KisMainWindow in which this view is currently.
     */
127
    QStatusBar *statusBar() const;
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

    /**
     * This adds a widget to the statusbar for this view.
     * If you use this method instead of using statusBar() directly,
     * KisView will take care of removing the items when the view GUI is deactivated
     * and readding them when it is reactivated.
     * The parameters are the same as QStatusBar::addWidget().
     */
    void addStatusBarItem(QWidget * widget, int stretch = 0, bool permanent = false);

    /**
     * Remove a widget from the statusbar for this view.
     */
    void removeStatusBarItem(QWidget * widget);

    /**
     * Return the zoomController for this view.
     */
146
    KoZoomController *zoomController() const;
147 148 149 150

    /// create a list of actions that when activated will change the unit on the document.
    QList<QAction*> createChangeUnitActions(bool addPixelUnit = false);

151 152
    void closeView();

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
public:

    /**
     * The zoommanager handles everything action-related to zooming
     */
    KisZoomManager *zoomManager() const;

    /**
     * The CanvasController decorates the canvas with scrollbars
     * and knows where to start painting on the canvas widget, i.e.,
     * the document offset.
     */
    KisCanvasController *canvasController() const;
    KisCanvasResourceProvider *resourceProvider() const;

168 169 170 171 172 173 174 175
    /**
     * Filters events and sends them to canvas actions. Shared
     * among all the views/canvases
     *
     * NOTE: May be null while initialization!
     */
    KisInputManager* globalInputManager() const;

176 177 178 179 180 181 182 183 184 185 186 187
    /**
     * @return the canvas object
     */
    KisCanvas2 *canvasBase() const;

    /// @return the image this view is displaying
    KisImageWSP image() const;


    KisCoordinatesConverter *viewConverter() const;

    void resetImageSizeAndScroll(bool changeCentering,
188 189
                                 const QPointF &oldImageStillPoint = QPointF(),
                                 const QPointF &newImageStillPoint = QPointF());
190 191 192 193 194

    void setCurrentNode(KisNodeSP node);
    KisNodeSP currentNode() const;
    KisLayerSP currentLayer() const;
    KisMaskSP currentMask() const;
195 196 197 198 199 200 201 202 203 204
    /**
     * @brief softProofing
     * @return whether or not we're softproofing in this view.
     */
    bool softProofing();
    /**
     * @brief gamutCheck
     * @return whether or not we're using gamut warnings in this view.
     */
    bool gamutCheck();
205 206 207 208 209 210

    /// Convenience method to get at the active selection (the
    /// selection of the current layer, or, if that does not exist,
    /// the global selection.
    KisSelectionSP selection();

211
    void notifyCurrentStateChanged(bool isCurrent);
212
    bool isCurrent() const;
213 214

    void setShowFloatingMessage(bool show);
215 216 217
    void showFloatingMessage(const QString &message, const QIcon& icon, int timeout = 4500,
                             KisFloatingMessage::Priority priority = KisFloatingMessage::Medium,
                             int alignment = Qt::AlignCenter | Qt::TextWordWrap);
218

219 220
    bool canvasIsMirrored() const;

221 222
    void syncLastActiveNodeToDocument();

223 224
    void saveViewState(KisPropertiesConfiguration &config) const;
    void restoreViewState(const KisPropertiesConfiguration &config);
225

226
public Q_SLOTS:
227 228 229 230

    /**
     * Display a message in the status bar (calls QStatusBar::message())
     * @todo rename to something more generic
231
     * @param value determines autosaving
232
     */
233
    void slotSavingStatusMessage(const QString &text, int timeout, bool isAutoSaving = false);
234 235 236 237 238 239

    /**
     * End of the message in the status bar (calls QStatusBar::clear())
     * @todo rename to something more generic
     */
    void slotClearStatusText();
240 241 242 243 244 245 246 247 248 249
    /**
     * @brief slotSoftProofing set whether or not we're softproofing in this view.
     * Will be setting the same in the canvas belonging to the view.
     */
    void slotSoftProofing(bool softProofing);
    /**
     * @brief slotGamutCheck set whether or not we're gamutchecking in this view.
     * Will be setting the same in the vans belonging to the view.
     */
    void slotGamutCheck(bool gamutCheck);
250

251
    bool queryClose();
252

253 254
    void slotScreenChanged();

255 256
    void slotThemeChanged(QPalette pal);

257
private Q_SLOTS:
258 259 260
    void slotImageNodeAdded(KisNodeSP node);
    void slotContinueAddNode(KisNodeSP newActiveNode);

261 262 263
    void slotImageNodeRemoved(KisNodeSP node);
    void slotContinueRemoveNode(KisNodeSP newActiveNode);

264
Q_SIGNALS:
265 266 267 268
    // From KisImage
    void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
    void sigProfileChanged(const KoColorProfile *  profile);
    void sigColorSpaceChanged(const KoColorSpace*  cs);
269
    void titleModified(QString,bool);
270

271
    void sigContinueAddNode(KisNodeSP newActiveNode);
272 273
    void sigContinueRemoveNode(KisNodeSP newActiveNode);

274 275 276
protected:

    // QWidget overrides
277 278 279
    void dragEnterEvent(QDragEnterEvent *event) override;
    void dropEvent(QDropEvent *event) override;
    void dragMoveEvent(QDragMoveEvent *event) override;
280
    void closeEvent(QCloseEvent *event) override;
281

282 283 284 285 286
    /**
     * Generate a name for this view.
     */
    QString newObjectName();

287
public Q_SLOTS:
288 289 290 291 292
    void slotLoadingFinished();
    void slotSavingFinished();
    void slotImageResolutionChanged();
    void slotImageSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);

293

294 295 296 297
private:

    class Private;
    Private * const d;
298 299

    static bool s_firstView;
300 301 302
};

#endif