Krita Source Code Documentation
Loading...
Searching...
No Matches
StoryboardItem.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "StoryboardItem.h"
8
9#include <QDomElement>
10#include <QDomDocument>
11
12#include "kis_pointer_utils.h"
13
15 : m_childData()
16{}
17
19 : QEnableSharedFromThis<StoryboardItem>()
20 , m_childData()
21{
22 cloneChildrenFrom(other);
23}
24
29
30void StoryboardItem::appendChild(QVariant data)
31{
33 child->setParent(sharedFromThis());
34 m_childData.append(child);
35}
36
38{
39 m_childData.clear();
40 for (int i = 0; i < other.m_childData.count(); i++) {
42 child->setParent(sharedFromThis());
43 m_childData.append(child);
44 }
45}
46
47void StoryboardItem::insertChild(int row, QVariant data)
48{
50 child->setParent(sharedFromThis());
51 m_childData.insert(row, child);
52}
53
55{
56 m_childData.removeAt(row);
57}
58
59void StoryboardItem::moveChild(int from, int to)
60{
61 m_childData.move(from, to);
62}
63
65{
66 return m_childData.count();
67}
68
70{
71 if (row < 0 || row >= m_childData.size()) {
72 return nullptr;
73 }
74 return m_childData.at(row);
75}
76
77QDomElement StoryboardItem::toXML(QDomDocument doc)
78{
79 QDomElement itemElement = doc.createElement("storyboarditem");
80
81 int frame = qvariant_cast<ThumbnailData>(child(FrameNumber)->data()).frameNum.toInt();
82 itemElement.setAttribute("frame", frame);
83 itemElement.setAttribute("item-name", child(ItemName)->data().toString());
84 itemElement.setAttribute("duration-second", child(DurationSecond)->data().toInt());
85 itemElement.setAttribute("duration-frame", child(DurationFrame)->data().toInt());
86
87 for (int i = Comments; i < childCount(); i++) {
88 CommentBox comment = qvariant_cast<CommentBox>(child(i)->data());
89 QDomElement commentElement = doc.createElement("comment");
90
91 commentElement.setAttribute("content", comment.content.toString());
92 commentElement.setAttribute("scroll-value", comment.scrollValue.toInt());
93
94 itemElement.appendChild(commentElement);
95 }
96
97 return itemElement;
98}
99
100void StoryboardItem::loadXML(const QDomElement &itemNode)
101{
102 ThumbnailData thumbnail;
103 thumbnail.frameNum = itemNode.attribute("frame").toInt();
104 appendChild(QVariant::fromValue<ThumbnailData>(thumbnail));
105 appendChild(itemNode.attribute("item-name"));
106 appendChild(itemNode.attribute("duration-second").toInt());
107 appendChild(itemNode.attribute("duration-frame").toInt());
108
109 for (QDomElement commentNode = itemNode.firstChildElement(); !commentNode.isNull(); commentNode = commentNode.nextSiblingElement()) {
110 if (commentNode.nodeName().toUpper() != "COMMENT") continue;
111
112 CommentBox comment;
113 if (commentNode.hasAttribute("content")) {
114 comment.content = commentNode.attribute("content");
115 }
116 if (commentNode.hasAttribute("scroll-value")) {
117 comment.scrollValue = commentNode.attribute("scroll-value");
118 }
119 appendChild(QVariant::fromValue<CommentBox>(comment));
120 }
121}
122
124{
125 StoryboardItemList clonedList;
126 for (auto i = 0; i < list.count(); i++) {
127 StoryboardItemSP item = toQShared( new StoryboardItem(*list.at(i)) );
128 item->cloneChildrenFrom(*list.at(i));
129 clonedList.append(item);
130 }
131 return clonedList;
132}
This class is a simple combination of two QVariants. It can be converted to and from QVariant type an...
QVariant scrollValue
the value of the scroll bar of the comment scrollbar
QVariant content
the text content of the Comment
This class makes up the StoryboardItem class. It consists of pointer to its parent item and the data ...
This class stores a list of StoryboardChild objects and provides functionality to manipulate the list...
void insertChild(int row, QVariant data=QVariant())
QDomElement toXML(QDomDocument doc)
QVector< QSharedPointer< StoryboardChild > > m_childData
int childCount() const
void moveChild(int from, int to)
void removeChild(int row)
@ DurationFrame
Store the duration in frame at index 3. Data type stored here should be int.
@ FrameNumber
Store the frame number at index 0. Data type stored here should be ThumbnailData.
@ DurationSecond
Store the duration in second at index 2. Data type stored here should be int.
@ ItemName
Store the item name at index 1. Data type stored here should be string.
@ Comments
Store the comments at indices greater_than_or_equal_to to index 4. Data type stored here should be Co...
void loadXML(const QDomElement &itemNode)
void cloneChildrenFrom(const StoryboardItem &other)
void appendChild(QVariant data)
static StoryboardItemList cloneStoryboardItemList(const StoryboardItemList &list)
QSharedPointer< StoryboardChild > child(int row) const
This class is a simple combination of two QVariants. It can be converted to and from QVariant type an...
QVariant frameNum
the frame number corresponding to this item in the timeline docker
QSharedPointer< T > toQShared(T *ptr)