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