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