1 /*
2  *  Copyright (c) 2016 Jouni Pentikäinen <joupent@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_TIME_BASED_ITEM_MODEL_H
20 #define _KIS_TIME_BASED_ITEM_MODEL_H
21 
22 #include <QAbstractTableModel>
23 #include <QList>
24 #include <KisKineticScroller.h>
25 
26 #include "kritaanimationdocker_export.h"
27 
28 #include "kis_types.h"
29 
30 class KisTimeRange;
31 class KisAnimationPlayer;
32 class KisKeyframeChannel;
33 
34 class KRITAANIMATIONDOCKER_EXPORT KisTimeBasedItemModel : public QAbstractTableModel
35 {
36     Q_OBJECT
37 
38 public:
39     KisTimeBasedItemModel(QObject *parent);
40     ~KisTimeBasedItemModel() override;
41 
42     void setImage(KisImageWSP image);
43     void setFrameCache(KisAnimationFrameCacheSP cache);
44     void setAnimationPlayer(KisAnimationPlayer *player);
45 
46     void setLastVisibleFrame(int time);
47 
48     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
49 
50     QVariant data(const QModelIndex &index, int role) const override;
51     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
52     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
53     bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override;
54 
55     bool removeFrames(const QModelIndexList &indexes);
56 
57     bool removeFramesAndOffset(QModelIndexList indicesToRemove);
58 
59     bool mirrorFrames(QModelIndexList indexes);
60 
61     void setScrubState(bool active);
62     void scrubTo(int time, bool preview);
63 
64     void setPlaybackRange(const KisTimeRange &range);
65     bool isPlaybackActive() const;
66     int currentTime() const;
67 
68     enum ItemDataRole
69     {
70         ActiveFrameRole = Qt::UserRole + 101,
71         FrameExistsRole,
72         SpecialKeyframeExists,
73         FrameCachedRole,
74         FrameEditableRole,
75         FramesPerSecondRole,
76         UserRole,
77         FrameHasContent // is it an empty frame with nothing in it?
78     };
79 
80 protected:
81     virtual KisNodeSP nodeAt(QModelIndex index) const = 0;
82     virtual QMap<QString, KisKeyframeChannel *> channelsAt(QModelIndex index) const = 0;
83     KisImageWSP image() const;
84 
85     KUndo2Command* createOffsetFramesCommand(QModelIndexList srcIndexes, const QPoint &offset,
86                                              bool copyFrames, bool moveEmptyFrames,
87                                              KUndo2Command *parentCommand = 0);
88 
89 
90 protected Q_SLOTS:
91     void slotCurrentTimeChanged(int time);
92 
93 private Q_SLOTS:
94     void slotFramerateChanged();
95     void slotCacheChanged();
96     void slotInternalScrubPreviewRequested(int time);
97 
98     void slotPlaybackFrameChanged();
99     void slotPlaybackStopped();
100 
101 private:
102     struct Private;
103     const QScopedPointer<Private> m_d;
104 };
105 
106 #endif
107