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 if (index.data().toString().isEmpty()) {
99 QItemDelegate::paint(painter, option, index);
102 QRect r1 = option.rect;
103 if (option.state & (QStyle::State_Selected)) {
104 painter->fillRect(r1, option.palette.highlight());
106 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
108 QItemDelegate::paint(painter, option, index);
113 class ProjectList : public QWidget {
117 ProjectList(QWidget *parent = 0);
118 virtual ~ProjectList();
120 QDomElement producersList();
121 void setRenderer(Render *projectRender);
122 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
123 void updateAllClips();
124 QByteArray headerInfo();
125 void setHeaderInfo(const QByteArray &state);
126 void setupMenu(QMenu *addMenu, QAction *defaultAction);
127 void setupGeneratorMenu(QMenu *addMenu);
130 void setDocument(KdenliveDoc *doc);
131 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
132 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
133 void slotAddClip(DocClipBase *clip, bool getProperties);
134 void slotDeleteClip(const QString &clipId);
135 void slotUpdateClip(const QString &id);
136 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
137 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
138 void slotRemoveInvalidClip(const QString &id);
139 void slotSelectClip(const QString &ix);
140 void slotRemoveClip();
141 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), QString group = QString());
142 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
143 void slotResetProjectList();
146 void slotReloadClip();
149 ProjectListView *listView;
150 KTreeWidgetSearchLine *searchView;
156 QUndoStack *m_commandStack;
157 void selectItemById(const QString &clipId);
158 ProjectItem *getItemById(const QString &id);
159 ProjectItem *getFolderItemById(const QString &id);
160 QAction *m_editAction;
161 QAction *m_deleteAction;
162 QAction *m_openAction;
163 QAction *m_reloadAction;
165 ProjectItem *m_selectedItem;
167 QToolButton *m_addButton;
168 QMap <QString, QDomElement> m_infoQueue;
169 void requestClipInfo(const QDomElement xml, const QString id);
170 QList <QString> m_thumbnailQueue;
171 void requestClipThumbnail(const QString &id);
172 void deleteProjectFolder(QMap <QString, QString> map);
173 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
176 void slotClipSelected();
177 void slotAddColorClip();
178 void slotAddSlideshowClip();
179 void slotAddTitleClip();
180 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
181 void slotAddFolder();
182 /** This is triggered when a clip description has been modified */
183 void slotItemEdited(QTreeWidgetItem *item, int column);
184 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
185 void slotProcessNextClipInQueue();
186 void slotProcessNextThumbnail();
187 void slotCheckForEmptyQueue();
188 void slotPauseMonitor();
189 //void slotShowMenu(const QPoint &pos);
192 void clipSelected(DocClipBase *);
193 void getFileProperties(const QDomElement&, const QString &, bool);
194 void receivedClipDuration(const QString &, int);
195 void showClipProperties(DocClipBase *);
196 void projectModified();
197 void loadingIsOver();
198 void clipNameChanged(const QString, const QString);