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