CuteLogger
Fast and simple logging solution for Qt based applications
playlistmodel.h
1 /*
2  * Copyright (c) 2012-2024 Meltytech, LLC
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef PLAYLISTMODEL_H
19 #define PLAYLISTMODEL_H
20 
21 #include <QAbstractTableModel>
22 #include <QMimeData>
23 #include <QStringList>
24 #include "MltPlaylist.h"
25 
26 
27 
28 class PlaylistModel : public QAbstractTableModel
29 {
30  Q_OBJECT
31 public:
32  enum ViewMode {
33  Invalid,
34  Detailed,
35  Tiled,
36  Icons,
37  };
38 
39  enum MediaType {
40  Video,
41  Image,
42  Audio,
43  Other,
44  Pending
45  };
46 
47  enum Columns {
48  COLUMN_INDEX = 0,
49  COLUMN_THUMBNAIL,
50  COLUMN_RESOURCE,
51  COLUMN_IN,
52  COLUMN_DURATION,
53  COLUMN_START,
54  COLUMN_DATE,
55  COLUMN_MEDIA_TYPE,
56  COLUMN_COMMENT,
57  COLUMN_BIN,
58  COLUMN_COUNT
59  };
60 
61  enum Fields {
62  FIELD_INDEX = Qt::UserRole,
63  FIELD_THUMBNAIL,
64  FIELD_RESOURCE,
65  FIELD_IN,
66  FIELD_DURATION,
67  FIELD_START,
68  FIELD_DATE,
69  FIELD_MEDIA_TYPE,
70  FIELD_MEDIA_TYPE_ENUM,
71  FIELD_COMMENT,
72  FIELD_BIN
73  };
74 
75  static const int THUMBNAIL_WIDTH = 80;
76  static const int THUMBNAIL_HEIGHT = 45;
77 
78  explicit PlaylistModel(QObject *parent = 0);
79  ~PlaylistModel();
80  int rowCount(const QModelIndex &parent = QModelIndex()) const;
81  int columnCount(const QModelIndex &parent = QModelIndex()) const;
82  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
83  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
84  Qt::DropActions supportedDropActions() const;
85  bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
86  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
87  bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
88  const QModelIndex &destinationParent, int destinationChild);
89  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
90  Qt::ItemFlags flags(const QModelIndex &index) const;
91  QStringList mimeTypes() const;
92  QMimeData *mimeData(const QModelIndexList &indexes) const;
93  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
94  const QModelIndex &parent);
95  QModelIndex createIndex(int row, int column) const;
96  void createIfNeeded();
97  void showThumbnail(int row);
98  void refreshThumbnails();
99  Mlt::Playlist *playlist()
100  {
101  return m_playlist;
102  }
103  void setPlaylist(Mlt::Playlist &playlist);
104  void setInOut(int row, int in, int out);
105 
106  ViewMode viewMode() const;
107  void setViewMode(ViewMode mode);
108  void setBin(int row, const QString &name);
109  void renameBin(const QString &bin, const QString &newName = QString());
110 
111 signals:
112  void created();
113  void cleared();
114  void closed();
115  void modified();
116  void loaded();
117  void dropped(const QMimeData *data, int row);
118  void moveClip(int from, int to);
119  void inChanged(int in);
120  void outChanged(int out);
121  void removing(Mlt::Service *service);
122 
123 public slots:
124  void clear();
125  void load();
126  void append(Mlt::Producer &, bool emitModified = true);
127  void insert(Mlt::Producer &, int row);
128  void remove(int row);
129  void update(int row, Mlt::Producer &producer, bool copyFilters = false);
130  void updateThumbnails(int row);
131  void appendBlank(int frames);
132  void insertBlank(int frames, int row);
133  void close();
134  void move(int from, int to);
135 
136 private:
137  Mlt::Playlist *m_playlist;
138  int m_dropRow;
139  ViewMode m_mode;
140  QList<int> m_rowsRemoved;
141 
142 private slots:
143  void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
144 };
145 
146 #endif // PLAYLISTMODEL_H