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>
35 #include <KTreeWidgetSearchLine>
40 #include <nepomuk/kratingpainter.h>
41 #include <nepomuk/resource.h>
44 #include "definitions.h"
46 #include "kdenlivesettings.h"
47 #include "folderprojectitem.h"
48 #include "subprojectitem.h"
56 class ProjectListView;
61 const int NameRole = Qt::UserRole;
62 const int DurationRole = NameRole + 1;
63 const int UsageRole = NameRole + 2;
65 class ItemDelegate: public QStyledItemDelegate
68 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
71 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
74 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
75 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
76 QRect r1 = option.rect;
78 QStyleOptionViewItemV4 opt(option);
79 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
80 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
82 if (option.state & QStyle::State_Selected) {
83 painter->setPen(option.palette.highlightedText().color());
85 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
86 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
87 if ((index.flags() & (Qt::ItemIsDragEnabled)) == false) {
88 KIcon icon("dialog-close");
90 p.drawPixmap(1, 1, icon.pixmap(16, 16));
94 painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
95 int decoWidth = pixmap.width() + 2 * textMargin;
97 QFont font = painter->font();
99 painter->setFont(font);
100 int mid = (int)((r1.height() / 2));
101 r1.adjust(decoWidth, 0, 0, -mid);
102 QRect r2 = option.rect;
103 r2.adjust(decoWidth, mid, 0, 0);
104 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
106 painter->setFont(font);
107 QString subText = index.data(DurationRole).toString();
108 int usage = index.data(UsageRole).toInt();
109 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
110 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
112 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
114 int proxy = index.data(Qt::UserRole + 5).toInt();
120 if (proxy == PROXYDONE) {
121 proxyText = i18n("Proxy");
122 brush = option.palette.mid();
123 color = option.palette.color(QPalette::WindowText);
128 proxyText = i18n("Generating proxy ...");
131 proxyText = i18n("Waiting proxy ...");
135 proxyText = i18n("Proxy crashed");
137 brush = option.palette.highlight();
138 color = option.palette.color(QPalette::HighlightedText);
141 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
142 painter->setPen(Qt::NoPen);
143 painter->setBrush(brush);
144 painter->drawRoundedRect(txtBounding, 2, 2);
145 painter->setPen(option.palette.highlightedText().color());
146 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
150 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
151 if (index.data().toString().isEmpty()) {
152 QStyledItemDelegate::paint(painter, option, index);
155 QRect r1 = option.rect;
156 if (option.state & (QStyle::State_Selected)) {
157 painter->fillRect(r1, option.palette.highlight());
160 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
163 QStyledItemDelegate::paint(painter, option, index);
168 class ProjectList : public QWidget
173 ProjectList(QWidget *parent = 0);
174 virtual ~ProjectList();
176 QDomElement producersList();
177 void setRenderer(Render *projectRender);
178 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
179 QByteArray headerInfo() const;
180 void setHeaderInfo(const QByteArray &state);
181 void updateProjectFormat(Timecode t);
182 void setupMenu(QMenu *addMenu, QAction *defaultAction);
183 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
184 QString currentClipUrl() const;
185 KUrl::List getConditionalUrls(const QString &condition) const;
186 void reloadClipThumbnails();
187 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
189 void trashUnusedClips();
190 QList <DocClipBase*> documentClipList() const;
191 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
192 void removeClipCut(const QString &id, int in, int out);
193 void focusTree() const;
194 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
195 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
196 bool hasMissingClips();
197 void deleteProjectFolder(QMap <QString, QString> map);
198 void selectItemById(const QString &clipId);
200 /** @brief Returns a string list of all supported mime extensions. */
201 static QString getExtensions();
202 /** @brief Returns a list of urls containing original and proxy urls. */
203 QMap <QString, QString> getProxies();
204 /** @brief Enable / disable proxies. */
205 void updateProxyConfig();
206 /** @brief Get a property from the document. */
207 QString getDocumentProperty(const QString &key) const;
209 /** @brief Does this project allow proxies. */
210 bool useProxy() const;
211 /** @brief Should we automatically create proxy clips for newly added clips. */
212 bool generateProxy() const;
213 /** @brief Should we automatically create proxy clips for newly added clips. */
214 bool generateImageProxy() const;
215 /** @brief Returns a list of the expanded folder ids. */
216 QStringList expandedFolders() const;
219 void setDocument(KdenliveDoc *doc);
220 void updateAllClips();
221 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
222 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip);
223 void slotAddClip(DocClipBase *clip, bool getProperties);
224 void slotDeleteClip(const QString &clipId);
225 void slotUpdateClip(const QString &id);
226 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
227 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
228 void slotRemoveInvalidClip(const QString &id, bool replace);
229 void slotRemoveInvalidProxy(const QString &id, bool durationError);
230 void slotSelectClip(const QString &ix);
232 /** @brief Prepares removing the selected items. */
233 void slotRemoveClip();
234 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
236 /** @brief Adds, edits or deletes a folder item.
238 * This is triggered by AddFolderCommand and EditFolderCommand. */
239 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
240 void slotResetProjectList();
243 void slotReloadClip(const QString &id = QString());
245 /** @brief Shows dialog for setting up a color clip. */
246 void slotAddColorClip();
247 void regenerateTemplate(const QString &id);
248 void slotUpdateClipCut(QPoint p);
249 void slotAddClipCut(const QString &id, int in, int out);
250 void slotForceProcessing(const QString &id);
253 ProjectListView *m_listView;
258 QFuture<void> m_queueRunner;
259 QUndoStack *m_commandStack;
260 ProjectItem *getItemById(const QString &id);
261 QTreeWidgetItem *getAnyItemById(const QString &id);
262 FolderProjectItem *getFolderItemById(const QString &id);
263 QAction *m_openAction;
264 QAction *m_reloadAction;
265 QMenu *m_transcodeAction;
267 ItemDelegate *m_listViewDelegate;
268 /** @brief True if we have not yet finished opening the document. */
270 QToolButton *m_addButton;
271 QToolButton *m_deleteButton;
272 QToolButton *m_editButton;
273 QMap <QString, QDomElement> m_infoQueue;
274 QMap <QString, QDomElement> m_producerQueue;
275 void requestClipInfo(const QDomElement xml, const QString id);
276 QList <QString> m_thumbnailQueue;
277 QAction *m_proxyAction;
278 QStringList m_processingClips;
279 /** @brief Holds a list of ids for the clips that need to be proxied. */
280 QStringList m_proxyList;
281 /** @brief Holds a list of proxy clip that should be aborted. */
282 QStringList m_abortProxyId;
284 void requestClipThumbnail(const QString id);
286 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
287 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
289 /** @brief Gets the selected folder (or the folder of the selected item). */
290 QStringList getGroup() const;
291 void regenerateTemplate(ProjectItem *clip);
292 void editClipSelection(QList<QTreeWidgetItem *> list);
294 /** @brief Enables and disables transcode actions based on the selected clip's type. */
295 void adjustTranscodeActions(ProjectItem *clip) const;
296 /** @brief Enables and disables proxy action based on the selected clip. */
297 void adjustProxyActions(ProjectItem *clip) const;
299 /** @brief Sets the buttons enabled/disabled according to selected item. */
300 void updateButtons() const;
302 /** @brief Set the Proxy status on a clip.
303 * @param item The clip item to set status
304 * @param status The proxy status (see definitions.h) */
305 void setProxyStatus(const QString id, PROXYSTATUS status);
306 void setProxyStatus(ProjectItem *item, PROXYSTATUS status);
308 void monitorItemEditing(bool enable);
311 void slotClipSelected();
312 void slotAddSlideshowClip();
313 void slotAddTitleClip();
314 void slotAddTitleTemplateClip();
316 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
317 * @param pos The position where the menu should pop up
318 * @param item The item for which the checks should be done */
319 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
321 /** @brief Creates an AddFolderCommand. */
322 void slotAddFolder();
324 /** @brief This is triggered when a clip description has been modified. */
325 void slotItemEdited(QTreeWidgetItem *item, int column);
326 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
327 void slotProcessNextClipInQueue();
328 void slotProcessNextThumbnail();
329 void slotCheckForEmptyQueue();
330 void slotPauseMonitor();
331 /** A clip was modified externally, change icon so that user knows it */
332 void slotModifiedClip(const QString &id);
333 void slotMissingClip(const QString &id);
334 void slotAvailableClip(const QString &id);
335 /** @brief Try to find a matching profile for given item. */
336 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
337 /** @brief Add a sequence from the stopmotion widget. */
338 void slotAddOrUpdateSequence(const QString frameName);
339 /** @brief A proxy clip was created, update display. */
340 void slotGotProxy(const QString &id);
341 /** @brief Enable / disable proxy for current clip. */
342 void slotProxyCurrentItem(bool doProxy);
343 /** @brief Put clip in the proxy waiting list. */
344 void slotCreateProxy(const QString id, bool createProducer = true);
345 /** @brief Stop creation of this clip's proxy. */
346 void slotAbortProxy(const QString id);
347 /** @brief Start creation of proxy clip. */
348 void slotGenerateProxy(const QString id);
351 void clipSelected(DocClipBase *, QPoint zone = QPoint());
352 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool, bool);
353 void receivedClipDuration(const QString &);
354 void showClipProperties(DocClipBase *);
355 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
356 void projectModified();
357 void loadingIsOver();
358 void displayMessage(const QString, int progress);
359 void clipNameChanged(const QString, const QString);
360 void clipNeedsReload(const QString&, bool);
361 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
362 * @param id: The clip's id string
363 * @param resetThumbs Should we recreate the timeline thumbnails. */
364 void refreshClip(const QString &id, bool resetThumbs);
365 void updateRenderStatus();
366 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
367 void findInTimeline(const QString &clipId);
368 /** @brief Request a profile change for current document. */
369 void updateProfile(const QString &);
370 void processNextThumbnail();