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