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>
32 #include <KTreeWidgetSearchLine>
35 #include "definitions.h"
43 class ProjectListView;
48 const int NameRole = Qt::UserRole;
49 const int DurationRole = NameRole + 1;
50 const int UsageRole = NameRole + 2;
52 class ItemDelegate: public QItemDelegate {
54 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
57 static_cast<ProjectItem *>( index.internalPointer() );
61 QWidget *w = new QWidget;
62 QVBoxLayout *layout = new QVBoxLayout;
63 layout->addWidget( new KColorButton(w));
64 w->setLayout( layout );
68 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
69 if (index.column() == 1) {
70 const bool hover = option.state & (QStyle::State_Selected);
71 QRect r1 = option.rect;
74 painter->setPen(option.palette.color(QPalette::HighlightedText));
75 QColor backgroundColor = option.palette.color(QPalette::Highlight);
76 painter->setBrush(QBrush(backgroundColor));
77 painter->fillRect(r1, QBrush(backgroundColor));
79 QFont font = painter->font();
81 painter->setFont(font);
82 int mid = (int)((r1.height() / 2));
83 r1.setBottom(r1.y() + mid);
84 QRect r2 = option.rect;
85 r2.setTop(r2.y() + mid);
86 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
87 //painter->setPen(Qt::green);
89 painter->setFont(font);
90 QString subText = index.data(DurationRole).toString();
91 int usage = index.data(UsageRole).toInt();
92 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
93 painter->setPen(option.palette.color(QPalette::Mid));
94 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
97 QItemDelegate::paint(painter, option, index);
102 class ProjectList : public QWidget {
106 ProjectList(QWidget *parent = 0);
107 virtual ~ProjectList();
109 QDomElement producersList();
110 void setRenderer(Render *projectRender);
111 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
112 void updateAllClips();
113 QByteArray headerInfo();
114 void setHeaderInfo(const QByteArray &state);
117 void setDocument(KdenliveDoc *doc);
118 void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
119 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
120 void slotAddClip(DocClipBase *clip, bool getProperties = true);
121 void slotDeleteClip(const QString &clipId);
122 void slotUpdateClip(const QString &id);
123 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
124 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
125 void slotRemoveInvalidClip(const QString &id);
126 void slotSelectClip(const QString &ix);
127 void slotRemoveClip();
130 ProjectListView *listView;
131 KTreeWidgetSearchLine *searchView;
137 QUndoStack *m_commandStack;
139 void selectItemById(const QString &clipId);
140 ProjectItem *getItemById(const QString &id);
141 QAction *m_editAction;
142 QAction *m_deleteAction;
144 ItemDelegate *m_listViewDelegate;
145 ProjectItem *m_selectedItem;
147 QMap <QString, QDomElement> m_infoQueue;
148 void requestClipInfo(const QDomElement xml, const QString id);
149 QList <QString> m_thumbnailQueue;
150 void requestClipThumbnail(const QString &id);
153 void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
155 void slotClipSelected();
156 void slotAddColorClip();
157 void slotAddSlideshowClip();
158 void slotAddTitleClip();
159 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
160 void slotAddFolder();
161 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit);
162 /** This is triggered when a clip description has been modified */
163 void slotItemEdited(QTreeWidgetItem *item, int column);
164 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
165 void slotProcessNextClipInQueue();
166 void slotProcessNextThumbnail();
167 void slotCheckForEmptyQueue();
168 void slotPauseMonitor();
169 //void slotShowMenu(const QPoint &pos);
172 void clipSelected(DocClipBase *);
173 void getFileProperties(const QDomElement&, const QString &);
174 void receivedClipDuration(const QString &, int);
175 void showClipProperties(DocClipBase *);
176 void projectModified();
177 void loadingIsOver();