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"
48 class ProjectListView;
53 const int NameRole = Qt::UserRole;
54 const int DurationRole = NameRole + 1;
55 const int UsageRole = NameRole + 2;
57 class ItemDelegate: public QItemDelegate
60 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
63 static_cast<ProjectItem *>( index.internalPointer() );
67 QWidget *w = new QWidget;
68 QVBoxLayout *layout = new QVBoxLayout;
69 layout->addWidget( new KColorButton(w));
70 w->setLayout( layout );
74 void drawFocus ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect ) const {
77 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
78 if (index.column() == 1) {
79 QRect r1 = option.rect;
81 if (option.state & (QStyle::State_Selected)) {
82 painter->setPen(option.palette.color(QPalette::HighlightedText));
83 painter->fillRect(r1, option.palette.highlight());
85 QFont font = painter->font();
87 painter->setFont(font);
88 int mid = (int)((r1.height() / 2));
89 r1.adjust(2, 0, 0, -mid);
90 QRect r2 = option.rect;
91 r2.adjust(2, mid, 0, 0);
92 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
93 //painter->setPen(Qt::green);
95 painter->setFont(font);
96 QString subText = index.data(DurationRole).toString();
97 int usage = index.data(UsageRole).toInt();
98 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
99 painter->setPen(option.palette.color(QPalette::Mid));
100 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
102 } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
103 if (index.data().toString().isEmpty()) {
104 QItemDelegate::paint(painter, option, index);
107 QRect r1 = option.rect;
108 if (option.state & (QStyle::State_Selected)) {
109 painter->fillRect(r1, option.palette.highlight());
111 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
113 QItemDelegate::paint(painter, option, index);
118 class ProjectList : public QWidget
123 ProjectList(QWidget *parent = 0);
124 virtual ~ProjectList();
126 QDomElement producersList();
127 void setRenderer(Render *projectRender);
128 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
129 QByteArray headerInfo() const;
130 void setHeaderInfo(const QByteArray &state);
131 void setupMenu(QMenu *addMenu, QAction *defaultAction);
132 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
133 QString currentClipUrl() const;
134 void reloadClipThumbnails();
135 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
138 void setDocument(KdenliveDoc *doc);
139 void updateAllClips();
140 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
141 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
142 void slotAddClip(DocClipBase *clip, bool getProperties);
143 void slotDeleteClip(const QString &clipId);
144 void slotUpdateClip(const QString &id);
145 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
146 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
147 void slotRemoveInvalidClip(const QString &id, bool replace);
148 void slotSelectClip(const QString &ix);
149 void slotRemoveClip();
150 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
151 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
152 void slotResetProjectList();
155 void slotReloadClip(const QString &id = QString());
156 void slotAddColorClip();
157 void regenerateTemplate(const QString &id);
160 ProjectListView *m_listView;
167 QUndoStack *m_commandStack;
168 void selectItemById(const QString &clipId);
169 ProjectItem *getItemById(const QString &id);
170 ProjectItem *getFolderItemById(const QString &id);
171 QAction *m_editAction;
172 QAction *m_deleteAction;
173 QAction *m_openAction;
174 QAction *m_reloadAction;
175 QMenu *m_transcodeAction;
177 ProjectItem *m_selectedItem;
178 ItemDelegate *m_listViewDelegate;
180 QToolButton *m_addButton;
181 QMap <QString, QDomElement> m_infoQueue;
182 QMap <QString, QDomElement> m_producerQueue;
183 void requestClipInfo(const QDomElement xml, const QString id);
184 QList <QString> m_thumbnailQueue;
185 void requestClipThumbnail(const QString id);
186 void deleteProjectFolder(QMap <QString, QString> map);
187 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
188 QStringList getGroup() const;
189 void regenerateTemplate(ProjectItem *clip);
192 void slotClipSelected();
193 void slotAddSlideshowClip();
194 void slotAddTitleClip();
195 void slotAddTitleTemplateClip();
196 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
197 void slotAddFolder();
198 /** This is triggered when a clip description has been modified */
199 void slotItemEdited(QTreeWidgetItem *item, int column);
200 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
201 void slotProcessNextClipInQueue();
202 void slotProcessNextThumbnail();
203 void slotCheckForEmptyQueue();
204 void slotPauseMonitor();
205 //void slotShowMenu(const QPoint &pos);
208 void clipSelected(DocClipBase *);
209 void getFileProperties(const QDomElement, const QString &, bool);
210 void receivedClipDuration(const QString &);
211 void showClipProperties(DocClipBase *);
212 void projectModified();
213 void loadingIsOver();
214 void displayMessage(const QString, MessageType);
215 void clipNameChanged(const QString, const QString);