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 __TIMELINE_FRAMES_MODEL_H 20 #define __TIMELINE_FRAMES_MODEL_H 21 22 23 #include <QScopedPointer> 24 #include <QIcon> 25 26 #include "kritaanimationdocker_export.h" 27 #include "kis_node_model.h" 28 #include "kis_types.h" 29 #include "kis_node.h" 30 #include "timeline_node_list_keeper.h" 31 32 class KisNodeDummy; 33 class KisDummiesFacadeBase; 34 class KisAnimationPlayer; 35 class KisNodeDisplayModeAdapter; 36 37 38 class KRITAANIMATIONDOCKER_EXPORT TimelineFramesModel : public TimelineNodeListKeeper::ModelWithExternalNotifications 39 { 40 Q_OBJECT 41 42 public: 43 enum MimeCopyPolicy { 44 UndefinedPolicy = 0, 45 MoveFramesPolicy, 46 CopyFramesPolicy 47 }; 48 49 public: 50 TimelineFramesModel(QObject *parent); 51 ~TimelineFramesModel() override; 52 53 bool hasConnectionToCanvas() const; 54 55 void setDummiesFacade(KisDummiesFacadeBase *dummiesFacade, 56 KisImageSP image, 57 KisNodeDisplayModeAdapter *displayModeAdapter); 58 59 bool canDropFrameData(const QMimeData *data, const QModelIndex &index); 60 bool insertOtherLayer(int index, int dstRow); 61 int activeLayerRow() const; 62 63 bool createFrame(const QModelIndex &dstIndex); 64 bool copyFrame(const QModelIndex &dstIndex); 65 66 bool insertFrames(int dstColumn, const QList<int> &dstRows, int count, int timing = 1); 67 68 bool insertHoldFrames(const QModelIndexList &selectedIndexes, int count); 69 70 QString audioChannelFileName() const; 71 void setAudioChannelFileName(const QString &fileName); 72 73 bool isAudioMuted() const; 74 void setAudioMuted(bool value); 75 76 qreal audioVolume() const; 77 void setAudioVolume(qreal value); 78 79 void setFullClipRangeStart(int column); 80 void setFullClipRangeEnd(int column); 81 82 void setLastClickedIndex(const QModelIndex &index); 83 84 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 85 QVariant data(const QModelIndex &index, int role) const override; 86 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 87 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 88 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override; 89 90 Qt::DropActions supportedDragActions() const override; 91 Qt::DropActions supportedDropActions() const override; 92 QStringList mimeTypes() const override; 93 QMimeData *mimeData(const QModelIndexList &indexes) const override; 94 QMimeData *mimeDataExtended(const QModelIndexList &indexes, const QModelIndex &baseIndex, MimeCopyPolicy copyPolicy) const; 95 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 96 97 bool dropMimeDataExtended(const QMimeData *data, Qt::DropAction action, const QModelIndex &parent, bool *dataMoved = 0); 98 99 Qt::ItemFlags flags(const QModelIndex &index) const override; 100 101 bool insertRows(int row, int count, const QModelIndex &parent) override; 102 bool removeRows(int row, int count, const QModelIndex &parent) override; 103 104 enum ItemDataRole 105 { 106 ActiveLayerRole = KisTimeBasedItemModel::UserRole, 107 TimelinePropertiesRole, 108 OtherLayersRole, 109 LayerUsedInTimelineRole, 110 FrameColorLabelIndexRole 111 }; 112 113 // metatype is added by the original implementation 114 typedef KisBaseNode::Property Property; 115 typedef KisBaseNode::PropertyList PropertyList; 116 117 typedef TimelineNodeListKeeper::OtherLayer OtherLayer; 118 typedef TimelineNodeListKeeper::OtherLayersList OtherLayersList; 119 120 121 struct NodeManipulationInterface { ~NodeManipulationInterfaceNodeManipulationInterface122 virtual ~NodeManipulationInterface() {} 123 virtual KisLayerSP addPaintLayer() const = 0; 124 virtual void removeNode(KisNodeSP node) const = 0; 125 virtual bool setNodeProperties(KisNodeSP node, KisImageSP image, KisBaseNode::PropertyList properties) const = 0; 126 }; 127 128 /** 129 * NOTE: the model has an ownership over the interface, that is it'll 130 * be deleted automatically later 131 */ 132 void setNodeManipulationInterface(NodeManipulationInterface *iface); 133 KisNodeSP nodeAt(QModelIndex index) const override; 134 135 protected: 136 QMap<QString, KisKeyframeChannel *> channelsAt(QModelIndex index) const override; 137 138 private Q_SLOTS: 139 void slotDummyChanged(KisNodeDummy *dummy); 140 void slotImageContentChanged(); 141 void processUpdateQueue(); 142 143 public Q_SLOTS: 144 void slotCurrentNodeChanged(KisNodeSP node); 145 146 Q_SIGNALS: 147 void requestCurrentNodeChanged(KisNodeSP node); 148 void sigInfiniteTimelineUpdateNeeded(); 149 void sigAudioChannelChanged(); 150 void sigEnsureRowVisible(int row); 151 152 private: 153 struct Private; 154 const QScopedPointer<Private> m_d; 155 }; 156 157 #endif /* __TIMELINE_FRAMES_MODEL_H */ 158