Krita Source Code Documentation
Loading...
Searching...
No Matches
StoryboardModel.h
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#ifndef STORYBOARD_MODEL
7#define STORYBOARD_MODEL
8
9#include "StoryboardItem.h"
10#include "CommentModel.h"
11
12#include <QAbstractListModel>
13#include <QItemSelection>
14
16#include "kis_idle_watcher.h"
17#include <kritastoryboarddocker_export.h>
18#include <kis_image.h>
20
21class StoryboardView;
22class KisTimeSpan;
24class KUndo2Command;
25
32class KRITASTORYBOARDDOCKER_EXPORT StoryboardModel : public QAbstractItemModel
33{
34 Q_OBJECT
35
36public:
38 TotalSceneDurationInFrames = Qt::UserRole + 1,
39 TotalSceneDurationInSeconds = Qt::UserRole + 2,
40 };
41
43 public:
45 : m_model(model)
46 , m_originalLock(!model->m_reorderingKeyframes) {
47 m_model->m_reorderingKeyframes = true;
48 }
49
51 m_model->m_reorderingKeyframes = !m_originalLock;
52 }
53
54 private:
56 bool m_originalLock = false;
57 };
58
59 StoryboardModel(QObject *parent);
60 ~StoryboardModel() override;
61
62 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
63 QModelIndex parent(const QModelIndex &index) const override;
64
65 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
66 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
67
68 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
69 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
70
78 bool setCommentScrollData(const QModelIndex & index, const QVariant & value);
79
87 bool setThumbnailPixmapData(const QModelIndex & parentIndex, const KisPaintDeviceSP & dev);
88
96 bool updateDurationData(const QModelIndex & parentIndex);
97
98 Qt::ItemFlags flags(const QModelIndex &index) const override;
99
100 //for removing and inserting rows
101 bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
102 bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex())override;
103 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
104 const QModelIndex &destinationParent, int destinationChild) override;
105
106 //for drag and drop
107 QStringList mimeTypes() const override;
108 QMimeData *mimeData(const QModelIndexList &indexes) const override;
109 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
110 Qt::DropActions supportedDropActions() const override;
111 Qt::DropActions supportedDragActions() const override;
112
113 //these function access the value from the comment model
120 int visibleCommentCount() const;
121
126 int totalCommentCount();
127
133 int visibleCommentsUpto(QModelIndex index) const;
134
143 void setCommentModel(StoryboardCommentModel *commentModel);
144
152 StoryboardComment getComment(int row) const;
153
154 void setFreeze(bool);
155 bool isFrozen() const;
156 void setLocked(bool);
157 bool isLocked() const;
158 int getFramesPerSecond() const;
159 void setView(StoryboardView *view);
160 void setImage(KisImageWSP image);
161
171 QModelIndex indexFromFrame(int frame, bool framePerfect = true) const;
172
179 QModelIndex lastIndexBeforeFrame(int frame) const;
180
187 QModelIndexList affectedIndexes(KisTimeSpan range) const;
188
194 int nextKeyframeGlobal(int keyframeTime) const;
195
201 int lastKeyframeWithin(QModelIndex index);
202
208 void reorderKeyframes();
209
217 bool changeSceneHoldLength(int oldDuration, QModelIndex itemIndex);
218
225 bool insertItem(QModelIndex index, bool after);
226
233 bool removeItem(QModelIndex index, KUndo2Command *command = nullptr);
234
235
240 void resetData(StoryboardItemList list);
241
245 StoryboardItemList getData();
246
247 void pushUndoCommand(KUndo2Command *command);
248
249 void shiftKeyframes(KisTimeSpan affected, int offset, KUndo2Command *cmd = nullptr);
250
251 int lastKeyframeGlobal() const;
252 void slotUpdateThumbnailsForItems(QModelIndexList indices);
253
259 void insertChildRows(int position, KUndo2Command* cmd = nullptr);
260
265 void insertChildRows(int position, StoryboardItemSP item);
266
267 void visualizeScene(const QModelIndex& index, bool useUndo = true);
268
269 void createDuplicateKeyframes(const QModelIndex& index, KUndo2Command* cmd = nullptr);
270 void createBlankKeyframes(const QModelIndex& index, KUndo2Command* cmd = nullptr);
271
272private:
273 // For now, board is structured as a tree, with each board element being the top level
274 // and storyboard components (numbers, comments, etc.) being children/leaves.
275 inline bool isValidBoard(const QModelIndex &index) const {return index.isValid() && !index.parent().isValid();}
276
277 bool moveRowsImpl(const QModelIndex &sourceParent, int sourceRow, int count,
278 const QModelIndex &destinationParent, int destinationChild, KUndo2Command *parentCMD = nullptr);
279
280private Q_SLOTS:
285 void slotCurrentFrameChanged(int frameId);
286 void slotKeyframeAdded(const KisKeyframeChannel *channel, int time);
287 void slotKeyframeRemoved(const KisKeyframeChannel *channel, int time);
288 void slotNodeRemoved(KisNodeSP node);
289
290 void slotFramerateChanged();
291
297 void slotUpdateThumbnailForFrame(int frame, bool delay = true);
298
302 void slotUpdateThumbnails();
303
309 void slotFrameRenderCompleted(int frame, KisPaintDeviceSP dev);
310
314 void slotFrameRenderCancelled(int frame);
315
316 void slotCommentDataChanged();
317 void slotCommentRowInserted(const QModelIndex, int, int);
318 void slotCommentRowRemoved(const QModelIndex, int, int);
319 void slotCommentRowMoved(const QModelIndex &sourceParent, int sourceRow, int count,
320 const QModelIndex &destinationParent, int destinationChild);
321
322
323public Q_SLOTS:
324 void slotSetActiveNode(KisNodeSP);
325
326Q_SIGNALS:
333
334private:
336
339 StoryboardCommentModel *m_commentModel {0};
340 bool m_freezeKeyframePositions {false};
341 bool m_lockBoards {false};
342 bool m_reorderingKeyframes {false};
343 int m_lastScene {0};
346 StoryboardView *m_view {0};
350};
351
352#endif
float value(const T *src, size_t ch)
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
This class maintains queues of dirty frames sorted in the order of proximity to the last changed fram...
KeyframeReorderLock(StoryboardModel *model)
The main storyboard model. This class manages a StoryboardItemList which is a list of StoryboardItem ...
void sigStoryboardItemListChanged()
This signal is emitted whenever m_items is changed. it is used to keep the StoryboardItemList in KisD...
KisIdleWatcher m_imageIdleWatcher
KisNodeWSP m_activeNode
bool isValidBoard(const QModelIndex &index) const
QVector< StoryboardComment > m_commentList
KisImageWSP m_image
KisSignalCompressor m_renderSchedulingCompressor
StoryboardItemList m_items