]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
User can now enable / disable proxy for each clip
[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
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 QStyledItemDelegate
65 {
66 public:
67     ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(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             QStyleOptionViewItemV4 opt(option);
78             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
79             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
80
81             if (option.state & QStyle::State_Selected) {
82                 painter->setPen(option.palette.highlightedText().color());
83             }
84             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
85             QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
86             if ((index.flags() & (Qt::ItemIsDragEnabled)) == false) {
87                 KIcon icon("dialog-close");
88                 QPainter p(&pixmap);
89                 p.drawPixmap(1, 1, icon.pixmap(16, 16));
90                 p.end();
91             }
92
93             painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
94             int decoWidth = pixmap.width() + 2 * textMargin;
95
96             QFont font = painter->font();
97             font.setBold(true);
98             painter->setFont(font);
99             int mid = (int)((r1.height() / 2));
100             r1.adjust(decoWidth, 0, 0, -mid);
101             QRect r2 = option.rect;
102             r2.adjust(decoWidth, mid, 0, 0);
103             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
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             QRectF bounding;
111             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
112             
113             int proxy = index.data(Qt::UserRole + 5).toInt();
114             if (proxy > 0) {
115                 QRectF txtBounding;
116                 QString proxyText;
117                 QBrush brush;
118                 QColor color;
119                 if (proxy == 1) {
120                     proxyText = i18n("Generating proxy...");
121                     brush = option.palette.highlight();
122                     color = option.palette.color(QPalette::HighlightedText);
123                 }
124                 else {
125                     proxyText = i18n("Proxy");
126                     brush = option.palette.mid();
127                     color = option.palette.color(QPalette::WindowText);
128                 }
129                 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
130                 painter->setPen(Qt::NoPen);
131                 painter->setBrush(brush);
132                 painter->drawRoundedRect(txtBounding, 2, 2);
133                 painter->setPen(option.palette.highlightedText().color());
134                 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
135             }
136             
137             painter->restore();
138         } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
139             if (index.data().toString().isEmpty()) {
140                 QStyledItemDelegate::paint(painter, option, index);
141                 return;
142             }
143             QRect r1 = option.rect;
144             if (option.state & (QStyle::State_Selected)) {
145                 painter->fillRect(r1, option.palette.highlight());
146             }
147 #ifdef NEPOMUK
148             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
149 #endif
150         } else {
151             QStyledItemDelegate::paint(painter, option, index);
152         }
153     }
154 };
155
156 class ProjectList : public QWidget
157 {
158     Q_OBJECT
159
160 public:
161     ProjectList(QWidget *parent = 0);
162     virtual ~ProjectList();
163
164     QDomElement producersList();
165     void setRenderer(Render *projectRender);
166     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
167     QByteArray headerInfo() const;
168     void setHeaderInfo(const QByteArray &state);
169     void updateProjectFormat(Timecode t);
170     void setupMenu(QMenu *addMenu, QAction *defaultAction);
171     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
172     QString currentClipUrl() const;
173     KUrl::List getConditionalUrls(const QString &condition) const;
174     void reloadClipThumbnails();
175     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
176     void cleanup();
177     void trashUnusedClips();
178     QList <DocClipBase*> documentClipList() const;
179     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
180     void removeClipCut(const QString &id, int in, int out);
181     void focusTree() const;
182     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
183     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
184     bool hasMissingClips();
185     void deleteProjectFolder(QMap <QString, QString> map);
186     void selectItemById(const QString &clipId);
187
188     /** @brief Returns a string list of all supported mime extensions. */
189     static QString getExtensions();
190     /** @brief Returns a list of urls containing original and proxy urls. */
191     QMap <QString, QString> getProxies();
192     /** @brief Enable / disable proxies. */
193     void updateProxyConfig();
194
195 public slots:
196     void setDocument(KdenliveDoc *doc);
197     void updateAllClips();
198     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
199     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
200     void slotAddClip(DocClipBase *clip, bool getProperties);
201     void slotDeleteClip(const QString &clipId);
202     void slotUpdateClip(const QString &id);
203     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
204     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
205     void slotRemoveInvalidClip(const QString &id, bool replace);
206     void slotSelectClip(const QString &ix);
207
208     /** @brief Prepares removing the selected items. */
209     void slotRemoveClip();
210     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
211
212     /** @brief Adds, edits or deletes a folder item.
213     *
214     * This is triggered by AddFolderCommand and EditFolderCommand. */
215     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
216     void slotResetProjectList();
217     void slotOpenClip();
218     void slotEditClip();
219     void slotReloadClip(const QString &id = QString());
220
221     /** @brief Shows dialog for setting up a color clip. */
222     void slotAddColorClip();
223     void regenerateTemplate(const QString &id);
224     void slotUpdateClipCut(QPoint p);
225     void slotAddClipCut(const QString &id, int in, int out);
226     void slotForceProcessing(const QString &id);
227
228 private:
229     ProjectListView *m_listView;
230     Render *m_render;
231     Timecode m_timecode;
232     double m_fps;
233     QTimer m_queueTimer;
234     QMenu *m_menu;
235     QUndoStack *m_commandStack;
236     ProjectItem *getItemById(const QString &id);
237     QTreeWidgetItem *getAnyItemById(const QString &id);
238     FolderProjectItem *getFolderItemById(const QString &id);
239     QAction *m_openAction;
240     QAction *m_reloadAction;
241     QMenu *m_transcodeAction;
242     KdenliveDoc *m_doc;
243     ItemDelegate *m_listViewDelegate;
244     bool m_refreshed;
245     QToolButton *m_addButton;
246     QToolButton *m_deleteButton;
247     QToolButton *m_editButton;
248     QMap <QString, QDomElement> m_infoQueue;
249     QMap <QString, QDomElement> m_producerQueue;
250     void requestClipInfo(const QDomElement xml, const QString id);
251     QList <QString> m_thumbnailQueue;
252     QAction *m_proxyAction;
253     void requestClipThumbnail(const QString id);
254
255     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
256     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
257
258     /** @brief Gets the selected folder (or the folder of the selected item). */
259     QStringList getGroup() const;
260     void regenerateTemplate(ProjectItem *clip);
261     void editClipSelection(QList<QTreeWidgetItem *> list);
262
263     /** @brief Enables and disables transcode actions based on the selected clip's type. */
264     void adjustTranscodeActions(ProjectItem *clip) const;
265     /** @brief Enables and disables proxy action based on the selected clip. */
266     void adjustProxyActions(ProjectItem *clip) const;
267
268     /** @brief Sets the buttons enabled/disabled according to selected item. */
269     void updateButtons() const;
270
271 private slots:
272     void slotClipSelected();
273     void slotAddSlideshowClip();
274     void slotAddTitleClip();
275     void slotAddTitleTemplateClip();
276
277     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
278     * @param pos The position where the menu should pop up
279     * @param item The item for which the checks should be done */
280     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
281
282     /** @brief Creates an AddFolderCommand. */
283     void slotAddFolder();
284
285     /** @brief This is triggered when a clip description has been modified. */
286     void slotItemEdited(QTreeWidgetItem *item, int column);
287     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
288     void slotProcessNextClipInQueue();
289     void slotProcessNextThumbnail();
290     void slotCheckForEmptyQueue();
291     void slotPauseMonitor();
292     /** A clip was modified externally, change icon so that user knows it */
293     void slotModifiedClip(const QString &id);
294     void slotMissingClip(const QString &id);
295     void slotAvailableClip(const QString &id);
296     /** @brief Try to find a matching profile for given item. */
297     bool adjustProjectProfileToItem(ProjectItem *item = NULL);
298     /** @brief Add a sequence from the stopmotion widget. */
299     void slotAddOrUpdateSequence(const QString frameName);
300     /** @brief A proxy clip was created, update display. */
301     void slotGotProxy(const QString id, bool success);
302     /** @brief Enable / disable proxy for current clip. */
303     void slotProxyCurrentItem(bool doProxy);
304
305 signals:
306     void clipSelected(DocClipBase *, QPoint zone = QPoint());
307     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
308     void receivedClipDuration(const QString &);
309     void showClipProperties(DocClipBase *);
310     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
311     void projectModified();
312     void loadingIsOver();
313     void displayMessage(const QString, int progress);
314     void clipNameChanged(const QString, const QString);
315     void clipNeedsReload(const QString&, bool);
316     void refreshClip();
317     void updateRenderStatus();
318     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
319     void findInTimeline(const QString &clipId);
320     /** @brief Request a profile change for current document. */
321     void updateProfile(const QString &);
322 };
323
324 #endif
325