1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #ifndef RENDERWIDGET_H
22 #define RENDERWIDGET_H
24 #include <kdeversion.h>
25 #if KDE_IS_VERSION(4,7,0)
26 #include <KMessageWidget>
29 #include <QPushButton>
31 #include <QStyledItemDelegate>
33 #include "definitions.h"
34 #include "ui_renderwidget_ui.h"
40 // RenderViewDelegate is used to draw the progress bars.
41 class RenderViewDelegate : public QStyledItemDelegate
45 RenderViewDelegate(QWidget *parent) : QStyledItemDelegate(parent) {}
47 void paint(QPainter *painter, const QStyleOptionViewItem &option,
48 const QModelIndex &index) const {
49 if (index.column() == 1) {
51 QStyleOptionViewItemV4 opt(option);
52 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
53 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
54 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
56 QFont font = painter->font();
58 painter->setFont(font);
59 QRect r1 = option.rect;
60 r1.adjust(0, textMargin, 0, - textMargin);
61 int mid = (int)((r1.height() / 2));
62 r1.setBottom(r1.y() + mid);
64 painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop ,index.data().toString(), &bounding);
65 r1.moveTop(r1.bottom() - textMargin);
67 painter->setFont(font);
68 painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop , index.data(Qt::UserRole).toString());
69 int progress = index.data(Qt::UserRole + 3).toInt();
70 if (progress > 0 && progress < 100) {
72 QColor color = option.palette.alternateBase().color();
73 QColor fgColor = option.palette.text().color();
75 fgColor.setAlpha(150);
76 painter->setBrush(QBrush(color));
77 painter->setPen(QPen(fgColor));
78 int width = qMin(200, r1.width() - 4);
79 QRect bgrect(r1.left() + 2, option.rect.bottom() - 6 - textMargin, width, 6);
80 painter->drawRoundedRect(bgrect, 3, 3);
81 painter->setBrush(QBrush(fgColor));
82 bgrect.adjust(2, 2, 0, -1);
83 painter->setPen(Qt::NoPen);
84 bgrect.setWidth((width - 2) * progress / 100);
85 painter->drawRect(bgrect);
87 r1.setBottom(opt.rect.bottom());
88 r1.setTop(r1.bottom() - mid);
89 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data(Qt::UserRole + 5).toString());
92 } else QStyledItemDelegate::paint(painter, option, index);
97 class RenderJobItem: public QTreeWidgetItem
100 explicit RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type = QTreeWidgetItem::Type);
101 void setStatus(int status);
103 void setMetadata(const QString &data);
104 const QString metadata() const;
112 class RenderWidget : public QDialog
117 explicit RenderWidget(const QString &projectfolder, bool enableProxy, const MltVideoProfile &profile, QWidget * parent = 0);
118 virtual ~RenderWidget();
119 void setGuides(QDomElement guidesxml, double duration);
120 void focusFirstVisibleItem(const QString &profile = QString());
121 void setProfile(const MltVideoProfile& profile);
122 void setRenderJob(const QString &dest, int progress = 0);
123 void setRenderStatus(const QString &dest, int status, const QString &error);
124 void setDocumentPath(const QString &path);
125 void reloadProfiles();
126 void setRenderProfile(const QMap <QString, QString>& props);
127 int waitingJobsCount() const;
128 QString getFreeScriptName(const KUrl &projectName = KUrl(), const QString &prefix = QString());
129 bool startWaitingRenderJobs();
130 void missingClips(bool hasMissing);
131 /** @brief Returns true if the export audio checkbox is set to automatic. */
132 bool automaticAudioExport() const;
133 /** @brief Returns true if user wants audio export. */
134 bool selectedAudioExport() const;
135 /** @brief Show / hide proxy settings. */
136 void updateProxyConfig(bool enable);
137 /** @brief Should we render using proxy clips. */
138 bool proxyRendering();
141 virtual QSize sizeHint() const;
142 virtual void keyPressEvent(QKeyEvent *e);
145 void slotExport(bool scriptExport, int zoneIn, int zoneOut, const QMap <QString, QString> &metadata, const QString &playlistPath, const QString &scriptPath, bool exportAudio);
148 void slotUpdateButtons(const KUrl &url);
149 void slotUpdateButtons();
150 void refreshView(const QString &profile = QString());
151 void refreshCategory(const QString &group = QString(), const QString &profile = QString());
153 /** @brief Updates available options when a new format has been selected. */
154 void refreshParams();
155 void slotSaveProfile();
156 void slotEditProfile();
157 void slotDeleteProfile(bool refresh = true);
158 void slotUpdateGuideBox();
159 void slotCheckStartGuidePosition();
160 void slotCheckEndGuidePosition();
161 void showInfoPanel();
162 void slotAbortCurrentJob();
163 void slotStartScript();
164 void slotDeleteScript();
165 void slotGenerateScript();
166 void parseScriptFiles();
167 void slotCheckScript();
169 void slotEditItem(QListWidgetItem *item);
170 void slotCLeanUpJobs();
172 void slotPrepareExport(bool scriptExport = false);
173 void slotPlayRendering(QTreeWidgetItem *item, int);
174 void slotStartCurrentJob();
175 void slotCopyToFavorites();
176 void slotUpdateEncodeThreads(int);
177 void slotUpdateRescaleHeight(int);
178 void slotUpdateRescaleWidth(int);
179 void slotSwitchAspectRatio();
180 /** @brief Update export audio label depending on current settings. */
181 void slotUpdateAudioLabel(int ix);
182 /** @brief Enable / disable the rescale options. */
183 void setRescaleEnabled(bool enable);
186 Ui::RenderWidget_UI m_view;
187 QString m_projectFolder;
188 MltVideoProfile m_profile;
189 RenderViewDelegate *m_scriptsDelegate;
190 RenderViewDelegate *m_jobsDelegate;
191 bool m_blockProcessing;
194 #if KDE_IS_VERSION(4,7,0)
195 KMessageWidget *m_infoMessage;
198 void parseProfiles(const QString &meta = QString(), const QString &group = QString(), const QString &profile = QString());
199 void parseFile(const QString &exportFile, bool editable);
200 void updateButtons();
201 KUrl filenameWithExtension(KUrl url, const QString &extension);
202 /** @brief Check if a job needs to be started. */
203 void checkRenderStatus();
204 void startRendering(RenderJobItem *item);
205 void saveProfile(const QDomElement &newprofile);
206 QList <QListWidgetItem *> m_renderItems;
207 QList <QListWidgetItem *> m_renderCategory;
208 void errorMessage(const QString &message);
211 void abortProcess(const QString &url);
212 void openDvdWizard(const QString &url);
213 /** Send the infos about rendering that will be saved in the document:
214 (profile destination, profile name and url of rendered file */
215 void selectedRenderProfile(const QMap <QString, QString> &renderProps);
216 void prepareRenderingData(bool scriptExport, bool zoneOnly, const QString &chapterFile);