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));
111 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
113 int proxy = index.data(Qt::UserRole + 5).toInt();
120 proxyText = i18n("Generating proxy...");
121 brush = option.palette.highlight();
122 color = option.palette.color(QPalette::HighlightedText);
125 proxyText = i18n("Proxy");
126 brush = option.palette.mid();
127 color = option.palette.color(QPalette::WindowText);
129 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
130 painter->setPen(Qt::NoPen);
131 painter->setBrush(brush);
132 painter->drawRoundedRect(txtBounding, 2, 2);
133 painter->setPen(option.palette.highlightedText().color());
134 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
138 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
139 if (index.data().toString().isEmpty()) {
140 QStyledItemDelegate::paint(painter, option, index);
143 QRect r1 = option.rect;
144 if (option.state & (QStyle::State_Selected)) {
145 painter->fillRect(r1, option.palette.highlight());
148 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
151 QStyledItemDelegate::paint(painter, option, index);
156 class ProjectList : public QWidget
161 ProjectList(QWidget *parent = 0);
162 virtual ~ProjectList();
164 QDomElement producersList();
165 void setRenderer(Render *projectRender);
166 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
167 QByteArray headerInfo() const;
168 void setHeaderInfo(const QByteArray &state);
169 void updateProjectFormat(Timecode t);
170 void setupMenu(QMenu *addMenu, QAction *defaultAction);
171 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
172 QString currentClipUrl() const;
173 KUrl::List getConditionalUrls(const QString &condition) const;
174 void reloadClipThumbnails();
175 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
177 void trashUnusedClips();
178 QList <DocClipBase*> documentClipList() const;
179 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
180 void removeClipCut(const QString &id, int in, int out);
181 void focusTree() const;
182 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
183 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
184 bool hasMissingClips();
185 void deleteProjectFolder(QMap <QString, QString> map);
186 void selectItemById(const QString &clipId);
188 /** @brief Returns a string list of all supported mime extensions. */
189 static QString getExtensions();
190 /** @brief Returns a list of urls containing original and proxy urls. */
191 QMap <QString, QString> getProxies();
192 /** @brief Enable / disable proxies. */
193 void updateProxyConfig();
196 void setDocument(KdenliveDoc *doc);
197 void updateAllClips();
198 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
199 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
200 void slotAddClip(DocClipBase *clip, bool getProperties);
201 void slotDeleteClip(const QString &clipId);
202 void slotUpdateClip(const QString &id);
203 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
204 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
205 void slotRemoveInvalidClip(const QString &id, bool replace);
206 void slotSelectClip(const QString &ix);
208 /** @brief Prepares removing the selected items. */
209 void slotRemoveClip();
210 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
212 /** @brief Adds, edits or deletes a folder item.
214 * This is triggered by AddFolderCommand and EditFolderCommand. */
215 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
216 void slotResetProjectList();
219 void slotReloadClip(const QString &id = QString());
221 /** @brief Shows dialog for setting up a color clip. */
222 void slotAddColorClip();
223 void regenerateTemplate(const QString &id);
224 void slotUpdateClipCut(QPoint p);
225 void slotAddClipCut(const QString &id, int in, int out);
226 void slotForceProcessing(const QString &id);
229 ProjectListView *m_listView;
235 QUndoStack *m_commandStack;
236 ProjectItem *getItemById(const QString &id);
237 QTreeWidgetItem *getAnyItemById(const QString &id);
238 FolderProjectItem *getFolderItemById(const QString &id);
239 QAction *m_openAction;
240 QAction *m_reloadAction;
241 QMenu *m_transcodeAction;
243 ItemDelegate *m_listViewDelegate;
245 QToolButton *m_addButton;
246 QToolButton *m_deleteButton;
247 QToolButton *m_editButton;
248 QMap <QString, QDomElement> m_infoQueue;
249 QMap <QString, QDomElement> m_producerQueue;
250 void requestClipInfo(const QDomElement xml, const QString id);
251 QList <QString> m_thumbnailQueue;
252 QAction *m_proxyAction;
253 void requestClipThumbnail(const QString id);
255 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
256 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
258 /** @brief Gets the selected folder (or the folder of the selected item). */
259 QStringList getGroup() const;
260 void regenerateTemplate(ProjectItem *clip);
261 void editClipSelection(QList<QTreeWidgetItem *> list);
263 /** @brief Enables and disables transcode actions based on the selected clip's type. */
264 void adjustTranscodeActions(ProjectItem *clip) const;
265 /** @brief Enables and disables proxy action based on the selected clip. */
266 void adjustProxyActions(ProjectItem *clip) const;
268 /** @brief Sets the buttons enabled/disabled according to selected item. */
269 void updateButtons() const;
272 void slotClipSelected();
273 void slotAddSlideshowClip();
274 void slotAddTitleClip();
275 void slotAddTitleTemplateClip();
277 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
278 * @param pos The position where the menu should pop up
279 * @param item The item for which the checks should be done */
280 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
282 /** @brief Creates an AddFolderCommand. */
283 void slotAddFolder();
285 /** @brief This is triggered when a clip description has been modified. */
286 void slotItemEdited(QTreeWidgetItem *item, int column);
287 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
288 void slotProcessNextClipInQueue();
289 void slotProcessNextThumbnail();
290 void slotCheckForEmptyQueue();
291 void slotPauseMonitor();
292 /** A clip was modified externally, change icon so that user knows it */
293 void slotModifiedClip(const QString &id);
294 void slotMissingClip(const QString &id);
295 void slotAvailableClip(const QString &id);
296 /** @brief Try to find a matching profile for given item. */
297 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
298 /** @brief Add a sequence from the stopmotion widget. */
299 void slotAddOrUpdateSequence(const QString frameName);
300 /** @brief A proxy clip was created, update display. */
301 void slotGotProxy(const QString id, bool success);
302 /** @brief Enable / disable proxy for current clip. */
303 void slotProxyCurrentItem(bool doProxy);
306 void clipSelected(DocClipBase *, QPoint zone = QPoint());
307 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
308 void receivedClipDuration(const QString &);
309 void showClipProperties(DocClipBase *);
310 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
311 void projectModified();
312 void loadingIsOver();
313 void displayMessage(const QString, int progress);
314 void clipNameChanged(const QString, const QString);
315 void clipNeedsReload(const QString&, bool);
316 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
317 * @param id: The clip's id string
318 * @param resetThumbs Should we recreate the timeline thumbnails. */
319 void refreshClip(const QString &id, bool resetThumbs);
320 void updateRenderStatus();
321 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
322 void findInTimeline(const QString &clipId);
323 /** @brief Request a profile change for current document. */
324 void updateProfile(const QString &);