]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Cleanup physical clip deletion:
[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             if (option.state & (QStyle::State_Selected)) 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     void trashUnusedClips();
138     QList <DocClipBase*> documentClipList() const;
139
140 public slots:
141     void setDocument(KdenliveDoc *doc);
142     void updateAllClips();
143     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
144     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
145     void slotAddClip(DocClipBase *clip, bool getProperties);
146     void slotDeleteClip(const QString &clipId);
147     void slotUpdateClip(const QString &id);
148     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
149     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
150     void slotRemoveInvalidClip(const QString &id, bool replace);
151     void slotSelectClip(const QString &ix);
152     void slotRemoveClip();
153     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
154     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
155     void slotResetProjectList();
156     void slotOpenClip();
157     void slotEditClip();
158     void slotReloadClip(const QString &id = QString());
159     void slotAddColorClip();
160     void regenerateTemplate(const QString &id);
161
162 private:
163     ProjectListView *m_listView;
164     Render *m_render;
165     Timecode m_timecode;
166     double m_fps;
167     QToolBar *m_toolbar;
168     QTimer m_queueTimer;
169     QMenu *m_menu;
170     QUndoStack *m_commandStack;
171     void selectItemById(const QString &clipId);
172     ProjectItem *getItemById(const QString &id);
173     ProjectItem *getFolderItemById(const QString &id);
174     QAction *m_editAction;
175     QAction *m_deleteAction;
176     QAction *m_openAction;
177     QAction *m_reloadAction;
178     QMenu *m_transcodeAction;
179     KdenliveDoc *m_doc;
180     ProjectItem *m_selectedItem;
181     ItemDelegate *m_listViewDelegate;
182     bool m_refreshed;
183     QToolButton *m_addButton;
184     QMap <QString, QDomElement> m_infoQueue;
185     QMap <QString, QDomElement> m_producerQueue;
186     void requestClipInfo(const QDomElement xml, const QString id);
187     QList <QString> m_thumbnailQueue;
188     void requestClipThumbnail(const QString id);
189     void deleteProjectFolder(QMap <QString, QString> map);
190     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
191     QStringList getGroup() const;
192     void regenerateTemplate(ProjectItem *clip);
193
194 private slots:
195     void slotClipSelected();
196     void slotAddSlideshowClip();
197     void slotAddTitleClip();
198     void slotAddTitleTemplateClip();
199     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
200     void slotAddFolder();
201     /** This is triggered when a clip description has been modified */
202     void slotItemEdited(QTreeWidgetItem *item, int column);
203     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
204     void slotProcessNextClipInQueue();
205     void slotProcessNextThumbnail();
206     void slotCheckForEmptyQueue();
207     void slotPauseMonitor();
208     //void slotShowMenu(const QPoint &pos);
209
210 signals:
211     void clipSelected(DocClipBase *);
212     void getFileProperties(const QDomElement, const QString &, bool);
213     void receivedClipDuration(const QString &);
214     void showClipProperties(DocClipBase *);
215     void projectModified();
216     void loadingIsOver();
217     void displayMessage(const QString, int progress);
218     void clipNameChanged(const QString, const QString);
219     void refreshClip();
220 };
221
222 #endif