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;
205 QUndoStack *m_commandStack;
206 ProjectItem *getItemById(const QString &id);
207 QTreeWidgetItem *getAnyItemById(const QString &id);
208 FolderProjectItem *getFolderItemById(const QString &id);
209 QAction *m_openAction;
210 QAction *m_reloadAction;
211 QMenu *m_transcodeAction;
213 ItemDelegate *m_listViewDelegate;
215 QToolButton *m_addButton;
216 QToolButton *m_deleteButton;
217 QToolButton *m_editButton;
218 QMap <QString, QDomElement> m_infoQueue;
219 QMap <QString, QDomElement> m_producerQueue;
220 void requestClipInfo(const QDomElement xml, const QString id);
221 QList <QString> m_thumbnailQueue;
222 void requestClipThumbnail(const QString id);
224 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
225 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
227 /** @brief Gets the selected folder (or the folder of the selected item). */
228 QStringList getGroup() const;
229 void regenerateTemplate(ProjectItem *clip);
230 void editClipSelection(QList<QTreeWidgetItem *> list);
232 /** @brief Enables and disables transcode actions based on the selected clip's type. */
233 void adjustTranscodeActions(ProjectItem *clip) const;
235 /** @brief Sets the buttons enabled/disabled according to selected item. */
236 void updateButtons() const;
239 void slotClipSelected();
240 void slotAddSlideshowClip();
241 void slotAddTitleClip();
242 void slotAddTitleTemplateClip();
244 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
245 * @param pos The position where the menu should pop up
246 * @param item The item for which the checks should be done */
247 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
249 /** @brief Creates an AddFolderCommand. */
250 void slotAddFolder();
252 /** @brief This is triggered when a clip description has been modified. */
253 void slotItemEdited(QTreeWidgetItem *item, int column);
254 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
255 void slotProcessNextClipInQueue();
256 void slotProcessNextThumbnail();
257 void slotCheckForEmptyQueue();
258 void slotPauseMonitor();
259 /** A clip was modified externally, change icon so that user knows it */
260 void slotModifiedClip(const QString &id);
261 void slotMissingClip(const QString &id);
262 void slotAvailableClip(const QString &id);
263 /** @brief Try to find a matching profile for given item. */
264 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
265 /** @brief Add a sequence from the stopmotion widget. */
266 void slotAddOrUpdateSequence(const QString frameName);
267 //void slotShowMenu(const QPoint &pos);
270 void clipSelected(DocClipBase *, QPoint zone = QPoint());
271 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
272 void receivedClipDuration(const QString &);
273 void showClipProperties(DocClipBase *);
274 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
275 void projectModified();
276 void loadingIsOver();
277 void displayMessage(const QString, int progress);
278 void clipNameChanged(const QString, const QString);
279 void clipNeedsReload(const QString&, bool);
281 void updateRenderStatus();
282 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
283 void findInTimeline(const QString &clipId);
284 /** @brief Request a profile change for current document. */
285 void updateProfile(const QString &);