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 {
47 ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent) {
52 QWidget *w = new QWidget;
53 QVBoxLayout *layout = new QVBoxLayout;
54 layout->addWidget( new KColorButton(w));
55 w->setLayout( layout );
60 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
61 if (index.column() == 1) {
62 const bool hover = option.state & (QStyle::State_Selected | QStyle::State_MouseOver | QStyle::State_HasFocus);
63 QRect r1 = option.rect;
66 painter->setPen(option.palette.color(QPalette::HighlightedText));
67 QColor backgroundColor = option.palette.color(QPalette::Highlight);
68 painter->setBrush(QBrush(backgroundColor));
69 painter->fillRect(r1, QBrush(backgroundColor));
71 QFont font = painter->font();
72 font.setPointSize(font.pointSize() - 1);
74 painter->setFont(font);
75 int mid = (int)((r1.height() / 2));
76 r1.setBottom(r1.y() + mid);
77 QRect r2 = option.rect;
78 r2.setTop(r2.y() + mid);
79 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
80 //painter->setPen(Qt::green);
82 painter->setFont(font);
83 QString subText = index.data(DurationRole).toString();
84 int usage = index.data(UsageRole).toInt();
85 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
86 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
89 KExtendableItemDelegate::paint(painter, option, index);
94 class ProjectList : public QWidget {
98 ProjectList(QWidget *parent = 0);
99 virtual ~ProjectList();
101 QDomElement producersList();
102 void setRenderer(Render *projectRender);
104 void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
107 void setDocument(KdenliveDoc *doc);
108 void addProducer(QDomElement producer, int parentId = -1);
109 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
110 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
111 void slotAddClip(DocClipBase *clip);
112 void slotDeleteClip(int clipId);
113 void slotUpdateClip(int id);
117 ProjectListView *listView;
118 KTreeWidgetSearchLine *searchView;
124 KUndoStack *m_commandStack;
126 void selectItemById(const int clipId);
127 ProjectItem *getItemById(int id);
128 QAction *m_editAction;
129 QAction *m_deleteAction;
130 ItemDelegate *m_listViewDelegate;
134 void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString());
135 void slotRemoveClip();
137 void slotClipSelected();
138 void slotAddColorClip();
139 void slotAddTitleClip();
140 void slotEditClip(QTreeWidgetItem *, int);
141 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
142 void slotAddFolder();
143 /** This is triggered when a clip description has been modified */
144 void slotUpdateItemDescription(QTreeWidgetItem *item, int column);
145 //void slotShowMenu(const QPoint &pos);
150 void clipSelected(const QDomElement &);
151 void getFileProperties(const QDomElement&, int);
152 void receivedClipDuration(int, int);