File indexing completed on 2024-05-12 15:58:29

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KIS_NODE_GRAPH_LISTENER_H_
0007 #define KIS_NODE_GRAPH_LISTENER_H_
0008 
0009 #include "kritaimage_export.h"
0010 
0011 #include <QScopedPointer>
0012 
0013 class KisTimeSpan;
0014 class KisNode;
0015 class QRect;
0016 class KisKeyframeChannel;
0017 
0018 /**
0019  * Implementations of this class are called by nodes whenever the node
0020  * graph changes. These implementations can then emit the right
0021  * signals so Qt interview models can be updated before and after
0022  * changes.
0023  *
0024  * The reason for this go-between is that we don't want our nodes to
0025  * be QObjects, nor to have sig-slot connections between every node
0026  * and every mode.
0027  *
0028  * It also manages the sequence number of the graph. This is a number
0029  * which can be used as a checksum for whether the graph has changed
0030  * from some period of time or not. \see graphSequenceNumber()
0031  */
0032 class KRITAIMAGE_EXPORT KisNodeGraphListener
0033 {
0034 
0035 public:
0036     KisNodeGraphListener();
0037 
0038     virtual ~KisNodeGraphListener();
0039 
0040     /**
0041      * Inform the model that we're going to add a node.
0042      */
0043     virtual void aboutToAddANode(KisNode *parent, int index);
0044 
0045     /**
0046      * Inform the model we're done adding a node.
0047      */
0048     virtual void nodeHasBeenAdded(KisNode *parent, int index);
0049 
0050     /**
0051      * Inform the model we're going to remove a node.
0052      */
0053     virtual void aboutToRemoveANode(KisNode *parent, int index);
0054 
0055     /**
0056      * Inform the model we're done removing a node.
0057      */
0058     virtual void nodeHasBeenRemoved(KisNode *parent, int index);
0059 
0060     /**
0061      * Inform the model we're about to start moving a node (which
0062      * includes removing and adding the same node)
0063      */
0064     virtual void aboutToMoveNode(KisNode * node, int oldIndex, int newIndex);
0065 
0066     /**
0067      * Inform the model we're done moving the node: it has been
0068      * removed and added successfully
0069      */
0070     virtual void nodeHasBeenMoved(KisNode * node, int oldIndex, int newIndex);
0071 
0072     virtual void nodeChanged(KisNode * node);
0073 
0074     virtual void nodeCollapsedChanged(KisNode * node);
0075 
0076     virtual void invalidateAllFrames();
0077 
0078     /**
0079      * Inform the model that one of the selections in the graph is
0080      * changed. The sender is not passed to the function (at least for
0081      * now) because the UI should decide itself whether it needs to
0082      * fetch new selection of not.
0083      */
0084     virtual void notifySelectionChanged();
0085 
0086     /**
0087      * Inform the model that a node has been changed (setDirty)
0088      */
0089     virtual void requestProjectionUpdate(KisNode * node, const QVector<QRect> &rects, bool resetAnimationCache);
0090 
0091     virtual void invalidateFrames(const KisTimeSpan &range, const QRect &rect);
0092 
0093     virtual void requestTimeSwitch(int time);
0094 
0095     virtual KisNode* graphOverlayNode() const;
0096 
0097     /**
0098      * Returns the sequence of the graph.
0099      *
0100      * Every time some operation performed, which might change the
0101      * hierarchy of the nodes, the sequence number grows by one. So
0102      * if you have any information about the graph which was acquired
0103      * when the sequence number was X and now it has become Y, it
0104      * means your information is outdated.
0105      *
0106      * It is used in the scheduler for checking whether queued walkers
0107      * should be regenerated.
0108      */
0109      int graphSequenceNumber() const;
0110 
0111      /**
0112       * Inform the model that a keyframe channel has been added or removed.
0113       */
0114      virtual void keyframeChannelHasBeenAdded(KisNode *node, KisKeyframeChannel *channel);
0115      virtual void keyframeChannelAboutToBeRemoved(KisNode *node, KisKeyframeChannel *channel);
0116 
0117 private:
0118     struct Private;
0119     QScopedPointer<Private> m_d;
0120 };
0121 
0122 #endif