CuteLogger
Fast and simple logging solution for Qt based applications
playlistmodel.h
1 /*
2  * Copyright (c) 2012 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef PLAYLISTMODEL_H
20 #define PLAYLISTMODEL_H
21 
22 #include <QAbstractTableModel>
23 #include <qmimedata.h>
24 #include <QStringList>
25 #include "mltcontroller.h"
26 #include "MltPlaylist.h"
27 
28 #define kDetailedMode "detailed"
29 #define kIconsMode "icons"
30 #define kTiledMode "tiled"
31 
32 class PlaylistModel : public QAbstractTableModel
33 {
34  Q_OBJECT
35 public:
36  enum ViewMode {
37  Invalid,
38  Detailed,
39  Tiled,
40  Icons,
41  };
42 
43  enum Columns {
44  COLUMN_INDEX = 0,
45  COLUMN_THUMBNAIL,
46  COLUMN_RESOURCE,
47  COLUMN_IN,
48  COLUMN_DURATION,
49  COLUMN_START,
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  };
61 
62  static const int THUMBNAIL_WIDTH = 80;
63  static const int THUMBNAIL_HEIGHT = 45;
64 
65  explicit PlaylistModel(QObject *parent = 0);
66  ~PlaylistModel();
67  int rowCount(const QModelIndex& parent = QModelIndex()) const;
68  int columnCount(const QModelIndex& parent = QModelIndex()) const;
69  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
70  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
71  Qt::DropActions supportedDropActions() const;
72  bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
73  bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
74  bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild);
75  Qt::ItemFlags flags(const QModelIndex &index) const;
76  QStringList mimeTypes() const;
77  QMimeData *mimeData(const QModelIndexList &indexes) const;
78  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
79  QModelIndex incrementIndex(const QModelIndex& index) const;
80  QModelIndex decrementIndex(const QModelIndex& index) const;
81  QModelIndex createIndex(int row, int column) const;
82  void createIfNeeded();
83  void showThumbnail(int row);
84  void refreshThumbnails();
85  Mlt::Playlist* playlist() { return m_playlist; }
86  void setPlaylist(Mlt::Playlist& playlist);
87 
88  ViewMode viewMode() const;
89  void setViewMode(ViewMode mode);
90 
91 signals:
92  void created();
93  void cleared();
94  void closed();
95  void modified();
96  void loaded();
97  void dropped(const QMimeData *data, int row);
98  void moveClip(int from, int to);
99 
100 public slots:
101  void clear();
102  void load();
103  void append(Mlt::Producer&, bool emitModified = true);
104  void insert(Mlt::Producer&, int row);
105  void remove(int row);
106  void update(int row, Mlt::Producer& producer);
107  void appendBlank(int frames);
108  void insertBlank(int frames, int row);
109  void close();
110  void move(int from, int to);
111 
112 private:
113  Mlt::Playlist* m_playlist;
114  int m_dropRow;
115  ViewMode m_mode;
116 };
117 
118 #endif // PLAYLISTMODEL_H