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"
34 #include "definitions.h"
38 class ProjectListView;
43 const int NameRole = Qt::UserRole;
44 const int DurationRole = NameRole + 1;
45 const int UsageRole = NameRole + 2;
47 class ItemDelegate: public KExtendableItemDelegate {
49 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 {
63 if (index.column() == 1) {
64 const bool hover = option.state & (QStyle::State_Selected | QStyle::State_MouseOver | QStyle::State_HasFocus);
65 QRect r1 = option.rect;
68 painter->setPen(option.palette.color(QPalette::HighlightedText));
69 QColor backgroundColor = option.palette.color(QPalette::Highlight);
70 painter->setBrush(QBrush(backgroundColor));
71 painter->fillRect(r1, QBrush(backgroundColor));
73 QFont font = painter->font();
74 font.setPointSize(font.pointSize() - 1);
76 painter->setFont(font);
77 int mid = (int)((r1.height() / 2));
78 r1.setBottom(r1.y() + mid);
79 QRect r2 = option.rect;
80 r2.setTop(r2.y() + mid);
81 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
82 //painter->setPen(Qt::green);
84 painter->setFont(font);
85 QString subText = index.data(DurationRole).toString();
86 int usage = index.data(UsageRole).toInt();
87 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
88 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
91 KExtendableItemDelegate::paint(painter, option, index);
96 class ProjectList : public QWidget {
100 ProjectList(QWidget *parent = 0);
101 virtual ~ProjectList();
103 QDomElement producersList();
104 void setRenderer(Render *projectRender);
106 void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
109 void setDocument(KdenliveDoc *doc);
110 void addProducer(QDomElement producer, int parentId = -1);
111 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
112 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
113 void slotAddClip(DocClipBase *clip);
114 void slotDeleteClip(int clipId);
115 void slotUpdateClip(int id);
119 ProjectListView *listView;
120 KTreeWidgetSearchLine *searchView;
126 KUndoStack *m_commandStack;
128 void selectItemById(const int clipId);
129 ProjectItem *getItemById(int id);
130 QAction *m_editAction;
131 QAction *m_deleteAction;
132 ItemDelegate *m_listViewDelegate;
136 void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString());
137 void slotRemoveClip();
139 void slotClipSelected();
140 void slotAddColorClip();
141 void slotAddTitleClip();
142 void slotEditClip(QTreeWidgetItem *, int);
143 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
144 void slotAddFolder();
145 /** This is triggered when a clip description has been modified */
146 void slotUpdateItemDescription(QTreeWidgetItem *item, int column);
147 //void slotShowMenu(const QPoint &pos);
152 void clipSelected(const QDomElement &);
153 void getFileProperties(const QDomElement&, int);
154 void receivedClipDuration(int, int);