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 paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
75 if (index.column() == 1) {
76 QRect r1 = option.rect;
78 if (option.state & (QStyle::State_Selected)) {
79 painter->setPen(option.palette.color(QPalette::HighlightedText));
80 painter->fillRect(r1, option.palette.highlight());
82 QFont font = painter->font();
84 painter->setFont(font);
85 int mid = (int)((r1.height() / 2));
86 r1.setBottom(r1.y() + mid);
87 QRect r2 = option.rect;
88 r2.setTop(r2.y() + mid);
89 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
90 //painter->setPen(Qt::green);
92 painter->setFont(font);
93 QString subText = index.data(DurationRole).toString();
94 int usage = index.data(UsageRole).toInt();
95 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
96 painter->setPen(option.palette.color(QPalette::Mid));
97 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
99 } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
100 if (index.data().toString().isEmpty()) {
101 QItemDelegate::paint(painter, option, index);
104 QRect r1 = option.rect;
105 if (option.state & (QStyle::State_Selected)) {
106 painter->fillRect(r1, option.palette.highlight());
108 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
110 QItemDelegate::paint(painter, option, index);
115 class ProjectList : public QWidget
120 ProjectList(QWidget *parent = 0);
121 virtual ~ProjectList();
123 QDomElement producersList();
124 void setRenderer(Render *projectRender);
125 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
126 void updateAllClips();
127 QByteArray headerInfo();
128 void setHeaderInfo(const QByteArray &state);
129 void setupMenu(QMenu *addMenu, QAction *defaultAction);
130 void setupGeneratorMenu(QMenu *addMenu);
133 void setDocument(KdenliveDoc *doc);
134 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
135 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
136 void slotAddClip(DocClipBase *clip, bool getProperties);
137 void slotDeleteClip(const QString &clipId);
138 void slotUpdateClip(const QString &id);
139 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
140 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
141 void slotRemoveInvalidClip(const QString &id);
142 void slotSelectClip(const QString &ix);
143 void slotRemoveClip();
144 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), QString group = QString());
145 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
146 void slotResetProjectList();
149 void slotReloadClip();
152 ProjectListView *m_listView;
158 QUndoStack *m_commandStack;
159 void selectItemById(const QString &clipId);
160 ProjectItem *getItemById(const QString &id);
161 ProjectItem *getFolderItemById(const QString &id);
162 QAction *m_editAction;
163 QAction *m_deleteAction;
164 QAction *m_openAction;
165 QAction *m_reloadAction;
167 ProjectItem *m_selectedItem;
169 QToolButton *m_addButton;
170 QMap <QString, QDomElement> m_infoQueue;
171 void requestClipInfo(const QDomElement xml, const QString id);
172 QList <QString> m_thumbnailQueue;
173 void requestClipThumbnail(const QString &id);
174 void deleteProjectFolder(QMap <QString, QString> map);
175 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
178 void slotClipSelected();
179 void slotAddColorClip();
180 void slotAddSlideshowClip();
181 void slotAddTitleClip();
182 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
183 void slotAddFolder();
184 /** This is triggered when a clip description has been modified */
185 void slotItemEdited(QTreeWidgetItem *item, int column);
186 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
187 void slotProcessNextClipInQueue();
188 void slotProcessNextThumbnail();
189 void slotCheckForEmptyQueue();
190 void slotPauseMonitor();
191 //void slotShowMenu(const QPoint &pos);
194 void clipSelected(DocClipBase *);
195 void getFileProperties(const QDomElement&, const QString &, bool);
196 void receivedClipDuration(const QString &);
197 void showClipProperties(DocClipBase *);
198 void projectModified();
199 void loadingIsOver();
200 void clipNameChanged(const QString, const QString);