]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Ask to change profile if first clip does not match project profile:
[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             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                 QStyledItemDelegate::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             QStyledItemDelegate::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 updateProjectFormat(Timecode t);
144     void setupMenu(QMenu *addMenu, QAction *defaultAction);
145     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
146     QString currentClipUrl() const;
147     KUrl::List getConditionalUrls(const QString &condition) const;
148     void reloadClipThumbnails();
149     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
150     void cleanup();
151     void trashUnusedClips();
152     QList <DocClipBase*> documentClipList() const;
153     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
154     void removeClipCut(const QString &id, int in, int out);
155     void focusTree() const;
156     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
157     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
158     bool hasMissingClips();
159     void deleteProjectFolder(QMap <QString, QString> map);
160     void selectItemById(const QString &clipId);
161
162     /** @brief Returns a string list of all supported mime extensions. */
163     static QString getExtensions();
164
165 public slots:
166     void setDocument(KdenliveDoc *doc);
167     void updateAllClips();
168     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
169     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
170     void slotAddClip(DocClipBase *clip, bool getProperties);
171     void slotDeleteClip(const QString &clipId);
172     void slotUpdateClip(const QString &id);
173     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
174     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
175     void slotRemoveInvalidClip(const QString &id, bool replace);
176     void slotSelectClip(const QString &ix);
177
178     /** @brief Prepares removing the selected items. */
179     void slotRemoveClip();
180     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
181
182     /** @brief Adds, edits or deletes a folder item.
183     *
184     * This is triggered by AddFolderCommand and EditFolderCommand. */
185     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
186     void slotResetProjectList();
187     void slotOpenClip();
188     void slotEditClip();
189     void slotReloadClip(const QString &id = QString());
190
191     /** @brief Shows dialog for setting up a color clip. */
192     void slotAddColorClip();
193     void regenerateTemplate(const QString &id);
194     void slotUpdateClipCut(QPoint p);
195     void slotAddClipCut(const QString &id, int in, int out);
196     void slotForceProcessing(const QString &id);
197
198 private:
199     ProjectListView *m_listView;
200     Render *m_render;
201     Timecode m_timecode;
202     double m_fps;
203     QToolBar *m_toolbar;
204     QTimer m_queueTimer;
205     QMenu *m_menu;
206     QUndoStack *m_commandStack;
207     ProjectItem *getItemById(const QString &id);
208     QTreeWidgetItem *getAnyItemById(const QString &id);
209     FolderProjectItem *getFolderItemById(const QString &id);
210     QAction *m_editAction;
211     QAction *m_deleteAction;
212     QAction *m_openAction;
213     QAction *m_reloadAction;
214     QMenu *m_transcodeAction;
215     KdenliveDoc *m_doc;
216     ItemDelegate *m_listViewDelegate;
217     bool m_refreshed;
218     QToolButton *m_addButton;
219     QMap <QString, QDomElement> m_infoQueue;
220     QMap <QString, QDomElement> m_producerQueue;
221     void requestClipInfo(const QDomElement xml, const QString id);
222     QList <QString> m_thumbnailQueue;
223     void requestClipThumbnail(const QString id);
224
225     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
226     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
227
228     /** @brief Gets the selected folder (or the folder of the selected item). */
229     QStringList getGroup() const;
230     void regenerateTemplate(ProjectItem *clip);
231     void editClipSelection(QList<QTreeWidgetItem *> list);
232
233     /** @brief Enables and disables transcode actions based on the selected clip's type. */
234     void adjustTranscodeActions(ProjectItem *clip) const;
235
236     /** @brief Sets the buttons enabled/disabled according to selected item. */
237     void updateButtons() const;
238
239 private slots:
240     void slotClipSelected();
241     void slotAddSlideshowClip();
242     void slotAddTitleClip();
243     void slotAddTitleTemplateClip();
244
245     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
246     * @param pos The position where the menu should pop up
247     * @param item The item for which the checks should be done */
248     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
249
250     /** @brief Creates an AddFolderCommand. */
251     void slotAddFolder();
252
253     /** @brief This is triggered when a clip description has been modified. */
254     void slotItemEdited(QTreeWidgetItem *item, int column);
255     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
256     void slotProcessNextClipInQueue();
257     void slotProcessNextThumbnail();
258     void slotCheckForEmptyQueue();
259     void slotPauseMonitor();
260     /** A clip was modified externally, change icon so that user knows it */
261     void slotModifiedClip(const QString &id);
262     void slotMissingClip(const QString &id);
263     void slotAvailableClip(const QString &id);
264     //void slotShowMenu(const QPoint &pos);
265
266 signals:
267     void clipSelected(DocClipBase *, QPoint zone = QPoint());
268     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
269     void receivedClipDuration(const QString &);
270     void showClipProperties(DocClipBase *);
271     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
272     void projectModified();
273     void loadingIsOver();
274     void displayMessage(const QString, int progress);
275     void clipNameChanged(const QString, const QString);
276     void clipNeedsReload(const QString&, bool);
277     void refreshClip();
278     void updateRenderStatus();
279     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
280     void findInTimeline(const QString &clipId);
281     /** @brief Request a profile change for current document. */
282     void updateProfile(const QString &);
283 };
284
285 #endif