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 <QTreeWidget>
28 #include <QItemDelegate>
31 #include <KTreeWidgetSearchLine>
34 #include "definitions.h"
42 class ProjectListView;
47 const int NameRole = Qt::UserRole;
48 const int DurationRole = NameRole + 1;
49 const int UsageRole = NameRole + 2;
51 class ItemDelegate: public QItemDelegate {
53 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
56 static_cast<ProjectItem *>( index.internalPointer() );
60 QWidget *w = new QWidget;
61 QVBoxLayout *layout = new QVBoxLayout;
62 layout->addWidget( new KColorButton(w));
63 w->setLayout( layout );
67 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
68 if (index.column() == 1) {
69 const bool hover = option.state & (QStyle::State_Selected);
70 QRect r1 = option.rect;
73 painter->setPen(option.palette.color(QPalette::HighlightedText));
74 QColor backgroundColor = option.palette.color(QPalette::Highlight);
75 painter->setBrush(QBrush(backgroundColor));
76 painter->fillRect(r1, QBrush(backgroundColor));
78 QFont font = painter->font();
80 painter->setFont(font);
81 int mid = (int)((r1.height() / 2));
82 r1.setBottom(r1.y() + mid);
83 QRect r2 = option.rect;
84 r2.setTop(r2.y() + mid);
85 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
86 //painter->setPen(Qt::green);
88 painter->setFont(font);
89 QString subText = index.data(DurationRole).toString();
90 int usage = index.data(UsageRole).toInt();
91 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
92 painter->setPen(option.palette.color(QPalette::Mid));
93 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
96 QItemDelegate::paint(painter, option, index);
101 class ProjectList : public QWidget {
105 ProjectList(QWidget *parent = 0);
106 virtual ~ProjectList();
108 QDomElement producersList();
109 void setRenderer(Render *projectRender);
110 void slotUpdateClipProperties(int id, QMap <QString, QString> properties);
113 void setDocument(KdenliveDoc *doc);
114 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
115 void slotReplyGetFileProperties(int clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
116 void slotAddClip(DocClipBase *clip);
117 void slotDeleteClip(int clipId);
118 void slotUpdateClip(int id);
119 void slotRefreshClipThumbnail(int clipId);
120 void slotRefreshClipThumbnail(ProjectItem *item);
121 void slotRemoveInvalidClip(int id);
124 ProjectListView *listView;
125 KTreeWidgetSearchLine *searchView;
131 KUndoStack *m_commandStack;
133 void selectItemById(const int clipId);
134 ProjectItem *getItemById(int id);
135 QAction *m_editAction;
136 QAction *m_deleteAction;
138 ItemDelegate *m_listViewDelegate;
139 ProjectItem *m_selectedItem;
142 void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
143 void slotRemoveClip();
145 void slotClipSelected();
146 void slotAddColorClip();
147 void slotAddSlideshowClip();
148 void slotAddTitleClip();
149 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
150 void slotAddFolder();
151 void slotAddFolder(const QString foldername, int clipId, bool remove, bool edit);
152 /** This is triggered when a clip description has been modified */
153 void slotItemEdited(QTreeWidgetItem *item, int column);
154 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
155 //void slotShowMenu(const QPoint &pos);
160 void clipSelected(DocClipBase *);
161 void getFileProperties(const QDomElement&, int);
162 void receivedClipDuration(int, int);
163 void showClipProperties(DocClipBase *);