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

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_PAINT_DEVICE_FRAMES_INTERFACE_H
0008 #define __KIS_PAINT_DEVICE_FRAMES_INTERFACE_H
0009 
0010 #include "kis_types.h"
0011 #include "kritaimage_export.h"
0012 
0013 class KisPaintDeviceData;
0014 class KisPaintDeviceWriter;
0015 class KisDataManager;
0016 typedef KisSharedPtr<KisDataManager> KisDataManagerSP;
0017 
0018 class KisInterstrokeData;
0019 using KisInterstrokeDataSP = QSharedPointer<KisInterstrokeData>;
0020 
0021 
0022 class KRITAIMAGE_EXPORT KisPaintDeviceFramesInterface
0023 {
0024 public:
0025     KisPaintDeviceFramesInterface(KisPaintDevice *parentDevice);
0026 
0027     /**
0028      * Return a list of IDs for the frames contained in this paint device
0029      * @return list of frame IDs
0030      */
0031     QList<int> frames();
0032 
0033     /**
0034      * Creates a new frame on the device and returns an identifier for it.
0035      * @return frame id of the newly created frame
0036      */
0037     int createFrame(bool copy, int copySrc, const QPoint &offset, KUndo2Command *parentCommand);
0038 
0039     /**
0040      * Delete the frame with given id
0041      * @param frame frame ID
0042      * @param parentCommand parent command
0043      */
0044     void deleteFrame(int frame, KUndo2Command *parentCommand);
0045 
0046     /**
0047      * Copy the given frame into the target device
0048      * @param frameId ID of the frame to be copied
0049      * @param targetDevice paint device to copy to
0050      */
0051     void writeFrameToDevice(int frameId, KisPaintDeviceSP targetDevice);
0052 
0053     /**
0054      * Copy the given paint device contents into the specified frame
0055      * @param srcFrameId ID of the frame to copy from (must exist)
0056      * @param dstFrameId ID of the frame to be overwritten (must exist)
0057      * @param srcDevice paint device to copy from
0058      */
0059     void uploadFrame(int srcFrameId, int dstFrameId, KisPaintDeviceSP srcDevice);
0060 
0061     /**
0062      * Copy the given paint device contents into the specified frame
0063      * @param dstFrameId ID of the frame to be overwritten (must exist)
0064      * @param srcDevice paint device to copy from
0065      */
0066     void uploadFrame(int dstFrameId, KisPaintDeviceSP srcDevice);
0067 
0068     /**
0069      * @return extent() of \p frameId
0070      */
0071     QRect frameBounds(int frameId);
0072 
0073     /**
0074      * @return offset of a data on \p frameId
0075      */
0076     QPoint frameOffset(int frameId) const;
0077 
0078     /**
0079      * Sets default pixel for \p frameId
0080      */
0081     void setFrameDefaultPixel(const KoColor &defPixel, int frameId);
0082 
0083     /**
0084      * @return default pixel for \p frameId
0085      */
0086     KoColor frameDefaultPixel(int frameId) const;
0087 
0088     /**
0089      * Write a \p frameId onto \p store
0090      */
0091     bool writeFrame(KisPaintDeviceWriter &store, int frameId);
0092 
0093     /**
0094      * Loads content of a \p frameId from \p stream.
0095      *
0096      * NOTE: the frame must be created manually with createFrame()
0097      *       beforehand!
0098      */
0099     bool readFrame(QIODevice *stream, int frameId);
0100 
0101 
0102     /**
0103      * Returns frameId of the currently active frame.
0104      * Should be used by Undo framework only!
0105      */
0106     int currentFrameId() const;
0107 
0108     /**
0109      * Returns the data manager of the specified frame.
0110      * Should be used by Undo framework only!
0111      */
0112     KisDataManagerSP frameDataManager(int frameId) const;
0113 
0114     /**
0115      * Resets the cache object associated with the frame.
0116      * Should be used by Undo framework only!
0117      */
0118     void invalidateFrameCache(int frameId);
0119 
0120     /**
0121      * Sets the offset for \p frameId.
0122      * Should be used by Undo framework only!
0123      */
0124     void setFrameOffset(int frameId, const QPoint &offset);
0125 
0126     struct TestingDataObjects {
0127         typedef KisPaintDeviceData Data;
0128         typedef QHash<int, Data*> FramesHash;
0129 
0130         Data *m_data;
0131         Data *m_lodData;
0132         Data *m_externalFrameData;
0133 
0134         FramesHash m_frames;
0135 
0136         Data *m_currentData;
0137     };
0138 
0139     TestingDataObjects testingGetDataObjects() const;
0140     QList<KisPaintDeviceData*> testingGetDataObjectsList() const;
0141 
0142 private:
0143     KisPaintDevice *q;
0144 };
0145 
0146 #endif /* __KIS_PAINT_DEVICE_FRAMES_INTERFACE_H */