]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
* Fix possible crash when creating new document
[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
36 #include "definitions.h"
37 #include "timecode.h"
38
39 namespace Mlt {
40 class Producer;
41 };
42
43 class ProjectItem;
44 class ProjectListView;
45 class Render;
46 class KdenliveDoc;
47 class DocClipBase;
48
49 const int NameRole = Qt::UserRole;
50 const int DurationRole = NameRole + 1;
51 const int UsageRole = NameRole + 2;
52
53 class ItemDelegate: public QItemDelegate {
54 public:
55     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
56     }
57     /*
58     static_cast<ProjectItem *>( index.internalPointer() );
59
60     void expand()
61     {
62       QWidget *w = new QWidget;
63       QVBoxLayout *layout = new QVBoxLayout;
64       layout->addWidget( new KColorButton(w));
65       w->setLayout( layout );
66       extendItem(w,
67     }
68     */
69     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
70         if (index.column() == 1) {
71             const bool hover = option.state & (QStyle::State_Selected);
72             QRect r1 = option.rect;
73             painter->save();
74             if (hover) {
75                 painter->setPen(option.palette.color(QPalette::HighlightedText));
76                 QColor backgroundColor = option.palette.color(QPalette::Highlight);
77                 painter->setBrush(QBrush(backgroundColor));
78                 painter->fillRect(r1, QBrush(backgroundColor));
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 {
98             QItemDelegate::paint(painter, option, index);
99         }
100     }
101 };
102
103 class ProjectList : public QWidget {
104     Q_OBJECT
105
106 public:
107     ProjectList(QWidget *parent = 0);
108     virtual ~ProjectList();
109
110     QDomElement producersList();
111     void setRenderer(Render *projectRender);
112     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
113     void updateAllClips();
114     QByteArray headerInfo();
115     void setHeaderInfo(const QByteArray &state);
116     void setupMenu(QMenu *addMenu, QAction *defaultAction);
117     void setupGeneratorMenu(QMenu *addMenu);
118
119 public slots:
120     void setDocument(KdenliveDoc *doc);
121     void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
122     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
123     void slotAddClip(DocClipBase *clip, bool getProperties);
124     void slotDeleteClip(const QString &clipId);
125     void slotUpdateClip(const QString &id);
126     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
127     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
128     void slotRemoveInvalidClip(const QString &id);
129     void slotSelectClip(const QString &ix);
130     void slotRemoveClip();
131     void slotAddClip(KUrl givenUrl = KUrl(), QString group = QString());
132     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
133     void slotResetProjectList();
134
135 private:
136     ProjectListView *listView;
137     KTreeWidgetSearchLine *searchView;
138     Render *m_render;
139     Timecode m_timecode;
140     double m_fps;
141     QToolBar *m_toolbar;
142     QMenu *m_menu;
143     QUndoStack *m_commandStack;
144     void selectItemById(const QString &clipId);
145     ProjectItem *getItemById(const QString &id);
146     ProjectItem *getFolderItemById(const QString &id);
147     QAction *m_editAction;
148     QAction *m_deleteAction;
149     KdenliveDoc *m_doc;
150     ProjectItem *m_selectedItem;
151     bool m_refreshed;
152     QToolButton *m_addButton;
153     QMap <QString, QDomElement> m_infoQueue;
154     void requestClipInfo(const QDomElement xml, const QString id);
155     QList <QString> m_thumbnailQueue;
156     void requestClipThumbnail(const QString &id);
157     void deleteProjectFolder(QMap <QString, QString> map);
158     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
159
160 private slots:
161     void slotEditClip();
162     void slotClipSelected();
163     void slotAddColorClip();
164     void slotAddSlideshowClip();
165     void slotAddTitleClip();
166     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
167     void slotAddFolder();
168     /** This is triggered when a clip description has been modified */
169     void slotItemEdited(QTreeWidgetItem *item, int column);
170     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
171     void slotProcessNextClipInQueue();
172     void slotProcessNextThumbnail();
173     void slotCheckForEmptyQueue();
174     void slotPauseMonitor();
175     //void slotShowMenu(const QPoint &pos);
176
177 signals:
178     void clipSelected(DocClipBase *);
179     void getFileProperties(const QDomElement&, const QString &);
180     void receivedClipDuration(const QString &, int);
181     void showClipProperties(DocClipBase *);
182     void projectModified();
183     void loadingIsOver();
184     void clipNameChanged(const QString, const QString);
185 };
186
187 #endif