]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Title clips now really usable (only transparency & duration change still missing)
[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
30 #include <KUndoStack>
31 #include <KTreeWidgetSearchLine>
32 #include <KUrl>
33
34 #include "definitions.h"
35 #include "timecode.h"
36
37 class ProjectItem;
38 class ProjectListView;
39 class Render;
40 class KdenliveDoc;
41 class DocClipBase;
42
43 const int NameRole = Qt::UserRole;
44 const int DurationRole = NameRole + 1;
45 const int UsageRole = NameRole + 2;
46
47 class ItemDelegate: public QItemDelegate {
48 public:
49     ItemDelegate(QAbstractItemView* parent = 0): QItemDelegate(parent) {
50     }
51     /*
52     static_cast<ProjectItem *>( index.internalPointer() );
53
54     void expand()
55     {
56       QWidget *w = new QWidget;
57       QVBoxLayout *layout = new QVBoxLayout;
58       layout->addWidget( new KColorButton(w));
59       w->setLayout( layout );
60       extendItem(w,
61     }
62     */
63
64     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
65         if (index.column() == 1) {
66             const bool hover = option.state & (QStyle::State_Selected);
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         } else {
93             QItemDelegate::paint(painter, option, index);
94         }
95     }
96 };
97
98 class ProjectList : public QWidget {
99     Q_OBJECT
100
101 public:
102     ProjectList(QWidget *parent = 0);
103     virtual ~ProjectList();
104
105     QDomElement producersList();
106     void setRenderer(Render *projectRender);
107
108     void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl(), const QString &group = QString::null, int parentId = -1);
109     void slotUpdateClipProperties(int id, QMap <QString, QString> properties);
110
111 public slots:
112     void setDocument(KdenliveDoc *doc);
113     void addProducer(QDomElement producer, int parentId = -1);
114     void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
115     void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
116     void slotAddClip(DocClipBase *clip);
117     void slotDeleteClip(int clipId);
118     void slotUpdateClip(int id);
119     void slotRefreshClipThumbnail(int clipId);
120
121
122 private:
123     ProjectListView *listView;
124     KTreeWidgetSearchLine *searchView;
125     Render *m_render;
126     Timecode m_timecode;
127     double m_fps;
128     QToolBar *m_toolbar;
129     QMenu *m_menu;
130     KUndoStack *m_commandStack;
131     int m_clipIdCounter;
132     void selectItemById(const int clipId);
133     ProjectItem *getItemById(int id);
134     QAction *m_editAction;
135     QAction *m_deleteAction;
136     KdenliveDoc *m_doc;
137     ItemDelegate *m_listViewDelegate;
138
139 private slots:
140     void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
141     void slotRemoveClip();
142     void slotClipSelected();
143     void slotAddColorClip();
144     void slotAddTitleClip();
145     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *);
146     void slotAddFolder();
147     void slotAddFolder(const QString foldername, int clipId, bool remove, bool edit);
148     /** This is triggered when a clip description has been modified */
149     void slotItemEdited(QTreeWidgetItem *item, int column);
150     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
151     //void slotShowMenu(const QPoint &pos);
152
153
154
155 signals:
156     void clipSelected(const QDomElement &);
157     void getFileProperties(const QDomElement&, int);
158     void receivedClipDuration(int, int);
159     void showClipProperties(DocClipBase *);
160 };
161
162 #endif