]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
7b1310c81ab4711c24fc9e837a2e15bd6ff8e660
[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 PROJECTLIST_H
22 #define PROJECTLIST_H
23
24 #include <QDomNodeList>
25 #include <QToolBar>
26 #include <QToolButton>
27 #include <QTreeWidget>
28 #include <QPainter>
29 #include <QItemDelegate>
30 #include <QUndoStack>
31 #include <QTimer>
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 {
44 class Producer;
45 };
46
47 class ProjectItem;
48 class ProjectListView;
49 class Render;
50 class KdenliveDoc;
51 class DocClipBase;
52
53 const int NameRole = Qt::UserRole;
54 const int DurationRole = NameRole + 1;
55 const int UsageRole = NameRole + 2;
56
57 class ItemDelegate: public QItemDelegate
58 {
59 public:
60     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
61     }
62     /*
63     static_cast<ProjectItem *>( index.internalPointer() );
64
65     void expand()
66     {
67       QWidget *w = new QWidget;
68       QVBoxLayout *layout = new QVBoxLayout;
69       layout->addWidget( new KColorButton(w));
70       w->setLayout( layout );
71       extendItem(w,
72     }
73     */
74     void drawFocus ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect ) const {
75     }
76     
77     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
78         if (index.column() == 1) {
79             QRect r1 = option.rect;
80             painter->save();
81             if (option.state & (QStyle::State_Selected)) {
82                 painter->setPen(option.palette.color(QPalette::HighlightedText));
83                 painter->fillRect(r1, option.palette.highlight());
84             }
85             QFont font = painter->font();
86             font.setBold(true);
87             painter->setFont(font);
88             int mid = (int)((r1.height() / 2));
89             r1.adjust(2, 0, 0, -mid);
90             QRect r2 = option.rect;
91             r2.adjust(2, mid, 0, 0);
92             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
93             //painter->setPen(Qt::green);
94             font.setBold(false);
95             painter->setFont(font);
96             QString subText = index.data(DurationRole).toString();
97             int usage = index.data(UsageRole).toInt();
98             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
99             painter->setPen(option.palette.color(QPalette::Mid));
100             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
101             painter->restore();
102         } else if (index.column() == 3 && KdenliveSettings::activate_nepomuk()) {
103             if (index.data().toString().isEmpty()) {
104                 QItemDelegate::paint(painter, option, index);
105                 return;
106             }
107             QRect r1 = option.rect;
108             if (option.state & (QStyle::State_Selected)) {
109                 painter->fillRect(r1, option.palette.highlight());
110             }
111             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
112         } else {
113             QItemDelegate::paint(painter, option, index);
114         }
115     }
116 };
117
118 class ProjectList : public QWidget
119 {
120     Q_OBJECT
121
122 public:
123     ProjectList(QWidget *parent = 0);
124     virtual ~ProjectList();
125
126     QDomElement producersList();
127     void setRenderer(Render *projectRender);
128     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
129     QByteArray headerInfo() const;
130     void setHeaderInfo(const QByteArray &state);
131     void setupMenu(QMenu *addMenu, QAction *defaultAction);
132     void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu);
133     QString currentClipUrl() const;
134     void reloadClipThumbnails();
135     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
136
137 public slots:
138     void setDocument(KdenliveDoc *doc);
139     void updateAllClips();
140     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
141     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
142     void slotAddClip(DocClipBase *clip, bool getProperties);
143     void slotDeleteClip(const QString &clipId);
144     void slotUpdateClip(const QString &id);
145     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
146     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
147     void slotRemoveInvalidClip(const QString &id, bool replace);
148     void slotSelectClip(const QString &ix);
149     void slotRemoveClip();
150     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
151     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
152     void slotResetProjectList();
153     void slotOpenClip();
154     void slotEditClip();
155     void slotReloadClip(const QString &id = QString());
156     void slotAddColorClip();
157     void regenerateTemplate(const QString &id);
158
159 private:
160     ProjectListView *m_listView;
161     Render *m_render;
162     Timecode m_timecode;
163     double m_fps;
164     QToolBar *m_toolbar;
165     QTimer m_queueTimer;
166     QMenu *m_menu;
167     QUndoStack *m_commandStack;
168     void selectItemById(const QString &clipId);
169     ProjectItem *getItemById(const QString &id);
170     ProjectItem *getFolderItemById(const QString &id);
171     QAction *m_editAction;
172     QAction *m_deleteAction;
173     QAction *m_openAction;
174     QAction *m_reloadAction;
175     QMenu *m_transcodeAction;
176     KdenliveDoc *m_doc;
177     ProjectItem *m_selectedItem;
178     ItemDelegate *m_listViewDelegate;
179     bool m_refreshed;
180     QToolButton *m_addButton;
181     QMap <QString, QDomElement> m_infoQueue;
182     QMap <QString, QDomElement> m_producerQueue;
183     void requestClipInfo(const QDomElement xml, const QString id);
184     QList <QString> m_thumbnailQueue;
185     void requestClipThumbnail(const QString id);
186     void deleteProjectFolder(QMap <QString, QString> map);
187     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
188     QStringList getGroup() const;
189     void regenerateTemplate(ProjectItem *clip);
190
191 private slots:
192     void slotClipSelected();
193     void slotAddSlideshowClip();
194     void slotAddTitleClip();
195     void slotAddTitleTemplateClip();
196     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
197     void slotAddFolder();
198     /** This is triggered when a clip description has been modified */
199     void slotItemEdited(QTreeWidgetItem *item, int column);
200     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
201     void slotProcessNextClipInQueue();
202     void slotProcessNextThumbnail();
203     void slotCheckForEmptyQueue();
204     void slotPauseMonitor();
205     //void slotShowMenu(const QPoint &pos);
206
207 signals:
208     void clipSelected(DocClipBase *);
209     void getFileProperties(const QDomElement, const QString &, bool);
210     void receivedClipDuration(const QString &);
211     void showClipProperties(DocClipBase *);
212     void projectModified();
213     void loadingIsOver();
214     void displayMessage(const QString, MessageType);
215     void clipNameChanged(const QString, const QString);
216     void refreshClip();
217 };
218
219 #endif