CuteLogger
Fast and simple logging solution for Qt based applications
playlistmodel.h
1 /*
2  * Copyright (c) 2012-2019 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.h>
23 #include <QStringList>
24 #include "mltcontroller.h"
25 #include "MltPlaylist.h"
26 
27 #define kDetailedMode "detailed"
28 #define kIconsMode "icons"
29 #define kTiledMode "tiled"
30 
31 class PlaylistModel : public QAbstractTableModel
32 {
33  Q_OBJECT
34 public:
35  enum ViewMode {
36  Invalid,
37  Detailed,
38  Tiled,
39  Icons,
40  };
41 
42  enum Columns {
43  COLUMN_INDEX = 0,
44  COLUMN_THUMBNAIL,
45  COLUMN_RESOURCE,
46  COLUMN_IN,
47  COLUMN_DURATION,
48  COLUMN_START,
49  COLUMN_DATE,
50  COLUMN_COUNT
51  };
52 
53  enum Fields {
54  FIELD_INDEX = Qt::UserRole,
55  FIELD_THUMBNAIL,
56  FIELD_RESOURCE,
57  FIELD_IN,
58  FIELD_DURATION,
59  FIELD_START,
60  FIELD_DATE,
61  };
62 
63  static const int THUMBNAIL_WIDTH = 80;
64  static const int THUMBNAIL_HEIGHT = 45;
65 
66  explicit PlaylistModel(QObject *parent = 0);
67  ~PlaylistModel();
68  int rowCount(const QModelIndex& parent = QModelIndex()) const;
69  int columnCount(const QModelIndex& parent = QModelIndex()) const;
70  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
71  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
72  Qt::DropActions supportedDropActions() const;
73  bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
74  bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
75  bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild);
76  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
77  Qt::ItemFlags flags(const QModelIndex &index) const;
78  QStringList mimeTypes() const;
79  QMimeData *mimeData(const QModelIndexList &indexes) const;
80  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
81  QModelIndex incrementIndex(const QModelIndex& index) const;
82  QModelIndex decrementIndex(const QModelIndex& index) const;
83  QModelIndex createIndex(int row, int column) const;
84  void createIfNeeded();
85  void showThumbnail(int row);
86  void refreshThumbnails();
87  Mlt::Playlist* playlist() { return m_playlist; }
88  void setPlaylist(Mlt::Playlist& playlist);
89  void setInOut(int row, int in, int out);
90 
91  ViewMode viewMode() const;
92  void setViewMode(ViewMode mode);
93 
94 signals:
95  void created();
96  void cleared();
97  void closed();
98  void modified();
99  void loaded();
100  void dropped(const QMimeData *data, int row);
101  void moveClip(int from, int to);
102  void inChanged(int in);
103  void outChanged(int out);
104 
105 public slots:
106  void clear();
107  void load();
108  void append(Mlt::Producer&, bool emitModified = true);
109  void insert(Mlt::Producer&, int row);
110  void remove(int row);
111  void update(int row, Mlt::Producer& producer);
112  void updateThumbnails(int row);
113  void appendBlank(int frames);
114  void insertBlank(int frames, int row);
115  void close();
116  void move(int from, int to);
117 
118 private:
119  Mlt::Playlist* m_playlist;
120  int m_dropRow;
121  ViewMode m_mode;
122  QList<int> m_rowsRemoved;
123 };
124 
125 #endif // PLAYLISTMODEL_H