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

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef STORYBOARD_ITEM
0008 #define STORYBOARD_ITEM
0009 
0010 #include <QVariant>
0011 #include <QVector>
0012 #include <QPixmap>
0013 
0014 #include "kritaui_export.h"
0015 #include "kis_types.h"
0016 
0017 //each storyboardItem contains pointer to child data
0018 class StoryboardItem;
0019 class QDomDocument;
0020 class QDomElement;
0021 
0022 /**
0023  * @struct Comment
0024  * @brief This class is a simple combination of two variables.
0025  * It stores the name and visibility of comments. It is used in
0026  * @c CommentModel and @c StoryboardModel.
0027  */
0028 class StoryboardComment
0029 {
0030 public:
0031     StoryboardComment() = default;
0032 
0033     QString name;
0034     bool visibility = true;
0035 };
0036 
0037 /**
0038  * @class CommentBox
0039  * @brief This class is a simple combination of two QVariants.
0040  * It can be converted to and from QVariant type and
0041  * is used in StoryboardModel.
0042  */
0043 class CommentBox
0044 {
0045 public:
0046     CommentBox()
0047     : content("")
0048     , scrollValue(0)
0049     {}
0050     CommentBox(const CommentBox& other)
0051     : content(other.content)
0052     , scrollValue(other.scrollValue)
0053     {}
0054     ~CommentBox()
0055     {}
0056 
0057     /**
0058      * @brief the text content of the Comment
0059      */
0060     QVariant content;
0061     /**
0062      * @brief the value of the scroll bar of the comment scrollbar
0063      */
0064     QVariant scrollValue;
0065 };
0066 
0067 
0068 /**
0069  * @class ThumbnailData
0070  * @brief This class is a simple combination of two QVariants.
0071  * It can be converted to and from QVariant type and
0072  * is used in StoryboardModel.
0073  */
0074 class ThumbnailData
0075 {
0076 public:
0077     ThumbnailData()
0078     : frameNum("")
0079     , pixmap(QPixmap())
0080     {}
0081     ThumbnailData(const ThumbnailData& other)
0082     : frameNum(other.frameNum)
0083     , pixmap(other.pixmap)
0084     {}
0085     ~ThumbnailData()
0086     {}
0087 
0088     /**
0089      * @brief the frame number corresponding to this item
0090      * in the timeline docker
0091      */
0092     QVariant frameNum;
0093 
0094     /**
0095      * @brief a scaled down thumbnail version of the frame
0096      */
0097     QVariant pixmap;
0098 };
0099 
0100 Q_DECLARE_METATYPE(CommentBox)
0101 Q_DECLARE_METATYPE(ThumbnailData)
0102 
0103 /**
0104  * @class StoryboardChild
0105  * @brief This class makes up the StoryboardItem
0106  * class. It consists of pointer to its parent item
0107  * and the data stored as QVariant.
0108  */
0109 class StoryboardChild
0110 {
0111 public:
0112     StoryboardChild(QVariant data)
0113         : m_data(data)
0114     {}
0115 
0116     StoryboardChild(const StoryboardChild &rhs)
0117         : m_data(rhs.m_data)
0118     {}
0119 
0120     StoryboardItemSP parent()
0121     {
0122         return m_parentItem.toStrongRef();
0123     }
0124 
0125     void setParent(StoryboardItemSP parent)
0126     {
0127         m_parentItem = parent;
0128     }
0129 
0130     QVariant data()
0131     { 
0132         return m_data;
0133     }
0134     void setData(QVariant value)
0135     {
0136         m_data = value;
0137     }
0138 
0139 private:
0140     QVariant m_data;
0141     QWeakPointer<StoryboardItem> m_parentItem;
0142 };
0143 
0144 /**
0145  * @class StoryboardItem
0146  * @brief This class stores a list of StoryboardChild objects
0147  * and provides functionality to manipulate the list. Specific
0148  * item type must be stored at specific indices
0149  * @param childType enum for the indices and corresponding data type to be stored.
0150  */
0151 class KRITAUI_EXPORT StoryboardItem : public QEnableSharedFromThis<StoryboardItem>
0152 {
0153 public:
0154     explicit StoryboardItem();
0155     StoryboardItem(const StoryboardItem& other);
0156     ~StoryboardItem();
0157 
0158     void appendChild(QVariant data);
0159     void cloneChildrenFrom(const StoryboardItem &other);
0160     void insertChild(int row, QVariant data = QVariant());
0161     void removeChild(int row);
0162     void moveChild(int from, int to);
0163     int childCount() const;
0164     QSharedPointer<StoryboardChild> child(int row) const;
0165 
0166     QDomElement toXML(QDomDocument doc);
0167     void loadXML(const QDomElement &itemNode);
0168 
0169     static StoryboardItemList cloneStoryboardItemList(const StoryboardItemList &list);
0170 
0171 
0172     /**
0173      * @enum childType
0174      * @brief This enum defines the data type to be stored at particular indices
0175      * @param FrameNumber Store the frame number at index 0. Data type stored here should be @c ThumbnailData.
0176      * @param ItemName Store the item name at index 1. Data type stored here should be @c string.
0177      * @param DurationSecond Store the duration in second at index 2. Data type should be @c int.
0178      * @param DurationFrame Store the duration in frame at index 3. Data type should be @c int.
0179      * @param Comments Store the comments at indices @a greater_than_or_equal_to to index 4. Data type should be @c CommentBox.
0180      */
0181     enum childType{
0182 
0183         /**
0184          * @brief Store the frame number at index 0. Data type stored here should be @c ThumbnailData
0185          */
0186         FrameNumber,
0187         /**
0188          * @brief Store the item name at index 1. Data type stored here should be @c string.
0189          */
0190         ItemName,
0191         /**
0192          * @brief Store the duration in second at index 2. Data type stored here should be @c int.
0193          */
0194         DurationSecond,
0195         /**
0196          * @brief Store the duration in frame at index 3. Data type stored here should be @c int.
0197          */
0198         DurationFrame,
0199         /**
0200          * @brief Store the comments at indices @a greater_than_or_equal_to to index 4. Data type stored here should be @c CommentBox
0201          */
0202         Comments
0203     };
0204 
0205 private:
0206     QVector<QSharedPointer<StoryboardChild>> m_childData;
0207 };
0208 
0209 #endif