3 #include <QStylePainter>
11 #include <KFileDialog>
13 #include "projectlist.h"
14 #include "projectitem.h"
15 #include "kdenlivesettings.h"
16 #include "ui_colorclip_ui.h"
20 const int NameRole = Qt::UserRole;
21 const int DurationRole = NameRole + 1;
22 const int FullPathRole = NameRole + 2;
23 const int ClipTypeRole = NameRole + 3;
25 class ItemDelegate: public QItemDelegate
28 ItemDelegate(QObject* parent = 0): QItemDelegate(parent)
32 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
34 if (index.column() == 1)
36 const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
37 QRect r1 = option.rect;
40 painter->setPen(option.palette.color(QPalette::HighlightedText));
41 QColor backgroundColor = option.palette.color(QPalette::Highlight);
42 painter->setBrush(QBrush(backgroundColor));
43 painter->fillRect(r1, QBrush(backgroundColor));
45 QFont font = painter->font();
46 font.setPointSize(font.pointSize() - 1 );
48 painter->setFont(font);
49 int mid = (int) ((r1.height() / 2 ));
50 r1.setBottom(r1.y() + mid);
51 QRect r2 = option.rect;
52 r2.setTop(r2.y() + mid);
53 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
54 //painter->setPen(Qt::green);
56 painter->setFont(font);
57 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(DurationRole).toString());
62 QItemDelegate::paint(painter, option, index);
68 ProjectList::ProjectList(QWidget *parent)
69 : QWidget(parent), m_render(NULL), m_fps(-1)
72 QWidget *vbox = new QWidget;
73 listView = new QTreeWidget(this);;
74 QVBoxLayout *layout = new QVBoxLayout;
77 searchView = new KTreeWidgetSearchLine (this);
78 m_toolbar = new QToolBar("projectToolBar", this);
79 m_toolbar->addWidget (searchView);
81 QToolButton *addButton = new QToolButton( m_toolbar );
82 QMenu *addMenu = new QMenu(this);
83 addButton->setMenu( addMenu );
84 addButton->setPopupMode(QToolButton::MenuButtonPopup);
85 m_toolbar->addWidget (addButton);
87 QAction *addClip = addMenu->addAction (KIcon("document-new"), i18n("Add Clip"));
88 connect(addClip, SIGNAL(triggered()), this, SLOT(slotAddClip()));
90 QAction *addColorClip = addMenu->addAction (KIcon("document-new"), i18n("Add Color Clip"));
91 connect(addColorClip, SIGNAL(triggered()), this, SLOT(slotAddColorClip()));
93 QAction *deleteClip = m_toolbar->addAction (KIcon("edit-delete"), i18n("Delete Clip"));
94 connect(deleteClip, SIGNAL(triggered()), this, SLOT(slotRemoveClip()));
96 QAction *editClip = m_toolbar->addAction (KIcon("document-properties"), i18n("Edit Clip"));
97 connect(editClip, SIGNAL(triggered()), this, SLOT(slotEditClip()));
99 addButton->setDefaultAction( addClip );
101 layout->addWidget( m_toolbar );
102 layout->addWidget( listView );
104 m_toolbar->setEnabled(false);
106 searchView->setTreeWidget(listView);
107 listView->setColumnCount(3);
108 listView->setDragEnabled(true);
109 listView->setDragDropMode(QAbstractItemView::DragOnly);
111 headers<<i18n("Thumbnail")<<i18n("Filename")<<i18n("Description");
112 listView->setHeaderLabels(headers);
113 listView->sortByColumn(1, Qt::AscendingOrder);
115 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
116 //connect(listView, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int )), this, SLOT(slotEditClip(QTreeWidgetItem *, int)));
119 listView->setItemDelegate(new ItemDelegate(listView));
120 listView->setIconSize(QSize(60, 40));
121 listView->setSortingEnabled (true);
125 void ProjectList::setRenderer(Render *projectRender)
127 m_render = projectRender;
130 void ProjectList::slotClipSelected()
132 ProjectItem *item = (ProjectItem*) listView->currentItem();
133 if (item) emit clipSelected(item->toXml());
136 void ProjectList::slotEditClip()
141 void ProjectList::slotRemoveClip()
143 kDebug()<<"////////// SLOT REMOVE";
144 if (!listView->currentItem()) return;
145 delete listView->currentItem();
148 void ProjectList::slotAddClip()
151 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");
152 if (list.isEmpty()) return;
153 KUrl::List::Iterator it;
157 for (it = list.begin(); it != list.end(); it++) {
158 QStringList itemEntry;
159 itemEntry.append(QString::null);
160 itemEntry.append((*it).fileName());
161 item = new ProjectItem(listView, itemEntry, QDomElement());
162 item->setData(1, FullPathRole, (*it).path());
163 emit getFileProperties((*it), 0);
165 listView->setCurrentItem(item);
168 void ProjectList::slotAddColorClip()
170 QDialog *dia = new QDialog;
171 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
172 dia_ui->setupUi(dia);
173 dia_ui->clip_name->setText(i18n("Color Clip"));
174 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
175 if (dia->exec() == QDialog::Accepted)
178 QDomElement element = doc.createElement("producer");
179 element.setAttribute("mlt_service", "colour");
180 QString color = dia_ui->clip_color->color().name();
181 color = color.replace(0, 1, "0x") + "ff";
182 element.setAttribute("colour", color);
183 element.setAttribute("type", (int) DocClipBase::COLOR);
184 element.setAttribute("in", "0");
185 element.setAttribute("out", m_timecode.getFrameCount(dia_ui->clip_duration->text(), m_fps));
186 element.setAttribute("name", dia_ui->clip_name->text());
187 QStringList itemEntry;
188 itemEntry.append(QString::null);
189 itemEntry.append(dia_ui->clip_name->text());
190 ProjectItem *item = new ProjectItem(listView, itemEntry, element);
192 pix.fill(dia_ui->clip_color->color());
193 item->setIcon(0, QIcon(pix));
194 listView->setCurrentItem(item);
199 /*for (it = list.begin(); it != list.end(); it++) {
200 QStringList itemEntry;
201 itemEntry.append(QString::null);
202 itemEntry.append((*it).fileName());
203 ProjectItem *item = new ProjectItem(listView, itemEntry, QDomElement());
204 item->setData(1, FullPathRole, (*it).path());
205 emit getFileProperties((*it), 0);
209 void ProjectList::setDocument(KdenliveDoc *doc)
212 m_timecode = doc->timecode();
214 QDomNodeList prods = doc->producersList();
216 for (int i = 0; i < prods.count () ; i++)
218 addProducer(prods.item(i).toElement());
220 QTreeWidgetItem *first = listView->topLevelItem(0);
221 if (first) listView->setCurrentItem(first);
222 m_toolbar->setEnabled(true);
225 QDomElement ProjectList::producersList()
228 QDomElement prods = doc.createElement("producerlist");
229 doc.appendChild(prods);
230 QTreeWidgetItem *parent = 0;
232 parent ? parent->childCount() : listView->topLevelItemCount();
234 for (int i = 0; i < count; i++)
236 QTreeWidgetItem *item =
237 parent ? parent->child(i) : listView->topLevelItem(i);
238 prods.appendChild(doc.importNode(((ProjectItem *)item)->toXml(), true));
240 //kDebug()<<"PRODUCERS: \n"<<doc.toString();
244 void ProjectList::slotReplyGetFileProperties(const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata)
246 QTreeWidgetItem *parent = 0;
248 parent ? parent->childCount() : listView->topLevelItemCount();
250 for (int i = 0; i < count; i++)
252 QTreeWidgetItem *item =
253 parent ? parent->child(i) : listView->topLevelItem(i);
255 if (item->data(1, FullPathRole).toString() == properties["filename"]) {
256 ((ProjectItem *) item)->setProperties(properties, metadata);
263 void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix, int w, int h)
265 QTreeWidgetItem *parent = 0;
267 parent ? parent->childCount() : listView->topLevelItemCount();
269 for (int i = 0; i < count; i++)
271 QTreeWidgetItem *item =
272 parent ? parent->child(i) : listView->topLevelItem(i);
274 if (item->data(1, FullPathRole).toString() == url.path()) {
275 item->setIcon(0,pix);
283 void ProjectList::addProducer(QDomElement producer)
285 DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
287 if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV)
289 KUrl resource = KUrl(producer.attribute("resource"));
290 if (!resource.isEmpty()) {
291 QStringList itemEntry;
292 itemEntry.append(QString::null);
293 itemEntry.append(resource.fileName());
294 ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
295 item->setData(1, FullPathRole, resource.path());
296 item->setData(1, ClipTypeRole, (int) type);
297 emit getFileProperties(resource, producer.attribute("frame_thumbnail", 0).toInt());
300 else if (type == DocClipBase::COLOR) {
301 QString colour = producer.attribute("colour");
303 colour = colour.replace(0, 2, "#");
304 pix.fill(QColor(colour.left(7)));
305 QStringList itemEntry;
306 itemEntry.append(QString::null);
307 itemEntry.append(producer.attribute("name"));
308 ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
309 item->setIcon(0, QIcon(pix));
310 item->setData(1, ClipTypeRole, (int) type);
315 #include "projectlist.moc"