1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
24 #include <QDomNodeList>
26 #include <QToolButton>
27 #include <QTreeWidget>
29 #include <QStyledItemDelegate>
32 #include <QApplication>
34 #include <KTreeWidgetSearchLine>
39 #include <nepomuk/kratingpainter.h>
40 #include <nepomuk/resource.h>
43 #include "definitions.h"
45 #include "kdenlivesettings.h"
46 #include "folderprojectitem.h"
47 #include "subprojectitem.h"
55 class ProjectListView;
60 const int NameRole = Qt::UserRole;
61 const int DurationRole = NameRole + 1;
62 const int UsageRole = NameRole + 2;
64 class ItemDelegate: public QStyledItemDelegate
67 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
70 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
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;
77 QStyleOptionViewItemV4 opt(option);
78 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
79 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
81 if (option.state & QStyle::State_Selected) {
82 painter->setPen(option.palette.highlightedText().color());
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");
89 p.drawPixmap(1, 1, icon.pixmap(16, 16));
93 painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
94 int decoWidth = pixmap.width() + 2 * textMargin;
96 QFont font = painter->font();
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());
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);
112 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
113 if (index.data().toString().isEmpty()) {
114 QStyledItemDelegate::paint(painter, option, index);
117 QRect r1 = option.rect;
118 if (option.state & (QStyle::State_Selected)) {
119 painter->fillRect(r1, option.palette.highlight());
122 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
125 QStyledItemDelegate::paint(painter, option, index);
130 class ProjectList : public QWidget
135 ProjectList(QWidget *parent = 0);
136 virtual ~ProjectList();
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);
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);
162 /** @brief Returns a string list of all supported mime extensions. */
163 static QString getExtensions();
166 void setDocument(KdenliveDoc *doc);
167 void updateAllClips();
168 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
169 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
170 void slotAddClip(DocClipBase *clip, bool getProperties);
171 void slotDeleteClip(const QString &clipId);
172 void slotUpdateClip(const QString &id);
173 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
174 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
175 void slotRemoveInvalidClip(const QString &id, bool replace);
176 void slotSelectClip(const QString &ix);
178 /** @brief Prepares removing the selected items. */
179 void slotRemoveClip();
180 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
182 /** @brief Adds, edits or deletes a folder item.
184 * This is triggered by AddFolderCommand and EditFolderCommand. */
185 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
186 void slotResetProjectList();
189 void slotReloadClip(const QString &id = QString());
191 /** @brief Shows dialog for setting up a color clip. */
192 void slotAddColorClip();
193 void regenerateTemplate(const QString &id);
194 void slotUpdateClipCut(QPoint p);
195 void slotAddClipCut(const QString &id, int in, int out);
196 void slotForceProcessing(const QString &id);
199 ProjectListView *m_listView;
206 QUndoStack *m_commandStack;
207 ProjectItem *getItemById(const QString &id);
208 QTreeWidgetItem *getAnyItemById(const QString &id);
209 FolderProjectItem *getFolderItemById(const QString &id);
210 QAction *m_editAction;
211 QAction *m_deleteAction;
212 QAction *m_openAction;
213 QAction *m_reloadAction;
214 QMenu *m_transcodeAction;
216 ItemDelegate *m_listViewDelegate;
218 QToolButton *m_addButton;
219 QMap <QString, QDomElement> m_infoQueue;
220 QMap <QString, QDomElement> m_producerQueue;
221 void requestClipInfo(const QDomElement xml, const QString id);
222 QList <QString> m_thumbnailQueue;
223 void requestClipThumbnail(const QString id);
225 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
226 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
228 /** @brief Gets the selected folder (or the folder of the selected item). */
229 QStringList getGroup() const;
230 void regenerateTemplate(ProjectItem *clip);
231 void editClipSelection(QList<QTreeWidgetItem *> list);
233 /** @brief Enables and disables transcode actions based on the selected clip's type. */
234 void adjustTranscodeActions(ProjectItem *clip) const;
236 /** @brief Sets the buttons enabled/disabled according to selected item. */
237 void updateButtons() const;
240 void slotClipSelected();
241 void slotAddSlideshowClip();
242 void slotAddTitleClip();
243 void slotAddTitleTemplateClip();
245 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
246 * @param pos The position where the menu should pop up
247 * @param item The item for which the checks should be done */
248 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
250 /** @brief Creates an AddFolderCommand. */
251 void slotAddFolder();
253 /** @brief This is triggered when a clip description has been modified. */
254 void slotItemEdited(QTreeWidgetItem *item, int column);
255 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
256 void slotProcessNextClipInQueue();
257 void slotProcessNextThumbnail();
258 void slotCheckForEmptyQueue();
259 void slotPauseMonitor();
260 /** A clip was modified externally, change icon so that user knows it */
261 void slotModifiedClip(const QString &id);
262 void slotMissingClip(const QString &id);
263 void slotAvailableClip(const QString &id);
264 //void slotShowMenu(const QPoint &pos);
267 void clipSelected(DocClipBase *, QPoint zone = QPoint());
268 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
269 void receivedClipDuration(const QString &);
270 void showClipProperties(DocClipBase *);
271 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
272 void projectModified();
273 void loadingIsOver();
274 void displayMessage(const QString, int progress);
275 void clipNameChanged(const QString, const QString);
276 void clipNeedsReload(const QString&, bool);
278 void updateRenderStatus();
279 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
280 void findInTimeline(const QString &clipId);