]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Allow to edit audio / image clips in external editor
[kdenlive] / src / projectlist.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef PRJECTLIST_H
22 #define PRJECTLIST_H
23
24 #include <QDomNodeList>
25 #include <QToolBar>
26 #include <QToolButton>
27 #include <QTreeWidget>
28 #include <QPainter>
29 #include <QItemDelegate>
30 #include <QUndoStack>
31
32
33 #include <KTreeWidgetSearchLine>
34 #include <KUrl>
35 #include <nepomuk/kratingpainter.h>
36 #include <nepomuk/resource.h>
37
38 #include "definitions.h"
39 #include "timecode.h"
40 #include "kdenlivesettings.h"
41
42 namespace Mlt {
43 class Producer;
44 };
45
46 class ProjectItem;
47 class ProjectListView;
48 class Render;
49 class KdenliveDoc;
50 class DocClipBase;
51
52 const int NameRole = Qt::UserRole;
53 const int DurationRole = NameRole + 1;
54 const int UsageRole = NameRole + 2;
55
56 class ItemDelegate: public QItemDelegate {
57 public:
58     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
59     }
60     /*
61     static_cast<ProjectItem *>( index.internalPointer() );
62
63     void expand()
64     {
65       QWidget *w = new QWidget;
66       QVBoxLayout *layout = new QVBoxLayout;
67       layout->addWidget( new KColorButton(w));
68       w->setLayout( layout );
69       extendItem(w,
70     }
71     */
72     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
73         if (index.column() == 1) {
74             QRect r1 = option.rect;
75             painter->save();
76             if (option.state & (QStyle::State_Selected)) {
77                 painter->setPen(option.palette.color(QPalette::HighlightedText));
78                 painter->fillRect(r1, option.palette.highlight());
79             }
80             QFont font = painter->font();
81             font.setBold(true);
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);
89             font.setBold(false);
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);
96             painter->restore();
97         } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
98             if (index.data().toString().isEmpty()) {
99                 QItemDelegate::paint(painter, option, index);
100                 return;
101             }
102             QRect r1 = option.rect;
103             if (option.state & (QStyle::State_Selected)) {
104                 painter->fillRect(r1, option.palette.highlight());
105             }
106             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
107         } else {
108             QItemDelegate::paint(painter, option, index);
109         }
110     }
111 };
112
113 class ProjectList : public QWidget {
114     Q_OBJECT
115
116 public:
117     ProjectList(QWidget *parent = 0);
118     virtual ~ProjectList();
119
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);
128
129 public slots:
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);
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(KUrl givenUrl = KUrl(), QString group = QString());
142     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
143     void slotResetProjectList();
144     void slotOpenClip();
145     void slotEditClip();
146
147 private:
148     ProjectListView *listView;
149     KTreeWidgetSearchLine *searchView;
150     Render *m_render;
151     Timecode m_timecode;
152     double m_fps;
153     QToolBar *m_toolbar;
154     QMenu *m_menu;
155     QUndoStack *m_commandStack;
156     void selectItemById(const QString &clipId);
157     ProjectItem *getItemById(const QString &id);
158     ProjectItem *getFolderItemById(const QString &id);
159     QAction *m_editAction;
160     QAction *m_deleteAction;
161     QAction *m_openAction;
162     KdenliveDoc *m_doc;
163     ProjectItem *m_selectedItem;
164     bool m_refreshed;
165     QToolButton *m_addButton;
166     QMap <QString, QDomElement> m_infoQueue;
167     void requestClipInfo(const QDomElement xml, const QString id);
168     QList <QString> m_thumbnailQueue;
169     void requestClipThumbnail(const QString &id);
170     void deleteProjectFolder(QMap <QString, QString> map);
171     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
172
173 private slots:
174     void slotClipSelected();
175     void slotAddColorClip();
176     void slotAddSlideshowClip();
177     void slotAddTitleClip();
178     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
179     void slotAddFolder();
180     /** This is triggered when a clip description has been modified */
181     void slotItemEdited(QTreeWidgetItem *item, int column);
182     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
183     void slotProcessNextClipInQueue();
184     void slotProcessNextThumbnail();
185     void slotCheckForEmptyQueue();
186     void slotPauseMonitor();
187     //void slotShowMenu(const QPoint &pos);
188
189 signals:
190     void clipSelected(DocClipBase *);
191     void getFileProperties(const QDomElement&, const QString &);
192     void receivedClipDuration(const QString &, int);
193     void showClipProperties(DocClipBase *);
194     void projectModified();
195     void loadingIsOver();
196     void clipNameChanged(const QString, const QString);
197 };
198
199 #endif