]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Fix "delete" key not working in project tree, allow deletion of several clips at...
[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
113 public slots:
114     void setDocument(KdenliveDoc *doc);
115     void slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h);
116     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
117     void slotAddClip(DocClipBase *clip, bool getProperties = true);
118     void slotDeleteClip(const QString &clipId);
119     void slotUpdateClip(const QString &id);
120     void slotRefreshClipThumbnail(const QString &clipId);
121     void slotRefreshClipThumbnail(ProjectItem *item, bool update = true);
122     void slotRemoveInvalidClip(const QString &id);
123     void slotSelectClip(const QString &ix);
124     void slotRemoveClip();
125
126 private:
127     ProjectListView *listView;
128     KTreeWidgetSearchLine *searchView;
129     Render *m_render;
130     Timecode m_timecode;
131     double m_fps;
132     QToolBar *m_toolbar;
133     QMenu *m_menu;
134     QUndoStack *m_commandStack;
135     int m_clipIdCounter;
136     void selectItemById(const QString &clipId);
137     ProjectItem *getItemById(const QString &id);
138     QAction *m_editAction;
139     QAction *m_deleteAction;
140     KdenliveDoc *m_doc;
141     ItemDelegate *m_listViewDelegate;
142     ProjectItem *m_selectedItem;
143
144 private slots:
145     void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
146     void slotEditClip();
147     void slotClipSelected();
148     void slotAddColorClip();
149     void slotAddSlideshowClip();
150     void slotAddTitleClip();
151     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
152     void slotAddFolder();
153     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit);
154     /** This is triggered when a clip description has been modified */
155     void slotItemEdited(QTreeWidgetItem *item, int column);
156     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
157     //void slotShowMenu(const QPoint &pos);
158
159 signals:
160     void clipSelected(DocClipBase *);
161     void getFileProperties(const QDomElement&, const QString &);
162     void receivedClipDuration(const QString &, int);
163     void showClipProperties(DocClipBase *);
164     void projectModified();
165 };
166
167 #endif