]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Add option to remove unused clips from project tree:
[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
33 #include <KTreeWidgetSearchLine>
34 #include <KUrl>
35 #include <nepomuk/kratingpainter.h>
36 #include <nepomuk/resource.h>
37
38 #include "definitions.h"
39 #include "timecode.h"
40 #include "kdenlivesettings.h"
41
42 namespace Mlt
43 {
44 class Producer;
45 };
46
47 class ProjectItem;
48 class ProjectListView;
49 class Render;
50 class KdenliveDoc;
51 class DocClipBase;
52
53 const int NameRole = Qt::UserRole;
54 const int DurationRole = NameRole + 1;
55 const int UsageRole = NameRole + 2;
56
57 class ItemDelegate: public QItemDelegate
58 {
59 public:
60     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
61     }
62     /*
63     static_cast<ProjectItem *>( index.internalPointer() );
64
65     void expand()
66     {
67       QWidget *w = new QWidget;
68       QVBoxLayout *layout = new QVBoxLayout;
69       layout->addWidget( new KColorButton(w));
70       w->setLayout( layout );
71       extendItem(w,
72     }
73     */
74     void drawFocus ( QPainter *, const QStyleOptionViewItem &, const QRect & ) const {
75     }
76     
77     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
78         if (index.column() == 1) {
79             QRect r1 = option.rect;
80             painter->save();
81             if (option.state & (QStyle::State_Selected)) {
82                 painter->setPen(option.palette.color(QPalette::HighlightedText));
83                 painter->fillRect(r1, option.palette.highlight());
84             }
85             QFont font = painter->font();
86             font.setBold(true);
87             painter->setFont(font);
88             int mid = (int)((r1.height() / 2));
89             r1.adjust(2, 0, 0, -mid);
90             QRect r2 = option.rect;
91             r2.adjust(2, mid, 0, 0);
92             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
93             //painter->setPen(Qt::green);
94             font.setBold(false);
95             painter->setFont(font);
96             QString subText = index.data(DurationRole).toString();
97             int usage = index.data(UsageRole).toInt();
98             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
99             painter->setPen(option.palette.color(QPalette::Mid));
100             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
101             painter->restore();
102         } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
103             if (index.data().toString().isEmpty()) {
104                 QItemDelegate::paint(painter, option, index);
105                 return;
106             }
107             QRect r1 = option.rect;
108             if (option.state & (QStyle::State_Selected)) {
109                 painter->fillRect(r1, option.palette.highlight());
110             }
111             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
112         } else {
113             QItemDelegate::paint(painter, option, index);
114         }
115     }
116 };
117
118 class ProjectList : public QWidget
119 {
120     Q_OBJECT
121
122 public:
123     ProjectList(QWidget *parent = 0);
124     virtual ~ProjectList();
125
126     QDomElement producersList();
127     void setRenderer(Render *projectRender);
128     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
129     QByteArray headerInfo() const;
130     void setHeaderInfo(const QByteArray &state);
131     void setupMenu(QMenu *addMenu, QAction *defaultAction);
132     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
133     QString currentClipUrl() const;
134     void reloadClipThumbnails();
135     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
136     void cleanup();
137
138 public slots:
139     void setDocument(KdenliveDoc *doc);
140     void updateAllClips();
141     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
142     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
143     void slotAddClip(DocClipBase *clip, bool getProperties);
144     void slotDeleteClip(const QString &clipId);
145     void slotUpdateClip(const QString &id);
146     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
147     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
148     void slotRemoveInvalidClip(const QString &id, bool replace);
149     void slotSelectClip(const QString &ix);
150     void slotRemoveClip();
151     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
152     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
153     void slotResetProjectList();
154     void slotOpenClip();
155     void slotEditClip();
156     void slotReloadClip(const QString &id = QString());
157     void slotAddColorClip();
158     void regenerateTemplate(const QString &id);
159
160 private:
161     ProjectListView *m_listView;
162     Render *m_render;
163     Timecode m_timecode;
164     double m_fps;
165     QToolBar *m_toolbar;
166     QTimer m_queueTimer;
167     QMenu *m_menu;
168     QUndoStack *m_commandStack;
169     void selectItemById(const QString &clipId);
170     ProjectItem *getItemById(const QString &id);
171     ProjectItem *getFolderItemById(const QString &id);
172     QAction *m_editAction;
173     QAction *m_deleteAction;
174     QAction *m_openAction;
175     QAction *m_reloadAction;
176     QMenu *m_transcodeAction;
177     KdenliveDoc *m_doc;
178     ProjectItem *m_selectedItem;
179     ItemDelegate *m_listViewDelegate;
180     bool m_refreshed;
181     QToolButton *m_addButton;
182     QMap <QString, QDomElement> m_infoQueue;
183     QMap <QString, QDomElement> m_producerQueue;
184     void requestClipInfo(const QDomElement xml, const QString id);
185     QList <QString> m_thumbnailQueue;
186     void requestClipThumbnail(const QString id);
187     void deleteProjectFolder(QMap <QString, QString> map);
188     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
189     QStringList getGroup() const;
190     void regenerateTemplate(ProjectItem *clip);
191
192 private slots:
193     void slotClipSelected();
194     void slotAddSlideshowClip();
195     void slotAddTitleClip();
196     void slotAddTitleTemplateClip();
197     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
198     void slotAddFolder();
199     /** This is triggered when a clip description has been modified */
200     void slotItemEdited(QTreeWidgetItem *item, int column);
201     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
202     void slotProcessNextClipInQueue();
203     void slotProcessNextThumbnail();
204     void slotCheckForEmptyQueue();
205     void slotPauseMonitor();
206     //void slotShowMenu(const QPoint &pos);
207
208 signals:
209     void clipSelected(DocClipBase *);
210     void getFileProperties(const QDomElement, const QString &, bool);
211     void receivedClipDuration(const QString &);
212     void showClipProperties(DocClipBase *);
213     void projectModified();
214     void loadingIsOver();
215     void displayMessage(const QString, MessageType);
216     void clipNameChanged(const QString, const QString);
217     void refreshClip();
218 };
219
220 #endif