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