]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
a39e84e9e42fffb6d0d1cf0e5cbbc9145e3977c9
[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 <QStyledItemDelegate>
30 #include <QUndoStack>
31 #include <QTimer>
32 #include <QApplication>
33 #include <QFuture>
34
35 #include <KTreeWidgetSearchLine>
36 #include <KUrl>
37 #include <KIcon>
38
39 #ifdef NEPOMUK
40 #include <nepomuk/kratingpainter.h>
41 #include <nepomuk/resource.h>
42 #endif
43
44 #include "definitions.h"
45 #include "timecode.h"
46 #include "kdenlivesettings.h"
47 #include "folderprojectitem.h"
48 #include "subprojectitem.h"
49
50 namespace Mlt
51 {
52 class Producer;
53 };
54
55 class ProjectItem;
56 class ProjectListView;
57 class Render;
58 class KdenliveDoc;
59 class DocClipBase;
60
61 const int NameRole = Qt::UserRole;
62 const int DurationRole = NameRole + 1;
63 const int UsageRole = NameRole + 2;
64
65 class ItemDelegate: public QStyledItemDelegate
66 {
67 public:
68     ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
69     }
70
71     /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
72     }*/
73
74     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
75         if (index.column() == 0 && !index.data(DurationRole).isNull()) {
76             QRect r1 = option.rect;
77             painter->save();
78             QStyleOptionViewItemV4 opt(option);
79             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
80             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
81
82             if (option.state & QStyle::State_Selected) {
83                 painter->setPen(option.palette.highlightedText().color());
84             }
85             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
86             QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
87             if ((index.flags() & (Qt::ItemIsDragEnabled)) == false) {
88                 KIcon icon("dialog-close");
89                 QPainter p(&pixmap);
90                 p.drawPixmap(1, 1, icon.pixmap(16, 16));
91                 p.end();
92             }
93
94             painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
95             int decoWidth = pixmap.width() + 2 * textMargin;
96
97             QFont font = painter->font();
98             font.setBold(true);
99             painter->setFont(font);
100             int mid = (int)((r1.height() / 2));
101             r1.adjust(decoWidth, 0, 0, -mid);
102             QRect r2 = option.rect;
103             r2.adjust(decoWidth, mid, 0, 0);
104             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
105             font.setBold(false);
106             painter->setFont(font);
107             QString subText = index.data(DurationRole).toString();
108             int usage = index.data(UsageRole).toInt();
109             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
110             if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
111             QRectF bounding;
112             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
113             
114             int proxy = index.data(Qt::UserRole + 5).toInt();
115             if (proxy > 0) {
116                 QRectF txtBounding;
117                 QString proxyText;
118                 QBrush brush;
119                 QColor color;
120                 if (proxy == PROXYDONE) {
121                     proxyText = i18n("Proxy");
122                     brush = option.palette.mid();
123                     color = option.palette.color(QPalette::WindowText);
124                 }
125                 else {
126                     if (proxy == CREATINGPROXY) proxyText = i18n("Generating proxy...");
127                     else if (proxy == PROXYWAITING) proxyText = i18n("Waiting proxy...");
128                     else if (proxy == PROXYCRASHED) proxyText = i18n("proxy crashed");
129                     brush = option.palette.highlight();
130                     color = option.palette.color(QPalette::HighlightedText);
131                 }
132                
133                 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
134                 painter->setPen(Qt::NoPen);
135                 painter->setBrush(brush);
136                 painter->drawRoundedRect(txtBounding, 2, 2);
137                 painter->setPen(option.palette.highlightedText().color());
138                 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
139             }
140             
141             painter->restore();
142         } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
143             if (index.data().toString().isEmpty()) {
144                 QStyledItemDelegate::paint(painter, option, index);
145                 return;
146             }
147             QRect r1 = option.rect;
148             if (option.state & (QStyle::State_Selected)) {
149                 painter->fillRect(r1, option.palette.highlight());
150             }
151 #ifdef NEPOMUK
152             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
153 #endif
154         } else {
155             QStyledItemDelegate::paint(painter, option, index);
156         }
157     }
158 };
159
160 class ProjectList : public QWidget
161 {
162     Q_OBJECT
163
164 public:
165     ProjectList(QWidget *parent = 0);
166     virtual ~ProjectList();
167
168     QDomElement producersList();
169     void setRenderer(Render *projectRender);
170     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
171     QByteArray headerInfo() const;
172     void setHeaderInfo(const QByteArray &state);
173     void updateProjectFormat(Timecode t);
174     void setupMenu(QMenu *addMenu, QAction *defaultAction);
175     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
176     QString currentClipUrl() const;
177     KUrl::List getConditionalUrls(const QString &condition) const;
178     void reloadClipThumbnails();
179     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
180     void cleanup();
181     void trashUnusedClips();
182     QList <DocClipBase*> documentClipList() const;
183     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
184     void removeClipCut(const QString &id, int in, int out);
185     void focusTree() const;
186     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
187     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
188     bool hasMissingClips();
189     void deleteProjectFolder(QMap <QString, QString> map);
190     void selectItemById(const QString &clipId);
191
192     /** @brief Returns a string list of all supported mime extensions. */
193     static QString getExtensions();
194     /** @brief Returns a list of urls containing original and proxy urls. */
195     QMap <QString, QString> getProxies();
196     /** @brief Enable / disable proxies. */
197     void updateProxyConfig();
198     /** @brief Get a property from the document. */
199     QString getDocumentProperty(const QString &key) const;
200     
201     /** @brief Does this project allow proxies. */
202     bool useProxy() const;
203     /** @brief Should we automatically create proxy clips for newly added clips. */
204     bool generateProxy() const;
205     /** @brief Should we automatically create proxy clips for newly added clips. */
206     bool generateImageProxy() const;
207
208 public slots:
209     void setDocument(KdenliveDoc *doc);
210     void updateAllClips();
211     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
212     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip);
213     void slotAddClip(DocClipBase *clip, bool getProperties);
214     void slotDeleteClip(const QString &clipId);
215     void slotUpdateClip(const QString &id);
216     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
217     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
218     void slotRemoveInvalidClip(const QString &id, bool replace);
219     void slotRemoveInvalidProxy(const QString &id);
220     void slotSelectClip(const QString &ix);
221
222     /** @brief Prepares removing the selected items. */
223     void slotRemoveClip();
224     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
225
226     /** @brief Adds, edits or deletes a folder item.
227     *
228     * This is triggered by AddFolderCommand and EditFolderCommand. */
229     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
230     void slotResetProjectList();
231     void slotOpenClip();
232     void slotEditClip();
233     void slotReloadClip(const QString &id = QString());
234
235     /** @brief Shows dialog for setting up a color clip. */
236     void slotAddColorClip();
237     void regenerateTemplate(const QString &id);
238     void slotUpdateClipCut(QPoint p);
239     void slotAddClipCut(const QString &id, int in, int out);
240     void slotForceProcessing(const QString &id);
241
242 private:
243     ProjectListView *m_listView;
244     Render *m_render;
245     Timecode m_timecode;
246     double m_fps;
247     QMenu *m_menu;
248     QFuture<void> m_queueRunner;
249     QUndoStack *m_commandStack;
250     ProjectItem *getItemById(const QString &id);
251     QTreeWidgetItem *getAnyItemById(const QString &id);
252     FolderProjectItem *getFolderItemById(const QString &id);
253     QAction *m_openAction;
254     QAction *m_reloadAction;
255     QMenu *m_transcodeAction;
256     KdenliveDoc *m_doc;
257     ItemDelegate *m_listViewDelegate;
258     bool m_refreshed;
259     QToolButton *m_addButton;
260     QToolButton *m_deleteButton;
261     QToolButton *m_editButton;
262     QMap <QString, QDomElement> m_infoQueue;
263     QMap <QString, QDomElement> m_producerQueue;
264     void requestClipInfo(const QDomElement xml, const QString id);
265     QList <QString> m_thumbnailQueue;
266     QAction *m_proxyAction;
267     QStringList m_processingClips;
268     /** @brief Holds a list of ids for the clips that need to be proxied. */
269     QStringList m_proxyList;
270     /** @brief Holds a list of proxy clip that should be aborted. */
271     QStringList m_abortProxyId;
272     
273     void requestClipThumbnail(const QString id);
274
275     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
276     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
277
278     /** @brief Gets the selected folder (or the folder of the selected item). */
279     QStringList getGroup() const;
280     void regenerateTemplate(ProjectItem *clip);
281     void editClipSelection(QList<QTreeWidgetItem *> list);
282
283     /** @brief Enables and disables transcode actions based on the selected clip's type. */
284     void adjustTranscodeActions(ProjectItem *clip) const;
285     /** @brief Enables and disables proxy action based on the selected clip. */
286     void adjustProxyActions(ProjectItem *clip) const;
287
288     /** @brief Sets the buttons enabled/disabled according to selected item. */
289     void updateButtons() const;
290
291     /** @brief Set the Proxy status on a clip. 
292      * @param item The clip item to set status
293      * @param status The proxy status (see definitions.h) */
294     void setProxyStatus(const QString id, PROXYSTATUS status);
295     void setProxyStatus(ProjectItem *item, PROXYSTATUS status);
296
297     void monitorItemEditing(bool enable);
298
299 private slots:
300     void slotClipSelected();
301     void slotAddSlideshowClip();
302     void slotAddTitleClip();
303     void slotAddTitleTemplateClip();
304
305     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
306     * @param pos The position where the menu should pop up
307     * @param item The item for which the checks should be done */
308     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
309
310     /** @brief Creates an AddFolderCommand. */
311     void slotAddFolder();
312
313     /** @brief This is triggered when a clip description has been modified. */
314     void slotItemEdited(QTreeWidgetItem *item, int column);
315     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
316     void slotProcessNextClipInQueue();
317     void slotProcessNextThumbnail();
318     void slotCheckForEmptyQueue();
319     void slotPauseMonitor();
320     /** A clip was modified externally, change icon so that user knows it */
321     void slotModifiedClip(const QString &id);
322     void slotMissingClip(const QString &id);
323     void slotAvailableClip(const QString &id);
324     /** @brief Try to find a matching profile for given item. */
325     bool adjustProjectProfileToItem(ProjectItem *item = NULL);
326     /** @brief Add a sequence from the stopmotion widget. */
327     void slotAddOrUpdateSequence(const QString frameName);
328     /** @brief A proxy clip was created, update display. */
329     void slotGotProxy(const QString &id);
330     /** @brief Enable / disable proxy for current clip. */
331     void slotProxyCurrentItem(bool doProxy);
332     /** @brief Put clip in the proxy waiting list. */
333     void slotCreateProxy(const QString id, bool createProducer = true);
334     /** @brief Stop creation of this clip's proxy. */
335     void slotAbortProxy(const QString id);
336     /** @brief Start creation of proxy clip. */
337     void slotGenerateProxy(const QString id);
338
339 signals:
340     void clipSelected(DocClipBase *, QPoint zone = QPoint());
341     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool, bool);
342     void receivedClipDuration(const QString &);
343     void showClipProperties(DocClipBase *);
344     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
345     void projectModified();
346     void loadingIsOver();
347     void displayMessage(const QString, int progress);
348     void clipNameChanged(const QString, const QString);
349     void clipNeedsReload(const QString&, bool);
350     /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
351      *  @param id: The clip's id string
352      *  @param resetThumbs Should we recreate the timeline thumbnails. */
353     void refreshClip(const QString &id, bool resetThumbs);
354     void updateRenderStatus();
355     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
356     void findInTimeline(const QString &clipId);
357     /** @brief Request a profile change for current document. */
358     void updateProfile(const QString &);
359     void processNextThumbnail();
360 };
361
362 #endif
363