]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Implement clipmanager
[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
29 #include <KUndoStack>
30 #include <KTreeWidgetSearchLine>
31 #include <KExtendableItemDelegate>
32
33 #include "definitions.h"
34 #include "kdenlivedoc.h"
35 #include "renderer.h"
36 #include "timecode.h"
37 #include "projectlistview.h"
38
39 class ProjectItem;
40
41   const int NameRole = Qt::UserRole;
42   const int DurationRole = NameRole + 1;
43   const int FullPathRole = NameRole + 2;
44   const int ClipTypeRole = NameRole + 3;
45
46 class ItemDelegate: public KExtendableItemDelegate
47 {
48   public:
49     ItemDelegate(QAbstractItemView* parent = 0): KExtendableItemDelegate(parent)
50     {
51     }
52 /*
53 void expand()
54 {
55   QWidget *w = new QWidget;
56   QVBoxLayout *layout = new QVBoxLayout;
57   layout->addWidget( new KColorButton(w)); 
58   w->setLayout( layout );
59   extendItem(w, 
60 }
61 */
62
63 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
64 {
65   if (index.column() == 1)
66   {
67     const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
68     QRect r1 = option.rect;
69     painter->save();
70     if (hover) {
71         painter->setPen(option.palette.color(QPalette::HighlightedText));
72         QColor backgroundColor = option.palette.color(QPalette::Highlight);
73         painter->setBrush(QBrush(backgroundColor));
74         painter->fillRect(r1, QBrush(backgroundColor));
75     }
76     QFont font = painter->font();
77     font.setPointSize(font.pointSize() - 1 );
78     font.setBold(true);
79     painter->setFont(font);
80     int mid = (int) ((r1.height() / 2 ));
81     r1.setBottom(r1.y() + mid);
82     QRect r2 = option.rect;
83     r2.setTop(r2.y() + mid);
84     painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
85     //painter->setPen(Qt::green);
86     font.setBold(false);
87     painter->setFont(font);
88     painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(DurationRole).toString());
89     painter->restore();
90   }
91   else
92   {
93     KExtendableItemDelegate::paint(painter, option, index);
94   }
95 }
96 };
97
98 class ProjectList : public QWidget
99 {
100   Q_OBJECT
101   
102   public:
103     ProjectList(QWidget *parent=0);
104     virtual ~ProjectList();
105
106     QDomElement producersList();
107     void setRenderer(Render *projectRender);
108
109     void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
110     void deleteClip(const int clipId);
111
112   public slots:
113     void setDocument(KdenliveDoc *doc);
114     void addProducer(QDomElement producer, int parentId = -1);
115     void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
116     void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
117     void slotAddClip(DocClipBase *clip);
118
119
120   private:
121     ProjectListView *listView;
122     KTreeWidgetSearchLine *searchView;
123     Render *m_render;
124     Timecode m_timecode;
125     double m_fps;
126     QToolBar *m_toolbar;
127     QMenu *m_menu;
128     KUndoStack *m_commandStack;
129     int m_clipIdCounter;
130     void selectItemById(const int clipId);
131     ProjectItem *getItemById(int id);
132     QAction *m_editAction;
133     QAction *m_deleteAction;
134     ItemDelegate *m_listViewDelegate;
135     KdenliveDoc *m_doc;
136
137   private slots:
138     void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString::null);
139     void slotRemoveClip();
140     void slotEditClip();
141     void slotClipSelected();
142     void slotAddColorClip();
143     void slotEditClip(QTreeWidgetItem *, int);
144     void slotContextMenu( const QPoint &pos, QTreeWidgetItem * );
145     void slotAddFolder();
146     /** This is triggered when a clip description has been modified */
147     void slotUpdateItemDescription(QTreeWidgetItem *item, int column);
148     //void slotShowMenu(const QPoint &pos);
149
150
151
152   signals:
153     void clipSelected(const QDomElement &);
154     void getFileProperties(const QDomElement&, int);
155     void receivedClipDuration(int, int);
156 };
157
158 #endif