]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
- Fix split audio with locked audio tracks
[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 public slots:
163     void setDocument(KdenliveDoc *doc);
164     void updateAllClips();
165     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
166     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
167     void slotAddClip(DocClipBase *clip, bool getProperties);
168     void slotDeleteClip(const QString &clipId);
169     void slotUpdateClip(const QString &id);
170     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
171     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
172     void slotRemoveInvalidClip(const QString &id, bool replace);
173     void slotSelectClip(const QString &ix);
174     /** @brief Prepares removing the selected items. */
175     void slotRemoveClip();
176     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
177
178     /** @brief Adds, edits or deletes a folder item.
179     *
180     * This is triggered by AddFolderCommand and EditFolderCommand. */
181     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
182     void slotResetProjectList();
183     void slotOpenClip();
184     void slotEditClip();
185     void slotReloadClip(const QString &id = QString());
186     void slotAddColorClip();
187     void regenerateTemplate(const QString &id);
188     void slotUpdateClipCut(QPoint p);
189     void slotAddClipCut(const QString &id, int in, int out);
190
191 private:
192     ProjectListView *m_listView;
193     Render *m_render;
194     Timecode m_timecode;
195     double m_fps;
196     QToolBar *m_toolbar;
197     QTimer m_queueTimer;
198     QMenu *m_menu;
199     QUndoStack *m_commandStack;
200     ProjectItem *getItemById(const QString &id);
201     QTreeWidgetItem *getAnyItemById(const QString &id);
202     FolderProjectItem *getFolderItemById(const QString &id);
203     QAction *m_editAction;
204     QAction *m_deleteAction;
205     QAction *m_openAction;
206     QAction *m_reloadAction;
207     QMenu *m_transcodeAction;
208     KdenliveDoc *m_doc;
209     ItemDelegate *m_listViewDelegate;
210     bool m_refreshed;
211     QToolButton *m_addButton;
212     QMap <QString, QDomElement> m_infoQueue;
213     QMap <QString, QDomElement> m_producerQueue;
214     void requestClipInfo(const QDomElement xml, const QString id);
215     QList <QString> m_thumbnailQueue;
216     void requestClipThumbnail(const QString id);
217     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
218     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
219     QStringList getGroup() const;
220     void regenerateTemplate(ProjectItem *clip);
221     void editClipSelection(QList<QTreeWidgetItem *> list);
222     /** @brief Enables and disables transcode actions based on the selected clip's type. */
223     void adjustTranscodeActions(ProjectItem *clip) const;
224     /** @brief Sets the buttons enabled/disabled according to selected item. */
225     void updateButtons() const;
226
227 private slots:
228     void slotClipSelected();
229     void slotAddSlideshowClip();
230     void slotAddTitleClip();
231     void slotAddTitleTemplateClip();
232
233     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
234     * @param pos The position where the menu should pop up
235     * @param item The item for which the checks should be done */
236     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
237     /** @brief Creates an AddFolderCommand. */
238     void slotAddFolder();
239     /** @brief This is triggered when a clip description has been modified. */
240     void slotItemEdited(QTreeWidgetItem *item, int column);
241     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
242     void slotProcessNextClipInQueue();
243     void slotProcessNextThumbnail();
244     void slotCheckForEmptyQueue();
245     void slotPauseMonitor();
246     /** A clip was modified externally, change icon so that user knows it */
247     void slotModifiedClip(const QString &id);
248     void slotMissingClip(const QString &id);
249     void slotAvailableClip(const QString &id);
250     //void slotShowMenu(const QPoint &pos);
251
252 signals:
253     void clipSelected(DocClipBase *, QPoint zone = QPoint());
254     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
255     void receivedClipDuration(const QString &);
256     void showClipProperties(DocClipBase *);
257     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
258     void projectModified();
259     void loadingIsOver();
260     void displayMessage(const QString, int progress);
261     void clipNameChanged(const QString, const QString);
262     void clipNeedsReload(const QString&, bool);
263     void refreshClip();
264     void updateRenderStatus();
265     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
266     void findInTimeline(const QString &clipId);
267 };
268
269 #endif