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