1 /* 2 * Copyright (c) 2015 Dmitry Kazakov <dimula73@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __KIS_ANIMATION_UTILS_H 20 #define __KIS_ANIMATION_UTILS_H 21 22 #include "kis_types.h" 23 24 #include <boost/operators.hpp> 25 #include <QModelIndexList> 26 27 #include <kritaanimationdocker_export.h> 28 29 30 namespace KisAnimationUtils 31 { 32 KUndo2Command* createKeyframeCommand(KisImageSP image, KisNodeSP node, const QString &channelId, int time, bool copy, KUndo2Command *parentCommand = 0); 33 void createKeyframeLazy(KisImageSP image, KisNodeSP node, const QString &channel, int time, bool copy); 34 35 struct KRITAANIMATIONDOCKER_EXPORT FrameItem : public boost::equality_comparable<FrameItem> 36 { FrameItemFrameItem37 FrameItem() : time(-1) {} FrameItemFrameItem38 FrameItem(KisNodeSP _node, const QString &_channel, int _time) : node(_node), channel(_channel), time(_time) {} 39 40 bool operator==(const FrameItem &rhs) const { 41 return rhs.node == node && rhs.channel == channel && rhs.time == time; 42 } 43 44 KisNodeSP node; 45 QString channel; 46 int time; 47 }; 48 49 KRITAANIMATIONDOCKER_EXPORT QDebug operator<<(QDebug dbg, const FrameItem &item); 50 qHash(const FrameItem & item)51 inline uint qHash(const FrameItem &item) 52 { 53 return ::qHash(item.node.data()) + ::qHash(item.channel) + ::qHash(item.time); 54 } 55 56 57 typedef QVector<FrameItem> FrameItemList; 58 typedef std::pair<FrameItem, FrameItem> FrameMovePair; 59 typedef QVector<FrameMovePair> FrameMovePairList; 60 61 62 void removeKeyframes(KisImageSP image, const FrameItemList &frames); 63 void removeKeyframe(KisImageSP image, KisNodeSP node, const QString &channel, int time); 64 65 void sortPointsForSafeMove(QModelIndexList *points, const QPoint &offset); 66 67 KUndo2Command* createMoveKeyframesCommand(const FrameItemList &srcFrames, const FrameItemList &dstFrames, 68 bool copy, bool moveEmpty, KUndo2Command *parentCommand = 0); 69 70 71 /** 72 * @brief implements safe moves of the frames (even if there are cycling move dependencies) 73 * @param movePairs the jobs for the moves 74 * @param copy shows if the frames should be copied or not 75 * @param moveEmpty allows an empty frame to replace a populated one 76 * @param parentCommand the command that should be a parent of the created command 77 * @return a created undo command 78 */ 79 KRITAANIMATIONDOCKER_EXPORT 80 KUndo2Command* createMoveKeyframesCommand(const FrameMovePairList &movePairs, 81 bool copy, bool moveEmptyFrames, KUndo2Command *parentCommand = 0); 82 83 bool supportsContentFrames(KisNodeSP node); 84 85 extern const QString lazyFrameCreationActionName; 86 extern const QString dropFramesActionName; 87 88 extern const QString newLayerActionName; 89 extern const QString addExistingLayerActionName; 90 extern const QString removeLayerActionName; 91 92 extern const QString addOpacityKeyframeActionName; 93 extern const QString addTransformKeyframeActionName; 94 extern const QString removeOpacityKeyframeActionName; 95 extern const QString removeTransformKeyframeActionName; 96 }; 97 98 99 #endif /* __KIS_ANIMATION_UTILS_H */ 100