]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Sequential rendering (one job after another)
[kdenlive] / src / renderwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2008 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 RENDERWIDGET_H
22 #define RENDERWIDGET_H
23
24 #include <QPushButton>
25 #include <QPainter>
26 #include <QItemDelegate>
27
28 #include "definitions.h"
29 #include "ui_renderwidget_ui.h"
30
31 class QDomElement;
32
33
34 // RenderViewDelegate is used to draw the progress bars.
35 class RenderViewDelegate : public QItemDelegate
36 {
37     Q_OBJECT
38 public:
39     RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
40
41     void paint(QPainter *painter, const QStyleOptionViewItem &option,
42                const QModelIndex &index) const {
43         if (index.column() == 0) {
44             QItemDelegate::paint(painter, option, index);
45             return;
46         } else if (index.column() == 1) {
47             QRect r1 = option.rect;
48             painter->save();
49             if (option.state & (QStyle::State_Selected)) {
50                 painter->setPen(option.palette.color(QPalette::HighlightedText));
51                 painter->fillRect(r1, option.palette.highlight());
52             } else painter->setPen(option.palette.color(QPalette::Text));
53             QFont font = painter->font();
54             font.setBold(true);
55             painter->setFont(font);
56             int mid = (int)((r1.height() / 2));
57             r1.setBottom(r1.y() + mid);
58             QRect r2 = option.rect;
59             r2.setTop(r2.y() + mid);
60             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
61             font.setBold(false);
62             painter->setFont(font);
63             painter->setPen(option.palette.color(QPalette::Mid));
64             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
65             painter->restore();
66             return;
67         }
68         // Set up a QStyleOptionProgressBar to precisely mimic the
69         // environment of a progress bar.
70         QStyleOptionProgressBar progressBarOption;
71         progressBarOption.state = option.state;
72         progressBarOption.direction = QApplication::layoutDirection();
73         QRect rect = option.rect;
74         if (option.state & (QStyle::State_Selected)) {
75             painter->setPen(option.palette.color(QPalette::HighlightedText));
76             painter->fillRect(rect, option.palette.highlight());
77         }
78
79         int mid = rect.height() / 2;
80         rect.setTop(rect.top() + mid / 2);
81         rect.setHeight(mid);
82         progressBarOption.rect = rect;
83         progressBarOption.fontMetrics = QApplication::fontMetrics();
84         progressBarOption.minimum = 0;
85         progressBarOption.maximum = 100;
86         progressBarOption.textAlignment = Qt::AlignCenter;
87         progressBarOption.textVisible = true;
88
89         // Set the progress and text values of the style option.
90         int progress = index.data(Qt::UserRole).toInt();
91         progressBarOption.progress = progress < 0 ? 0 : progress;
92         progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
93
94         // Draw the progress bar onto the view.
95         QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
96     }
97 };
98
99
100 // RenderScriptDelegate is used to draw the script items.
101 class RenderScriptDelegate : public QItemDelegate
102 {
103     Q_OBJECT
104 public:
105     RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
106
107     void paint(QPainter *painter, const QStyleOptionViewItem &option,
108                const QModelIndex &index) const {
109         if (index.column() == 0) {
110             QRect r1 = option.rect;
111             painter->save();
112             if (option.state & (QStyle::State_Selected)) {
113                 painter->setPen(option.palette.color(QPalette::HighlightedText));
114                 painter->fillRect(r1, option.palette.highlight());
115             } else painter->setPen(option.palette.color(QPalette::Text));
116             QFont font = painter->font();
117             font.setBold(true);
118             painter->setFont(font);
119             int mid = (int)((r1.height() / 2));
120             r1.setBottom(r1.y() + mid);
121             r1.setLeft(r1.left() + 3);
122             QRect r2 = option.rect;
123             r2.setTop(r2.y() + mid);
124             r2.setLeft(r2.left() + 3);
125             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
126             font.setBold(false);
127             painter->setFont(font);
128             painter->setPen(option.palette.color(QPalette::Mid));
129             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
130             painter->restore();
131             return;
132         } else QItemDelegate::paint(painter, option, index);
133     }
134 };
135
136 class RenderWidget : public QDialog
137 {
138     Q_OBJECT
139
140 public:
141     explicit RenderWidget(const QString &projectfolder, QWidget * parent = 0);
142     void setGuides(QDomElement guidesxml, double duration);
143     void focusFirstVisibleItem();
144     void setProfile(MltVideoProfile profile);
145     void setRenderJob(const QString &dest, int progress = 0);
146     void setRenderStatus(const QString &dest, int status, const QString &error);
147     void setDocumentPath(const QString path);
148     void reloadProfiles();
149
150 private slots:
151     void slotUpdateButtons(KUrl url);
152     void slotUpdateButtons();
153     void slotExport(bool scriptExport = false);
154     void refreshView();
155     void refreshParams();
156     void slotSaveProfile();
157     void slotEditProfile();
158     void slotDeleteProfile(bool refresh = true);
159     void slotUpdateGuideBox();
160     void slotCheckStartGuidePosition();
161     void slotCheckEndGuidePosition();
162     void showInfoPanel();
163     void slotAbortCurrentJob();
164     void slotStartScript();
165     void slotDeleteScript();
166     void slotGenerateScript();
167     void parseScriptFiles();
168     void slotCheckScript();
169     void slotCheckJob();
170     void slotEditItem(QListWidgetItem *item);
171     void slotCLeanUpJobs();
172     void slotHideLog();
173
174 private:
175     Ui::RenderWidget_UI m_view;
176     MltVideoProfile m_profile;
177     QString m_projectFolder;
178     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
179     void parseFile(QString exportFile, bool editable);
180     void updateButtons();
181     KUrl filenameWithExtension(KUrl url, QString extension);
182     void checkRenderStatus();
183
184 signals:
185     void doRender(const QStringList&, const QStringList&);
186     void abortProcess(const QString &url);
187     void openDvdWizard(const QString &url, const QString &profile);
188 };
189
190
191 #endif
192