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>
32 #include <QApplication>
34 #include <KTreeWidgetSearchLine>
37 #include <nepomuk/kratingpainter.h>
38 #include <nepomuk/resource.h>
40 #include "definitions.h"
42 #include "kdenlivesettings.h"
43 #include "folderprojectitem.h"
51 class ProjectListView;
56 const int NameRole = Qt::UserRole;
57 const int DurationRole = NameRole + 1;
58 const int UsageRole = NameRole + 2;
60 class ItemDelegate: public QItemDelegate
63 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
66 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
69 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
70 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
71 QRect r1 = option.rect;
73 if (option.state & (QStyle::State_Selected)) {
74 painter->setPen(option.palette.color(QPalette::HighlightedText));
75 painter->fillRect(r1, option.palette.highlight());
77 QStyleOptionViewItemV2 opt = setOptions(index, option);
78 QPixmap pixmap = decoration(opt, index.data(Qt::DecorationRole));
79 QRect decorationRect = pixmap.rect(); //QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect());
80 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
81 decorationRect.moveTo(r1.topLeft() + QPoint(0, 1));
82 drawDecoration(painter, opt, decorationRect, pixmap);
83 int decoWidth = pixmap.width() + 2 * textMargin;
85 QFont font = painter->font();
87 painter->setFont(font);
88 int mid = (int)((r1.height() / 2));
89 r1.adjust(decoWidth, 0, 0, -mid);
90 QRect r2 = option.rect;
91 r2.adjust(decoWidth, 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 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
100 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
102 } else if (index.column() == 2 && 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());
112 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
115 QItemDelegate::paint(painter, option, index);
120 class ProjectList : public QWidget
125 ProjectList(QWidget *parent = 0);
126 virtual ~ProjectList();
128 QDomElement producersList();
129 void setRenderer(Render *projectRender);
130 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
131 QByteArray headerInfo() const;
132 void setHeaderInfo(const QByteArray &state);
133 void setupMenu(QMenu *addMenu, QAction *defaultAction);
134 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
135 QString currentClipUrl() const;
136 void reloadClipThumbnails();
137 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
139 void trashUnusedClips();
140 QList <DocClipBase*> documentClipList() const;
141 void addClipCut(const QString &id, int in, int out);
142 void removeClipCut(const QString &id, int in, int out);
143 void focusTree() const;
146 void setDocument(KdenliveDoc *doc);
147 void updateAllClips();
148 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
149 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
150 void slotAddClip(DocClipBase *clip, bool getProperties);
151 void slotDeleteClip(const QString &clipId);
152 void slotUpdateClip(const QString &id);
153 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
154 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
155 void slotRemoveInvalidClip(const QString &id, bool replace);
156 void slotSelectClip(const QString &ix);
157 void slotRemoveClip();
158 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
159 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
160 void slotResetProjectList();
163 void slotReloadClip(const QString &id = QString());
164 void slotAddColorClip();
165 void regenerateTemplate(const QString &id);
168 ProjectListView *m_listView;
175 QUndoStack *m_commandStack;
176 void selectItemById(const QString &clipId);
177 ProjectItem *getItemById(const QString &id);
178 QTreeWidgetItem *getAnyItemById(const QString &id);
179 FolderProjectItem *getFolderItemById(const QString &id);
180 QAction *m_editAction;
181 QAction *m_deleteAction;
182 QAction *m_openAction;
183 QAction *m_reloadAction;
184 QMenu *m_transcodeAction;
186 ItemDelegate *m_listViewDelegate;
188 QToolButton *m_addButton;
189 QMap <QString, QDomElement> m_infoQueue;
190 QMap <QString, QDomElement> m_producerQueue;
191 void requestClipInfo(const QDomElement xml, const QString id);
192 QList <QString> m_thumbnailQueue;
193 void requestClipThumbnail(const QString id);
194 void deleteProjectFolder(QMap <QString, QString> map);
195 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
196 QStringList getGroup() const;
197 void regenerateTemplate(ProjectItem *clip);
200 void slotClipSelected();
201 void slotAddSlideshowClip();
202 void slotAddTitleClip();
203 void slotAddTitleTemplateClip();
204 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
205 void slotAddFolder();
206 /** This is triggered when a clip description has been modified */
207 void slotItemEdited(QTreeWidgetItem *item, int column);
208 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
209 void slotProcessNextClipInQueue();
210 void slotProcessNextThumbnail();
211 void slotCheckForEmptyQueue();
212 void slotPauseMonitor();
213 void slotAddClipCut(const QString &id, int in, int out);
214 //void slotShowMenu(const QPoint &pos);
217 void clipSelected(DocClipBase *, QPoint zone = QPoint());
218 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
219 void receivedClipDuration(const QString &);
220 void showClipProperties(DocClipBase *);
221 void projectModified();
222 void loadingIsOver();
223 void displayMessage(const QString, int progress);
224 void clipNameChanged(const QString, const QString);