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"
38 class ProjectListView;
43 const int NameRole = Qt::UserRole;
44 const int DurationRole = NameRole + 1;
45 const int UsageRole = NameRole + 2;
47 class ItemDelegate: public QItemDelegate {
49 ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
52 static_cast<ProjectItem *>( index.internalPointer() );
56 QWidget *w = new QWidget;
57 QVBoxLayout *layout = new QVBoxLayout;
58 layout->addWidget( new KColorButton(w));
59 w->setLayout( layout );
63 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
64 if (index.column() == 1) {
65 const bool hover = option.state & (QStyle::State_Selected);
66 QRect r1 = option.rect;
69 painter->setPen(option.palette.color(QPalette::HighlightedText));
70 QColor backgroundColor = option.palette.color(QPalette::Highlight);
71 painter->setBrush(QBrush(backgroundColor));
72 painter->fillRect(r1, QBrush(backgroundColor));
74 QFont font = painter->font();
76 painter->setFont(font);
77 int mid = (int)((r1.height() / 2));
78 r1.setBottom(r1.y() + mid);
79 QRect r2 = option.rect;
80 r2.setTop(r2.y() + mid);
81 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
82 //painter->setPen(Qt::green);
84 painter->setFont(font);
85 QString subText = index.data(DurationRole).toString();
86 int usage = index.data(UsageRole).toInt();
87 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
88 painter->setPen(option.palette.color(QPalette::Mid));
89 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
92 QItemDelegate::paint(painter, option, index);
97 class ProjectList : public QWidget {
101 ProjectList(QWidget *parent = 0);
102 virtual ~ProjectList();
104 QDomElement producersList();
105 void setRenderer(Render *projectRender);
106 void slotUpdateClipProperties(int id, QMap <QString, QString> properties);
109 void setDocument(KdenliveDoc *doc);
110 void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
111 void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
112 void slotAddClip(DocClipBase *clip);
113 void slotDeleteClip(int clipId);
114 void slotUpdateClip(int id);
115 void slotRefreshClipThumbnail(int clipId);
116 void slotRefreshClipThumbnail(ProjectItem *item);
120 ProjectListView *listView;
121 KTreeWidgetSearchLine *searchView;
127 KUndoStack *m_commandStack;
129 void selectItemById(const int clipId);
130 ProjectItem *getItemById(int id);
131 QAction *m_editAction;
132 QAction *m_deleteAction;
134 ItemDelegate *m_listViewDelegate;
135 ProjectItem *m_selectedItem;
138 void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
139 void slotRemoveClip();
141 void slotClipSelected();
142 void slotAddColorClip();
143 void slotAddSlideshowClip();
144 void slotAddTitleClip();
145 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
146 void slotAddFolder();
147 void slotAddFolder(const QString foldername, int clipId, bool remove, bool edit);
148 /** This is triggered when a clip description has been modified */
149 void slotItemEdited(QTreeWidgetItem *item, int column);
150 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
151 //void slotShowMenu(const QPoint &pos);
156 void clipSelected(DocClipBase *);
157 void getFileProperties(const QDomElement&, int);
158 void receivedClipDuration(int, int);
159 void showClipProperties(DocClipBase *);