]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Fix crash on clip deletion, fix issues with placeholder clips
[kdenlive] / src / projectlist.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
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                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #ifndef PROJECTLIST_H
22 #define PROJECTLIST_H
23
24 #include <QDomNodeList>
25 #include <QToolBar>
26 #include <QToolButton>
27 #include <QTreeWidget>
28 #include <QPainter>
29 #include <QItemDelegate>
30 #include <QUndoStack>
31 #include <QTimer>
32 #include <QApplication>
33
34 #include <KTreeWidgetSearchLine>
35 #include <KUrl>
36 #include <KIcon>
37
38 #ifdef NEPOMUK
39 #include <nepomuk/kratingpainter.h>
40 #include <nepomuk/resource.h>
41 #endif
42
43 #include "definitions.h"
44 #include "timecode.h"
45 #include "kdenlivesettings.h"
46 #include "folderprojectitem.h"
47 #include "subprojectitem.h"
48
49 namespace Mlt
50 {
51 class Producer;
52 };
53
54 class ProjectItem;
55 class ProjectListView;
56 class Render;
57 class KdenliveDoc;
58 class DocClipBase;
59
60 const int NameRole = Qt::UserRole;
61 const int DurationRole = NameRole + 1;
62 const int UsageRole = NameRole + 2;
63
64 class ItemDelegate: public QItemDelegate
65 {
66 public:
67     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
68     }
69
70     /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
71     }*/
72
73     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
74         if (index.column() == 0 && !index.data(DurationRole).isNull()) {
75             QRect r1 = option.rect;
76             painter->save();
77             if (option.state & (QStyle::State_Selected)) {
78                 painter->setPen(option.palette.color(QPalette::HighlightedText));
79                 painter->fillRect(r1, option.palette.highlight());
80             }
81             QStyleOptionViewItemV2 opt = setOptions(index, option);
82             QPixmap pixmap = decoration(opt, index.data(Qt::DecorationRole));
83             if ((index.flags() & (Qt::ItemIsDragEnabled)) == false) {
84                 KIcon icon("dialog-close");
85                 QPainter p(&pixmap);
86                 p.drawPixmap(1, 1, icon.pixmap(16, 16));
87                 p.end();
88             }
89             QRect decorationRect = pixmap.rect(); //QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect());
90             const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
91             decorationRect.moveTo(r1.topLeft() + QPoint(0, 1));
92             drawDecoration(painter, opt, decorationRect, pixmap);
93             int decoWidth = pixmap.width() + 2 * textMargin;
94
95             QFont font = painter->font();
96             font.setBold(true);
97             painter->setFont(font);
98             int mid = (int)((r1.height() / 2));
99             r1.adjust(decoWidth, 0, 0, -mid);
100             QRect r2 = option.rect;
101             r2.adjust(decoWidth, mid, 0, 0);
102             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
103             //painter->setPen(Qt::green);
104             font.setBold(false);
105             painter->setFont(font);
106             QString subText = index.data(DurationRole).toString();
107             int usage = index.data(UsageRole).toInt();
108             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
109             if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
110             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
111             painter->restore();
112         } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
113             if (index.data().toString().isEmpty()) {
114                 QItemDelegate::paint(painter, option, index);
115                 return;
116             }
117             QRect r1 = option.rect;
118             if (option.state & (QStyle::State_Selected)) {
119                 painter->fillRect(r1, option.palette.highlight());
120             }
121 #ifdef NEPOMUK
122             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
123 #endif
124         } else {
125             QItemDelegate::paint(painter, option, index);
126         }
127     }
128 };
129
130 class ProjectList : public QWidget
131 {
132     Q_OBJECT
133
134 public:
135     ProjectList(QWidget *parent = 0);
136     virtual ~ProjectList();
137
138     QDomElement producersList();
139     void setRenderer(Render *projectRender);
140     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
141     QByteArray headerInfo() const;
142     void setHeaderInfo(const QByteArray &state);
143     void setupMenu(QMenu *addMenu, QAction *defaultAction);
144     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
145     QString currentClipUrl() const;
146     KUrl::List getConditionalUrls(const QString &condition) const;
147     void reloadClipThumbnails();
148     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
149     void cleanup();
150     void trashUnusedClips();
151     QList <DocClipBase*> documentClipList() const;
152     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
153     void removeClipCut(const QString &id, int in, int out);
154     void focusTree() const;
155     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
156     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
157
158 public slots:
159     void setDocument(KdenliveDoc *doc);
160     void updateAllClips();
161     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
162     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
163     void slotAddClip(DocClipBase *clip, bool getProperties);
164     void slotDeleteClip(const QString &clipId);
165     void slotUpdateClip(const QString &id);
166     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
167     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
168     void slotRemoveInvalidClip(const QString &id, bool replace);
169     void slotSelectClip(const QString &ix);
170     void slotRemoveClip();
171     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
172     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
173     void slotResetProjectList();
174     void slotOpenClip();
175     void slotEditClip();
176     void slotReloadClip(const QString &id = QString());
177     void slotAddColorClip();
178     void regenerateTemplate(const QString &id);
179     void slotUpdateClipCut(QPoint p);
180     void slotAddClipCut(const QString &id, int in, int out);
181
182 private:
183     ProjectListView *m_listView;
184     Render *m_render;
185     Timecode m_timecode;
186     double m_fps;
187     QToolBar *m_toolbar;
188     QTimer m_queueTimer;
189     QMenu *m_menu;
190     QUndoStack *m_commandStack;
191     void selectItemById(const QString &clipId);
192     ProjectItem *getItemById(const QString &id);
193     QTreeWidgetItem *getAnyItemById(const QString &id);
194     FolderProjectItem *getFolderItemById(const QString &id);
195     QAction *m_editAction;
196     QAction *m_deleteAction;
197     QAction *m_openAction;
198     QAction *m_reloadAction;
199     QMenu *m_transcodeAction;
200     KdenliveDoc *m_doc;
201     ItemDelegate *m_listViewDelegate;
202     bool m_refreshed;
203     QToolButton *m_addButton;
204     QMap <QString, QDomElement> m_infoQueue;
205     QMap <QString, QDomElement> m_producerQueue;
206     void requestClipInfo(const QDomElement xml, const QString id);
207     QList <QString> m_thumbnailQueue;
208     void requestClipThumbnail(const QString id);
209     void deleteProjectFolder(QMap <QString, QString> map);
210     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
211     QStringList getGroup() const;
212     void regenerateTemplate(ProjectItem *clip);
213     void editClipSelection(QList<QTreeWidgetItem *> list);
214     void adjustTranscodeActions(ProjectItem *clip) const;
215
216 private slots:
217     void slotClipSelected();
218     void slotAddSlideshowClip();
219     void slotAddTitleClip();
220     void slotAddTitleTemplateClip();
221     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
222     void slotAddFolder();
223     /** This is triggered when a clip description has been modified */
224     void slotItemEdited(QTreeWidgetItem *item, int column);
225     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
226     void slotProcessNextClipInQueue();
227     void slotProcessNextThumbnail();
228     void slotCheckForEmptyQueue();
229     void slotPauseMonitor();
230     //void slotShowMenu(const QPoint &pos);
231
232 signals:
233     void clipSelected(DocClipBase *, QPoint zone = QPoint());
234     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
235     void receivedClipDuration(const QString &);
236     void showClipProperties(DocClipBase *);
237     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
238     void projectModified();
239     void loadingIsOver();
240     void displayMessage(const QString, int progress);
241     void clipNameChanged(const QString, const QString);
242     void refreshClip();
243 };
244
245 #endif