]> git.sesse.net Git - kdenlive/blob - src/renderwidget.h
Cleanup UI for render job list
[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 <kdeversion.h>
25 #if KDE_IS_VERSION(4,7,0)
26 #include <KMessageWidget>
27 #endif
28
29 #include <QPushButton>
30 #include <QPainter>
31 #include <QStyledItemDelegate>
32
33 #include "definitions.h"
34 #include "ui_renderwidget_ui.h"
35
36 class QDomElement;
37
38
39 // RenderViewDelegate is used to draw the progress bars.
40 class RenderViewDelegate : public QStyledItemDelegate
41 {
42     Q_OBJECT
43 public:
44     RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
45
46     void paint(QPainter *painter, const QStyleOptionViewItem &option,
47                const QModelIndex &index) const {
48         if (index.column() == 1) {
49             painter->save();
50             QStyleOptionViewItemV4 opt(option);
51             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
52             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
53             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
54
55             QFont font = painter->font();
56             font.setBold(true);
57             painter->setFont(font);
58             QRect r1 = option.rect;
59             r1.adjust(0, textMargin, 0, - textMargin);
60             int mid = (int)((r1.height() / 2));
61             r1.setBottom(r1.y() + mid);
62             QRect bounding;
63             painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop ,index.data().toString(), &bounding);
64             r1.moveTop(r1.bottom() - textMargin);
65             font.setBold(false);
66             painter->setFont(font);
67             painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop , index.data(Qt::UserRole).toString());
68             int progress = index.data(Qt::UserRole + 3).toInt();
69             if (progress > 0 && progress < 100) {
70                 QColor color = option.palette.alternateBase().color();
71                 QColor fgColor = option.palette.text().color();
72                 color.setAlpha(150);
73                 fgColor.setAlpha(150);
74                 painter->setBrush(QBrush(color));
75                 painter->setPen(QPen(fgColor));
76                 int width = qMin(200, r1.width() - 4);
77                 QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
78                 painter->drawRect(bgrect);
79                 painter->setBrush(QBrush(fgColor));
80                 bgrect.adjust(2, 2, 0, -1);
81                 painter->setPen(Qt::NoPen);
82                 bgrect.setWidth((width - 2) * progress / 100);
83                 painter->drawRect(bgrect);
84             } else {
85                 r1.setBottom(opt.rect.bottom());
86                 r1.setTop(r1.bottom() - mid);
87                 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data(Qt::UserRole + 5).toString());
88             }
89             painter->restore();
90         } else if (index.column() == 2) {
91             // Set up a QStyleOptionProgressBar to precisely mimic the
92             // environment of a progress bar.
93             QStyleOptionViewItemV4 opt(option);
94             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
95             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
96
97             QStyleOptionProgressBar progressBarOption;
98             progressBarOption.state = option.state;
99             progressBarOption.direction = QApplication::layoutDirection();
100             QRect rect = option.rect;
101             int mid = rect.height() / 2;
102             rect.setTop(rect.top() + mid / 2);
103             rect.setHeight(mid);
104             progressBarOption.rect = rect;
105             progressBarOption.fontMetrics = QApplication::fontMetrics();
106             progressBarOption.minimum = 0;
107             progressBarOption.maximum = 100;
108             progressBarOption.textAlignment = Qt::AlignCenter;
109             progressBarOption.textVisible = true;
110
111             // Set the progress and text values of the style option.
112             int progress = index.data(Qt::UserRole).toInt();
113             progressBarOption.progress = progress < 0 ? 0 : progress;
114             progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
115
116             // Draw the progress bar onto the view.
117             QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
118         } else QStyledItemDelegate::paint(painter, option, index);
119     }
120 };
121
122
123 class RenderJobItem: public QTreeWidgetItem
124 {
125 public:
126     explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
127     void setStatus(int status);
128     int status() const;
129     void setMetadata(const QString &data);
130     const QString metadata() const;
131     void render();
132
133 private:
134     int m_status;
135     QString m_data;    
136 };
137
138 class RenderWidget : public QDialog
139 {
140     Q_OBJECT
141
142 public:
143     explicit RenderWidget(const QString &projectfolder, bool enableProxy, MltVideoProfile profile, QWidget * parent = 0);
144     virtual ~RenderWidget();
145     void setGuides(QDomElement guidesxml, double duration);
146     void focusFirstVisibleItem();
147     void setProfile(MltVideoProfile profile);
148     void setRenderJob(const QString &dest, int progress = 0);
149     void setRenderStatus(const QString &dest, int status, const QString &error);
150     void setDocumentPath(const QString &path);
151     void reloadProfiles();
152     void setRenderProfile(QMap <QString, QString> props);
153     int waitingJobsCount() const;
154     QString getFreeScriptName(const QString &prefix = QString());
155     bool startWaitingRenderJobs();
156     void missingClips(bool hasMissing);
157     /** @brief Returns true if the export audio checkbox is set to automatic. */
158     bool automaticAudioExport() const;
159     /** @brief Returns true if user wants audio export. */
160     bool selectedAudioExport() const;
161     /** @brief Show / hide proxy settings. */
162     void updateProxyConfig(bool enable);
163     /** @brief Should we render using proxy clips. */
164     bool proxyRendering();
165
166 protected:
167     virtual QSize sizeHint() const;
168
169 public slots:
170     void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
171
172 private slots:
173     void slotUpdateButtons(KUrl url);
174     void slotUpdateButtons();
175     void refreshView();
176     void refreshCategory();
177
178     /** @brief Updates available options when a new format has been selected. */
179     void refreshParams();
180     void slotSaveProfile();
181     void slotEditProfile();
182     void slotDeleteProfile(bool refresh = true);
183     void slotUpdateGuideBox();
184     void slotCheckStartGuidePosition();
185     void slotCheckEndGuidePosition();
186     void showInfoPanel();
187     void slotAbortCurrentJob();
188     void slotStartScript();
189     void slotDeleteScript();
190     void slotGenerateScript();
191     void parseScriptFiles();
192     void slotCheckScript();
193     void slotCheckJob();
194     void slotEditItem(QListWidgetItem *item);
195     void slotCLeanUpJobs();
196     void slotHideLog();
197     void slotPrepareExport(bool scriptExport = false);
198     void slotPlayRendering(QTreeWidgetItem *item, int);
199     void slotStartCurrentJob();
200     void slotCopyToFavorites();
201     void slotUpdateEncodeThreads(int);
202     void slotUpdateRescaleHeight(int);
203     void slotUpdateRescaleWidth(int);
204     void slotSwitchAspectRatio();
205     /** @brief Update export audio label depending on current settings. */
206     void slotUpdateAudioLabel(int ix);
207     /** @brief Enable / disable the rescale options. */
208     void setRescaleEnabled(bool enable);
209
210 private:
211     Ui::RenderWidget_UI m_view;
212     QString m_projectFolder;
213     MltVideoProfile m_profile;
214     RenderViewDelegate *m_scriptsDelegate;
215     RenderViewDelegate *m_jobsDelegate;
216     bool m_blockProcessing;
217     QString m_renderer;
218
219 #if KDE_IS_VERSION(4,7,0)
220     KMessageWidget *m_infoMessage;
221 #endif
222
223     void parseProfiles(QString meta = QString(), QString group = QString(), QString profile = QString());
224     void parseFile(QString exportFile, bool editable);
225     void updateButtons();
226     KUrl filenameWithExtension(KUrl url, QString extension);
227     /** @brief Check if a job needs to be started. */
228     void checkRenderStatus();
229     void startRendering(RenderJobItem *item);
230     void saveProfile(QDomElement newprofile);
231     QList <QListWidgetItem *> m_renderItems;
232     QList <QListWidgetItem *> m_renderCategory;
233     void errorMessage(const QString &message);
234
235 signals:
236     void abortProcess(const QString &url);
237     void openDvdWizard(const QString &url, const QString &profile);
238     /** Send the infos about rendering that will be saved in the document:
239     (profile destination, profile name and url of rendered file */
240     void selectedRenderProfile(QMap <QString, QString> renderProps);
241     void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);
242     void shutdown();
243 };
244
245
246 #endif
247