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"
42 class ProjectListView;
47 const int NameRole = Qt::UserRole;
48 const int DurationRole = NameRole + 1;
49 const int UsageRole = NameRole + 2;
51 class ItemDelegate: public QItemDelegate {
53 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
56 static_cast<ProjectItem *>( index.internalPointer() );
60 QWidget *w = new QWidget;
61 QVBoxLayout *layout = new QVBoxLayout;
62 layout->addWidget( new KColorButton(w));
63 w->setLayout( layout );
67 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
68 if (index.column() == 1) {
69 const bool hover = option.state & (QStyle::State_Selected);
70 QRect r1 = option.rect;
73 painter->setPen(option.palette.color(QPalette::HighlightedText));
74 QColor backgroundColor = option.palette.color(QPalette::Highlight);
75 painter->setBrush(QBrush(backgroundColor));
76 painter->fillRect(r1, QBrush(backgroundColor));
78 QFont font = painter->font();
80 painter->setFont(font);
81 int mid = (int)((r1.height() / 2));
82 r1.setBottom(r1.y() + mid);
83 QRect r2 = option.rect;
84 r2.setTop(r2.y() + mid);
85 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
86 //painter->setPen(Qt::green);
88 painter->setFont(font);
89 QString subText = index.data(DurationRole).toString();
90 int usage = index.data(UsageRole).toInt();
91 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
92 painter->setPen(option.palette.color(QPalette::Mid));
93 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
96 QItemDelegate::paint(painter, option, index);
101 class ProjectList : public QWidget {
105 ProjectList(QWidget *parent = 0);
106 virtual ~ProjectList();
108 QDomElement producersList();
109 void setRenderer(Render *projectRender);
110 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
113 void setDocument(KdenliveDoc *doc);
114 void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
115 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
116 void slotAddClip(DocClipBase *clip);
117 void slotDeleteClip(const QString &clipId);
118 void slotUpdateClip(const QString &id);
119 void slotRefreshClipThumbnail(const QString &clipId);
120 void slotRefreshClipThumbnail(ProjectItem *item);
121 void slotRemoveInvalidClip(const QString &id);
122 void slotSelectClip(const QString &ix);
125 ProjectListView *listView;
126 KTreeWidgetSearchLine *searchView;
132 QUndoStack *m_commandStack;
134 void selectItemById(const QString &clipId);
135 ProjectItem *getItemById(const QString &id);
136 QAction *m_editAction;
137 QAction *m_deleteAction;
139 ItemDelegate *m_listViewDelegate;
140 ProjectItem *m_selectedItem;
143 void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
144 void slotRemoveClip();
146 void slotClipSelected();
147 void slotAddColorClip();
148 void slotAddSlideshowClip();
149 void slotAddTitleClip();
150 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
151 void slotAddFolder();
152 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit);
153 /** This is triggered when a clip description has been modified */
154 void slotItemEdited(QTreeWidgetItem *item, int column);
155 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
156 //void slotShowMenu(const QPoint &pos);
159 void clipSelected(DocClipBase *);
160 void getFileProperties(const QDomElement&, const QString &);
161 void receivedClipDuration(const QString &, int);
162 void showClipProperties(DocClipBase *);
163 void projectModified();