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>
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 FullPathRole = NameRole + 2;
44 const int ClipTypeRole = NameRole + 3;
46 class ItemDelegate: public KExtendableItemDelegate
49 ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent)
55 QWidget *w = new QWidget;
56 QVBoxLayout *layout = new QVBoxLayout;
57 layout->addWidget( new KColorButton(w));
58 w->setLayout( layout );
63 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
65 if (index.column() == 1)
67 const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
68 QRect r1 = option.rect;
71 painter->setPen(option.palette.color(QPalette::HighlightedText));
72 QColor backgroundColor = option.palette.color(QPalette::Highlight);
73 painter->setBrush(QBrush(backgroundColor));
74 painter->fillRect(r1, QBrush(backgroundColor));
76 QFont font = painter->font();
77 font.setPointSize(font.pointSize() - 1 );
79 painter->setFont(font);
80 int mid = (int) ((r1.height() / 2 ));
81 r1.setBottom(r1.y() + mid);
82 QRect r2 = option.rect;
83 r2.setTop(r2.y() + mid);
84 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
85 //painter->setPen(Qt::green);
87 painter->setFont(font);
88 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(DurationRole).toString());
93 KExtendableItemDelegate::paint(painter, option, index);
98 class ProjectList : public QWidget
103 ProjectList(QWidget *parent=0);
104 virtual ~ProjectList();
106 QDomElement producersList();
107 void setRenderer(Render *projectRender);
109 void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
110 void deleteClip(const int clipId);
113 void setDocument(KdenliveDoc *doc);
114 void addProducer(QDomElement producer, int parentId = -1);
115 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
116 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
120 ProjectListView *listView;
121 KTreeWidgetSearchLine *searchView;
127 KUndoStack *m_commandStack;
129 void selectItemById(const int clipId);
130 ProjectItem *getItemById(int id);
131 QAction *m_editAction;
132 QAction *m_deleteAction;
133 ItemDelegate *m_listViewDelegate;
136 void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString::null);
137 void slotRemoveClip();
139 void slotClipSelected();
140 void slotAddColorClip();
141 void slotEditClip(QTreeWidgetItem *, int);
142 void slotContextMenu( const QPoint &pos, QTreeWidgetItem * );
143 void slotAddFolder();
144 /** This is triggered when a clip description has been modified */
145 void slotUpdateItemDescription(QTreeWidgetItem *item, int column);
146 //void slotShowMenu(const QPoint &pos);
151 void clipSelected(const QDomElement &);
152 void getFileProperties(const QDomElement&, int);
153 void receivedClipDuration(int, int);