3 #include <QStylePainter>
11 #include <KFileDialog>
13 #include "projectlist.h"
14 #include "projectitem.h"
15 #include "kdenlivesettings.h"
16 #include "ui_colorclip_ui.h"
18 #include "addclipcommand.h"
22 const int NameRole = Qt::UserRole;
23 const int DurationRole = NameRole + 1;
24 const int FullPathRole = NameRole + 2;
25 const int ClipTypeRole = NameRole + 3;
27 class ItemDelegate: public QItemDelegate
30 ItemDelegate(QObject* parent = 0): QItemDelegate(parent)
34 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
36 if (index.column() == 1)
38 const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
39 QRect r1 = option.rect;
42 painter->setPen(option.palette.color(QPalette::HighlightedText));
43 QColor backgroundColor = option.palette.color(QPalette::Highlight);
44 painter->setBrush(QBrush(backgroundColor));
45 painter->fillRect(r1, QBrush(backgroundColor));
47 QFont font = painter->font();
48 font.setPointSize(font.pointSize() - 1 );
50 painter->setFont(font);
51 int mid = (int) ((r1.height() / 2 ));
52 r1.setBottom(r1.y() + mid);
53 QRect r2 = option.rect;
54 r2.setTop(r2.y() + mid);
55 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
56 //painter->setPen(Qt::green);
58 painter->setFont(font);
59 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(DurationRole).toString());
64 QItemDelegate::paint(painter, option, index);
70 ProjectList::ProjectList(QWidget *parent)
71 : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL)
74 QWidget *vbox = new QWidget;
75 listView = new QTreeWidget(this);;
76 QVBoxLayout *layout = new QVBoxLayout;
80 searchView = new KTreeWidgetSearchLine (this);
81 m_toolbar = new QToolBar("projectToolBar", this);
82 m_toolbar->addWidget (searchView);
84 QToolButton *addButton = new QToolButton( m_toolbar );
85 QMenu *addMenu = new QMenu(this);
86 addButton->setMenu( addMenu );
87 addButton->setPopupMode(QToolButton::MenuButtonPopup);
88 m_toolbar->addWidget (addButton);
90 QAction *addClip = addMenu->addAction (KIcon("document-new"), i18n("Add Clip"));
91 connect(addClip, SIGNAL(triggered()), this, SLOT(slotAddClip()));
93 QAction *addColorClip = addMenu->addAction (KIcon("document-new"), i18n("Add Color Clip"));
94 connect(addColorClip, SIGNAL(triggered()), this, SLOT(slotAddColorClip()));
96 QAction *deleteClip = m_toolbar->addAction (KIcon("edit-delete"), i18n("Delete Clip"));
97 connect(deleteClip, SIGNAL(triggered()), this, SLOT(slotRemoveClip()));
99 QAction *editClip = m_toolbar->addAction (KIcon("document-properties"), i18n("Edit Clip"));
100 connect(editClip, SIGNAL(triggered()), this, SLOT(slotEditClip()));
102 addButton->setDefaultAction( addClip );
104 layout->addWidget( m_toolbar );
105 layout->addWidget( listView );
107 m_toolbar->setEnabled(false);
109 searchView->setTreeWidget(listView);
110 listView->setColumnCount(3);
111 listView->setDragEnabled(true);
112 listView->setDragDropMode(QAbstractItemView::DragOnly);
114 headers<<i18n("Thumbnail")<<i18n("Filename")<<i18n("Description");
115 listView->setHeaderLabels(headers);
116 listView->sortByColumn(1, Qt::AscendingOrder);
118 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
119 //connect(listView, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int )), this, SLOT(slotEditClip(QTreeWidgetItem *, int)));
122 listView->setItemDelegate(new ItemDelegate(listView));
123 listView->setIconSize(QSize(60, 40));
124 listView->setSortingEnabled (true);
128 void ProjectList::setRenderer(Render *projectRender)
130 m_render = projectRender;
133 void ProjectList::slotClipSelected()
135 ProjectItem *item = (ProjectItem*) listView->currentItem();
136 if (item) emit clipSelected(item->toXml());
139 void ProjectList::slotEditClip()
144 void ProjectList::slotRemoveClip()
146 if (!listView->currentItem()) return;
147 ProjectItem *item = ((ProjectItem *)listView->currentItem());
148 AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), KUrl(item->data(1, FullPathRole).toString()), false);
149 m_commandStack->push(command);
153 void ProjectList::selectItemById(const int clipId)
155 QTreeWidgetItem *parent = 0;
157 parent ? parent->childCount() : listView->topLevelItemCount();
159 for (int i = 0; i < count; i++)
161 QTreeWidgetItem *item =
162 parent ? parent->child(i) : listView->topLevelItem(i);
163 if (((ProjectItem *)item)->clipId() == clipId) {
164 listView->setCurrentItem(item);
170 void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url)
172 ProjectItem *item = new ProjectItem(listView, name, elem, clipId);
173 if (!url.isEmpty()) {
174 item->setData(1, FullPathRole, url.path());
176 if (elem.isNull() ) {
178 QDomElement element = doc.createElement("producer");
179 element.setAttribute("resource", url.path());
180 emit getFileProperties(element, clipId);
182 else emit getFileProperties(elem, clipId);
183 selectItemById(clipId);
186 void ProjectList::deleteClip(const int clipId)
188 QTreeWidgetItem *parent = 0;
190 parent ? parent->childCount() : listView->topLevelItemCount();
192 for (int i = 0; i < count; i++)
194 QTreeWidgetItem *item =
195 parent ? parent->child(i) : listView->topLevelItem(i);
196 if (((ProjectItem *)item)->clipId() == clipId) {
203 void ProjectList::slotAddClip()
206 KUrl::List list = KFileDialog::getOpenUrls( KUrl(), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/x-msvideo video/mpeg video/x-ms-wmv audio/x-mp3 audio/x-wav application/ogg *.m2t *.dv video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr");
207 if (list.isEmpty()) return;
208 KUrl::List::Iterator it;
210 // ProjectItem *item;
212 for (it = list.begin(); it != list.end(); it++) {
213 QStringList itemEntry;
214 itemEntry.append(QString::null);
215 itemEntry.append((*it).fileName());
216 AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, *it, true);
217 m_commandStack->push(command);
218 //item = new ProjectItem(listView, itemEntry, QDomElement());
219 //item->setData(1, FullPathRole, (*it).path());
221 //listView->setCurrentItem(item);
224 void ProjectList::slotAddColorClip()
226 QDialog *dia = new QDialog;
227 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
228 dia_ui->setupUi(dia);
229 dia_ui->clip_name->setText(i18n("Color Clip"));
230 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
231 if (dia->exec() == QDialog::Accepted)
234 QDomElement element = doc.createElement("producer");
235 element.setAttribute("mlt_service", "colour");
236 QString color = dia_ui->clip_color->color().name();
237 color = color.replace(0, 1, "0x") + "ff";
238 element.setAttribute("colour", color);
239 element.setAttribute("type", (int) DocClipBase::COLOR);
240 element.setAttribute("in", "0");
241 element.setAttribute("out", m_timecode.getFrameCount(dia_ui->clip_duration->text(), m_fps));
242 element.setAttribute("name", dia_ui->clip_name->text());
243 QStringList itemEntry;
244 itemEntry.append(QString::null);
245 itemEntry.append(dia_ui->clip_name->text());
246 AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), true);
247 m_commandStack->push(command);
248 //ProjectItem *item = new ProjectItem(listView, itemEntry, element);
249 /*QPixmap pix(60, 40);
250 pix.fill(dia_ui->clip_color->color());
251 item->setIcon(0, QIcon(pix));*/
252 //listView->setCurrentItem(item);
257 /*for (it = list.begin(); it != list.end(); it++) {
258 QStringList itemEntry;
259 itemEntry.append(QString::null);
260 itemEntry.append((*it).fileName());
261 ProjectItem *item = new ProjectItem(listView, itemEntry, QDomElement());
262 item->setData(1, FullPathRole, (*it).path());
263 emit getFileProperties((*it), 0);
267 void ProjectList::setDocument(KdenliveDoc *doc)
270 m_timecode = doc->timecode();
271 m_commandStack = doc->commandStack();
272 QDomNodeList prods = doc->producersList();
274 for (int i = 0; i < prods.count () ; i++)
276 addProducer(prods.item(i).toElement());
278 QTreeWidgetItem *first = listView->topLevelItem(0);
279 if (first) listView->setCurrentItem(first);
280 m_toolbar->setEnabled(true);
283 QDomElement ProjectList::producersList()
286 QDomElement prods = doc.createElement("producerlist");
287 doc.appendChild(prods);
288 QTreeWidgetItem *parent = 0;
290 parent ? parent->childCount() : listView->topLevelItemCount();
292 for (int i = 0; i < count; i++)
294 QTreeWidgetItem *item =
295 parent ? parent->child(i) : listView->topLevelItem(i);
296 prods.appendChild(doc.importNode(((ProjectItem *)item)->toXml(), true));
303 void ProjectList::slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata)
305 QTreeWidgetItem *parent = 0;
307 parent ? parent->childCount() : listView->topLevelItemCount();
309 for (int i = 0; i < count; i++)
311 QTreeWidgetItem *item =
312 parent ? parent->child(i) : listView->topLevelItem(i);
314 if (((ProjectItem *)item)->clipId() == clipId) {
315 ((ProjectItem *) item)->setProperties(properties, metadata);
323 void ProjectList::slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h)
325 QTreeWidgetItem *parent = 0;
327 parent ? parent->childCount() : listView->topLevelItemCount();
329 for (int i = 0; i < count; i++)
331 QTreeWidgetItem *item =
332 parent ? parent->child(i) : listView->topLevelItem(i);
334 if (((ProjectItem *)item)->clipId() == clipId) {
335 item->setIcon(0, pix);
342 void ProjectList::addProducer(QDomElement producer)
344 DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
347 QDomElement prods = doc.createElement("list");
348 prods.appendChild(doc.importNode(producer, true));
351 kDebug()<<"////// ADDING PRODUCER:\n "<<doc.toString()<<"\n+++++++++++++++++";
352 int id = producer.attribute("id").toInt();
353 if (id >= m_clipIdCounter) m_clipIdCounter = id + 1;
355 if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV)
357 KUrl resource = KUrl(producer.attribute("resource"));
358 if (!resource.isEmpty()) {
359 QStringList itemEntry;
360 itemEntry.append(QString::null);
361 itemEntry.append(resource.fileName());
362 addClip(itemEntry, producer, id, resource);
363 /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, resource, true);
364 m_commandStack->push(command);*/
367 /*ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
368 item->setData(1, FullPathRole, resource.path());
369 item->setData(1, ClipTypeRole, (int) type);*/
373 else if (type == DocClipBase::COLOR) {
374 QString colour = producer.attribute("colour");
376 colour = colour.replace(0, 2, "#");
377 pix.fill(QColor(colour.left(7)));
378 QStringList itemEntry;
379 itemEntry.append(QString::null);
380 itemEntry.append(producer.attribute("name"));
381 addClip(itemEntry, producer, id, KUrl());
382 /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, KUrl(), true);
383 m_commandStack->push(command);*/
384 //ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
385 /*item->setIcon(0, QIcon(pix));
386 item->setData(1, ClipTypeRole, (int) type);*/
391 #include "projectlist.moc"