Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAddRemoveStoryboardCommand.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Saurabh Kumar <saurabhk660@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include <StoryboardItem.h>
8#include <kis_time_span.h>
9
10#include "StoryboardModel.h"
12#include "kis_image.h"
14#include "kis_layer_utils.h"
15
18 StoryboardModel *model,
19 KUndo2Command *parent)
20 : KUndo2Command(kundo2_i18n("Add Storyboard Scene"), parent)
21 , m_position(position)
22 , m_item(new StoryboardItem(*item))
23 , m_modelItem(item)
24 , m_model(model)
25{
26}
27
31
33{
34 QModelIndex existingEntry = m_model->index(m_position, 0);
35 if (existingEntry.isValid()){
36 const int firstFrameOfScene = m_model->data(m_model->index(StoryboardItem::FrameNumber, 0, existingEntry)).toInt();
37 int durationDeletedScene = m_item->child(StoryboardItem::DurationSecond)->data().toInt() * m_model->getFramesPerSecond()
38 + m_item->child(StoryboardItem::DurationFrame)->data().toInt();
39 m_model->shiftKeyframes(KisTimeSpan::infinite(firstFrameOfScene), durationDeletedScene);
40 }
41 m_model->insertRow(m_position);
44}
45
47{
49 updateItem();
50
51 QModelIndex nextEntry = m_model->index(m_position + 1, 0);
52 if (nextEntry.isValid()){
53 const int firstFrameOfScene = m_model->data(m_model->index(StoryboardItem::FrameNumber, 0, nextEntry)).toInt();
54 int durationDeletedScene = m_item->child(StoryboardItem::DurationSecond)->data().toInt() * m_model->getFramesPerSecond()
55 + m_item->child(StoryboardItem::DurationFrame)->data().toInt();
56 m_model->shiftKeyframes(KisTimeSpan::infinite(firstFrameOfScene), -durationDeletedScene);
57 }
59}
60
62{
63 m_item->cloneChildrenFrom(*m_modelItem);
64}
65
66
67//remove command
70 StoryboardModel *model,
71 KUndo2Command *parent)
72 : KUndo2Command(kundo2_i18n("Remove Storyboard Scene"), parent)
73 , m_position(position)
74 , m_item(new StoryboardItem(*item))
75 , m_model(model)
76{
77}
78
82
88
95
97 int count,
98 int to,
99 StoryboardModel *model,
100 KUndo2Command *parent)
101 : KUndo2Command(kundo2_i18n("Move Storyboard Scene"), parent)
102 , m_from(from)
103 , m_count(count)
104 , m_to(to)
105 , m_model(model)
106{
107}
108
112
114{
115 m_model->moveRowsImpl(QModelIndex(), m_from, m_count, QModelIndex(), m_to);
117}
118
120{
121 const int to = m_to > m_from ? m_to - m_count : m_to;
122 const int from = m_to <= m_from ? m_from + m_count : m_from;
123 m_model->moveRowsImpl(QModelIndex(), to, m_count, QModelIndex(), from);
125}
126
128 : KUndo2Command(parent)
129 , m_fromTime(fromTime)
130 , m_toSceneIndex(toSceneIndex)
131 , m_model(model)
132 , m_image(image)
133{}
134
137
142
147
148
150 QVariant newValue,
151 int parentRow,
152 int childRow,
153 StoryboardModel *model,
154 KUndo2Command *parent)
155 : KUndo2Command(kundo2_i18n("Edit Storyboard Child"), parent)
156 , m_oldValue(oldValue)
157 , m_newValue(newValue)
158 , m_parentRow(parentRow)
159 , m_childRow(childRow)
160 , m_model(model)
161{
162}
163
168
173
175{
176 const KisStoryboardChildEditCommand* storyboardChildCmd = dynamic_cast<const KisStoryboardChildEditCommand*>(other);
177
178 if (storyboardChildCmd) {
179 if (storyboardChildCmd->m_parentRow == m_parentRow && storyboardChildCmd->m_childRow == m_childRow) {
180 m_newValue = storyboardChildCmd->m_newValue;
181 return true;
182 }
183 }
184
185 return false;
186}
187
188
190 : KUndo2Command(parent)
191 , m_position(position + 1)
192 , m_duplicate(new StoryboardItem(*model->getData().at(position)))
193 , m_model(model)
194{
195 StoryboardItemSP original = model->getData().at(position);
196 QVariant sceneLength = model->data(model->index(position, 0), StoryboardModel::TotalSceneDurationInFrames);
197 m_duplicate->cloneChildrenFrom(*original);
198
199 ThumbnailData m_frameThumbnail = qvariant_cast<ThumbnailData>(m_duplicate->child(StoryboardItem::FrameNumber)->data());
200 m_frameThumbnail.frameNum = m_frameThumbnail.frameNum.toInt() + sceneLength.toInt();
201 m_duplicate->child(StoryboardItem::FrameNumber)->setData(QVariant::fromValue<ThumbnailData>(m_frameThumbnail));
202
204}
205
209
222
virtual void undo()
virtual void redo()
KisAddStoryboardCommand(int position, StoryboardItemSP item, StoryboardModel *model, KUndo2Command *parent=0)
QScopedPointer< KUndo2Command > m_keyframeCommands
QScopedPointer< KUndo2Command > m_addCommand
KisDuplicateStoryboardCommand(int position, StoryboardModel *model, KUndo2Command *parent=0)
void requestTimeSwitchNonGUI(int time, bool useUndo=false)
KisImageAnimationInterface * animationInterface() const
KisMoveStoryboardCommand(int from, int to, int count, StoryboardModel *model, KUndo2Command *parent=0)
KisRemoveStoryboardCommand(int position, StoryboardItemSP item, StoryboardModel *model, KUndo2Command *parent=0)
bool mergeWith(const KUndo2Command *other) override
KisStoryboardChildEditCommand(QVariant oldValue, QVariant newValue, int parentRow, int childRow, StoryboardModel *model, KUndo2Command *parent=0)
static KisTimeSpan infinite(int start)
KisVisualizeStoryboardCommand(int fromTime, int toSceneIndex, StoryboardModel *model, KisImageSP image, KUndo2Command *parent=0)
This class stores a list of StoryboardChild objects and provides functionality to manipulate the list...
@ 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.
The main storyboard model. This class manages a StoryboardItemList which is a list of StoryboardItem ...
void insertChildRows(int position, KUndo2Command *cmd=nullptr)
must be called after a first level index is inserted. Adds child nodes to the first level indices
int getFramesPerSecond() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void visualizeScene(const QModelIndex &index, bool useUndo=true)
StoryboardItemList getData()
bool removeItem(QModelIndex index, KUndo2Command *command=nullptr)
removes item, deletes keyframes within and shifts keyframe after the scene to fill in the gap
bool moveRowsImpl(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild, KUndo2Command *parentCMD=nullptr)
void createDuplicateKeyframes(const QModelIndex &index, KUndo2Command *cmd=nullptr)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
void shiftKeyframes(KisTimeSpan affected, int offset, KUndo2Command *cmd=nullptr)
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
KUndo2MagicString kundo2_i18n(const char *text)