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 <QItemDelegate>
32 #include <QApplication>
34 #include <KTreeWidgetSearchLine>
36 #include <nepomuk/kratingpainter.h>
37 #include <nepomuk/resource.h>
39 #include "definitions.h"
41 #include "kdenlivesettings.h"
42 #include "folderprojectitem.h"
50 class ProjectListView;
55 const int NameRole = Qt::UserRole;
56 const int DurationRole = NameRole + 1;
57 const int UsageRole = NameRole + 2;
59 class ItemDelegate: public QItemDelegate
62 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
65 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
68 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
69 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
70 QRect r1 = option.rect;
72 if (option.state & (QStyle::State_Selected)) {
73 painter->setPen(option.palette.color(QPalette::HighlightedText));
74 painter->fillRect(r1, option.palette.highlight());
76 QStyleOptionViewItemV2 opt = setOptions(index, option);
77 QPixmap pixmap = decoration(opt, index.data(Qt::DecorationRole));
78 QRect decorationRect = pixmap.rect(); //QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect());
79 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
80 decorationRect.moveTo(r1.topLeft() + QPoint(0, 1));
81 drawDecoration(painter, opt, decorationRect, pixmap);
82 int decoWidth = pixmap.width() + 2 * textMargin;
84 QFont font = painter->font();
86 painter->setFont(font);
87 int mid = (int)((r1.height() / 2));
88 r1.adjust(decoWidth, 0, 0, -mid);
89 QRect r2 = option.rect;
90 r2.adjust(decoWidth, mid, 0, 0);
91 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
92 //painter->setPen(Qt::green);
94 painter->setFont(font);
95 QString subText = index.data(DurationRole).toString();
96 int usage = index.data(UsageRole).toInt();
97 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
98 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
99 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
101 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
102 if (index.data().toString().isEmpty()) {
103 QItemDelegate::paint(painter, option, index);
106 QRect r1 = option.rect;
107 if (option.state & (QStyle::State_Selected)) {
108 painter->fillRect(r1, option.palette.highlight());
110 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
112 QItemDelegate::paint(painter, option, index);
117 class ProjectList : public QWidget
122 ProjectList(QWidget *parent = 0);
123 virtual ~ProjectList();
125 QDomElement producersList();
126 void setRenderer(Render *projectRender);
127 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
128 QByteArray headerInfo() const;
129 void setHeaderInfo(const QByteArray &state);
130 void setupMenu(QMenu *addMenu, QAction *defaultAction);
131 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
132 QString currentClipUrl() const;
133 void reloadClipThumbnails();
134 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
136 void trashUnusedClips();
137 QList <DocClipBase*> documentClipList() const;
138 void addClipCut(const QString &id, int in, int out);
139 void removeClipCut(const QString &id, int in, int out);
140 void focusTree() const;
143 void setDocument(KdenliveDoc *doc);
144 void updateAllClips();
145 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
146 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
147 void slotAddClip(DocClipBase *clip, bool getProperties);
148 void slotDeleteClip(const QString &clipId);
149 void slotUpdateClip(const QString &id);
150 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
151 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
152 void slotRemoveInvalidClip(const QString &id, bool replace);
153 void slotSelectClip(const QString &ix);
154 void slotRemoveClip();
155 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
156 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
157 void slotResetProjectList();
160 void slotReloadClip(const QString &id = QString());
161 void slotAddColorClip();
162 void regenerateTemplate(const QString &id);
165 ProjectListView *m_listView;
172 QUndoStack *m_commandStack;
173 void selectItemById(const QString &clipId);
174 ProjectItem *getItemById(const QString &id);
175 QTreeWidgetItem *getAnyItemById(const QString &id);
176 FolderProjectItem *getFolderItemById(const QString &id);
177 QAction *m_editAction;
178 QAction *m_deleteAction;
179 QAction *m_openAction;
180 QAction *m_reloadAction;
181 QMenu *m_transcodeAction;
183 ItemDelegate *m_listViewDelegate;
185 QToolButton *m_addButton;
186 QMap <QString, QDomElement> m_infoQueue;
187 QMap <QString, QDomElement> m_producerQueue;
188 void requestClipInfo(const QDomElement xml, const QString id);
189 QList <QString> m_thumbnailQueue;
190 void requestClipThumbnail(const QString id);
191 void deleteProjectFolder(QMap <QString, QString> map);
192 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
193 QStringList getGroup() const;
194 void regenerateTemplate(ProjectItem *clip);
197 void slotClipSelected();
198 void slotAddSlideshowClip();
199 void slotAddTitleClip();
200 void slotAddTitleTemplateClip();
201 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
202 void slotAddFolder();
203 /** This is triggered when a clip description has been modified */
204 void slotItemEdited(QTreeWidgetItem *item, int column);
205 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
206 void slotProcessNextClipInQueue();
207 void slotProcessNextThumbnail();
208 void slotCheckForEmptyQueue();
209 void slotPauseMonitor();
210 void slotAddClipCut(const QString &id, int in, int out);
211 //void slotShowMenu(const QPoint &pos);
214 void clipSelected(DocClipBase *, QPoint zone = QPoint());
215 void getFileProperties(const QDomElement, const QString &, bool);
216 void receivedClipDuration(const QString &);
217 void showClipProperties(DocClipBase *);
218 void projectModified();
219 void loadingIsOver();
220 void displayMessage(const QString, int progress);
221 void clipNameChanged(const QString, const QString);