]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Cleanup some mess introduced by last commit, looking for missing slideshow clips...
[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 <QTreeWidget>
27 #include <QPainter>
28 #include <QItemDelegate>
29 #include <QUndoStack>
30
31
32 #include <KTreeWidgetSearchLine>
33 #include <KUrl>
34
35 #include "definitions.h"
36 #include "timecode.h"
37
38 namespace Mlt {
39 class Producer;
40 };
41
42 class ProjectItem;
43 class ProjectListView;
44 class Render;
45 class KdenliveDoc;
46 class DocClipBase;
47
48 const int NameRole = Qt::UserRole;
49 const int DurationRole = NameRole + 1;
50 const int UsageRole = NameRole + 2;
51
52 class ItemDelegate: public QItemDelegate {
53 public:
54     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
55     }
56     /*
57     static_cast<ProjectItem *>( index.internalPointer() );
58
59     void expand()
60     {
61       QWidget *w = new QWidget;
62       QVBoxLayout *layout = new QVBoxLayout;
63       layout->addWidget( new KColorButton(w));
64       w->setLayout( layout );
65       extendItem(w,
66     }
67     */
68     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
69         if (index.column() == 1) {
70             const bool hover = option.state & (QStyle::State_Selected);
71             QRect r1 = option.rect;
72             painter->save();
73             if (hover) {
74                 painter->setPen(option.palette.color(QPalette::HighlightedText));
75                 QColor backgroundColor = option.palette.color(QPalette::Highlight);
76                 painter->setBrush(QBrush(backgroundColor));
77                 painter->fillRect(r1, QBrush(backgroundColor));
78             }
79             QFont font = painter->font();
80             font.setBold(true);
81             painter->setFont(font);
82             int mid = (int)((r1.height() / 2));
83             r1.setBottom(r1.y() + mid);
84             QRect r2 = option.rect;
85             r2.setTop(r2.y() + mid);
86             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
87             //painter->setPen(Qt::green);
88             font.setBold(false);
89             painter->setFont(font);
90             QString subText = index.data(DurationRole).toString();
91             int usage = index.data(UsageRole).toInt();
92             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
93             painter->setPen(option.palette.color(QPalette::Mid));
94             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
95             painter->restore();
96         } else {
97             QItemDelegate::paint(painter, option, index);
98         }
99     }
100 };
101
102 class ProjectList : public QWidget {
103     Q_OBJECT
104
105 public:
106     ProjectList(QWidget *parent = 0);
107     virtual ~ProjectList();
108
109     QDomElement producersList();
110     void setRenderer(Render *projectRender);
111     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
112     void updateAllClips();
113     QByteArray headerInfo();
114     void setHeaderInfo(const QByteArray &state);
115
116 public slots:
117     void setDocument(KdenliveDoc *doc);
118     void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
119     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
120     void slotAddClip(DocClipBase *clip, bool getProperties = true);
121     void slotDeleteClip(const QString &clipId);
122     void slotUpdateClip(const QString &id);
123     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
124     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
125     void slotRemoveInvalidClip(const QString &id);
126     void slotSelectClip(const QString &ix);
127     void slotRemoveClip();
128
129 private:
130     ProjectListView *listView;
131     KTreeWidgetSearchLine *searchView;
132     Render *m_render;
133     Timecode m_timecode;
134     double m_fps;
135     QToolBar *m_toolbar;
136     QMenu *m_menu;
137     QUndoStack *m_commandStack;
138     int m_clipIdCounter;
139     void selectItemById(const QString &clipId);
140     ProjectItem *getItemById(const QString &id);
141     QAction *m_editAction;
142     QAction *m_deleteAction;
143     KdenliveDoc *m_doc;
144     ItemDelegate *m_listViewDelegate;
145     ProjectItem *m_selectedItem;
146     bool m_refreshed;
147     QMap <QString, QDomElement> m_infoQueue;
148     void requestClipInfo(const QDomElement xml, const QString id);
149     QList <QString> m_thumbnailQueue;
150     void requestClipThumbnail(const QString &id);
151
152 private slots:
153     void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
154     void slotEditClip();
155     void slotClipSelected();
156     void slotAddColorClip();
157     void slotAddSlideshowClip();
158     void slotAddTitleClip();
159     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
160     void slotAddFolder();
161     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit);
162     /** This is triggered when a clip description has been modified */
163     void slotItemEdited(QTreeWidgetItem *item, int column);
164     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
165     void slotProcessNextClipInQueue();
166     void slotProcessNextThumbnail();
167     void slotCheckForEmptyQueue();
168     void slotPauseMonitor();
169     //void slotShowMenu(const QPoint &pos);
170
171 signals:
172     void clipSelected(DocClipBase *);
173     void getFileProperties(const QDomElement&, const QString &);
174     void receivedClipDuration(const QString &, int);
175     void showClipProperties(DocClipBase *);
176     void projectModified();
177     void loadingIsOver();
178 };
179
180 #endif