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 <QTreeWidget>
30 #include <KTreeWidgetSearchLine>
31 #include "kextendableitemdelegate.h"
33 #include "definitions.h"
34 #include "kdenlivedoc.h"
37 #include "projectlistview.h"
41 const int NameRole = Qt::UserRole;
42 const int DurationRole = NameRole + 1;
43 const int UsageRole = NameRole + 2;
45 class ItemDelegate: public KExtendableItemDelegate
48 ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent)
54 QWidget *w = new QWidget;
55 QVBoxLayout *layout = new QVBoxLayout;
56 layout->addWidget( new KColorButton(w));
57 w->setLayout( layout );
62 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
64 if (index.column() == 1)
66 const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
67 QRect r1 = option.rect;
70 painter->setPen(option.palette.color(QPalette::HighlightedText));
71 QColor backgroundColor = option.palette.color(QPalette::Highlight);
72 painter->setBrush(QBrush(backgroundColor));
73 painter->fillRect(r1, QBrush(backgroundColor));
75 QFont font = painter->font();
76 font.setPointSize(font.pointSize() - 1 );
78 painter->setFont(font);
79 int mid = (int) ((r1.height() / 2 ));
80 r1.setBottom(r1.y() + mid);
81 QRect r2 = option.rect;
82 r2.setTop(r2.y() + mid);
83 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
84 //painter->setPen(Qt::green);
86 painter->setFont(font);
87 QString subText = index.data(DurationRole).toString();
88 int usage = index.data(UsageRole).toInt();
89 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
90 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
95 KExtendableItemDelegate::paint(painter, option, index);
100 class ProjectList : public QWidget
105 ProjectList(QWidget *parent=0);
106 virtual ~ProjectList();
108 QDomElement producersList();
109 void setRenderer(Render *projectRender);
111 void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
114 void setDocument(KdenliveDoc *doc);
115 void addProducer(QDomElement producer, int parentId = -1);
116 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
117 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
118 void slotAddClip(DocClipBase *clip);
119 void slotDeleteClip(int clipId);
120 void slotUpdateClip(int id);
124 ProjectListView *listView;
125 KTreeWidgetSearchLine *searchView;
131 KUndoStack *m_commandStack;
133 void selectItemById(const int clipId);
134 ProjectItem *getItemById(int id);
135 QAction *m_editAction;
136 QAction *m_deleteAction;
137 ItemDelegate *m_listViewDelegate;
141 void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString::null);
142 void slotRemoveClip();
144 void slotClipSelected();
145 void slotAddColorClip();
146 void slotAddTitleClip();
147 void slotEditClip(QTreeWidgetItem *, int);
148 void slotContextMenu( const QPoint &pos, QTreeWidgetItem * );
149 void slotAddFolder();
150 /** This is triggered when a clip description has been modified */
151 void slotUpdateItemDescription(QTreeWidgetItem *item, int column);
152 //void slotShowMenu(const QPoint &pos);
157 void clipSelected(const QDomElement &);
158 void getFileProperties(const QDomElement&, int);
159 void receivedClipDuration(int, int);