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>
28 #include <QItemDelegate>
31 #include <KTreeWidgetSearchLine>
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 QItemDelegate {
49 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
52 static_cast<ProjectItem *>( index.internalPointer() );
56 QWidget *w = new QWidget;
57 QVBoxLayout *layout = new QVBoxLayout;
58 layout->addWidget( new KColorButton(w));
59 w->setLayout( layout );
64 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
65 if (index.column() == 1) {
66 const bool hover = option.state & (QStyle::State_Selected);
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());
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);
93 QItemDelegate::paint(painter, option, index);
98 class ProjectList : public QWidget {
102 ProjectList(QWidget *parent = 0);
103 virtual ~ProjectList();
105 QDomElement producersList();
106 void setRenderer(Render *projectRender);
108 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 slotUpdateClipProperties(int id, QMap <QString, QString> properties);
112 void setDocument(KdenliveDoc *doc);
113 void addProducer(QDomElement producer, int parentId = -1);
114 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
115 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
116 void slotAddClip(DocClipBase *clip);
117 void slotDeleteClip(int clipId);
118 void slotUpdateClip(int id);
119 void slotRefreshClipThumbnail(int clipId);
120 void slotRefreshClipThumbnail(ProjectItem *item);
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;
138 ItemDelegate *m_listViewDelegate;
141 void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
142 void slotRemoveClip();
143 void slotClipSelected();
144 void slotAddColorClip();
145 void slotAddSlideshowClip();
146 void slotAddTitleClip();
147 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
148 void slotAddFolder();
149 void slotAddFolder(const QString foldername, int clipId, bool remove, bool edit);
150 /** This is triggered when a clip description has been modified */
151 void slotItemEdited(QTreeWidgetItem *item, int column);
152 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
153 //void slotShowMenu(const QPoint &pos);
158 void clipSelected(const QDomElement &);
159 void getFileProperties(const QDomElement&, int);
160 void receivedClipDuration(int, int);
161 void showClipProperties(DocClipBase *);