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