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