]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
- Include frei0r.hueshift0r XML GUI
[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 <QStyledItemDelegate>
30 #include <QUndoStack>
31 #include <QTimer>
32 #include <QApplication>
33
34 #include <KTreeWidgetSearchLine>
35 #include <KUrl>
36 #include <KIcon>
37
38 #ifdef NEPOMUK
39 #include <nepomuk/kratingpainter.h>
40 #include <nepomuk/resource.h>
41 #endif
42
43 #include "definitions.h"
44 #include "timecode.h"
45 #include "kdenlivesettings.h"
46 #include "folderprojectitem.h"
47 #include "subprojectitem.h"
48
49 namespace Mlt
50 {
51 class Producer;
52 };
53
54 class ProjectItem;
55 class ProjectListView;
56 class Render;
57 class KdenliveDoc;
58 class DocClipBase;
59
60 const int NameRole = Qt::UserRole;
61 const int DurationRole = NameRole + 1;
62 const int UsageRole = NameRole + 2;
63
64 class ItemDelegate: public QStyledItemDelegate
65 {
66 public:
67     ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
68     }
69
70     /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
71     }*/
72
73     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
74         if (index.column() == 0 && !index.data(DurationRole).isNull()) {
75             QRect r1 = option.rect;
76             painter->save();
77             QStyleOptionViewItemV4 opt(option);
78             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
79             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
80
81             if (option.state & QStyle::State_Selected) {
82                 painter->setPen(option.palette.highlightedText().color());
83             }
84             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
85             QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
86             if ((index.flags() & (Qt::ItemIsDragEnabled)) == false) {
87                 KIcon icon("dialog-close");
88                 QPainter p(&pixmap);
89                 p.drawPixmap(1, 1, icon.pixmap(16, 16));
90                 p.end();
91             }
92
93             painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
94             int decoWidth = pixmap.width() + 2 * textMargin;
95
96             QFont font = painter->font();
97             font.setBold(true);
98             painter->setFont(font);
99             int mid = (int)((r1.height() / 2));
100             r1.adjust(decoWidth, 0, 0, -mid);
101             QRect r2 = option.rect;
102             r2.adjust(decoWidth, mid, 0, 0);
103             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
104             font.setBold(false);
105             painter->setFont(font);
106             QString subText = index.data(DurationRole).toString();
107             int usage = index.data(UsageRole).toInt();
108             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
109             if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
110             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
111             painter->restore();
112         } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
113             if (index.data().toString().isEmpty()) {
114                 QStyledItemDelegate::paint(painter, option, index);
115                 return;
116             }
117             QRect r1 = option.rect;
118             if (option.state & (QStyle::State_Selected)) {
119                 painter->fillRect(r1, option.palette.highlight());
120             }
121 #ifdef NEPOMUK
122             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
123 #endif
124         } else {
125             QStyledItemDelegate::paint(painter, option, index);
126         }
127     }
128 };
129
130 class ProjectList : public QWidget
131 {
132     Q_OBJECT
133
134 public:
135     ProjectList(QWidget *parent = 0);
136     virtual ~ProjectList();
137
138     QDomElement producersList();
139     void setRenderer(Render *projectRender);
140     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
141     QByteArray headerInfo() const;
142     void setHeaderInfo(const QByteArray &state);
143     void updateProjectFormat(Timecode t);
144     void setupMenu(QMenu *addMenu, QAction *defaultAction);
145     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
146     QString currentClipUrl() const;
147     KUrl::List getConditionalUrls(const QString &condition) const;
148     void reloadClipThumbnails();
149     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
150     void cleanup();
151     void trashUnusedClips();
152     QList <DocClipBase*> documentClipList() const;
153     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
154     void removeClipCut(const QString &id, int in, int out);
155     void focusTree() const;
156     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
157     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
158     bool hasMissingClips();
159     void deleteProjectFolder(QMap <QString, QString> map);
160     void selectItemById(const QString &clipId);
161
162 public slots:
163     void setDocument(KdenliveDoc *doc);
164     void updateAllClips();
165     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
166     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
167     void slotAddClip(DocClipBase *clip, bool getProperties);
168     void slotDeleteClip(const QString &clipId);
169     void slotUpdateClip(const QString &id);
170     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
171     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
172     void slotRemoveInvalidClip(const QString &id, bool replace);
173     void slotSelectClip(const QString &ix);
174     /** @brief Prepares removing the selected items. */
175     void slotRemoveClip();
176     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
177     /** @brief Adds, edits or deletes a folder item.
178     *
179     * This is triggered by AddFolderCommand and EditFolderCommand. */
180     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
181     void slotResetProjectList();
182     void slotOpenClip();
183     void slotEditClip();
184     void slotReloadClip(const QString &id = QString());
185     void slotAddColorClip();
186     void regenerateTemplate(const QString &id);
187     void slotUpdateClipCut(QPoint p);
188     void slotAddClipCut(const QString &id, int in, int out);
189
190 private:
191     ProjectListView *m_listView;
192     Render *m_render;
193     Timecode m_timecode;
194     double m_fps;
195     QToolBar *m_toolbar;
196     QTimer m_queueTimer;
197     QMenu *m_menu;
198     QUndoStack *m_commandStack;
199     ProjectItem *getItemById(const QString &id);
200     QTreeWidgetItem *getAnyItemById(const QString &id);
201     FolderProjectItem *getFolderItemById(const QString &id);
202     QAction *m_editAction;
203     QAction *m_deleteAction;
204     QAction *m_openAction;
205     QAction *m_reloadAction;
206     QMenu *m_transcodeAction;
207     KdenliveDoc *m_doc;
208     ItemDelegate *m_listViewDelegate;
209     bool m_refreshed;
210     QToolButton *m_addButton;
211     QMap <QString, QDomElement> m_infoQueue;
212     QMap <QString, QDomElement> m_producerQueue;
213     void requestClipInfo(const QDomElement xml, const QString id);
214     QList <QString> m_thumbnailQueue;
215     void requestClipThumbnail(const QString id);
216     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
217     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
218     QStringList getGroup() const;
219     void regenerateTemplate(ProjectItem *clip);
220     void editClipSelection(QList<QTreeWidgetItem *> list);
221     /** @brief Enables and disables transcode actions based on the selected clip's type. */
222     void adjustTranscodeActions(ProjectItem *clip) const;
223     /** @brief Sets the buttons enabled/disabled according to selected item. */
224     void updateButtons() const;
225
226 private slots:
227     void slotClipSelected();
228     void slotAddSlideshowClip();
229     void slotAddTitleClip();
230     void slotAddTitleTemplateClip();
231     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
232     * @param pos The position where the menu should pop up
233     * @param item The item for which the checks should be done */
234     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
235     /** @brief Creates an AddFolderCommand. */
236     void slotAddFolder();
237     /** @brief This is triggered when a clip description has been modified. */
238     void slotItemEdited(QTreeWidgetItem *item, int column);
239     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
240     void slotProcessNextClipInQueue();
241     void slotProcessNextThumbnail();
242     void slotCheckForEmptyQueue();
243     void slotPauseMonitor();
244     /** A clip was modified externally, change icon so that user knows it */
245     void slotModifiedClip(const QString &id);
246     void slotMissingClip(const QString &id);
247     void slotAvailableClip(const QString &id);
248     //void slotShowMenu(const QPoint &pos);
249
250 signals:
251     void clipSelected(DocClipBase *, QPoint zone = QPoint());
252     void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
253     void receivedClipDuration(const QString &);
254     void showClipProperties(DocClipBase *);
255     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
256     void projectModified();
257     void loadingIsOver();
258     void displayMessage(const QString, int progress);
259     void clipNameChanged(const QString, const QString);
260     void clipNeedsReload(const QString&, bool);
261     void refreshClip();
262     void updateRenderStatus();
263     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
264     void findInTimeline(const QString &clipId);
265 };
266
267 #endif