]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Fix clip count & duration on document opening
[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     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
64         if (index.column() == 1) {
65             const bool hover = option.state & (QStyle::State_Selected);
66             QRect r1 = option.rect;
67             painter->save();
68             if (hover) {
69                 painter->setPen(option.palette.color(QPalette::HighlightedText));
70                 QColor backgroundColor = option.palette.color(QPalette::Highlight);
71                 painter->setBrush(QBrush(backgroundColor));
72                 painter->fillRect(r1, QBrush(backgroundColor));
73             }
74             QFont font = painter->font();
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->setPen(option.palette.color(QPalette::Mid));
89             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
90             painter->restore();
91         } else {
92             QItemDelegate::paint(painter, option, index);
93         }
94     }
95 };
96
97 class ProjectList : public QWidget {
98     Q_OBJECT
99
100 public:
101     ProjectList(QWidget *parent = 0);
102     virtual ~ProjectList();
103
104     QDomElement producersList();
105     void setRenderer(Render *projectRender);
106     void slotUpdateClipProperties(int id, QMap <QString, QString> properties);
107
108 public slots:
109     void setDocument(KdenliveDoc *doc);
110     void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
111     void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata);
112     void slotAddClip(DocClipBase *clip);
113     void slotDeleteClip(int clipId);
114     void slotUpdateClip(int id);
115     void slotRefreshClipThumbnail(int clipId);
116     void slotRefreshClipThumbnail(ProjectItem *item);
117
118
119 private:
120     ProjectListView *listView;
121     KTreeWidgetSearchLine *searchView;
122     Render *m_render;
123     Timecode m_timecode;
124     double m_fps;
125     QToolBar *m_toolbar;
126     QMenu *m_menu;
127     KUndoStack *m_commandStack;
128     int m_clipIdCounter;
129     void selectItemById(const int clipId);
130     ProjectItem *getItemById(int id);
131     QAction *m_editAction;
132     QAction *m_deleteAction;
133     KdenliveDoc *m_doc;
134     ItemDelegate *m_listViewDelegate;
135     ProjectItem *m_selectedItem;
136
137 private slots:
138     void slotAddClip(QUrl givenUrl = QUrl(), QString group = QString());
139     void slotRemoveClip();
140     void slotEditClip();
141     void slotClipSelected();
142     void slotAddColorClip();
143     void slotAddSlideshowClip();
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(DocClipBase *);
157     void getFileProperties(const QDomElement&, int);
158     void receivedClipDuration(int, int);
159     void showClipProperties(DocClipBase *);
160 };
161
162 #endif