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 <QToolButton>
27 #include <QTreeWidget>
29 #include <QItemDelegate>
33 #include <KTreeWidgetSearchLine>
35 #include <nepomuk/kratingpainter.h>
36 #include <nepomuk/resource.h>
38 #include "definitions.h"
40 #include "kdenlivesettings.h"
47 class ProjectListView;
52 const int NameRole = Qt::UserRole;
53 const int DurationRole = NameRole + 1;
54 const int UsageRole = NameRole + 2;
56 class ItemDelegate: public QItemDelegate {
58 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
61 static_cast<ProjectItem *>( index.internalPointer() );
65 QWidget *w = new QWidget;
66 QVBoxLayout *layout = new QVBoxLayout;
67 layout->addWidget( new KColorButton(w));
68 w->setLayout( layout );
72 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
73 if (index.column() == 1) {
74 QRect r1 = option.rect;
76 if (option.state & (QStyle::State_Selected)) {
77 painter->setPen(option.palette.color(QPalette::HighlightedText));
78 painter->fillRect(r1, option.palette.highlight());
80 QFont font = painter->font();
82 painter->setFont(font);
83 int mid = (int)((r1.height() / 2));
84 r1.setBottom(r1.y() + mid);
85 QRect r2 = option.rect;
86 r2.setTop(r2.y() + mid);
87 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
88 //painter->setPen(Qt::green);
90 painter->setFont(font);
91 QString subText = index.data(DurationRole).toString();
92 int usage = index.data(UsageRole).toInt();
93 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
94 painter->setPen(option.palette.color(QPalette::Mid));
95 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
97 } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
98 const QString url = index.data(Qt::UserRole).toString();
100 QItemDelegate::paint(painter, option, index);
103 QRect r1 = option.rect;
104 if (option.state & (QStyle::State_Selected)) {
105 painter->fillRect(r1, option.palette.highlight());
107 Nepomuk::Resource f(url);
108 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, f.rating());
110 QItemDelegate::paint(painter, option, index);
115 class ProjectList : public QWidget {
119 ProjectList(QWidget *parent = 0);
120 virtual ~ProjectList();
122 QDomElement producersList();
123 void setRenderer(Render *projectRender);
124 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
125 void updateAllClips();
126 QByteArray headerInfo();
127 void setHeaderInfo(const QByteArray &state);
128 void setupMenu(QMenu *addMenu, QAction *defaultAction);
129 void setupGeneratorMenu(QMenu *addMenu);
132 void setDocument(KdenliveDoc *doc);
133 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
134 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
135 void slotAddClip(DocClipBase *clip, bool getProperties);
136 void slotDeleteClip(const QString &clipId);
137 void slotUpdateClip(const QString &id);
138 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
139 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
140 void slotRemoveInvalidClip(const QString &id);
141 void slotSelectClip(const QString &ix);
142 void slotRemoveClip();
143 void slotAddClip(KUrl givenUrl = KUrl(), QString group = QString());
144 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
145 void slotResetProjectList();
148 ProjectListView *listView;
149 KTreeWidgetSearchLine *searchView;
155 QUndoStack *m_commandStack;
156 void selectItemById(const QString &clipId);
157 ProjectItem *getItemById(const QString &id);
158 ProjectItem *getFolderItemById(const QString &id);
159 QAction *m_editAction;
160 QAction *m_deleteAction;
162 ProjectItem *m_selectedItem;
164 QToolButton *m_addButton;
165 QMap <QString, QDomElement> m_infoQueue;
166 void requestClipInfo(const QDomElement xml, const QString id);
167 QList <QString> m_thumbnailQueue;
168 void requestClipThumbnail(const QString &id);
169 void deleteProjectFolder(QMap <QString, QString> map);
170 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
174 void slotClipSelected();
175 void slotAddColorClip();
176 void slotAddSlideshowClip();
177 void slotAddTitleClip();
178 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
179 void slotAddFolder();
180 /** This is triggered when a clip description has been modified */
181 void slotItemEdited(QTreeWidgetItem *item, int column);
182 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
183 void slotProcessNextClipInQueue();
184 void slotProcessNextThumbnail();
185 void slotCheckForEmptyQueue();
186 void slotPauseMonitor();
187 //void slotShowMenu(const QPoint &pos);
190 void clipSelected(DocClipBase *);
191 void getFileProperties(const QDomElement&, const QString &);
192 void receivedClipDuration(const QString &, int);
193 void showClipProperties(DocClipBase *);
194 void projectModified();
195 void loadingIsOver();
196 void clipNameChanged(const QString, const QString);