]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
a68ec1c23c95b981bd16c68c0d4c9b3b530b6998
[kdenlive] / src / projectlist.cpp
1
2 #include <QMouseEvent>
3 #include <QStylePainter>
4 #include <QPixmap>
5 #include <QIcon>
6
7 #include <KDebug>
8 #include <KLocale>
9 #include <KFileDialog>
10 #include <klistwidgetsearchline.h>
11
12 #include "projectlist.h"
13 #include "projectitem.h"
14
15 #include <QtGui>
16
17   const int NameRole = Qt::UserRole;
18   const int DurationRole = NameRole + 1;
19   const int FullPathRole = NameRole + 2;
20   const int ClipTypeRole = NameRole + 3;
21
22 class ItemDelegate: public QItemDelegate
23 {
24   public:
25     ItemDelegate(QObject* parent = 0): QItemDelegate(parent)
26     {
27     }
28
29 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
30 {
31   if (index.column() == 1)
32   {
33     QFont font = painter->font();
34     font.setPointSize(font.pointSize() - 2 );
35     QRect r1 = option.rect;
36     r1.setBottom(r1.y() + (r1.height() *2 / 3 ));
37     QRect r2 = option.rect;
38     r2.setTop(r2.y() + (r2.height() *2 / 3 ));
39     painter->drawText(r1, Qt::AlignLeft | Qt::AlignVCenter , index.data().toString());
40     painter->setPen(Qt::green);
41     painter->drawText(r2, Qt::AlignLeft | Qt::AlignTop , index.data(DurationRole).toString());
42     painter->setPen(Qt::black);
43   }
44   else
45   {
46     QItemDelegate::paint(painter, option, index);
47   }
48 }
49 };
50
51
52 ProjectList::ProjectList(Render *projectRender, QWidget *parent)
53     : QWidget(parent), m_render(projectRender)
54 {
55
56   ui.setupUi(this);
57   ui.project_search->setTreeWidget(ui.project_list);
58       QStringList itemEntry;
59       itemEntry.append(QString::null);
60       itemEntry.append("coucou");
61   new ProjectItem(ui.project_list, itemEntry);
62   connect(ui.button_add, SIGNAL(clicked ( bool )), this, SLOT(slotAddClip()));
63   connect(ui.project_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
64   connect(ui.project_list, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int )), this, SLOT(slotEditClip(QTreeWidgetItem *, int)));
65
66
67   ui.project_list->setItemDelegate(new ItemDelegate(ui.project_list));
68   ui.project_list->setIconSize(QSize(60, 40));
69   ui.project_list->setSortingEnabled (true);
70
71 }
72
73 void ProjectList::setRenderer(Render *projectRender)
74 {
75   m_render = projectRender;
76 }
77
78 void ProjectList::slotDoubleClicked(QListWidgetItem *item, const QPoint &pos)
79 {
80   kDebug()<<" / / / DBL CLICK";
81   if (item) {
82     KUrl url = KFileDialog::getOpenUrl( KUrl(), "video/mpeg");
83   }
84 }
85
86 void ProjectList::slotClipSelected()
87 {
88   ProjectItem *item = (ProjectItem*) ui.project_list->currentItem();
89   if (item) emit clipSelected(item->toXml());
90 }
91
92 void ProjectList::slotEditClip(QTreeWidgetItem *item, int column)
93 {
94   if (column != 2){
95     return;
96   }
97 }
98
99 void ProjectList::slotAddClip()
100 {
101    
102   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");
103
104   KUrl::List::Iterator it;
105   KUrl url;
106         
107   for (it = list.begin(); it != list.end(); it++) {
108       QStringList itemEntry;
109       itemEntry.append(QString::null);
110       itemEntry.append((*it).fileName());
111       ProjectItem *item = new ProjectItem(ui.project_list, itemEntry, QDomElement());
112       item->setData(1, FullPathRole, (*it).path());
113       emit getFileProperties((*it), 0);
114   }
115
116 }
117
118 void ProjectList::populate(QDomNodeList prods)
119 {
120   ui.project_list->clear();
121   for (int i = 0; i <  prods.count () ; i++)
122   {
123     addProducer(prods.item(i).toElement());
124   }
125 }
126
127 void ProjectList::slotReplyGetFileProperties(const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata)
128 {
129   QTreeWidgetItem *parent = 0;
130   int count =
131     parent ? parent->childCount() : ui.project_list->topLevelItemCount();
132
133   for (int i = 0; i < count; i++)
134   {
135     QTreeWidgetItem *item =
136       parent ? parent->child(i) : ui.project_list->topLevelItem(i);
137
138     if (item->data(1, FullPathRole).toString() == properties["filename"]) {
139       ((ProjectItem *) item)->setProperties(properties, metadata);
140       break;
141     }
142   }
143 }
144
145
146 void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix, int w, int h)
147 {
148    QTreeWidgetItem *parent = 0;
149   int count =
150     parent ? parent->childCount() : ui.project_list->topLevelItemCount();
151
152   for (int i = 0; i < count; i++)
153   {
154     QTreeWidgetItem *item =
155       parent ? parent->child(i) : ui.project_list->topLevelItem(i);
156
157     if (item->data(1, FullPathRole).toString() == url.path()) {
158       item->setIcon(0,pix);
159       break;
160     }
161   }
162
163 }
164
165
166 void ProjectList::addProducer(QDomElement producer)
167 {
168   DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
169   
170   if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV)
171   {
172     KUrl resource = KUrl(producer.attribute("resource"));
173     if (!resource.isEmpty()) {
174       QStringList itemEntry;
175       itemEntry.append(QString::null);
176       itemEntry.append(resource.fileName());
177       ProjectItem *item = new ProjectItem(ui.project_list, itemEntry, producer);
178       //item->setIcon(0, Render::getVideoThumbnail(resource, 0, 60, 40));
179       item->setData(1, FullPathRole, resource.path());
180       item->setData(1, ClipTypeRole, (int) type);
181       emit getFileProperties(resource, producer.attribute("frame_thumbnail", 0).toInt());
182     }
183   }
184   else if (type == DocClipBase::COLOR) {
185     QString colour = producer.attribute("colour");
186     QPixmap pix(60, 40);
187     colour = colour.replace(0, 2, "#");
188     pix.fill(QColor(colour.left(7)));
189     QStringList itemEntry;
190     itemEntry.append(QString::null);
191     itemEntry.append(i18n("Color Clip"));
192     ProjectItem *item = new ProjectItem(ui.project_list, itemEntry, producer);
193     item->setIcon(0, QIcon(pix));
194     item->setData(1, ClipTypeRole, (int) type);
195   }
196       
197 }
198
199 #include "projectlist.moc"