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