File indexing completed on 2024-06-23 04:26:14
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Jouni Pentikäinen <joupent@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _KIS_ANIMATION_CURVES_MODEL_H 0008 #define _KIS_ANIMATION_CURVES_MODEL_H 0009 0010 #include <QScopedPointer> 0011 #include <QIcon> 0012 #include <QAbstractItemModel> 0013 0014 #include "KisTimeBasedItemModel.h" 0015 #include "kis_types.h" 0016 #include "kundo2command.h" 0017 0018 class KisScalarKeyframeChannel; 0019 0020 class KisAnimationCurve { 0021 public: 0022 KisAnimationCurve(KisScalarKeyframeChannel *channel, QColor color); 0023 KisScalarKeyframeChannel *channel() const; 0024 QColor color() const; 0025 0026 void setVisible(bool visible); 0027 bool visible() const; 0028 0029 private: 0030 struct Private; 0031 const QScopedPointer<Private> m_d; 0032 }; 0033 0034 class KisAnimCurvesModel : public KisTimeBasedItemModel 0035 { 0036 Q_OBJECT 0037 public: 0038 KisAnimCurvesModel(QObject *parent); 0039 ~KisAnimCurvesModel() override; 0040 0041 bool hasConnectionToCanvas() const; 0042 0043 KisAnimationCurve *addCurve(KisScalarKeyframeChannel *channel); 0044 void removeCurve(KisAnimationCurve *curve); 0045 void setCurveVisible(KisAnimationCurve *curve, bool visible); 0046 0047 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0048 QVariant data(const QModelIndex &index, int role) const override; 0049 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0050 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0051 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override; 0052 0053 /** 0054 * Begins a block of commands. The following calls to setData will be grouped to a single undo step. 0055 * Note: MUST be followed by a call to endCommand(). 0056 */ 0057 void beginCommand(const KUndo2MagicString &text); 0058 void endCommand(); 0059 0060 bool adjustKeyframes(const QModelIndexList &indexes, int timeOffset, qreal valueOffset); 0061 0062 enum ItemDataRole 0063 { 0064 ScalarValueRole = KisTimeBasedItemModel::UserRole + 101, 0065 InterpolationModeRole, 0066 TangentsModeRole, 0067 LeftTangentRole, 0068 RightTangentRole, 0069 CurveColorRole, 0070 CurveVisibleRole, 0071 PreviousKeyframeTime, 0072 NextKeyframeTime, 0073 ChannelIdentifier, 0074 ChannelLimits 0075 }; 0076 0077 Q_SIGNALS: 0078 void dataAdded(const QModelIndex& index); 0079 0080 protected: 0081 KisNodeSP nodeAt(QModelIndex index) const override; 0082 QMap<QString, KisKeyframeChannel *> channelsAt(QModelIndex index) const override; 0083 KisKeyframeChannel* channelByID(QModelIndex index, const QString &id) const override; 0084 0085 private Q_SLOTS: 0086 void slotKeyframeChanged(const KisKeyframeChannel *channel, int time); 0087 void slotKeyframeAdded(const KisKeyframeChannel *channel, int time); 0088 0089 private: 0090 struct Private; 0091 const QScopedPointer<Private> m_d; 0092 }; 0093 0094 // Used to return a range as a QVariant (see KisAnimationCurvesModel::data) 0095 typedef QPair<qreal,qreal> ChannelLimitsMetatype; 0096 Q_DECLARE_METATYPE(ChannelLimitsMetatype); 0097 0098 #endif