]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Rewrote & cleanup(not finished) the handling of renderings jobs creation in order...
[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     void setRenderProfile(const QString &dest, const QString &name);
150     int waitingJobsCount() const;
151     QMap <QStringList, QStringList> waitingJobsData();
152     QString getFreeScriptName();
153
154 public slots:
155     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath);
156
157 private slots:
158     void slotUpdateButtons(KUrl url);
159     void slotUpdateButtons();
160     void refreshView();
161     void refreshParams();
162     void slotSaveProfile();
163     void slotEditProfile();
164     void slotDeleteProfile(bool refresh = true);
165     void slotUpdateGuideBox();
166     void slotCheckStartGuidePosition();
167     void slotCheckEndGuidePosition();
168     void showInfoPanel();
169     void slotAbortCurrentJob();
170     void slotStartScript();
171     void slotDeleteScript();
172     void slotGenerateScript();
173     void parseScriptFiles();
174     void slotCheckScript();
175     void slotCheckJob();
176     void slotEditItem(QListWidgetItem *item);
177     void slotCLeanUpJobs();
178     void slotHideLog();
179     void slotPrepareExport(bool scriptExport = false);
180     void slotPlayRendering(QTreeWidgetItem *item, int);
181
182 private:
183     Ui::RenderWidget_UI m_view;
184     MltVideoProfile m_profile;
185     QString m_projectFolder;
186     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
187     void parseFile(QString exportFile, bool editable);
188     void updateButtons();
189     KUrl filenameWithExtension(KUrl url, QString extension);
190     void checkRenderStatus();
191
192 signals:
193     void doRender(const QStringList&, const QStringList&);
194     void abortProcess(const QString &url);
195     void openDvdWizard(const QString &url, const QString &profile);
196     void selectedRenderProfile(const QString &category, const QString &name);
197     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
198 };
199
200
201 #endif
202