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>
36 #include "definitions.h"
44 class ProjectListView;
49 const int NameRole = Qt::UserRole;
50 const int DurationRole = NameRole + 1;
51 const int UsageRole = NameRole + 2;
53 class ItemDelegate: public QItemDelegate {
55 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
58 static_cast<ProjectItem *>( index.internalPointer() );
62 QWidget *w = new QWidget;
63 QVBoxLayout *layout = new QVBoxLayout;
64 layout->addWidget( new KColorButton(w));
65 w->setLayout( layout );
69 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
70 if (index.column() == 1) {
71 const bool hover = option.state & (QStyle::State_Selected);
72 QRect r1 = option.rect;
75 painter->setPen(option.palette.color(QPalette::HighlightedText));
76 QColor backgroundColor = option.palette.color(QPalette::Highlight);
77 painter->setBrush(QBrush(backgroundColor));
78 painter->fillRect(r1, QBrush(backgroundColor));
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);
98 QItemDelegate::paint(painter, option, index);
103 class ProjectList : public QWidget {
107 ProjectList(QWidget *parent = 0);
108 virtual ~ProjectList();
110 QDomElement producersList();
111 void setRenderer(Render *projectRender);
112 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
113 void updateAllClips();
114 QByteArray headerInfo();
115 void setHeaderInfo(const QByteArray &state);
116 void setupMenu(QMenu *addMenu, QAction *defaultAction);
117 void setupGeneratorMenu(QMenu *addMenu);
120 void setDocument(KdenliveDoc *doc);
121 void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
122 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
123 void slotAddClip(DocClipBase *clip, bool getProperties);
124 void slotDeleteClip(const QString &clipId);
125 void slotUpdateClip(const QString &id);
126 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
127 void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
128 void slotRemoveInvalidClip(const QString &id);
129 void slotSelectClip(const QString &ix);
130 void slotRemoveClip();
131 void slotAddClip(KUrl givenUrl = KUrl(), QString group = QString());
134 ProjectListView *listView;
135 KTreeWidgetSearchLine *searchView;
141 QUndoStack *m_commandStack;
143 void selectItemById(const QString &clipId);
144 ProjectItem *getItemById(const QString &id);
145 QAction *m_editAction;
146 QAction *m_deleteAction;
148 ProjectItem *m_selectedItem;
150 QToolButton *m_addButton;
151 QMap <QString, QDomElement> m_infoQueue;
152 void requestClipInfo(const QDomElement xml, const QString id);
153 QList <QString> m_thumbnailQueue;
154 void requestClipThumbnail(const QString &id);
158 void slotClipSelected();
159 void slotAddColorClip();
160 void slotAddSlideshowClip();
161 void slotAddTitleClip();
162 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
163 void slotAddFolder();
164 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit);
165 /** This is triggered when a clip description has been modified */
166 void slotItemEdited(QTreeWidgetItem *item, int column);
167 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
168 void slotProcessNextClipInQueue();
169 void slotProcessNextThumbnail();
170 void slotCheckForEmptyQueue();
171 void slotPauseMonitor();
172 //void slotShowMenu(const QPoint &pos);
175 void clipSelected(DocClipBase *);
176 void getFileProperties(const QDomElement&, const QString &);
177 void receivedClipDuration(const QString &, int);
178 void showClipProperties(DocClipBase *);
179 void projectModified();
180 void loadingIsOver();